source: palm/trunk/SOURCE/check_open.f90 @ 1784

Last change on this file since 1784 was 1784, checked in by raasch, 8 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 43.5 KB
RevLine 
[1682]1!> @file check_open.f90
[1036]2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
[1310]16! Copyright 1997-2014 Leibniz Universitaet Hannover
[1036]17!--------------------------------------------------------------------------------!
18!
[247]19! Current revisions:
[1]20! -----------------
[1780]21!
[1784]22!
[1321]23! Former revisions:
24! -----------------
25! $Id: check_open.f90 1784 2016-03-06 19:14:40Z raasch $
26!
[1784]27! 1783 2016-03-06 18:36:17Z raasch
28! name change of netcdf routines and module + related changes
29!
[1780]30! 1779 2016-03-03 08:01:28Z raasch
31! coupling_char is trimmed at every place it occurs, because it can have
32! different length now
33!
[1746]34! 1745 2016-02-05 13:06:51Z gronemeier
35! Bugfix: added MPI barrier after deleting existing non-extendable file by PE0
36!
[1683]37! 1682 2015-10-07 23:56:08Z knoop
38! Code annotations made doxygen readable
39!
[1552]40! 1551 2015-03-03 14:18:16Z maronga
41! Removed redundant output for combine_plot_fields
42!
[1469]43! 1468 2014-09-24 14:06:57Z maronga
44! Adapted for use on up to 6-digit processor cores
45! Added file unit 117 (PROGRESS)
46!
[1360]47! 1359 2014-04-11 17:15:14Z hoffmann
48! Format of particle exchange statistics extended to reasonable numbers of     
49! particles.
50!
[1354]51! 1353 2014-04-08 15:21:23Z heinze
52! REAL constants provided with KIND-attribute,
53! declaration for unused variables xkoor, ykoor, zkoor removed
54!
[1329]55! 1327 2014-03-21 11:00:16Z raasch
56! parts concerning iso2d and avs output removed
57!
[1321]58! 1320 2014-03-20 08:40:49Z raasch
[1320]59! ONLY-attribute added to USE-statements,
60! kind-parameters added to all INTEGER and REAL declaration statements,
61! kinds are defined in new module kinds,
62! old module precision_kind is removed,
63! revision history before 2012 removed,
64! comment fields (!:) to be used for variable explanations added to
65! all variable declaration statements
[1]66!
[1107]67! 1106 2013-03-04 05:31:38Z raasch
68! array_kind renamed precision_kind
69!
[1093]70! 1092 2013-02-02 11:24:22Z raasch
71! unused variables removed
72!
[1037]73! 1036 2012-10-22 13:43:42Z raasch
74! code put under GPL (PALM 3.9)
75!
[1035]76! 1031 2012-10-19 14:35:30Z raasch
77! netCDF4 without parallel file support implemented,
78! opening of netCDF files are done by new routines create_netcdf_file and
79! open_write_netcdf_file
80!
[965]81! 964 2012-07-26 09:14:24Z raasch
82! old profil-units (40:49) removed,
83! append feature removed from unit 14
84!
[850]85! 849 2012-03-15 10:35:09Z raasch
86! comment changed
87!
[810]88! 809 2012-01-30 13:32:58Z maronga
89! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives
90!
[808]91! 807 2012-01-25 11:53:51Z maronga
92! New cpp directive "__check" implemented which is used by check_namelist_files
93!
[1]94! Revision 1.1  1997/08/11 06:10:55  raasch
95! Initial revision
96!
97!
98! Description:
99! ------------
[1682]100!> Check if file unit is open. If not, open file and, if necessary, write a
101!> header or start other initializing actions, respectively.
[1]102!------------------------------------------------------------------------------!
[1682]103SUBROUTINE check_open( file_id )
104 
[1]105
[1320]106    USE arrays_3d,                                                             &
107        ONLY:  zu
108
109    USE control_parameters,                                                    &
[1327]110        ONLY:  avs_data_file, coupling_char, data_output_2d_on_each_pe, host,  &
[1783]111               max_masks, message_string, mid, nz_do3d, openfile,              &
[1320]112               return_addres, return_username, run_description_header, runnr
113
114    USE grid_variables,                                                        &
115        ONLY:  dx, dy
116
117    USE indices,                                                               &
[1551]118        ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nyng, nys, nysg, nz, nzb, nzt 
[1320]119
120    USE kinds
121
[1783]122#if defined( __netcdf )
123    USE NETCDF
124#endif
[1320]125
[1783]126    USE netcdf_interface,                                                      &
127        ONLY:  id_set_mask, id_set_pr, id_set_prt, id_set_pts, id_set_sp,      &
128               id_set_ts, id_set_xy, id_set_xz, id_set_yz, id_set_3d, nc_stat, &
129               netcdf_create_file, netcdf_data_format, netcdf_define_header,   &
130               netcdf_handle_error, netcdf_open_write_file
131
[1320]132    USE particle_attributes,                                                   &
133        ONLY:  max_number_of_particle_groups, number_of_particle_groups,       &
134               particle_groups
135
[1]136    USE pegrid
137
[1320]138    USE profil_parameter,                                                      &
139        ONLY:  cross_ts_numbers, cross_ts_number_count
140
141    USE statistics,                                                            &
142        ONLY:  region, statistic_regions
143
144
[1]145    IMPLICIT NONE
146
[1682]147    CHARACTER (LEN=2)   ::  mask_char               !<
148    CHARACTER (LEN=2)   ::  suffix                  !<
149    CHARACTER (LEN=20)  ::  xtext = 'time in s'     !<
150    CHARACTER (LEN=30)  ::  filename                !<
151    CHARACTER (LEN=40)  ::  avs_coor_file           !<
152    CHARACTER (LEN=40)  ::  avs_coor_file_localname !<
153    CHARACTER (LEN=40)  ::  avs_data_file_localname !<
154    CHARACTER (LEN=80)  ::  rtext                   !<
155    CHARACTER (LEN=100) ::  avs_coor_file_catalog   !<
156    CHARACTER (LEN=100) ::  avs_data_file_catalog   !<
157    CHARACTER (LEN=100) ::  batch_scp               !<
158    CHARACTER (LEN=100) ::  line                    !<
159    CHARACTER (LEN=400) ::  command                 !<
[1]160
[1682]161    INTEGER(iwp) ::  av          !<
162    INTEGER(iwp) ::  numline = 1 !<
163    INTEGER(iwp) ::  cranz       !<
164    INTEGER(iwp) ::  file_id     !<
165    INTEGER(iwp) ::  i           !<
166    INTEGER(iwp) ::  iaddres     !<
167    INTEGER(iwp) ::  iusern      !<
168    INTEGER(iwp) ::  j           !<
169    INTEGER(iwp) ::  k           !<
170    INTEGER(iwp) ::  legpos = 1  !<
171    INTEGER(iwp) ::  timodex = 1 !<
[1320]172   
[1682]173    INTEGER(iwp), DIMENSION(10) ::  klist !<
[1]174
[1682]175    LOGICAL ::  avs_coor_file_found = .FALSE. !<
176    LOGICAL ::  avs_data_file_found = .FALSE. !<
177    LOGICAL ::  datleg = .TRUE.               !<
178    LOGICAL ::  get_filenames                 !<
179    LOGICAL ::  grid = .TRUE.                 !<
180    LOGICAL ::  netcdf_extend                 !<
181    LOGICAL ::  rand = .TRUE.                 !<
182    LOGICAL ::  swap = .TRUE.                 !<
183    LOGICAL ::  twoxa = .TRUE.                !<
184    LOGICAL ::  twoya = .TRUE.                !<
[1]185
[1682]186    REAL(wp) ::  ansx = -999.999_wp !<
187    REAL(wp) ::  ansy = -999.999_wp !<
188    REAL(wp) ::  gwid = 0.1_wp      !<
189    REAL(wp) ::  rlegfak = 1.5_wp   !<
190    REAL(wp) ::  sizex = 250.0_wp   !<
191    REAL(wp) ::  sizey = 40.0_wp    !<
192    REAL(wp) ::  texfac = 1.5_wp    !<
[1]193
[1682]194    REAL(wp), DIMENSION(:), ALLOCATABLE      ::  eta !<
195    REAL(wp), DIMENSION(:), ALLOCATABLE      ::  ho  !<
196    REAL(wp), DIMENSION(:), ALLOCATABLE      ::  hu  !<
[1353]197 
[1]198
199
[1320]200    NAMELIST /RAHMEN/  numline, cranz, datleg, rtext, swap
201    NAMELIST /CROSS/   ansx, ansy, grid, gwid, klist, legpos,                  &
202                       rand, rlegfak, sizex, sizey, texfac,                    &
[1]203                       timodex, twoxa, twoya, xtext
204                       
205
206!
207!-- Immediate return if file already open
208    IF ( openfile(file_id)%opened )  RETURN
209
[809]210#if ! defined ( __check )
[1]211!
212!-- Only certain files are allowed to be re-opened
213!-- NOTE: some of the other files perhaps also could be re-opened, but it
214!--       has not been checked so far, if it works!
215    IF ( openfile(file_id)%opened_before )  THEN
216       SELECT CASE ( file_id )
[1468]217          CASE ( 13, 14, 21, 22, 23, 80:85, 117 )
[1]218             IF ( file_id == 14 .AND. openfile(file_id)%opened_before )  THEN
[1320]219                message_string = 're-open of unit ' //                         &
[274]220                                 '14 is not verified. Please check results!'
[247]221                CALL message( 'check_open', 'PA0165', 0, 1, 0, 6, 0 )       
[1]222             ENDIF
[143]223
[1]224          CASE DEFAULT
[1320]225             WRITE( message_string, * ) 're-opening of file-id ', file_id,     &
[274]226                                        ' is not allowed'
[247]227             CALL message( 'check_open', 'PA0166', 0, 1, 0, 6, 0 )   
228               
[1]229             RETURN
[143]230
[1]231       END SELECT
232    ENDIF
[807]233#endif
[1]234
235!
236!-- Check if file may be opened on the relevant PE
237    SELECT CASE ( file_id )
238
[1468]239       CASE ( 15, 16, 17, 18, 19, 50:59, 81:84, 104:105, 107, 109, 117 )
[410]240             
[493]241          IF ( myid /= 0 )  THEN
[1320]242             WRITE( message_string, * ) 'opening file-id ',file_id,            &
[493]243                                        ' not allowed for PE ',myid
244             CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
245          ENDIF
246
[564]247       CASE ( 101:103, 106, 111:113, 116, 201:200+2*max_masks )
[493]248
[1031]249          IF ( netcdf_data_format < 5 )  THEN
[247]250         
[410]251             IF ( myid /= 0 )  THEN
[1320]252                WRITE( message_string, * ) 'opening file-id ',file_id,         &
[410]253                                           ' not allowed for PE ',myid
254                CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
255             ENDIF
256             
[493]257          ENDIF
[1]258
259       CASE ( 21, 22, 23 )
260
261          IF ( .NOT.  data_output_2d_on_each_pe )  THEN
262             IF ( myid /= 0 )  THEN
[1320]263                WRITE( message_string, * ) 'opening file-id ',file_id,         &
[247]264                                           ' not allowed for PE ',myid
[277]265                CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
[247]266             END IF
[1]267          ENDIF
268
[1327]269       CASE ( 27, 28, 29, 31, 33, 71:73, 90:99 )
[1]270
271!
272!--       File-ids that are used temporarily in other routines
[1320]273          WRITE( message_string, * ) 'opening file-id ',file_id,               &
[274]274                                    ' is not allowed since it is used otherwise'
[247]275          CALL message( 'check_open', 'PA0168', 0, 1, 0, 6, 0 ) 
276         
[1]277    END SELECT
278
279!
280!-- Open relevant files
281    SELECT CASE ( file_id )
282
283       CASE ( 11 )
284
[807]285#if defined ( __check )
286!
287!--       In case of a prior parameter file check, the p3d data is stored in
288!--       PARIN, while the p3df is stored in PARINF. This only applies to
289!--       check_namelist_files!
290          IF ( check_restart == 2 ) THEN
[1779]291             OPEN ( 11, FILE='PARINF'//TRIM( coupling_char ),                  &
292                        FORM='FORMATTED', STATUS='OLD' )
[807]293          ELSE
[1779]294             OPEN ( 11, FILE='PARIN'//TRIM( coupling_char ), FORM='FORMATTED', &
[807]295                        STATUS='OLD' )
296          END IF
297#else
298
[1779]299          OPEN ( 11, FILE='PARIN'//TRIM( coupling_char ), FORM='FORMATTED',    &
[102]300                     STATUS='OLD' )
[807]301#endif
[1]302
303       CASE ( 13 )
304
305          IF ( myid_char == '' )  THEN
[1779]306             OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//myid_char,        &
[102]307                        FORM='UNFORMATTED', STATUS='OLD' )
[1]308          ELSE
[143]309!
[1468]310!--          First opening of unit 13 openes file _000000 on all PEs because
311!--          only this file contains the global variables
[143]312             IF ( .NOT. openfile(file_id)%opened_before )  THEN
[1779]313                OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//'/_000000',    &
[143]314                           FORM='UNFORMATTED', STATUS='OLD' )
315             ELSE
[1779]316                OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//'/'//          &
317                           myid_char, FORM='UNFORMATTED', STATUS='OLD' )
[143]318             ENDIF
[1]319          ENDIF
320
321       CASE ( 14 )
322
323          IF ( myid_char == '' )  THEN
[1779]324             OPEN ( 14, FILE='BINOUT'//TRIM( coupling_char )//myid_char,       &
[102]325                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]326          ELSE
327             IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
[1779]328                CALL local_system( 'mkdir  BINOUT' // TRIM( coupling_char ) )
[1]329             ENDIF
[809]330#if defined( __parallel ) && ! defined ( __check )
[1]331!
332!--          Set a barrier in order to allow that all other processors in the
333!--          directory created by PE0 can open their file
334             CALL MPI_BARRIER( comm2d, ierr )
335#endif
[1320]336             OPEN ( 14, FILE='BINOUT'//TRIM(coupling_char)//'/'//myid_char,    &
[887]337                        FORM='UNFORMATTED' )
[1]338          ENDIF
339
340       CASE ( 15 )
341
[1779]342          OPEN ( 15, FILE='RUN_CONTROL'//TRIM( coupling_char ),                &
343                     FORM='FORMATTED' )
[1]344
345       CASE ( 16 )
346
[1779]347          OPEN ( 16, FILE='LIST_PROFIL'//TRIM( coupling_char ),                &
348                     FORM='FORMATTED' )
[1]349
350       CASE ( 17 )
351
[1779]352          OPEN ( 17, FILE='LIST_PROFIL_1D'//TRIM( coupling_char ),             &
353                     FORM='FORMATTED' )
[1]354
355       CASE ( 18 )
356
[1779]357          OPEN ( 18, FILE='CPU_MEASURES'//TRIM( coupling_char ),               &
358                     FORM='FORMATTED' )
[1]359
360       CASE ( 19 )
361
[1779]362          OPEN ( 19, FILE='HEADER'//TRIM( coupling_char ), FORM='FORMATTED' )
[1]363
364       CASE ( 20 )
365
366          IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
[1779]367             CALL local_system( 'mkdir  DATA_LOG' // TRIM( coupling_char ) )
[1]368          ENDIF
369          IF ( myid_char == '' )  THEN
[1779]370             OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/_000000',    &
[102]371                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]372          ELSE
[809]373#if defined( __parallel ) && ! defined ( __check )
[1]374!
375!--          Set a barrier in order to allow that all other processors in the
376!--          directory created by PE0 can open their file
377             CALL MPI_BARRIER( comm2d, ierr )
378#endif
[1779]379             OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/'//          &
380                        myid_char, FORM='UNFORMATTED', POSITION='APPEND' )
[1]381          ENDIF
382
383       CASE ( 21 )
384
385          IF ( data_output_2d_on_each_pe )  THEN
[1320]386             OPEN ( 21, FILE='PLOT2D_XY'//TRIM( coupling_char )//myid_char,    &
[102]387                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]388          ELSE
[1779]389             OPEN ( 21, FILE='PLOT2D_XY'//TRIM( coupling_char ),                       &
[102]390                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]391          ENDIF
392
393          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
394!
395!--          Output for combine_plot_fields
396             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
[667]397                WRITE (21)  -nbgp, nx+nbgp, -nbgp, ny+nbgp    ! total array size
[1]398                WRITE (21)   0, nx+1,  0, ny+1    ! output part
399             ENDIF
400!
401!--          Determine and write ISO2D coordiante header
402             ALLOCATE( eta(0:ny+1), ho(0:nx+1), hu(0:nx+1) )
[1353]403             hu = 0.0_wp
[1]404             ho = (ny+1) * dy
405             DO  i = 1, ny
[1353]406                eta(i) = REAL( i ) / ( ny + 1.0_wp )
[1]407             ENDDO
[1353]408             eta(0)    = 0.0_wp
409             eta(ny+1) = 1.0_wp
[1]410
411             WRITE (21)  dx,eta,hu,ho
412             DEALLOCATE( eta, ho, hu )
413
414          ENDIF
415
416       CASE ( 22 )
417
418          IF ( data_output_2d_on_each_pe )  THEN
[1320]419             OPEN ( 22, FILE='PLOT2D_XZ'//TRIM( coupling_char )//myid_char,    &
[102]420                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]421          ELSE
[1779]422             OPEN ( 22, FILE='PLOT2D_XZ'//TRIM( coupling_char ),               &
423                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]424          ENDIF
425
426          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
427!
428!--          Output for combine_plot_fields
429             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
[667]430                WRITE (22)  -nbgp, nx+nbgp, 0, nz+1    ! total array size
[1]431                WRITE (22)   0, nx+1, 0, nz+1    ! output part
432             ENDIF
433!
[1327]434!--          Determine and write ISO2D coordinate header
[1]435             ALLOCATE( eta(0:nz+1), ho(0:nx+1), hu(0:nx+1) )
[1353]436             hu = 0.0_wp
[1]437             ho = zu(nz+1)
438             DO  i = 1, nz
439                eta(i) = REAL( zu(i) ) / zu(nz+1)
440             ENDDO
[1353]441             eta(0)    = 0.0_wp
442             eta(nz+1) = 1.0_wp
[1]443
444             WRITE (22)  dx,eta,hu,ho
445             DEALLOCATE( eta, ho, hu )
446
447          ENDIF
448
449       CASE ( 23 )
450
451          IF ( data_output_2d_on_each_pe )  THEN
[1320]452             OPEN ( 23, FILE='PLOT2D_YZ'//TRIM( coupling_char )//myid_char,    &
[102]453                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]454          ELSE
[1779]455             OPEN ( 23, FILE='PLOT2D_YZ'//TRIM( coupling_char ),               &
456                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]457          ENDIF
458
459          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
460!
461!--          Output for combine_plot_fields
462             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
[667]463                WRITE (23)  -nbgp, ny+nbgp, 0, nz+1    ! total array size
[1]464                WRITE (23)   0, ny+1, 0, nz+1    ! output part
465             ENDIF
466!
467!--          Determine and write ISO2D coordiante header
468             ALLOCATE( eta(0:nz+1), ho(0:ny+1), hu(0:ny+1) )
[1353]469             hu = 0.0_wp
[1]470             ho = zu(nz+1)
471             DO  i = 1, nz
472                eta(i) = REAL( zu(i) ) / zu(nz+1)
473             ENDDO
[1353]474             eta(0)    = 0.0_wp
475             eta(nz+1) = 1.0_wp
[1]476
477             WRITE (23)  dx,eta,hu,ho
478             DEALLOCATE( eta, ho, hu )
479
480          ENDIF
481
482       CASE ( 30 )
483
[1320]484          OPEN ( 30, FILE='PLOT3D_DATA'//TRIM( coupling_char )//myid_char,     &
[102]485                     FORM='UNFORMATTED' )
[1]486!
487!--       Write coordinate file for AVS
488          IF ( myid == 0 )  THEN
489#if defined( __parallel )
490!
491!--          Specifications for combine_plot_fields
[1551]492             WRITE ( 30 )  -nbgp,nx+nbgp,-nbgp,ny+nbgp
[1327]493             WRITE ( 30 )  0,nx+1,0,ny+1,0,nz_do3d
[1]494#endif
495          ENDIF
496
497       CASE ( 50:59 )
498
499          IF ( statistic_regions == 0  .AND.  file_id == 50 )  THEN
500             suffix = ''
501          ELSE
502             WRITE ( suffix, '(''_'',I1)' )  file_id - 50
503          ENDIF
[1320]504          OPEN ( file_id, FILE='PLOTTS_DATA'//TRIM( coupling_char )//          &
505                               TRIM( suffix ),                                 &
[102]506                          FORM='FORMATTED', RECL=496 )
[1]507!
508!--       Write PROFIL parameter file for output of time series
509!--       NOTE: To be on the safe side, this output is done at the beginning of
510!--             the model run (in case of collapse) and it is repeated in
511!--             close_file, then, however, with value ranges for the coordinate
512!--             systems
513!
514!--       Firstly determine the number of the coordinate systems to be drawn
515          cranz = 0
516          DO  j = 1, 10
517             IF ( cross_ts_number_count(j) /= 0 )  cranz = cranz+1
518          ENDDO
[1320]519          rtext = '\1.0 ' // TRIM( run_description_header ) // '    ' //       &
[1]520                  TRIM( region( file_id - 50 ) )
521!
522!--       Write RAHMEN parameter
[1320]523          OPEN ( 90, FILE='PLOTTS_PAR'//TRIM( coupling_char )//                &
524                           TRIM( suffix ),                                     &
[102]525                     FORM='FORMATTED', DELIM='APOSTROPHE' )
[1]526          WRITE ( 90, RAHMEN )
527!
528!--       Determine and write CROSS parameters for the individual coordinate
529!--       systems
530          DO  j = 1, 10
531             k = cross_ts_number_count(j)
532             IF ( k /= 0 )  THEN
533!
534!--             Store curve numbers, colours and line style
535                klist(1:k) = cross_ts_numbers(1:k,j)
536                klist(k+1:10) = 999999
537!
538!--             Write CROSS parameter
539                WRITE ( 90, CROSS )
540
541             ENDIF
542          ENDDO
543
544          CLOSE ( 90 )
545!
546!--       Write all labels at the top of the data file, but only during the
547!--       first run of a sequence of jobs. The following jobs copy the time
548!--       series data to the bottom of that file.
549          IF ( runnr == 0 )  THEN
[1320]550             WRITE ( file_id, 5000 )  TRIM( run_description_header ) //        &
[1]551                                      '    ' // TRIM( region( file_id - 50 ) )
552          ENDIF
553
554
555       CASE ( 80 )
556
557          IF ( myid_char == '' )  THEN
[105]558             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM(coupling_char)//myid_char, &
[102]559                        FORM='FORMATTED', POSITION='APPEND' )
[1]560          ELSE
561             IF ( myid == 0  .AND.  .NOT. openfile(80)%opened_before )  THEN
[1779]562                CALL local_system( 'mkdir  PARTICLE_INFOS' //                  &
563                                   TRIM( coupling_char ) )
[1]564             ENDIF
[809]565#if defined( __parallel ) && ! defined ( __check )
[1]566!
567!--          Set a barrier in order to allow that thereafter all other
568!--          processors in the directory created by PE0 can open their file.
569!--          WARNING: The following barrier will lead to hanging jobs, if
570!--                   check_open is first called from routine
571!--                   allocate_prt_memory!
572             IF ( .NOT. openfile(80)%opened_before )  THEN
573                CALL MPI_BARRIER( comm2d, ierr )
574             ENDIF
575#endif
[1320]576             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM( coupling_char )//'/'//    &
577                             myid_char,                                        &
[102]578                        FORM='FORMATTED', POSITION='APPEND' )
[1]579          ENDIF
580
581          IF ( .NOT. openfile(80)%opened_before )  THEN
582             WRITE ( 80, 8000 )  TRIM( run_description_header )
583          ENDIF
584
585       CASE ( 81 )
586
[1779]587             OPEN ( 81, FILE='PLOTSP_X_PAR'//TRIM( coupling_char ),            &
588                        FORM='FORMATTED', DELIM='APOSTROPHE', RECL=1500,       &
589                        POSITION='APPEND' )
[1]590
591       CASE ( 82 )
592
[1779]593             OPEN ( 82, FILE='PLOTSP_X_DATA'//TRIM( coupling_char ),           &
594                        FORM='FORMATTED', POSITION = 'APPEND' )
[1]595
596       CASE ( 83 )
597
[1779]598             OPEN ( 83, FILE='PLOTSP_Y_PAR'//TRIM( coupling_char ),            &
599                        FORM='FORMATTED', DELIM='APOSTROPHE', RECL=1500,       &
600                        POSITION='APPEND' )
[1]601
602       CASE ( 84 )
603
[1779]604             OPEN ( 84, FILE='PLOTSP_Y_DATA'//TRIM( coupling_char ),           &
605                        FORM='FORMATTED', POSITION='APPEND' )
[1]606
607       CASE ( 85 )
608
609          IF ( myid_char == '' )  THEN
[1320]610             OPEN ( 85, FILE='PARTICLE_DATA'//TRIM(coupling_char)//myid_char,  &
[102]611                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]612          ELSE
613             IF ( myid == 0  .AND.  .NOT. openfile(85)%opened_before )  THEN
[1779]614                CALL local_system( 'mkdir  PARTICLE_DATA' //                   &
615                                   TRIM( coupling_char ) )
[1]616             ENDIF
[809]617#if defined( __parallel ) && ! defined ( __check )
[1]618!
619!--          Set a barrier in order to allow that thereafter all other
620!--          processors in the directory created by PE0 can open their file
621             CALL MPI_BARRIER( comm2d, ierr )
622#endif
[1320]623             OPEN ( 85, FILE='PARTICLE_DATA'//TRIM( coupling_char )//'/'//     &
624                        myid_char,                                             &
[102]625                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]626          ENDIF
627
628          IF ( .NOT. openfile(85)%opened_before )  THEN
629             WRITE ( 85 )  run_description_header
630!
631!--          Attention: change version number whenever the output format on
[849]632!--                     unit 85 is changed (see also in routine
633!--                     lpm_data_output_particles)
[1359]634             rtext = 'data format version 3.1'
[1]635             WRITE ( 85 )  rtext
[1320]636             WRITE ( 85 )  number_of_particle_groups,                          &
[1]637                           max_number_of_particle_groups
638             WRITE ( 85 )  particle_groups
[1359]639             WRITE ( 85 )  nxl, nxr, nys, nyn, nzb, nzt, nbgp
[1]640          ENDIF
641
642#if defined( __netcdf )
643       CASE ( 101, 111 )
644!
645!--       Set filename depending on unit number
646          IF ( file_id == 101 )  THEN
[1779]647             filename = 'DATA_2D_XY_NETCDF' // TRIM( coupling_char )
[1]648             av = 0
649          ELSE
[1779]650             filename = 'DATA_2D_XY_AV_NETCDF' // TRIM( coupling_char )
[1]651             av = 1
652          ENDIF
653!
[1031]654!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]655!--       be opened for extension, if its dimensions and variables match the
656!--       actual run.
657          INQUIRE( FILE=filename, EXIST=netcdf_extend )
658
659          IF ( netcdf_extend )  THEN
660!
[1031]661!--          Open an existing netCDF file for output
[1783]662             CALL netcdf_open_write_file( filename, id_set_xy(av), .TRUE., 20 )
[1]663!
664!--          Read header information and set all ids. If there is a mismatch
665!--          between the previuos and the actual run, netcdf_extend is returned
666!--          as .FALSE.
[1783]667             CALL netcdf_define_header( 'xy', netcdf_extend, av )
[1]668
669!
670!--          Remove the local file, if it can not be extended
671             IF ( .NOT. netcdf_extend )  THEN
672                nc_stat = NF90_CLOSE( id_set_xy(av) )
[1783]673                CALL netcdf_handle_error( 'check_open', 21 )
[493]674                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1745]675#if defined( __parallel ) && ! defined ( __check )
676!
677!--             Set a barrier in order to assure that PE0 deleted the old file
678!--             before any other processor tries to open a new file
679                CALL MPI_BARRIER( comm2d, ierr )
680#endif
[1]681             ENDIF
682
[1745]683          ENDIF
[1]684
685          IF ( .NOT. netcdf_extend )  THEN
686!
[1031]687!--          Create a new netCDF output file with requested netCDF format
[1783]688             CALL netcdf_create_file( filename, id_set_xy(av), .TRUE., 22 )
[493]689
690!
[1]691!--          Define the header
[1783]692             CALL netcdf_define_header( 'xy', netcdf_extend, av )
[1]693
[493]694!
[1031]695!--          In case of parallel netCDF output, create flag file which tells
[493]696!--          combine_plot_fields that nothing is to do.
[1031]697             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
[493]698                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XY' )
699                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
700                CLOSE( 99 )
701             ENDIF
702
[1]703          ENDIF
704
705       CASE ( 102, 112 )
706!
707!--       Set filename depending on unit number
708          IF ( file_id == 102 )  THEN
[1779]709             filename = 'DATA_2D_XZ_NETCDF' // TRIM( coupling_char )
[1]710             av = 0
711          ELSE
[1779]712             filename = 'DATA_2D_XZ_AV_NETCDF' // TRIM( coupling_char )
[1]713             av = 1
714          ENDIF
715!
[1031]716!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]717!--       be opened for extension, if its dimensions and variables match the
718!--       actual run.
719          INQUIRE( FILE=filename, EXIST=netcdf_extend )
720
721          IF ( netcdf_extend )  THEN
722!
[1031]723!--          Open an existing netCDF file for output
[1783]724             CALL netcdf_open_write_file( filename, id_set_xz(av), .TRUE., 23 )
[1]725!
726!--          Read header information and set all ids. If there is a mismatch
727!--          between the previuos and the actual run, netcdf_extend is returned
728!--          as .FALSE.
[1783]729             CALL netcdf_define_header( 'xz', netcdf_extend, av )
[1]730
731!
732!--          Remove the local file, if it can not be extended
733             IF ( .NOT. netcdf_extend )  THEN
734                nc_stat = NF90_CLOSE( id_set_xz(av) )
[1783]735                CALL netcdf_handle_error( 'check_open', 24 )
[493]736                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1745]737#if defined( __parallel ) && ! defined ( __check )
738!
739!--             Set a barrier in order to assure that PE0 deleted the old file
740!--             before any other processor tries to open a new file
741                CALL MPI_BARRIER( comm2d, ierr )
742#endif
[1]743             ENDIF
744
[1745]745          ENDIF
[1]746
747          IF ( .NOT. netcdf_extend )  THEN
748!
[1031]749!--          Create a new netCDF output file with requested netCDF format
[1783]750             CALL netcdf_create_file( filename, id_set_xz(av), .TRUE., 25 )
[493]751
752!
[1]753!--          Define the header
[1783]754             CALL netcdf_define_header( 'xz', netcdf_extend, av )
[1]755
[493]756!
[1031]757!--          In case of parallel netCDF output, create flag file which tells
[493]758!--          combine_plot_fields that nothing is to do.
[1031]759             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
[493]760                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XZ' )
761                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
762                CLOSE( 99 )
763             ENDIF
764
[1]765          ENDIF
766
767       CASE ( 103, 113 )
768!
769!--       Set filename depending on unit number
770          IF ( file_id == 103 )  THEN
[1779]771             filename = 'DATA_2D_YZ_NETCDF' // TRIM( coupling_char )
[1]772             av = 0
773          ELSE
[1779]774             filename = 'DATA_2D_YZ_AV_NETCDF' // TRIM( coupling_char )
[1]775             av = 1
776          ENDIF
777!
[1031]778!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]779!--       be opened for extension, if its dimensions and variables match the
780!--       actual run.
781          INQUIRE( FILE=filename, EXIST=netcdf_extend )
782
783          IF ( netcdf_extend )  THEN
784!
[1031]785!--          Open an existing netCDF file for output
[1783]786             CALL netcdf_open_write_file( filename, id_set_yz(av), .TRUE., 26 )
[1]787!
788!--          Read header information and set all ids. If there is a mismatch
789!--          between the previuos and the actual run, netcdf_extend is returned
790!--          as .FALSE.
[1783]791             CALL netcdf_define_header( 'yz', netcdf_extend, av )
[1]792
793!
794!--          Remove the local file, if it can not be extended
795             IF ( .NOT. netcdf_extend )  THEN
796                nc_stat = NF90_CLOSE( id_set_yz(av) )
[1783]797                CALL netcdf_handle_error( 'check_open', 27 )
[493]798                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1745]799#if defined( __parallel ) && ! defined ( __check )
800!
801!--             Set a barrier in order to assure that PE0 deleted the old file
802!--             before any other processor tries to open a new file
803                CALL MPI_BARRIER( comm2d, ierr )
804#endif
[1]805             ENDIF
806
[1745]807          ENDIF
[1]808
809          IF ( .NOT. netcdf_extend )  THEN
810!
[1031]811!--          Create a new netCDF output file with requested netCDF format
[1783]812             CALL netcdf_create_file( filename, id_set_yz(av), .TRUE., 28 )
[493]813
814!
[1]815!--          Define the header
[1783]816             CALL netcdf_define_header( 'yz', netcdf_extend, av )
[1]817
[493]818!
[1031]819!--          In case of parallel netCDF output, create flag file which tells
[493]820!--          combine_plot_fields that nothing is to do.
[1031]821             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
[493]822                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_YZ' )
823                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
824                CLOSE( 99 )
825             ENDIF
826
[1]827          ENDIF
828
829       CASE ( 104 )
830!
[102]831!--       Set filename
[1779]832          filename = 'DATA_1D_PR_NETCDF' // TRIM( coupling_char )
[102]833
834!
[1031]835!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]836!--       be opened for extension, if its variables match the actual run.
[102]837          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1]838
839          IF ( netcdf_extend )  THEN
840!
[1031]841!--          Open an existing netCDF file for output
[1783]842             CALL netcdf_open_write_file( filename, id_set_pr, .FALSE., 29 )
[1]843!
844!--          Read header information and set all ids. If there is a mismatch
845!--          between the previuos and the actual run, netcdf_extend is returned
846!--          as .FALSE.
[1783]847             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
[1]848
849!
850!--          Remove the local file, if it can not be extended
851             IF ( .NOT. netcdf_extend )  THEN
852                nc_stat = NF90_CLOSE( id_set_pr )
[1783]853                CALL netcdf_handle_error( 'check_open', 30 )
[102]854                CALL local_system( 'rm ' // TRIM( filename ) )
[1]855             ENDIF
856
857          ENDIF         
858
859          IF ( .NOT. netcdf_extend )  THEN
860!
[1031]861!--          Create a new netCDF output file with requested netCDF format
[1783]862             CALL netcdf_create_file( filename, id_set_pr, .FALSE., 31 )
[1]863!
864!--          Define the header
[1783]865             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
[1]866
867          ENDIF
868
869       CASE ( 105 )
870!
[102]871!--       Set filename
[1779]872          filename = 'DATA_1D_TS_NETCDF' // TRIM( coupling_char )
[102]873
874!
[1031]875!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]876!--       be opened for extension, if its variables match the actual run.
[102]877          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1]878
879          IF ( netcdf_extend )  THEN
880!
[1031]881!--          Open an existing netCDF file for output
[1783]882             CALL netcdf_open_write_file( filename, id_set_ts, .FALSE., 32 )
[1]883!
884!--          Read header information and set all ids. If there is a mismatch
885!--          between the previuos and the actual run, netcdf_extend is returned
886!--          as .FALSE.
[1783]887             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
[1]888
889!
890!--          Remove the local file, if it can not be extended
891             IF ( .NOT. netcdf_extend )  THEN
892                nc_stat = NF90_CLOSE( id_set_ts )
[1783]893                CALL netcdf_handle_error( 'check_open', 33 )
[102]894                CALL local_system( 'rm ' // TRIM( filename ) )
[1]895             ENDIF
896
897          ENDIF         
898
899          IF ( .NOT. netcdf_extend )  THEN
900!
[1031]901!--          Create a new netCDF output file with requested netCDF format
[1783]902             CALL netcdf_create_file( filename, id_set_ts, .FALSE., 34 )
[1]903!
904!--          Define the header
[1783]905             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
[1]906
907          ENDIF
908
909
910       CASE ( 106, 116 )
911!
912!--       Set filename depending on unit number
913          IF ( file_id == 106 )  THEN
[1779]914             filename = 'DATA_3D_NETCDF' // TRIM( coupling_char )
[1]915             av = 0
916          ELSE
[1779]917             filename = 'DATA_3D_AV_NETCDF' // TRIM( coupling_char )
[1]918             av = 1
919          ENDIF
920!
[1031]921!--       Inquire, if there is a netCDF file from a previous run. This should
[1]922!--       be opened for extension, if its dimensions and variables match the
923!--       actual run.
924          INQUIRE( FILE=filename, EXIST=netcdf_extend )
925
926          IF ( netcdf_extend )  THEN
927!
[1031]928!--          Open an existing netCDF file for output
[1783]929             CALL netcdf_open_write_file( filename, id_set_3d(av), .TRUE., 35 )
[1]930!
931!--          Read header information and set all ids. If there is a mismatch
932!--          between the previuos and the actual run, netcdf_extend is returned
933!--          as .FALSE.
[1783]934             CALL netcdf_define_header( '3d', netcdf_extend, av )
[1]935
936!
937!--          Remove the local file, if it can not be extended
938             IF ( .NOT. netcdf_extend )  THEN
939                nc_stat = NF90_CLOSE( id_set_3d(av) )
[1783]940                CALL netcdf_handle_error( 'check_open', 36 )
[1745]941                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
942#if defined( __parallel ) && ! defined ( __check )
943!
944!--             Set a barrier in order to assure that PE0 deleted the old file
945!--             before any other processor tries to open a new file
946                CALL MPI_BARRIER( comm2d, ierr )
947#endif
948
[1]949             ENDIF
950
[1745]951          ENDIF
[1]952
953          IF ( .NOT. netcdf_extend )  THEN
954!
[1031]955!--          Create a new netCDF output file with requested netCDF format
[1783]956             CALL netcdf_create_file( filename, id_set_3d(av), .TRUE., 37 )
[493]957
958!
[1]959!--          Define the header
[1783]960             CALL netcdf_define_header( '3d', netcdf_extend, av )
[1]961
[493]962!
[1031]963!--          In case of parallel netCDF output, create flag file which tells
[493]964!--          combine_plot_fields that nothing is to do.
[1031]965             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
[493]966                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_3D' )
967                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
968                CLOSE( 99 )
969             ENDIF
970
[1]971          ENDIF
972
973
974       CASE ( 107 )
975!
[102]976!--       Set filename
[1779]977          filename = 'DATA_1D_SP_NETCDF' // TRIM( coupling_char )
[102]978
979!
[1031]980!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]981!--       be opened for extension, if its variables match the actual run.
[102]982          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1]983
984          IF ( netcdf_extend )  THEN
985!
[1031]986!--          Open an existing netCDF file for output
[1783]987             CALL netcdf_open_write_file( filename, id_set_sp, .FALSE., 38 )
[263]988
[1]989!
990!--          Read header information and set all ids. If there is a mismatch
991!--          between the previuos and the actual run, netcdf_extend is returned
992!--          as .FALSE.
[1783]993             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
[1]994
995!
996!--          Remove the local file, if it can not be extended
997             IF ( .NOT. netcdf_extend )  THEN
998                nc_stat = NF90_CLOSE( id_set_sp )
[1783]999                CALL netcdf_handle_error( 'check_open', 39 )
[102]1000                CALL local_system( 'rm ' // TRIM( filename ) )
[1]1001             ENDIF
1002
1003          ENDIF         
1004
1005          IF ( .NOT. netcdf_extend )  THEN
1006!
[1031]1007!--          Create a new netCDF output file with requested netCDF format
[1783]1008             CALL netcdf_create_file( filename, id_set_sp, .FALSE., 40 )
[1]1009!
1010!--          Define the header
[1783]1011             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
[1]1012
1013          ENDIF
1014
1015
1016       CASE ( 108 )
1017
1018          IF ( myid_char == '' )  THEN
[1779]1019             filename = 'DATA_PRT_NETCDF' // TRIM( coupling_char )
[1]1020          ELSE
[1320]1021             filename = 'DATA_PRT_NETCDF' // TRIM( coupling_char ) // '/' //   &
[105]1022                        myid_char
[1]1023          ENDIF
1024!
[1031]1025!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]1026!--       be opened for extension, if its variables match the actual run.
1027          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1028
1029          IF ( netcdf_extend )  THEN
1030!
[1031]1031!--          Open an existing netCDF file for output
[1783]1032             CALL netcdf_open_write_file( filename, id_set_prt, .FALSE., 41 )
[1]1033!
1034!--          Read header information and set all ids. If there is a mismatch
1035!--          between the previuos and the actual run, netcdf_extend is returned
1036!--          as .FALSE.
[1783]1037             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
[1]1038
1039!
1040!--          Remove the local file, if it can not be extended
1041             IF ( .NOT. netcdf_extend )  THEN
1042                nc_stat = NF90_CLOSE( id_set_prt )
[1783]1043                CALL netcdf_handle_error( 'check_open', 42 )
[1745]1044                CALL local_system( 'rm ' // TRIM( filename ) )
[1]1045             ENDIF
1046
1047          ENDIF         
1048
1049          IF ( .NOT. netcdf_extend )  THEN
1050
1051!
1052!--          For runs on multiple processors create the subdirectory
1053             IF ( myid_char /= '' )  THEN
[1320]1054                IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  &
[1]1055                THEN    ! needs modification in case of non-extendable sets
[1320]1056                   CALL local_system( 'mkdir  DATA_PRT_NETCDF' //              &
[105]1057                                       TRIM( coupling_char ) // '/' )
[1]1058                ENDIF
[809]1059#if defined( __parallel ) && ! defined ( __check )
[807]1060!
[1]1061!--             Set a barrier in order to allow that all other processors in the
1062!--             directory created by PE0 can open their file
1063                CALL MPI_BARRIER( comm2d, ierr )
1064#endif
1065             ENDIF
1066
1067!
[1031]1068!--          Create a new netCDF output file with requested netCDF format
[1783]1069             CALL netcdf_create_file( filename, id_set_prt, .FALSE., 43 )
[519]1070
1071!
[1]1072!--          Define the header
[1783]1073             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
[1]1074
1075          ENDIF
1076
1077       CASE ( 109 )
1078!
[102]1079!--       Set filename
[1779]1080          filename = 'DATA_1D_PTS_NETCDF' // TRIM( coupling_char )
[102]1081
1082!
[1031]1083!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]1084!--       be opened for extension, if its variables match the actual run.
[102]1085          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1]1086
1087          IF ( netcdf_extend )  THEN
1088!
[1031]1089!--          Open an existing netCDF file for output
[1783]1090             CALL netcdf_open_write_file( filename, id_set_pts, .FALSE., 393 )
[1]1091!
1092!--          Read header information and set all ids. If there is a mismatch
1093!--          between the previuos and the actual run, netcdf_extend is returned
1094!--          as .FALSE.
[1783]1095             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
[1]1096
1097!
1098!--          Remove the local file, if it can not be extended
1099             IF ( .NOT. netcdf_extend )  THEN
1100                nc_stat = NF90_CLOSE( id_set_pts )
[1783]1101                CALL netcdf_handle_error( 'check_open', 394 )
[102]1102                CALL local_system( 'rm ' // TRIM( filename ) )
[1]1103             ENDIF
1104
1105          ENDIF         
1106
1107          IF ( .NOT. netcdf_extend )  THEN
1108!
[1031]1109!--          Create a new netCDF output file with requested netCDF format
[1783]1110             CALL netcdf_create_file( filename, id_set_pts, .FALSE., 395 )
[1]1111!
1112!--          Define the header
[1783]1113             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
[1]1114
1115          ENDIF
[410]1116
[1468]1117
1118!
1119!--    Progress file that is used by the PALM watchdog
1120       CASE ( 117 )
1121
[1779]1122          OPEN ( 117, FILE='PROGRESS'//TRIM( coupling_char ),                  &
1123                      STATUS='REPLACE', FORM='FORMATTED' )
[1468]1124
1125
[564]1126       CASE ( 201:200+2*max_masks )
[410]1127!
1128!--       Set filename depending on unit number
[564]1129          IF ( file_id <= 200+max_masks )  THEN
1130             mid = file_id - 200
[410]1131             WRITE ( mask_char,'(I2.2)')  mid
[1779]1132             filename = 'DATA_MASK_' // mask_char // '_NETCDF' //              &
1133                        TRIM( coupling_char )
[410]1134             av = 0
1135          ELSE
[564]1136             mid = file_id - (200+max_masks)
[410]1137             WRITE ( mask_char,'(I2.2)')  mid
[1320]1138             filename = 'DATA_MASK_' // mask_char // '_AV_NETCDF' //           &
[1779]1139                        TRIM( coupling_char )
[410]1140             av = 1
1141          ENDIF
1142!
[1031]1143!--       Inquire, if there is a netCDF file from a previuos run. This should
[410]1144!--       be opened for extension, if its dimensions and variables match the
1145!--       actual run.
1146          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1147
1148          IF ( netcdf_extend )  THEN
1149!
[1031]1150!--          Open an existing netCDF file for output
[1783]1151             CALL netcdf_open_write_file( filename, id_set_mask(mid,av),       &
[1031]1152                                          .TRUE., 456 )
[410]1153!
1154!--          Read header information and set all ids. If there is a mismatch
1155!--          between the previuos and the actual run, netcdf_extend is returned
1156!--          as .FALSE.
[1783]1157             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
[1]1158
[410]1159!
1160!--          Remove the local file, if it can not be extended
1161             IF ( .NOT. netcdf_extend )  THEN
1162                nc_stat = NF90_CLOSE( id_set_mask(mid,av) )
[1783]1163                CALL netcdf_handle_error( 'check_open', 457 )
[410]1164                CALL local_system('rm ' // TRIM( filename ) )
1165             ENDIF
[1]1166
[410]1167          ENDIF         
1168
1169          IF ( .NOT. netcdf_extend )  THEN
[1]1170!
[1031]1171!--          Create a new netCDF output file with requested netCDF format
[1783]1172             CALL netcdf_create_file( filename, id_set_mask(mid,av), .TRUE., 458 )
[493]1173!
[410]1174!--          Define the header
[1783]1175             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
[410]1176
1177          ENDIF
1178
1179
1180#else
1181
[564]1182       CASE ( 101:109, 111:113, 116, 201:200+2*max_masks )
[410]1183
1184!
[1]1185!--       Nothing is done in case of missing netcdf support
1186          RETURN
1187
1188#endif
1189
1190       CASE DEFAULT
1191
[247]1192          WRITE( message_string, * ) 'no OPEN-statement for file-id ',file_id
[277]1193          CALL message( 'check_open', 'PA0172', 2, 2, -1, 6, 1 )
[1]1194
1195    END SELECT
1196
1197!
1198!-- Set open flag
1199    openfile(file_id)%opened = .TRUE.
1200
1201!
1202!-- Formats
[1320]12033300 FORMAT ('#'/                                                              &
1204             'coord 1  file=',A,'  filetype=unformatted'/                      &
1205             'coord 2  file=',A,'  filetype=unformatted  skip=',I6/            &
1206             'coord 3  file=',A,'  filetype=unformatted  skip=',I6/            &
[1]1207             '#')
12084000 FORMAT ('# ',A)
[1320]12095000 FORMAT ('# ',A/                                                           &
1210             '#1 E'/'#2 E*'/'#3 dt'/'#4 u*'/'#5 th*'/'#6 umax'/'#7 vmax'/      &
1211             '#8 wmax'/'#9 div_new'/'#10 div_old'/'#11 z_i_wpt'/'#12 z_i_pt'/  &
1212             '#13 w*'/'#14 w''pt''0'/'#15 w''pt'''/'#16 wpt'/'#17 pt(0)'/      &
[1]1213             '#18 pt(zp)'/'#19 splptx'/'#20 splpty'/'#21 splptz')
[1320]12148000 FORMAT (A/                                                                &
[1359]1215             '  step    time    # of parts     lPE sent/recv  rPE sent/recv  ',&
1216             'sPE sent/recv  nPE sent/recv    max # of parts  '/               &
1217             109('-'))
[1]1218
1219 END SUBROUTINE check_open
Note: See TracBrowser for help on using the repository browser.