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

Last change on this file since 1958 was 1958, checked in by suehring, 8 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 44.3 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!
[1804]13! You should have received a copy of the GNU fGeneral Public License along with
[1036]14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
[1818]16! Copyright 1997-2016 Leibniz Universitaet Hannover
[1036]17!--------------------------------------------------------------------------------!
18!
[247]19! Current revisions:
[1]20! -----------------
[1805]21!
[1958]22!
[1321]23! Former revisions:
24! -----------------
25! $Id: check_open.f90 1958 2016-07-07 10:51:40Z suehring $
26!
[1958]27! 1957 2016-07-07 10:43:48Z suehring
28! flight module added
29!
[1805]30! 1804 2016-04-05 16:30:18Z maronga
31! Removed code for parameter file check (__check)
32!
[1784]33! 1783 2016-03-06 18:36:17Z raasch
34! name change of netcdf routines and module + related changes
35!
[1780]36! 1779 2016-03-03 08:01:28Z raasch
37! coupling_char is trimmed at every place it occurs, because it can have
38! different length now
39!
[1746]40! 1745 2016-02-05 13:06:51Z gronemeier
41! Bugfix: added MPI barrier after deleting existing non-extendable file by PE0
42!
[1683]43! 1682 2015-10-07 23:56:08Z knoop
44! Code annotations made doxygen readable
45!
[1552]46! 1551 2015-03-03 14:18:16Z maronga
47! Removed redundant output for combine_plot_fields
48!
[1469]49! 1468 2014-09-24 14:06:57Z maronga
50! Adapted for use on up to 6-digit processor cores
51! Added file unit 117 (PROGRESS)
52!
[1360]53! 1359 2014-04-11 17:15:14Z hoffmann
54! Format of particle exchange statistics extended to reasonable numbers of     
55! particles.
56!
[1354]57! 1353 2014-04-08 15:21:23Z heinze
58! REAL constants provided with KIND-attribute,
59! declaration for unused variables xkoor, ykoor, zkoor removed
60!
[1329]61! 1327 2014-03-21 11:00:16Z raasch
62! parts concerning iso2d and avs output removed
63!
[1321]64! 1320 2014-03-20 08:40:49Z raasch
[1320]65! ONLY-attribute added to USE-statements,
66! kind-parameters added to all INTEGER and REAL declaration statements,
67! kinds are defined in new module kinds,
68! old module precision_kind is removed,
69! revision history before 2012 removed,
70! comment fields (!:) to be used for variable explanations added to
71! all variable declaration statements
[1]72!
[1107]73! 1106 2013-03-04 05:31:38Z raasch
74! array_kind renamed precision_kind
75!
[1093]76! 1092 2013-02-02 11:24:22Z raasch
77! unused variables removed
78!
[1037]79! 1036 2012-10-22 13:43:42Z raasch
80! code put under GPL (PALM 3.9)
81!
[1035]82! 1031 2012-10-19 14:35:30Z raasch
83! netCDF4 without parallel file support implemented,
84! opening of netCDF files are done by new routines create_netcdf_file and
85! open_write_netcdf_file
86!
[965]87! 964 2012-07-26 09:14:24Z raasch
88! old profil-units (40:49) removed,
89! append feature removed from unit 14
90!
[850]91! 849 2012-03-15 10:35:09Z raasch
92! comment changed
93!
[810]94! 809 2012-01-30 13:32:58Z maronga
95! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives
96!
[808]97! 807 2012-01-25 11:53:51Z maronga
98! New cpp directive "__check" implemented which is used by check_namelist_files
99!
[1]100! Revision 1.1  1997/08/11 06:10:55  raasch
101! Initial revision
102!
103!
104! Description:
105! ------------
[1682]106!> Check if file unit is open. If not, open file and, if necessary, write a
107!> header or start other initializing actions, respectively.
[1]108!------------------------------------------------------------------------------!
[1682]109SUBROUTINE check_open( file_id )
110 
[1]111
[1320]112    USE arrays_3d,                                                             &
113        ONLY:  zu
114
115    USE control_parameters,                                                    &
[1327]116        ONLY:  avs_data_file, coupling_char, data_output_2d_on_each_pe, host,  &
[1783]117               max_masks, message_string, mid, nz_do3d, openfile,              &
[1320]118               return_addres, return_username, run_description_header, runnr
119
120    USE grid_variables,                                                        &
121        ONLY:  dx, dy
122
123    USE indices,                                                               &
[1551]124        ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nyng, nys, nysg, nz, nzb, nzt 
[1320]125
126    USE kinds
127
[1783]128#if defined( __netcdf )
129    USE NETCDF
130#endif
[1320]131
[1783]132    USE netcdf_interface,                                                      &
[1957]133        ONLY:  id_set_fl, id_set_mask, id_set_pr, id_set_prt, id_set_pts,      &
134               id_set_sp, id_set_ts, id_set_xy, id_set_xz, id_set_yz,          &
135               id_set_3d, nc_stat, netcdf_create_file, netcdf_data_format,     &
136               netcdf_define_header, netcdf_handle_error, netcdf_open_write_file
[1783]137
[1320]138    USE particle_attributes,                                                   &
139        ONLY:  max_number_of_particle_groups, number_of_particle_groups,       &
140               particle_groups
141
[1]142    USE pegrid
143
[1320]144    USE profil_parameter,                                                      &
145        ONLY:  cross_ts_numbers, cross_ts_number_count
146
147    USE statistics,                                                            &
148        ONLY:  region, statistic_regions
149
150
[1]151    IMPLICIT NONE
152
[1682]153    CHARACTER (LEN=2)   ::  mask_char               !<
154    CHARACTER (LEN=2)   ::  suffix                  !<
155    CHARACTER (LEN=20)  ::  xtext = 'time in s'     !<
156    CHARACTER (LEN=30)  ::  filename                !<
157    CHARACTER (LEN=40)  ::  avs_coor_file           !<
158    CHARACTER (LEN=40)  ::  avs_coor_file_localname !<
159    CHARACTER (LEN=40)  ::  avs_data_file_localname !<
160    CHARACTER (LEN=80)  ::  rtext                   !<
161    CHARACTER (LEN=100) ::  avs_coor_file_catalog   !<
162    CHARACTER (LEN=100) ::  avs_data_file_catalog   !<
163    CHARACTER (LEN=100) ::  batch_scp               !<
164    CHARACTER (LEN=100) ::  line                    !<
165    CHARACTER (LEN=400) ::  command                 !<
[1]166
[1682]167    INTEGER(iwp) ::  av          !<
168    INTEGER(iwp) ::  numline = 1 !<
169    INTEGER(iwp) ::  cranz       !<
170    INTEGER(iwp) ::  file_id     !<
171    INTEGER(iwp) ::  i           !<
172    INTEGER(iwp) ::  iaddres     !<
173    INTEGER(iwp) ::  iusern      !<
174    INTEGER(iwp) ::  j           !<
175    INTEGER(iwp) ::  k           !<
176    INTEGER(iwp) ::  legpos = 1  !<
177    INTEGER(iwp) ::  timodex = 1 !<
[1320]178   
[1682]179    INTEGER(iwp), DIMENSION(10) ::  klist !<
[1]180
[1682]181    LOGICAL ::  avs_coor_file_found = .FALSE. !<
182    LOGICAL ::  avs_data_file_found = .FALSE. !<
183    LOGICAL ::  datleg = .TRUE.               !<
184    LOGICAL ::  get_filenames                 !<
185    LOGICAL ::  grid = .TRUE.                 !<
186    LOGICAL ::  netcdf_extend                 !<
187    LOGICAL ::  rand = .TRUE.                 !<
188    LOGICAL ::  swap = .TRUE.                 !<
189    LOGICAL ::  twoxa = .TRUE.                !<
190    LOGICAL ::  twoya = .TRUE.                !<
[1]191
[1682]192    REAL(wp) ::  ansx = -999.999_wp !<
193    REAL(wp) ::  ansy = -999.999_wp !<
194    REAL(wp) ::  gwid = 0.1_wp      !<
195    REAL(wp) ::  rlegfak = 1.5_wp   !<
196    REAL(wp) ::  sizex = 250.0_wp   !<
197    REAL(wp) ::  sizey = 40.0_wp    !<
198    REAL(wp) ::  texfac = 1.5_wp    !<
[1]199
[1682]200    REAL(wp), DIMENSION(:), ALLOCATABLE      ::  eta !<
201    REAL(wp), DIMENSION(:), ALLOCATABLE      ::  ho  !<
202    REAL(wp), DIMENSION(:), ALLOCATABLE      ::  hu  !<
[1353]203 
[1]204
205
[1320]206    NAMELIST /RAHMEN/  numline, cranz, datleg, rtext, swap
207    NAMELIST /CROSS/   ansx, ansy, grid, gwid, klist, legpos,                  &
208                       rand, rlegfak, sizex, sizey, texfac,                    &
[1]209                       timodex, twoxa, twoya, xtext
210                       
211
212!
213!-- Immediate return if file already open
214    IF ( openfile(file_id)%opened )  RETURN
215
216!
217!-- Only certain files are allowed to be re-opened
218!-- NOTE: some of the other files perhaps also could be re-opened, but it
219!--       has not been checked so far, if it works!
220    IF ( openfile(file_id)%opened_before )  THEN
221       SELECT CASE ( file_id )
[1468]222          CASE ( 13, 14, 21, 22, 23, 80:85, 117 )
[1]223             IF ( file_id == 14 .AND. openfile(file_id)%opened_before )  THEN
[1320]224                message_string = 're-open of unit ' //                         &
[274]225                                 '14 is not verified. Please check results!'
[247]226                CALL message( 'check_open', 'PA0165', 0, 1, 0, 6, 0 )       
[1]227             ENDIF
[143]228
[1]229          CASE DEFAULT
[1320]230             WRITE( message_string, * ) 're-opening of file-id ', file_id,     &
[274]231                                        ' is not allowed'
[247]232             CALL message( 'check_open', 'PA0166', 0, 1, 0, 6, 0 )   
233               
[1]234             RETURN
[143]235
[1]236       END SELECT
237    ENDIF
238
239!
240!-- Check if file may be opened on the relevant PE
241    SELECT CASE ( file_id )
242
[1468]243       CASE ( 15, 16, 17, 18, 19, 50:59, 81:84, 104:105, 107, 109, 117 )
[410]244             
[493]245          IF ( myid /= 0 )  THEN
[1320]246             WRITE( message_string, * ) 'opening file-id ',file_id,            &
[493]247                                        ' not allowed for PE ',myid
248             CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
249          ENDIF
250
[564]251       CASE ( 101:103, 106, 111:113, 116, 201:200+2*max_masks )
[493]252
[1031]253          IF ( netcdf_data_format < 5 )  THEN
[247]254         
[410]255             IF ( myid /= 0 )  THEN
[1320]256                WRITE( message_string, * ) 'opening file-id ',file_id,         &
[410]257                                           ' not allowed for PE ',myid
258                CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
259             ENDIF
260             
[493]261          ENDIF
[1]262
263       CASE ( 21, 22, 23 )
264
265          IF ( .NOT.  data_output_2d_on_each_pe )  THEN
266             IF ( myid /= 0 )  THEN
[1320]267                WRITE( message_string, * ) 'opening file-id ',file_id,         &
[247]268                                           ' not allowed for PE ',myid
[277]269                CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
[247]270             END IF
[1]271          ENDIF
272
[1327]273       CASE ( 27, 28, 29, 31, 33, 71:73, 90:99 )
[1]274
275!
276!--       File-ids that are used temporarily in other routines
[1320]277          WRITE( message_string, * ) 'opening file-id ',file_id,               &
[274]278                                    ' is not allowed since it is used otherwise'
[247]279          CALL message( 'check_open', 'PA0168', 0, 1, 0, 6, 0 ) 
280         
[1]281    END SELECT
282
283!
284!-- Open relevant files
285    SELECT CASE ( file_id )
286
287       CASE ( 11 )
288
[1779]289          OPEN ( 11, FILE='PARIN'//TRIM( coupling_char ), FORM='FORMATTED',    &
[102]290                     STATUS='OLD' )
[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
[1804]319#if defined( __parallel )
[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
[1804]362#if defined( __parallel )
[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
[1804]554#if defined( __parallel )
[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
[1804]606#if defined( __parallel )
[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
[1783]651             CALL netcdf_open_write_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.
[1783]656             CALL netcdf_define_header( 'xy', netcdf_extend, av )
[1]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) )
[1783]662                CALL netcdf_handle_error( 'check_open', 21 )
[493]663                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1804]664#if defined( __parallel )
[1745]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
[1783]677             CALL netcdf_create_file( filename, id_set_xy(av), .TRUE., 22 )
[493]678
679!
[1]680!--          Define the header
[1783]681             CALL netcdf_define_header( 'xy', netcdf_extend, av )
[1]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
[1783]713             CALL netcdf_open_write_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.
[1783]718             CALL netcdf_define_header( 'xz', netcdf_extend, av )
[1]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) )
[1783]724                CALL netcdf_handle_error( 'check_open', 24 )
[493]725                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1804]726#if defined( __parallel )
[1745]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
[1783]739             CALL netcdf_create_file( filename, id_set_xz(av), .TRUE., 25 )
[493]740
741!
[1]742!--          Define the header
[1783]743             CALL netcdf_define_header( 'xz', netcdf_extend, av )
[1]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
[1783]775             CALL netcdf_open_write_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.
[1783]780             CALL netcdf_define_header( 'yz', netcdf_extend, av )
[1]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) )
[1783]786                CALL netcdf_handle_error( 'check_open', 27 )
[493]787                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1804]788#if defined( __parallel )
[1745]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
[1783]801             CALL netcdf_create_file( filename, id_set_yz(av), .TRUE., 28 )
[493]802
803!
[1]804!--          Define the header
[1783]805             CALL netcdf_define_header( 'yz', netcdf_extend, av )
[1]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
[1783]831             CALL netcdf_open_write_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.
[1783]836             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
[1]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 )
[1783]842                CALL netcdf_handle_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
[1783]851             CALL netcdf_create_file( filename, id_set_pr, .FALSE., 31 )
[1]852!
853!--          Define the header
[1783]854             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
[1]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
[1783]871             CALL netcdf_open_write_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.
[1783]876             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
[1]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 )
[1783]882                CALL netcdf_handle_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
[1783]891             CALL netcdf_create_file( filename, id_set_ts, .FALSE., 34 )
[1]892!
893!--          Define the header
[1783]894             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
[1]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
[1783]918             CALL netcdf_open_write_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.
[1783]923             CALL netcdf_define_header( '3d', netcdf_extend, av )
[1]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) )
[1783]929                CALL netcdf_handle_error( 'check_open', 36 )
[1745]930                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1804]931#if defined( __parallel )
[1745]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
[1783]945             CALL netcdf_create_file( filename, id_set_3d(av), .TRUE., 37 )
[493]946
947!
[1]948!--          Define the header
[1783]949             CALL netcdf_define_header( '3d', netcdf_extend, av )
[1]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
[1783]976             CALL netcdf_open_write_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.
[1783]982             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
[1]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 )
[1783]988                CALL netcdf_handle_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
[1783]997             CALL netcdf_create_file( filename, id_set_sp, .FALSE., 40 )
[1]998!
999!--          Define the header
[1783]1000             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
[1]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
[1783]1021             CALL netcdf_open_write_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.
[1783]1026             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
[1]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 )
[1783]1032                CALL netcdf_handle_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
[1804]1048#if defined( __parallel )
[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
[1783]1058             CALL netcdf_create_file( filename, id_set_prt, .FALSE., 43 )
[519]1059
1060!
[1]1061!--          Define the header
[1783]1062             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
[1]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
[1783]1079             CALL netcdf_open_write_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.
[1783]1084             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
[1]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 )
[1783]1090                CALL netcdf_handle_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
[1783]1099             CALL netcdf_create_file( filename, id_set_pts, .FALSE., 395 )
[1]1100!
1101!--          Define the header
[1783]1102             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
[1]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' )
[1957]1113!
1114!--    nc-file for virtual flight measurements
1115       CASE ( 199 )
1116!
1117!--       Set filename
1118          filename = 'DATA_1D_FL_NETCDF' // TRIM( coupling_char )
[1468]1119
[1957]1120!
1121!--       Inquire, if there is a netCDF file from a previuos run. This should
1122!--       be opened for extension, if its variables match the actual run.
1123          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1468]1124
[1957]1125          IF ( netcdf_extend )  THEN
1126!
1127!--          Open an existing netCDF file for output
1128             CALL netcdf_open_write_file( filename, id_set_fl, .FALSE., 532 )
1129!
1130!--          Read header information and set all ids. If there is a mismatch
1131!--          between the previuos and the actual run, netcdf_extend is returned
1132!--          as .FALSE.
1133             CALL netcdf_define_header( 'fl', netcdf_extend, 0 )
1134
1135!
1136!--          Remove the local file, if it can not be extended
1137             IF ( .NOT. netcdf_extend )  THEN
1138                nc_stat = NF90_CLOSE( id_set_fl )
1139                CALL netcdf_handle_error( 'check_open', 533 )
1140                CALL local_system( 'rm ' // TRIM( filename ) )
1141             ENDIF
1142
1143          ENDIF         
1144
1145          IF ( .NOT. netcdf_extend )  THEN
1146!
1147!--          Create a new netCDF output file with requested netCDF format
1148             CALL netcdf_create_file( filename, id_set_fl, .FALSE., 534 )
1149!
1150!--          Define the header
1151             CALL netcdf_define_header( 'fl', netcdf_extend, 0 )
1152
1153          ENDIF
1154
1155
[564]1156       CASE ( 201:200+2*max_masks )
[410]1157!
1158!--       Set filename depending on unit number
[564]1159          IF ( file_id <= 200+max_masks )  THEN
1160             mid = file_id - 200
[410]1161             WRITE ( mask_char,'(I2.2)')  mid
[1779]1162             filename = 'DATA_MASK_' // mask_char // '_NETCDF' //              &
1163                        TRIM( coupling_char )
[410]1164             av = 0
1165          ELSE
[564]1166             mid = file_id - (200+max_masks)
[410]1167             WRITE ( mask_char,'(I2.2)')  mid
[1320]1168             filename = 'DATA_MASK_' // mask_char // '_AV_NETCDF' //           &
[1779]1169                        TRIM( coupling_char )
[410]1170             av = 1
1171          ENDIF
1172!
[1031]1173!--       Inquire, if there is a netCDF file from a previuos run. This should
[410]1174!--       be opened for extension, if its dimensions and variables match the
1175!--       actual run.
1176          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1177
1178          IF ( netcdf_extend )  THEN
1179!
[1031]1180!--          Open an existing netCDF file for output
[1783]1181             CALL netcdf_open_write_file( filename, id_set_mask(mid,av),       &
[1031]1182                                          .TRUE., 456 )
[410]1183!
1184!--          Read header information and set all ids. If there is a mismatch
1185!--          between the previuos and the actual run, netcdf_extend is returned
1186!--          as .FALSE.
[1783]1187             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
[1]1188
[410]1189!
1190!--          Remove the local file, if it can not be extended
1191             IF ( .NOT. netcdf_extend )  THEN
1192                nc_stat = NF90_CLOSE( id_set_mask(mid,av) )
[1783]1193                CALL netcdf_handle_error( 'check_open', 457 )
[410]1194                CALL local_system('rm ' // TRIM( filename ) )
1195             ENDIF
[1]1196
[410]1197          ENDIF         
1198
1199          IF ( .NOT. netcdf_extend )  THEN
[1]1200!
[1031]1201!--          Create a new netCDF output file with requested netCDF format
[1783]1202             CALL netcdf_create_file( filename, id_set_mask(mid,av), .TRUE., 458 )
[493]1203!
[410]1204!--          Define the header
[1783]1205             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
[410]1206
1207          ENDIF
1208
1209
1210#else
1211
[564]1212       CASE ( 101:109, 111:113, 116, 201:200+2*max_masks )
[410]1213
1214!
[1]1215!--       Nothing is done in case of missing netcdf support
1216          RETURN
1217
1218#endif
1219
1220       CASE DEFAULT
1221
[247]1222          WRITE( message_string, * ) 'no OPEN-statement for file-id ',file_id
[277]1223          CALL message( 'check_open', 'PA0172', 2, 2, -1, 6, 1 )
[1]1224
1225    END SELECT
1226
1227!
1228!-- Set open flag
1229    openfile(file_id)%opened = .TRUE.
1230
1231!
1232!-- Formats
[1320]12333300 FORMAT ('#'/                                                              &
1234             'coord 1  file=',A,'  filetype=unformatted'/                      &
1235             'coord 2  file=',A,'  filetype=unformatted  skip=',I6/            &
1236             'coord 3  file=',A,'  filetype=unformatted  skip=',I6/            &
[1]1237             '#')
12384000 FORMAT ('# ',A)
[1320]12395000 FORMAT ('# ',A/                                                           &
1240             '#1 E'/'#2 E*'/'#3 dt'/'#4 u*'/'#5 th*'/'#6 umax'/'#7 vmax'/      &
1241             '#8 wmax'/'#9 div_new'/'#10 div_old'/'#11 z_i_wpt'/'#12 z_i_pt'/  &
1242             '#13 w*'/'#14 w''pt''0'/'#15 w''pt'''/'#16 wpt'/'#17 pt(0)'/      &
[1]1243             '#18 pt(zp)'/'#19 splptx'/'#20 splpty'/'#21 splptz')
[1320]12448000 FORMAT (A/                                                                &
[1359]1245             '  step    time    # of parts     lPE sent/recv  rPE sent/recv  ',&
1246             'sPE sent/recv  nPE sent/recv    max # of parts  '/               &
1247             109('-'))
[1]1248
1249 END SUBROUTINE check_open
Note: See TracBrowser for help on using the repository browser.