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

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

last commit documented

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