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

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

NetCDF routines modularized; new parameter netcdf_deflate; further changes in the pmc

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