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

Last change on this file since 1986 was 1986, checked in by gronemeier, 8 years ago

Bugfix: check if output can be opened in newly created directory

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