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

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

last commit documented

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