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

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

Forced header and separation lines into 80 columns

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