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

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

informative message added if files cannot be opened in newly created directory

  • Property svn:keywords set to Id
File size: 46.5 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! informative message added if files cannot be opened in newly created directory
22!
23! Former revisions:
24! -----------------
25! $Id: check_open.f90 1988 2016-08-10 14:49:06Z 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 )  THEN
342                   WRITE( 9, * )  '*** could not open "BINOUT'//         &
343                                  TRIM(coupling_char)//'/'//myid_char//  &
344                                  '"! Trying again in 1 sec.'
345                   CALL fortran_sleep( 1 )
346                ENDIF
347             ENDDO
348
349          ENDIF
350
351       CASE ( 15 )
352
353          OPEN ( 15, FILE='RUN_CONTROL'//TRIM( coupling_char ),                &
354                     FORM='FORMATTED' )
355
356       CASE ( 16 )
357
358          OPEN ( 16, FILE='LIST_PROFIL'//TRIM( coupling_char ),                &
359                     FORM='FORMATTED' )
360
361       CASE ( 17 )
362
363          OPEN ( 17, FILE='LIST_PROFIL_1D'//TRIM( coupling_char ),             &
364                     FORM='FORMATTED' )
365
366       CASE ( 18 )
367
368          OPEN ( 18, FILE='CPU_MEASURES'//TRIM( coupling_char ),               &
369                     FORM='FORMATTED' )
370
371       CASE ( 19 )
372
373          OPEN ( 19, FILE='HEADER'//TRIM( coupling_char ), FORM='FORMATTED' )
374
375       CASE ( 20 )
376
377          IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
378             CALL local_system( 'mkdir  DATA_LOG' // TRIM( coupling_char ) )
379          ENDIF
380          IF ( myid_char == '' )  THEN
381             OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/_000000',    &
382                        FORM='UNFORMATTED', POSITION='APPEND' )
383          ELSE
384#if defined( __parallel )
385!
386!--          Set a barrier in order to allow that all other processors in the
387!--          directory created by PE0 can open their file
388             CALL MPI_BARRIER( comm2d, ierr )
389#endif
390             ioerr = 1
391             DO WHILE ( ioerr /= 0 )
392                OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/'//       &
393                           myid_char, FORM='UNFORMATTED', POSITION='APPEND',   &
394                           IOSTAT=ioerr )
395                IF ( ioerr /= 0 )  THEN
396                   WRITE( 9, * )  '*** could not open "DATA_LOG'//         &
397                                  TRIM( coupling_char )//'/'//myid_char//  &
398                                  '"! Trying again in 1 sec.'
399                   CALL fortran_sleep( 1 )
400                ENDIF
401             ENDDO
402
403          ENDIF
404
405       CASE ( 21 )
406
407          IF ( data_output_2d_on_each_pe )  THEN
408             OPEN ( 21, FILE='PLOT2D_XY'//TRIM( coupling_char )//myid_char,    &
409                        FORM='UNFORMATTED', POSITION='APPEND' )
410          ELSE
411             OPEN ( 21, FILE='PLOT2D_XY'//TRIM( coupling_char ),                       &
412                        FORM='UNFORMATTED', POSITION='APPEND' )
413          ENDIF
414
415          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
416!
417!--          Output for combine_plot_fields
418             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
419                WRITE (21)  -nbgp, nx+nbgp, -nbgp, ny+nbgp    ! total array size
420                WRITE (21)   0, nx+1,  0, ny+1    ! output part
421             ENDIF
422!
423!--          Determine and write ISO2D coordiante header
424             ALLOCATE( eta(0:ny+1), ho(0:nx+1), hu(0:nx+1) )
425             hu = 0.0_wp
426             ho = (ny+1) * dy
427             DO  i = 1, ny
428                eta(i) = REAL( i ) / ( ny + 1.0_wp )
429             ENDDO
430             eta(0)    = 0.0_wp
431             eta(ny+1) = 1.0_wp
432
433             WRITE (21)  dx,eta,hu,ho
434             DEALLOCATE( eta, ho, hu )
435
436          ENDIF
437
438       CASE ( 22 )
439
440          IF ( data_output_2d_on_each_pe )  THEN
441             OPEN ( 22, FILE='PLOT2D_XZ'//TRIM( coupling_char )//myid_char,    &
442                        FORM='UNFORMATTED', POSITION='APPEND' )
443          ELSE
444             OPEN ( 22, FILE='PLOT2D_XZ'//TRIM( coupling_char ),               &
445                        FORM='UNFORMATTED', POSITION='APPEND' )
446          ENDIF
447
448          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
449!
450!--          Output for combine_plot_fields
451             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
452                WRITE (22)  -nbgp, nx+nbgp, 0, nz+1    ! total array size
453                WRITE (22)   0, nx+1, 0, nz+1    ! output part
454             ENDIF
455!
456!--          Determine and write ISO2D coordinate header
457             ALLOCATE( eta(0:nz+1), ho(0:nx+1), hu(0:nx+1) )
458             hu = 0.0_wp
459             ho = zu(nz+1)
460             DO  i = 1, nz
461                eta(i) = REAL( zu(i) ) / zu(nz+1)
462             ENDDO
463             eta(0)    = 0.0_wp
464             eta(nz+1) = 1.0_wp
465
466             WRITE (22)  dx,eta,hu,ho
467             DEALLOCATE( eta, ho, hu )
468
469          ENDIF
470
471       CASE ( 23 )
472
473          IF ( data_output_2d_on_each_pe )  THEN
474             OPEN ( 23, FILE='PLOT2D_YZ'//TRIM( coupling_char )//myid_char,    &
475                        FORM='UNFORMATTED', POSITION='APPEND' )
476          ELSE
477             OPEN ( 23, FILE='PLOT2D_YZ'//TRIM( coupling_char ),               &
478                        FORM='UNFORMATTED', POSITION='APPEND' )
479          ENDIF
480
481          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
482!
483!--          Output for combine_plot_fields
484             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
485                WRITE (23)  -nbgp, ny+nbgp, 0, nz+1    ! total array size
486                WRITE (23)   0, ny+1, 0, nz+1    ! output part
487             ENDIF
488!
489!--          Determine and write ISO2D coordiante header
490             ALLOCATE( eta(0:nz+1), ho(0:ny+1), hu(0:ny+1) )
491             hu = 0.0_wp
492             ho = zu(nz+1)
493             DO  i = 1, nz
494                eta(i) = REAL( zu(i) ) / zu(nz+1)
495             ENDDO
496             eta(0)    = 0.0_wp
497             eta(nz+1) = 1.0_wp
498
499             WRITE (23)  dx,eta,hu,ho
500             DEALLOCATE( eta, ho, hu )
501
502          ENDIF
503
504       CASE ( 30 )
505
506          OPEN ( 30, FILE='PLOT3D_DATA'//TRIM( coupling_char )//myid_char,     &
507                     FORM='UNFORMATTED' )
508!
509!--       Write coordinate file for AVS
510          IF ( myid == 0 )  THEN
511#if defined( __parallel )
512!
513!--          Specifications for combine_plot_fields
514             WRITE ( 30 )  -nbgp,nx+nbgp,-nbgp,ny+nbgp
515             WRITE ( 30 )  0,nx+1,0,ny+1,0,nz_do3d
516#endif
517          ENDIF
518
519       CASE ( 50:59 )
520
521          IF ( statistic_regions == 0  .AND.  file_id == 50 )  THEN
522             suffix = ''
523          ELSE
524             WRITE ( suffix, '(''_'',I1)' )  file_id - 50
525          ENDIF
526          OPEN ( file_id, FILE='PLOTTS_DATA'//TRIM( coupling_char )//          &
527                               TRIM( suffix ),                                 &
528                          FORM='FORMATTED', RECL=496 )
529!
530!--       Write PROFIL parameter file for output of time series
531!--       NOTE: To be on the safe side, this output is done at the beginning of
532!--             the model run (in case of collapse) and it is repeated in
533!--             close_file, then, however, with value ranges for the coordinate
534!--             systems
535!
536!--       Firstly determine the number of the coordinate systems to be drawn
537          cranz = 0
538          DO  j = 1, 10
539             IF ( cross_ts_number_count(j) /= 0 )  cranz = cranz+1
540          ENDDO
541          rtext = '\1.0 ' // TRIM( run_description_header ) // '    ' //       &
542                  TRIM( region( file_id - 50 ) )
543!
544!--       Write RAHMEN parameter
545          OPEN ( 90, FILE='PLOTTS_PAR'//TRIM( coupling_char )//                &
546                           TRIM( suffix ),                                     &
547                     FORM='FORMATTED', DELIM='APOSTROPHE' )
548          WRITE ( 90, RAHMEN )
549!
550!--       Determine and write CROSS parameters for the individual coordinate
551!--       systems
552          DO  j = 1, 10
553             k = cross_ts_number_count(j)
554             IF ( k /= 0 )  THEN
555!
556!--             Store curve numbers, colours and line style
557                klist(1:k) = cross_ts_numbers(1:k,j)
558                klist(k+1:10) = 999999
559!
560!--             Write CROSS parameter
561                WRITE ( 90, CROSS )
562
563             ENDIF
564          ENDDO
565
566          CLOSE ( 90 )
567!
568!--       Write all labels at the top of the data file, but only during the
569!--       first run of a sequence of jobs. The following jobs copy the time
570!--       series data to the bottom of that file.
571          IF ( runnr == 0 )  THEN
572             WRITE ( file_id, 5000 )  TRIM( run_description_header ) //        &
573                                      '    ' // TRIM( region( file_id - 50 ) )
574          ENDIF
575
576
577       CASE ( 80 )
578
579          IF ( myid_char == '' )  THEN
580             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM(coupling_char)//myid_char, &
581                        FORM='FORMATTED', POSITION='APPEND' )
582          ELSE
583             IF ( myid == 0  .AND.  .NOT. openfile(80)%opened_before )  THEN
584                CALL local_system( 'mkdir  PARTICLE_INFOS' //                  &
585                                   TRIM( coupling_char ) )
586             ENDIF
587#if defined( __parallel )
588!
589!--          Set a barrier in order to allow that thereafter all other
590!--          processors in the directory created by PE0 can open their file.
591!--          WARNING: The following barrier will lead to hanging jobs, if
592!--                   check_open is first called from routine
593!--                   allocate_prt_memory!
594             IF ( .NOT. openfile(80)%opened_before )  THEN
595                CALL MPI_BARRIER( comm2d, ierr )
596             ENDIF
597#endif
598             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM( coupling_char )//'/'//    &
599                             myid_char,                                        &
600                        FORM='FORMATTED', POSITION='APPEND' )
601          ENDIF
602
603          IF ( .NOT. openfile(80)%opened_before )  THEN
604             WRITE ( 80, 8000 )  TRIM( run_description_header )
605          ENDIF
606
607       CASE ( 81 )
608
609             OPEN ( 81, FILE='PLOTSP_X_PAR'//TRIM( coupling_char ),            &
610                        FORM='FORMATTED', DELIM='APOSTROPHE', RECL=1500,       &
611                        POSITION='APPEND' )
612
613       CASE ( 82 )
614
615             OPEN ( 82, FILE='PLOTSP_X_DATA'//TRIM( coupling_char ),           &
616                        FORM='FORMATTED', POSITION = 'APPEND' )
617
618       CASE ( 83 )
619
620             OPEN ( 83, FILE='PLOTSP_Y_PAR'//TRIM( coupling_char ),            &
621                        FORM='FORMATTED', DELIM='APOSTROPHE', RECL=1500,       &
622                        POSITION='APPEND' )
623
624       CASE ( 84 )
625
626             OPEN ( 84, FILE='PLOTSP_Y_DATA'//TRIM( coupling_char ),           &
627                        FORM='FORMATTED', POSITION='APPEND' )
628
629       CASE ( 85 )
630
631          IF ( myid_char == '' )  THEN
632             OPEN ( 85, FILE='PARTICLE_DATA'//TRIM(coupling_char)//myid_char,  &
633                        FORM='UNFORMATTED', POSITION='APPEND' )
634          ELSE
635             IF ( myid == 0  .AND.  .NOT. openfile(85)%opened_before )  THEN
636                CALL local_system( 'mkdir  PARTICLE_DATA' //                   &
637                                   TRIM( coupling_char ) )
638             ENDIF
639#if defined( __parallel )
640!
641!--          Set a barrier in order to allow that thereafter all other
642!--          processors in the directory created by PE0 can open their file
643             CALL MPI_BARRIER( comm2d, ierr )
644#endif
645             ioerr = 1
646             DO WHILE ( ioerr /= 0 )
647                OPEN ( 85, FILE='PARTICLE_DATA'//TRIM( coupling_char )//'/'//  &
648                           myid_char,                                          &
649                           FORM='UNFORMATTED', POSITION='APPEND', IOSTAT=ioerr )
650                IF ( ioerr /= 0 )  THEN
651                   WRITE( 9, * )  '*** could not open "PARTICLE_DATA'//    &
652                                  TRIM( coupling_char )//'/'//myid_char//  &
653                                  '"! Trying again in 1 sec.'
654                   CALL fortran_sleep( 1 )
655                ENDIF
656             ENDDO
657
658          ENDIF
659
660          IF ( .NOT. openfile(85)%opened_before )  THEN
661             WRITE ( 85 )  run_description_header
662!
663!--          Attention: change version number whenever the output format on
664!--                     unit 85 is changed (see also in routine
665!--                     lpm_data_output_particles)
666             rtext = 'data format version 3.1'
667             WRITE ( 85 )  rtext
668             WRITE ( 85 )  number_of_particle_groups,                          &
669                           max_number_of_particle_groups
670             WRITE ( 85 )  particle_groups
671             WRITE ( 85 )  nxl, nxr, nys, nyn, nzb, nzt, nbgp
672          ENDIF
673
674#if defined( __netcdf )
675       CASE ( 101, 111 )
676!
677!--       Set filename depending on unit number
678          IF ( file_id == 101 )  THEN
679             filename = 'DATA_2D_XY_NETCDF' // TRIM( coupling_char )
680             av = 0
681          ELSE
682             filename = 'DATA_2D_XY_AV_NETCDF' // TRIM( coupling_char )
683             av = 1
684          ENDIF
685!
686!--       Inquire, if there is a netCDF file from a previuos run. This should
687!--       be opened for extension, if its dimensions and variables match the
688!--       actual run.
689          INQUIRE( FILE=filename, EXIST=netcdf_extend )
690          IF ( netcdf_extend )  THEN
691!
692!--          Open an existing netCDF file for output
693             CALL netcdf_open_write_file( filename, id_set_xy(av), .TRUE., 20 )
694!
695!--          Read header information and set all ids. If there is a mismatch
696!--          between the previuos and the actual run, netcdf_extend is returned
697!--          as .FALSE.
698             CALL netcdf_define_header( 'xy', netcdf_extend, av )
699
700!
701!--          Remove the local file, if it can not be extended
702             IF ( .NOT. netcdf_extend )  THEN
703                nc_stat = NF90_CLOSE( id_set_xy(av) )
704                CALL netcdf_handle_error( 'check_open', 21 )
705                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
706#if defined( __parallel )
707!
708!--             Set a barrier in order to assure that PE0 deleted the old file
709!--             before any other processor tries to open a new file.
710!--             Barrier is only needed in case of parallel I/O
711                IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
712#endif
713             ENDIF
714
715          ENDIF
716
717          IF ( .NOT. netcdf_extend )  THEN
718!
719!--          Create a new netCDF output file with requested netCDF format
720             CALL netcdf_create_file( filename, id_set_xy(av), .TRUE., 22 )
721
722!
723!--          Define the header
724             CALL netcdf_define_header( 'xy', netcdf_extend, av )
725
726!
727!--          In case of parallel netCDF output, create flag file which tells
728!--          combine_plot_fields that nothing is to do.
729             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
730                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XY' )
731                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
732                CLOSE( 99 )
733             ENDIF
734
735          ENDIF
736
737       CASE ( 102, 112 )
738!
739!--       Set filename depending on unit number
740          IF ( file_id == 102 )  THEN
741             filename = 'DATA_2D_XZ_NETCDF' // TRIM( coupling_char )
742             av = 0
743          ELSE
744             filename = 'DATA_2D_XZ_AV_NETCDF' // TRIM( coupling_char )
745             av = 1
746          ENDIF
747!
748!--       Inquire, if there is a netCDF file from a previuos run. This should
749!--       be opened for extension, if its dimensions and variables match the
750!--       actual run.
751          INQUIRE( FILE=filename, EXIST=netcdf_extend )
752
753          IF ( netcdf_extend )  THEN
754!
755!--          Open an existing netCDF file for output
756             CALL netcdf_open_write_file( filename, id_set_xz(av), .TRUE., 23 )
757!
758!--          Read header information and set all ids. If there is a mismatch
759!--          between the previuos and the actual run, netcdf_extend is returned
760!--          as .FALSE.
761             CALL netcdf_define_header( 'xz', netcdf_extend, av )
762
763!
764!--          Remove the local file, if it can not be extended
765             IF ( .NOT. netcdf_extend )  THEN
766                nc_stat = NF90_CLOSE( id_set_xz(av) )
767                CALL netcdf_handle_error( 'check_open', 24 )
768                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
769#if defined( __parallel )
770!
771!--             Set a barrier in order to assure that PE0 deleted the old file
772!--             before any other processor tries to open a new file
773!--             Barrier is only needed in case of parallel I/O
774                IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
775#endif
776             ENDIF
777
778          ENDIF
779
780          IF ( .NOT. netcdf_extend )  THEN
781!
782!--          Create a new netCDF output file with requested netCDF format
783             CALL netcdf_create_file( filename, id_set_xz(av), .TRUE., 25 )
784
785!
786!--          Define the header
787             CALL netcdf_define_header( 'xz', netcdf_extend, av )
788
789!
790!--          In case of parallel netCDF output, create flag file which tells
791!--          combine_plot_fields that nothing is to do.
792             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
793                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XZ' )
794                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
795                CLOSE( 99 )
796             ENDIF
797
798          ENDIF
799
800       CASE ( 103, 113 )
801!
802!--       Set filename depending on unit number
803          IF ( file_id == 103 )  THEN
804             filename = 'DATA_2D_YZ_NETCDF' // TRIM( coupling_char )
805             av = 0
806          ELSE
807             filename = 'DATA_2D_YZ_AV_NETCDF' // TRIM( coupling_char )
808             av = 1
809          ENDIF
810!
811!--       Inquire, if there is a netCDF file from a previuos run. This should
812!--       be opened for extension, if its dimensions and variables match the
813!--       actual run.
814          INQUIRE( FILE=filename, EXIST=netcdf_extend )
815
816          IF ( netcdf_extend )  THEN
817!
818!--          Open an existing netCDF file for output
819             CALL netcdf_open_write_file( filename, id_set_yz(av), .TRUE., 26 )
820!
821!--          Read header information and set all ids. If there is a mismatch
822!--          between the previuos and the actual run, netcdf_extend is returned
823!--          as .FALSE.
824             CALL netcdf_define_header( 'yz', netcdf_extend, av )
825
826!
827!--          Remove the local file, if it can not be extended
828             IF ( .NOT. netcdf_extend )  THEN
829                nc_stat = NF90_CLOSE( id_set_yz(av) )
830                CALL netcdf_handle_error( 'check_open', 27 )
831                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
832#if defined( __parallel )
833!
834!--             Set a barrier in order to assure that PE0 deleted the old file
835!--             before any other processor tries to open a new file
836!--             Barrier is only needed in case of parallel I/O
837                IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
838#endif
839             ENDIF
840
841          ENDIF
842
843          IF ( .NOT. netcdf_extend )  THEN
844!
845!--          Create a new netCDF output file with requested netCDF format
846             CALL netcdf_create_file( filename, id_set_yz(av), .TRUE., 28 )
847
848!
849!--          Define the header
850             CALL netcdf_define_header( 'yz', netcdf_extend, av )
851
852!
853!--          In case of parallel netCDF output, create flag file which tells
854!--          combine_plot_fields that nothing is to do.
855             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
856                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_YZ' )
857                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
858                CLOSE( 99 )
859             ENDIF
860
861          ENDIF
862
863       CASE ( 104 )
864!
865!--       Set filename
866          filename = 'DATA_1D_PR_NETCDF' // TRIM( coupling_char )
867
868!
869!--       Inquire, if there is a netCDF file from a previuos run. This should
870!--       be opened for extension, if its variables match the actual run.
871          INQUIRE( FILE=filename, EXIST=netcdf_extend )
872
873          IF ( netcdf_extend )  THEN
874!
875!--          Open an existing netCDF file for output
876             CALL netcdf_open_write_file( filename, id_set_pr, .FALSE., 29 )
877!
878!--          Read header information and set all ids. If there is a mismatch
879!--          between the previuos and the actual run, netcdf_extend is returned
880!--          as .FALSE.
881             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
882
883!
884!--          Remove the local file, if it can not be extended
885             IF ( .NOT. netcdf_extend )  THEN
886                nc_stat = NF90_CLOSE( id_set_pr )
887                CALL netcdf_handle_error( 'check_open', 30 )
888                CALL local_system( 'rm ' // TRIM( filename ) )
889             ENDIF
890
891          ENDIF         
892
893          IF ( .NOT. netcdf_extend )  THEN
894!
895!--          Create a new netCDF output file with requested netCDF format
896             CALL netcdf_create_file( filename, id_set_pr, .FALSE., 31 )
897!
898!--          Define the header
899             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
900
901          ENDIF
902
903       CASE ( 105 )
904!
905!--       Set filename
906          filename = 'DATA_1D_TS_NETCDF' // TRIM( coupling_char )
907
908!
909!--       Inquire, if there is a netCDF file from a previuos run. This should
910!--       be opened for extension, if its variables match the actual run.
911          INQUIRE( FILE=filename, EXIST=netcdf_extend )
912
913          IF ( netcdf_extend )  THEN
914!
915!--          Open an existing netCDF file for output
916             CALL netcdf_open_write_file( filename, id_set_ts, .FALSE., 32 )
917!
918!--          Read header information and set all ids. If there is a mismatch
919!--          between the previuos and the actual run, netcdf_extend is returned
920!--          as .FALSE.
921             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
922
923!
924!--          Remove the local file, if it can not be extended
925             IF ( .NOT. netcdf_extend )  THEN
926                nc_stat = NF90_CLOSE( id_set_ts )
927                CALL netcdf_handle_error( 'check_open', 33 )
928                CALL local_system( 'rm ' // TRIM( filename ) )
929             ENDIF
930
931          ENDIF         
932
933          IF ( .NOT. netcdf_extend )  THEN
934!
935!--          Create a new netCDF output file with requested netCDF format
936             CALL netcdf_create_file( filename, id_set_ts, .FALSE., 34 )
937!
938!--          Define the header
939             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
940
941          ENDIF
942
943
944       CASE ( 106, 116 )
945!
946!--       Set filename depending on unit number
947          IF ( file_id == 106 )  THEN
948             filename = 'DATA_3D_NETCDF' // TRIM( coupling_char )
949             av = 0
950          ELSE
951             filename = 'DATA_3D_AV_NETCDF' // TRIM( coupling_char )
952             av = 1
953          ENDIF
954!
955!--       Inquire, if there is a netCDF file from a previous run. This should
956!--       be opened for extension, if its dimensions and variables match the
957!--       actual run.
958          INQUIRE( FILE=filename, EXIST=netcdf_extend )
959
960          IF ( netcdf_extend )  THEN
961!
962!--          Open an existing netCDF file for output
963             CALL netcdf_open_write_file( filename, id_set_3d(av), .TRUE., 35 )
964!
965!--          Read header information and set all ids. If there is a mismatch
966!--          between the previuos and the actual run, netcdf_extend is returned
967!--          as .FALSE.
968             CALL netcdf_define_header( '3d', netcdf_extend, av )
969
970!
971!--          Remove the local file, if it can not be extended
972             IF ( .NOT. netcdf_extend )  THEN
973                nc_stat = NF90_CLOSE( id_set_3d(av) )
974                CALL netcdf_handle_error( 'check_open', 36 )
975                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
976#if defined( __parallel )
977!
978!--             Set a barrier in order to assure that PE0 deleted the old file
979!--             before any other processor tries to open a new file
980!--             Barrier is only needed in case of parallel I/O
981                IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
982#endif
983             ENDIF
984
985          ENDIF
986
987          IF ( .NOT. netcdf_extend )  THEN
988!
989!--          Create a new netCDF output file with requested netCDF format
990             CALL netcdf_create_file( filename, id_set_3d(av), .TRUE., 37 )
991
992!
993!--          Define the header
994             CALL netcdf_define_header( '3d', netcdf_extend, av )
995
996!
997!--          In case of parallel netCDF output, create flag file which tells
998!--          combine_plot_fields that nothing is to do.
999             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
1000                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_3D' )
1001                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
1002                CLOSE( 99 )
1003             ENDIF
1004
1005          ENDIF
1006
1007
1008       CASE ( 107 )
1009!
1010!--       Set filename
1011          filename = 'DATA_1D_SP_NETCDF' // TRIM( coupling_char )
1012
1013!
1014!--       Inquire, if there is a netCDF file from a previuos run. This should
1015!--       be opened for extension, if its variables match the actual run.
1016          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1017
1018          IF ( netcdf_extend )  THEN
1019!
1020!--          Open an existing netCDF file for output
1021             CALL netcdf_open_write_file( filename, id_set_sp, .FALSE., 38 )
1022
1023!
1024!--          Read header information and set all ids. If there is a mismatch
1025!--          between the previuos and the actual run, netcdf_extend is returned
1026!--          as .FALSE.
1027             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
1028
1029!
1030!--          Remove the local file, if it can not be extended
1031             IF ( .NOT. netcdf_extend )  THEN
1032                nc_stat = NF90_CLOSE( id_set_sp )
1033                CALL netcdf_handle_error( 'check_open', 39 )
1034                CALL local_system( 'rm ' // TRIM( filename ) )
1035             ENDIF
1036
1037          ENDIF         
1038
1039          IF ( .NOT. netcdf_extend )  THEN
1040!
1041!--          Create a new netCDF output file with requested netCDF format
1042             CALL netcdf_create_file( filename, id_set_sp, .FALSE., 40 )
1043!
1044!--          Define the header
1045             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
1046
1047          ENDIF
1048
1049
1050       CASE ( 108 )
1051
1052          IF ( myid_char == '' )  THEN
1053             filename = 'DATA_PRT_NETCDF' // TRIM( coupling_char )
1054          ELSE
1055             filename = 'DATA_PRT_NETCDF' // TRIM( coupling_char ) // '/' //   &
1056                        myid_char
1057          ENDIF
1058!
1059!--       Inquire, if there is a netCDF file from a previuos run. This should
1060!--       be opened for extension, if its variables match the actual run.
1061          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1062
1063          IF ( netcdf_extend )  THEN
1064!
1065!--          Open an existing netCDF file for output
1066             CALL netcdf_open_write_file( filename, id_set_prt, .FALSE., 41 )
1067!
1068!--          Read header information and set all ids. If there is a mismatch
1069!--          between the previuos and the actual run, netcdf_extend is returned
1070!--          as .FALSE.
1071             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
1072
1073!
1074!--          Remove the local file, if it can not be extended
1075             IF ( .NOT. netcdf_extend )  THEN
1076                nc_stat = NF90_CLOSE( id_set_prt )
1077                CALL netcdf_handle_error( 'check_open', 42 )
1078                CALL local_system( 'rm ' // TRIM( filename ) )
1079             ENDIF
1080
1081          ENDIF         
1082
1083          IF ( .NOT. netcdf_extend )  THEN
1084
1085!
1086!--          For runs on multiple processors create the subdirectory
1087             IF ( myid_char /= '' )  THEN
1088                IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  &
1089                THEN    ! needs modification in case of non-extendable sets
1090                   CALL local_system( 'mkdir  DATA_PRT_NETCDF' //              &
1091                                       TRIM( coupling_char ) // '/' )
1092                ENDIF
1093#if defined( __parallel )
1094!
1095!--             Set a barrier in order to allow that all other processors in the
1096!--             directory created by PE0 can open their file
1097                CALL MPI_BARRIER( comm2d, ierr )
1098#endif
1099             ENDIF
1100
1101!
1102!--          Create a new netCDF output file with requested netCDF format
1103             CALL netcdf_create_file( filename, id_set_prt, .FALSE., 43 )
1104
1105!
1106!--          Define the header
1107             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
1108
1109          ENDIF
1110
1111       CASE ( 109 )
1112!
1113!--       Set filename
1114          filename = 'DATA_1D_PTS_NETCDF' // TRIM( coupling_char )
1115
1116!
1117!--       Inquire, if there is a netCDF file from a previuos run. This should
1118!--       be opened for extension, if its variables match the actual run.
1119          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1120
1121          IF ( netcdf_extend )  THEN
1122!
1123!--          Open an existing netCDF file for output
1124             CALL netcdf_open_write_file( filename, id_set_pts, .FALSE., 393 )
1125!
1126!--          Read header information and set all ids. If there is a mismatch
1127!--          between the previuos and the actual run, netcdf_extend is returned
1128!--          as .FALSE.
1129             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
1130
1131!
1132!--          Remove the local file, if it can not be extended
1133             IF ( .NOT. netcdf_extend )  THEN
1134                nc_stat = NF90_CLOSE( id_set_pts )
1135                CALL netcdf_handle_error( 'check_open', 394 )
1136                CALL local_system( 'rm ' // TRIM( filename ) )
1137             ENDIF
1138
1139          ENDIF         
1140
1141          IF ( .NOT. netcdf_extend )  THEN
1142!
1143!--          Create a new netCDF output file with requested netCDF format
1144             CALL netcdf_create_file( filename, id_set_pts, .FALSE., 395 )
1145!
1146!--          Define the header
1147             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
1148
1149          ENDIF
1150
1151
1152!
1153!--    Progress file that is used by the PALM watchdog
1154       CASE ( 117 )
1155
1156          OPEN ( 117, FILE='PROGRESS'//TRIM( coupling_char ),                  &
1157                      STATUS='REPLACE', FORM='FORMATTED' )
1158!
1159!--    nc-file for virtual flight measurements
1160       CASE ( 199 )
1161!
1162!--       Set filename
1163          filename = 'DATA_1D_FL_NETCDF' // TRIM( coupling_char )
1164
1165!
1166!--       Inquire, if there is a netCDF file from a previuos run. This should
1167!--       be opened for extension, if its variables match the actual run.
1168          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1169
1170          IF ( netcdf_extend )  THEN
1171!
1172!--          Open an existing netCDF file for output
1173             CALL netcdf_open_write_file( filename, id_set_fl, .FALSE., 532 )
1174!
1175!--          Read header information and set all ids. If there is a mismatch
1176!--          between the previuos and the actual run, netcdf_extend is returned
1177!--          as .FALSE.
1178             CALL netcdf_define_header( 'fl', netcdf_extend, 0 )
1179
1180!
1181!--          Remove the local file, if it can not be extended
1182             IF ( .NOT. netcdf_extend )  THEN
1183                nc_stat = NF90_CLOSE( id_set_fl )
1184                CALL netcdf_handle_error( 'check_open', 533 )
1185                CALL local_system( 'rm ' // TRIM( filename ) )
1186             ENDIF
1187
1188          ENDIF         
1189
1190          IF ( .NOT. netcdf_extend )  THEN
1191!
1192!--          Create a new netCDF output file with requested netCDF format
1193             CALL netcdf_create_file( filename, id_set_fl, .FALSE., 534 )
1194!
1195!--          Define the header
1196             CALL netcdf_define_header( 'fl', netcdf_extend, 0 )
1197
1198          ENDIF
1199
1200
1201       CASE ( 201:200+2*max_masks )
1202!
1203!--       Set filename depending on unit number
1204          IF ( file_id <= 200+max_masks )  THEN
1205             mid = file_id - 200
1206             WRITE ( mask_char,'(I2.2)')  mid
1207             filename = 'DATA_MASK_' // mask_char // '_NETCDF' //              &
1208                        TRIM( coupling_char )
1209             av = 0
1210          ELSE
1211             mid = file_id - (200+max_masks)
1212             WRITE ( mask_char,'(I2.2)')  mid
1213             filename = 'DATA_MASK_' // mask_char // '_AV_NETCDF' //           &
1214                        TRIM( coupling_char )
1215             av = 1
1216          ENDIF
1217!
1218!--       Inquire, if there is a netCDF file from a previuos run. This should
1219!--       be opened for extension, if its dimensions and variables match the
1220!--       actual run.
1221          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1222
1223          IF ( netcdf_extend )  THEN
1224!
1225!--          Open an existing netCDF file for output
1226             CALL netcdf_open_write_file( filename, id_set_mask(mid,av),       &
1227                                          .TRUE., 456 )
1228!
1229!--          Read header information and set all ids. If there is a mismatch
1230!--          between the previuos and the actual run, netcdf_extend is returned
1231!--          as .FALSE.
1232             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
1233
1234!
1235!--          Remove the local file, if it can not be extended
1236             IF ( .NOT. netcdf_extend )  THEN
1237                nc_stat = NF90_CLOSE( id_set_mask(mid,av) )
1238                CALL netcdf_handle_error( 'check_open', 457 )
1239                CALL local_system('rm ' // TRIM( filename ) )
1240             ENDIF
1241
1242          ENDIF         
1243
1244          IF ( .NOT. netcdf_extend )  THEN
1245!
1246!--          Create a new netCDF output file with requested netCDF format
1247             CALL netcdf_create_file( filename, id_set_mask(mid,av), .TRUE., 458 )
1248!
1249!--          Define the header
1250             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
1251
1252          ENDIF
1253
1254
1255#else
1256
1257       CASE ( 101:109, 111:113, 116, 201:200+2*max_masks )
1258
1259!
1260!--       Nothing is done in case of missing netcdf support
1261          RETURN
1262
1263#endif
1264
1265       CASE DEFAULT
1266
1267          WRITE( message_string, * ) 'no OPEN-statement for file-id ',file_id
1268          CALL message( 'check_open', 'PA0172', 2, 2, -1, 6, 1 )
1269
1270    END SELECT
1271
1272!
1273!-- Set open flag
1274    openfile(file_id)%opened = .TRUE.
1275
1276!
1277!-- Formats
12783300 FORMAT ('#'/                                                              &
1279             'coord 1  file=',A,'  filetype=unformatted'/                      &
1280             'coord 2  file=',A,'  filetype=unformatted  skip=',I6/            &
1281             'coord 3  file=',A,'  filetype=unformatted  skip=',I6/            &
1282             '#')
12834000 FORMAT ('# ',A)
12845000 FORMAT ('# ',A/                                                           &
1285             '#1 E'/'#2 E*'/'#3 dt'/'#4 u*'/'#5 th*'/'#6 umax'/'#7 vmax'/      &
1286             '#8 wmax'/'#9 div_new'/'#10 div_old'/'#11 z_i_wpt'/'#12 z_i_pt'/  &
1287             '#13 w*'/'#14 w''pt''0'/'#15 w''pt'''/'#16 wpt'/'#17 pt(0)'/      &
1288             '#18 pt(zp)'/'#19 splptx'/'#20 splpty'/'#21 splptz')
12898000 FORMAT (A/                                                                &
1290             '  step    time    # of parts     lPE sent/recv  rPE sent/recv  ',&
1291             'sPE sent/recv  nPE sent/recv    max # of parts  '/               &
1292             109('-'))
1293
1294 END SUBROUTINE check_open
Note: See TracBrowser for help on using the repository browser.