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

Last change on this file since 1805 was 1805, checked in by maronga, 8 years ago

last commit documented

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