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

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

pmc array management changed from linked list to sequential loop; further small changes and cosmetics for the pmc

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