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

Last change on this file since 2000 was 2000, checked in by knoop, 8 years ago

Forced header and separation lines into 80 columns

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