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

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

last commit documented

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