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

Last change on this file since 520 was 520, checked in by raasch, 14 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 54.9 KB
Line 
1SUBROUTINE check_open( file_id )
2
3!------------------------------------------------------------------------------!
4! Current revisions:
5! -----------------
6!
7!
8! Former revisions:
9! -----------------
10! $Id: check_open.f90 520 2010-03-19 05:39:46Z raasch $
11!
12! 519 2010-03-19 05:30:02Z raasch
13! NetCDF4 support for particle data
14!
15! 493 2010-03-01 08:30:24Z raasch
16! NetCDF4 support (parallel output)
17!
18! 410 2009-12-04 17:05:40Z letzel
19! masked data output
20!
21! 277 2009-03-31 09:13:47Z heinze
22! Output of NetCDF messages with aid of message handling routine.
23! Output of messages replaced by message handling routine
24!
25! 146 2008-01-17 13:08:34Z raasch
26! First opening of unit 13 openes file _0000 on all PEs (parallel version)
27! because only this file contains the global variables,
28! myid_char_14 removed
29!
30! 120 2007-10-17 11:54:43Z raasch
31! Status of 3D-volume NetCDF data file only depends on switch netcdf_64bit_3d
32!
33! 105 2007-08-08 07:12:55Z raasch
34! Different filenames are used in case of a coupled simulation,
35! coupling_char added to all relevant filenames
36!
37! 82 2007-04-16 15:40:52Z raasch
38! Call of local_getenv removed, preprocessor directives for old systems removed
39!
40! 46 2007-03-05 06:00:47Z raasch
41! +netcdf_64bit_3d to switch on 64bit offset only for 3D files
42!
43! RCS Log replace by Id keyword, revision history cleaned up
44!
45! Revision 1.44  2006/08/22 13:48:34  raasch
46! xz and yz cross sections now up to nzt+1
47!
48! Revision 1.1  1997/08/11 06:10:55  raasch
49! Initial revision
50!
51!
52! Description:
53! ------------
54! Check if file unit is open. If not, open file and, if necessary, write a
55! header or start other initializing actions, respectively.
56!------------------------------------------------------------------------------!
57
58    USE array_kind
59    USE arrays_3d
60    USE control_parameters
61    USE grid_variables
62    USE indices
63    USE netcdf_control
64    USE particle_attributes
65    USE pegrid
66    USE profil_parameter
67    USE statistics
68
69    IMPLICIT NONE
70
71    CHARACTER (LEN=2)   ::  mask_char, suffix
72    CHARACTER (LEN=20)  ::  xtext = 'time in s'
73    CHARACTER (LEN=30)  ::  filename
74    CHARACTER (LEN=40)  ::  avs_coor_file, avs_coor_file_localname, &
75                            avs_data_file_localname
76    CHARACTER (LEN=80)  ::  rtext
77    CHARACTER (LEN=100) ::  avs_coor_file_catalog, avs_data_file_catalog, &
78                            batch_scp, zeile
79    CHARACTER (LEN=400) ::  command
80
81    INTEGER ::  av, anzzeile = 1, cranz, file_id, i, iaddres, ierr1, iusern, &
82                j, k, legpos = 1, timodex = 1
83    INTEGER, DIMENSION(10) ::  cucol, klist, lstyle
84
85    LOGICAL ::  avs_coor_file_found = .FALSE., avs_data_file_found = .FALSE., &
86                datleg = .TRUE., get_filenames, grid = .TRUE., netcdf_extend, &
87                rand = .TRUE., swap = .TRUE., twoxa = .TRUE., twoya = .TRUE.
88
89    REAL ::  ansx = -999.999, ansy = -999.999, gwid = 0.1, rlegfak = 1.5, &
90             sizex = 250.0, sizey = 40.0, texfac = 1.5
91
92    REAL, DIMENSION(:), ALLOCATABLE      ::  eta, ho, hu
93    REAL(spk), DIMENSION(:), ALLOCATABLE ::  xkoor, ykoor, zkoor 
94
95
96    NAMELIST /RAHMEN/  anzzeile, cranz, datleg, rtext, swap
97    NAMELIST /CROSS/   ansx, ansy, cucol, grid, gwid, klist, legpos, lstyle, &
98                       rand, rlegfak, sizex, sizey, texfac, &
99                       timodex, twoxa, twoya, xtext
100                       
101
102!
103!-- Immediate return if file already open
104    IF ( openfile(file_id)%opened )  RETURN
105
106!
107!-- Only certain files are allowed to be re-opened
108!-- NOTE: some of the other files perhaps also could be re-opened, but it
109!--       has not been checked so far, if it works!
110    IF ( openfile(file_id)%opened_before )  THEN
111       SELECT CASE ( file_id )
112          CASE ( 13, 14, 21, 22, 23, 80:85 )
113             IF ( file_id == 14 .AND. openfile(file_id)%opened_before )  THEN
114                message_string = 're-open of unit ' // &
115                                 '14 is not verified. Please check results!'
116                CALL message( 'check_open', 'PA0165', 0, 1, 0, 6, 0 )       
117             ENDIF
118
119          CASE DEFAULT
120             WRITE( message_string, * ) 're-opening of file-id ', file_id, &
121                                        ' is not allowed'
122             CALL message( 'check_open', 'PA0166', 0, 1, 0, 6, 0 )   
123               
124             RETURN
125
126       END SELECT
127    ENDIF
128
129!
130!-- Check if file may be opened on the relevant PE
131    SELECT CASE ( file_id )
132
133       CASE ( 15, 16, 17, 18, 19, 40:49, 50:59, 81:84, 104:105, 107, 109 )
134             
135          IF ( myid /= 0 )  THEN
136             WRITE( message_string, * ) 'opening file-id ',file_id, &
137                                        ' not allowed for PE ',myid
138             CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
139          ENDIF
140
141       CASE ( 101:103, 106, 111:113, 116, 121:160 )
142
143          IF ( netcdf_data_format < 3 )  THEN
144         
145             IF ( myid /= 0 )  THEN
146                WRITE( message_string, * ) 'opening file-id ',file_id, &
147                                           ' not allowed for PE ',myid
148                CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
149             ENDIF
150             
151          ENDIF
152
153       CASE ( 21, 22, 23 )
154
155          IF ( .NOT.  data_output_2d_on_each_pe )  THEN
156             IF ( myid /= 0 )  THEN
157                WRITE( message_string, * ) 'opening file-id ',file_id, &
158                                           ' not allowed for PE ',myid
159                CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
160             END IF
161          ENDIF
162
163       CASE ( 27, 28, 29, 31, 32, 33, 71:73, 90:99 )
164
165!
166!--       File-ids that are used temporarily in other routines
167          WRITE( message_string, * ) 'opening file-id ',file_id, &
168                                    ' is not allowed since it is used otherwise'
169          CALL message( 'check_open', 'PA0168', 0, 1, 0, 6, 0 ) 
170         
171    END SELECT
172
173!
174!-- Open relevant files
175    SELECT CASE ( file_id )
176
177       CASE ( 11 )
178
179          OPEN ( 11, FILE='PARIN'//coupling_char, FORM='FORMATTED', &
180                     STATUS='OLD' )
181
182       CASE ( 13 )
183
184          IF ( myid_char == '' )  THEN
185             OPEN ( 13, FILE='BININ'//coupling_char//myid_char, &
186                        FORM='UNFORMATTED', STATUS='OLD' )
187          ELSE
188!
189!--          First opening of unit 13 openes file _0000 on all PEs because only
190!--          this file contains the global variables
191             IF ( .NOT. openfile(file_id)%opened_before )  THEN
192                OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//'/_0000',&
193                           FORM='UNFORMATTED', STATUS='OLD' )
194             ELSE
195                OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//'/'//myid_char,&
196                           FORM='UNFORMATTED', STATUS='OLD' )
197             ENDIF
198          ENDIF
199
200       CASE ( 14 )
201
202          IF ( myid_char == '' )  THEN
203             OPEN ( 14, FILE='BINOUT'//coupling_char//myid_char, &
204                        FORM='UNFORMATTED', POSITION='APPEND' )
205          ELSE
206             IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
207                CALL local_system( 'mkdir  BINOUT' // coupling_char )
208             ENDIF
209#if defined( __parallel )
210!
211!--          Set a barrier in order to allow that all other processors in the
212!--          directory created by PE0 can open their file
213             CALL MPI_BARRIER( comm2d, ierr )
214#endif
215             OPEN ( 14, FILE='BINOUT'//TRIM(coupling_char)//'/'//myid_char, &
216                        FORM='UNFORMATTED', POSITION='APPEND' )
217          ENDIF
218
219       CASE ( 15 )
220
221          OPEN ( 15, FILE='RUN_CONTROL'//coupling_char, FORM='FORMATTED' )
222
223       CASE ( 16 )
224
225          OPEN ( 16, FILE='LIST_PROFIL'//coupling_char, FORM='FORMATTED' )
226
227       CASE ( 17 )
228
229          OPEN ( 17, FILE='LIST_PROFIL_1D'//coupling_char, FORM='FORMATTED' )
230
231       CASE ( 18 )
232
233          OPEN ( 18, FILE='CPU_MEASURES'//coupling_char, FORM='FORMATTED' )
234
235       CASE ( 19 )
236
237          OPEN ( 19, FILE='HEADER'//coupling_char, FORM='FORMATTED' )
238
239       CASE ( 20 )
240
241          IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
242             CALL local_system( 'mkdir  DATA_LOG' // coupling_char )
243          ENDIF
244          IF ( myid_char == '' )  THEN
245             OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/_0000', &
246                        FORM='UNFORMATTED', POSITION='APPEND' )
247          ELSE
248#if defined( __parallel )
249!
250!--          Set a barrier in order to allow that all other processors in the
251!--          directory created by PE0 can open their file
252             CALL MPI_BARRIER( comm2d, ierr )
253#endif
254             OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/'//myid_char,&
255                        FORM='UNFORMATTED', POSITION='APPEND' )
256          ENDIF
257
258       CASE ( 21 )
259
260          IF ( data_output_2d_on_each_pe )  THEN
261             OPEN ( 21, FILE='PLOT2D_XY'//TRIM( coupling_char )//myid_char, &
262                        FORM='UNFORMATTED', POSITION='APPEND' )
263          ELSE
264             OPEN ( 21, FILE='PLOT2D_XY'//coupling_char, &
265                        FORM='UNFORMATTED', POSITION='APPEND' )
266          ENDIF
267
268          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
269!
270!--          Output for combine_plot_fields
271             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
272                WRITE (21)  -1, nx+1, -1, ny+1    ! total array size
273                WRITE (21)   0, nx+1,  0, ny+1    ! output part
274             ENDIF
275!
276!--          Determine and write ISO2D coordiante header
277             ALLOCATE( eta(0:ny+1), ho(0:nx+1), hu(0:nx+1) )
278             hu = 0.0
279             ho = (ny+1) * dy
280             DO  i = 1, ny
281                eta(i) = REAL( i ) / ( ny + 1.0 )
282             ENDDO
283             eta(0)    = 0.0
284             eta(ny+1) = 1.0
285
286             WRITE (21)  dx,eta,hu,ho
287             DEALLOCATE( eta, ho, hu )
288
289!
290!--          Create output file for local parameters
291             IF ( iso2d_output )  THEN
292                OPEN ( 27, FILE='PLOT2D_XY_LOCAL'//coupling_char, &
293                           FORM='FORMATTED', DELIM='APOSTROPHE' )
294                openfile(27)%opened = .TRUE.
295             ENDIF
296
297          ENDIF
298
299       CASE ( 22 )
300
301          IF ( data_output_2d_on_each_pe )  THEN
302             OPEN ( 22, FILE='PLOT2D_XZ'//TRIM( coupling_char )//myid_char, &
303                        FORM='UNFORMATTED', POSITION='APPEND' )
304          ELSE
305             OPEN ( 22, FILE='PLOT2D_XZ'//coupling_char, FORM='UNFORMATTED', &
306                        POSITION='APPEND' )
307          ENDIF
308
309          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
310!
311!--          Output for combine_plot_fields
312             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
313                WRITE (22)  -1, nx+1, 0, nz+1    ! total array size
314                WRITE (22)   0, nx+1, 0, nz+1    ! output part
315             ENDIF
316!
317!--          Determine and write ISO2D coordiante header
318             ALLOCATE( eta(0:nz+1), ho(0:nx+1), hu(0:nx+1) )
319             hu = 0.0
320             ho = zu(nz+1)
321             DO  i = 1, nz
322                eta(i) = REAL( zu(i) ) / zu(nz+1)
323             ENDDO
324             eta(0)    = 0.0
325             eta(nz+1) = 1.0
326
327             WRITE (22)  dx,eta,hu,ho
328             DEALLOCATE( eta, ho, hu )
329!
330!--          Create output file for local parameters
331             OPEN ( 28, FILE='PLOT2D_XZ_LOCAL'//coupling_char, &
332                        FORM='FORMATTED', DELIM='APOSTROPHE' )
333             openfile(28)%opened = .TRUE.
334
335          ENDIF
336
337       CASE ( 23 )
338
339          IF ( data_output_2d_on_each_pe )  THEN
340             OPEN ( 23, FILE='PLOT2D_YZ'//TRIM( coupling_char )//myid_char, &
341                        FORM='UNFORMATTED', POSITION='APPEND' )
342          ELSE
343             OPEN ( 23, FILE='PLOT2D_YZ'//coupling_char, FORM='UNFORMATTED', &
344                        POSITION='APPEND' )
345          ENDIF
346
347          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
348!
349!--          Output for combine_plot_fields
350             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
351                WRITE (23)  -1, ny+1, 0, nz+1    ! total array size
352                WRITE (23)   0, ny+1, 0, nz+1    ! output part
353             ENDIF
354!
355!--          Determine and write ISO2D coordiante header
356             ALLOCATE( eta(0:nz+1), ho(0:ny+1), hu(0:ny+1) )
357             hu = 0.0
358             ho = zu(nz+1)
359             DO  i = 1, nz
360                eta(i) = REAL( zu(i) ) / zu(nz+1)
361             ENDDO
362             eta(0)    = 0.0
363             eta(nz+1) = 1.0
364
365             WRITE (23)  dx,eta,hu,ho
366             DEALLOCATE( eta, ho, hu )
367!
368!--          Create output file for local parameters
369             OPEN ( 29, FILE='PLOT2D_YZ_LOCAL'//coupling_char, &
370                        FORM='FORMATTED', DELIM='APOSTROPHE' )
371             openfile(29)%opened = .TRUE.
372
373          ENDIF
374
375       CASE ( 30 )
376
377          OPEN ( 30, FILE='PLOT3D_DATA'//TRIM( coupling_char )//myid_char, &
378                     FORM='UNFORMATTED' )
379!
380!--       Write coordinate file for AVS
381          IF ( myid == 0 )  THEN
382#if defined( __parallel )
383!
384!--          Specifications for combine_plot_fields
385             IF ( .NOT. do3d_compress )  THEN
386                WRITE ( 30 )  -1,nx+1,-1,ny+1,0,nz_do3d
387                WRITE ( 30 )  0,nx+1,0,ny+1,0,nz_do3d
388             ENDIF
389#endif
390!
391!--          Write coordinate file for AVS:
392!--          First determine file names (including cyle numbers) of AVS files on
393!--          target machine (to which the files are to be transferred).
394!--          Therefore path information has to be obtained first.
395             IF ( avs_output )  THEN
396                iaddres = LEN_TRIM( return_addres )
397                iusern  = LEN_TRIM( return_username )
398
399                OPEN ( 3, FILE='OUTPUT_FILE_CONNECTIONS', FORM='FORMATTED' )
400                DO  WHILE ( .NOT. avs_coor_file_found  .OR. &
401                            .NOT. avs_data_file_found )
402
403                   READ ( 3, '(A)', END=1 )  zeile
404
405                   SELECT CASE ( zeile(1:11) )
406
407                      CASE ( 'PLOT3D_COOR' )
408                         READ ( 3, '(A/A)' )  avs_coor_file_catalog, &
409                                              avs_coor_file_localname
410                         avs_coor_file_found = .TRUE.
411
412                      CASE ( 'PLOT3D_DATA' )
413                         READ ( 3, '(A/A)' )  avs_data_file_catalog, &
414                                              avs_data_file_localname
415                         avs_data_file_found = .TRUE.
416
417                      CASE DEFAULT
418                         READ ( 3, '(A/A)' )  zeile, zeile
419
420                   END SELECT
421
422                ENDDO
423!
424!--             Now the cycle numbers on the remote machine must be obtained
425!--             using batch_scp
426       1        CLOSE ( 3 )
427                IF ( .NOT. avs_coor_file_found  .OR. &
428                     .NOT. avs_data_file_found )  THEN
429                   message_string= 'no filename for AVS-data-file ' //       &
430                                   'found in MRUN-config-file' //            &
431                                   ' &filename in FLD-file set to "unknown"'
432                   CALL message( 'check_open', 'PA0169', 0, 1, 0, 6, 0 )
433
434                   avs_coor_file = 'unknown'
435                   avs_data_file = 'unknown'
436                ELSE
437                   get_filenames = .TRUE.
438                   IF ( TRIM( host ) == 'hpmuk'  .OR.  &
439                        TRIM( host ) == 'lcmuk' )  THEN
440                      batch_scp = '/home/raasch/pub/batch_scp'
441                   ELSEIF ( TRIM( host ) == 'nech' )  THEN
442                      batch_scp = '/ipf/b/b323011/pub/batch_scp'
443                   ELSEIF ( TRIM( host ) == 'ibmh'  .OR.  &
444                            TRIM( host ) == 'ibmb' )  THEN
445                      batch_scp = '/home/h/niksiraa/pub/batch_scp'
446                   ELSEIF ( TRIM( host ) == 't3eb' )  THEN
447                      batch_scp = '/home/nhbksira/pub/batch_scp'
448                   ELSE
449                      message_string= 'no path for batch_scp on host "' // &
450                                       TRIM( host ) // '"'
451                      CALL message( 'check_open', 'PA0170', 0, 1, 0, 6, 0 )
452                      get_filenames = .FALSE.
453                   ENDIF
454
455                   IF ( get_filenames )  THEN
456!
457!--                   Determine the coordinate file name.
458!--                   /etc/passwd serves as Dummy-Datei, because it is not
459!--                   really transferred.
460                      command = TRIM( batch_scp ) // ' -n -u ' // &
461                         return_username(1:iusern) // ' ' // &
462                         return_addres(1:iaddres) // ' /etc/passwd "' // &
463                         TRIM( avs_coor_file_catalog ) // '" ' // &
464                         TRIM( avs_coor_file_localname ) // ' > REMOTE_FILENAME'
465
466                      CALL local_system( command )
467                      OPEN ( 3, FILE='REMOTE_FILENAME', FORM='FORMATTED' )
468                      READ ( 3, '(A)' )  avs_coor_file
469                      CLOSE ( 3 )
470!
471!--                   Determine the data file name
472                      command = TRIM( batch_scp ) // ' -n -u ' // &
473                         return_username(1:iusern) // ' ' // &
474                         return_addres(1:iaddres) // ' /etc/passwd "' // &
475                         TRIM( avs_data_file_catalog ) // '" ' // &
476                         TRIM( avs_data_file_localname ) // ' > REMOTE_FILENAME'
477
478                      CALL local_system( command )
479                      OPEN ( 3, FILE='REMOTE_FILENAME', FORM='FORMATTED' )
480                      READ ( 3, '(A)' )  avs_data_file
481                      CLOSE ( 3 )
482
483                   ELSE
484
485                      avs_coor_file = 'unknown'
486                      avs_data_file = 'unknown'
487
488                   ENDIF
489
490                ENDIF
491
492!
493!--             Output of the coordinate file description for FLD-file
494                OPEN ( 33, FILE='PLOT3D_FLD_COOR', FORM='FORMATTED' )
495                openfile(33)%opened = .TRUE.
496                WRITE ( 33, 3300 )  TRIM( avs_coor_file ), &
497                                    TRIM( avs_coor_file ), (nx+2)*4, &
498                                    TRIM( avs_coor_file ), (nx+2)*4+(ny+2)*4
499           
500
501                ALLOCATE( xkoor(0:nx+1), ykoor(0:ny+1), zkoor(0:nz_do3d) )
502                DO  i = 0, nx+1
503                   xkoor(i) = i * dx
504                ENDDO
505                DO  j = 0, ny+1
506                   ykoor(j) = j * dy
507                ENDDO
508                DO  k = 0, nz_do3d
509                   zkoor(k) = zu(k)
510                ENDDO
511
512!
513!--             Create and write on AVS coordinate file
514                OPEN ( 31, FILE='PLOT3D_COOR', FORM='UNFORMATTED' )
515                openfile(31)%opened = .TRUE.
516
517                WRITE (31)  xkoor, ykoor, zkoor
518                DEALLOCATE( xkoor, ykoor, zkoor )
519
520!
521!--             Create FLD file (being written on in close_file)
522                OPEN ( 32, FILE='PLOT3D_FLD', FORM='FORMATTED' )
523                openfile(32)%opened = .TRUE.
524
525!
526!--             Create flag file for compressed 3D output,
527!--             influences output commands in mrun
528                IF ( do3d_compress )  THEN
529                   OPEN ( 3, FILE='PLOT3D_COMPRESSED', FORM='FORMATTED' )
530                   WRITE ( 3, '(1X)' )
531                   CLOSE ( 3 )
532                ENDIF
533
534             ENDIF
535
536          ENDIF
537
538!
539!--       In case of data compression output of the coordinates of the
540!--       corresponding partial array of a PE only once at the top of the file
541          IF ( avs_output  .AND.  do3d_compress )  THEN
542             WRITE ( 30 )  nxl-1, nxr+1, nys-1, nyn+1, nzb, nz_do3d
543          ENDIF
544
545       CASE ( 40:49 )
546
547          IF ( statistic_regions == 0  .AND.  file_id == 40 )  THEN
548             suffix = ''
549          ELSE
550             WRITE ( suffix, '(''_'',I1)' )  file_id - 40
551          ENDIF
552          OPEN ( file_id, FILE='PLOT1D_DATA'//TRIM( coupling_char )// &
553                               TRIM( suffix ),                        &
554                          FORM='FORMATTED' )
555!
556!--       Write contents comments at the top of the file
557          WRITE ( file_id, 4000 )  TRIM( run_description_header ) // '    ' // &
558                                   TRIM( region( file_id - 40 ) )
559
560       CASE ( 50:59 )
561
562          IF ( statistic_regions == 0  .AND.  file_id == 50 )  THEN
563             suffix = ''
564          ELSE
565             WRITE ( suffix, '(''_'',I1)' )  file_id - 50
566          ENDIF
567          OPEN ( file_id, FILE='PLOTTS_DATA'//TRIM( coupling_char )// &
568                               TRIM( suffix ),                        &
569                          FORM='FORMATTED', RECL=496 )
570!
571!--       Write PROFIL parameter file for output of time series
572!--       NOTE: To be on the safe side, this output is done at the beginning of
573!--             the model run (in case of collapse) and it is repeated in
574!--             close_file, then, however, with value ranges for the coordinate
575!--             systems
576!
577!--       Firstly determine the number of the coordinate systems to be drawn
578          cranz = 0
579          DO  j = 1, 10
580             IF ( cross_ts_number_count(j) /= 0 )  cranz = cranz+1
581          ENDDO
582          rtext = '\1.0 ' // TRIM( run_description_header ) // '    ' // &
583                  TRIM( region( file_id - 50 ) )
584!
585!--       Write RAHMEN parameter
586          OPEN ( 90, FILE='PLOTTS_PAR'//TRIM( coupling_char )// &
587                           TRIM( suffix ),                      &
588                     FORM='FORMATTED', DELIM='APOSTROPHE' )
589          WRITE ( 90, RAHMEN )
590!
591!--       Determine and write CROSS parameters for the individual coordinate
592!--       systems
593          DO  j = 1, 10
594             k = cross_ts_number_count(j)
595             IF ( k /= 0 )  THEN
596!
597!--             Store curve numbers, colours and line style
598                klist(1:k) = cross_ts_numbers(1:k,j)
599                klist(k+1:10) = 999999
600                cucol(1:k) = linecolors(1:k)
601                lstyle(1:k) = linestyles(1:k)
602!
603!--             Write CROSS parameter
604                WRITE ( 90, CROSS )
605
606             ENDIF
607          ENDDO
608
609          CLOSE ( 90 )
610!
611!--       Write all labels at the top of the data file, but only during the
612!--       first run of a sequence of jobs. The following jobs copy the time
613!--       series data to the bottom of that file.
614          IF ( runnr == 0 )  THEN
615             WRITE ( file_id, 5000 )  TRIM( run_description_header ) // &
616                                      '    ' // TRIM( region( file_id - 50 ) )
617          ENDIF
618
619
620       CASE ( 80 )
621
622          IF ( myid_char == '' )  THEN
623             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM(coupling_char)//myid_char, &
624                        FORM='FORMATTED', POSITION='APPEND' )
625          ELSE
626             IF ( myid == 0  .AND.  .NOT. openfile(80)%opened_before )  THEN
627                CALL local_system( 'mkdir  PARTICLE_INFOS' // coupling_char )
628             ENDIF
629#if defined( __parallel )
630!
631!--          Set a barrier in order to allow that thereafter all other
632!--          processors in the directory created by PE0 can open their file.
633!--          WARNING: The following barrier will lead to hanging jobs, if
634!--                   check_open is first called from routine
635!--                   allocate_prt_memory!
636             IF ( .NOT. openfile(80)%opened_before )  THEN
637                CALL MPI_BARRIER( comm2d, ierr )
638             ENDIF
639#endif
640             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM( coupling_char )//'/'// &
641                             myid_char,                                     &
642                        FORM='FORMATTED', POSITION='APPEND' )
643          ENDIF
644
645          IF ( .NOT. openfile(80)%opened_before )  THEN
646             WRITE ( 80, 8000 )  TRIM( run_description_header )
647          ENDIF
648
649       CASE ( 81 )
650
651             OPEN ( 81, FILE='PLOTSP_X_PAR'//coupling_char, FORM='FORMATTED', &
652                        DELIM='APOSTROPHE', RECL=1500, POSITION='APPEND' )
653
654       CASE ( 82 )
655
656             OPEN ( 82, FILE='PLOTSP_X_DATA'//coupling_char, FORM='FORMATTED', &
657                        POSITION = 'APPEND' )
658
659       CASE ( 83 )
660
661             OPEN ( 83, FILE='PLOTSP_Y_PAR'//coupling_char, FORM='FORMATTED', &
662                        DELIM='APOSTROPHE', RECL=1500, POSITION='APPEND' )
663
664       CASE ( 84 )
665
666             OPEN ( 84, FILE='PLOTSP_Y_DATA'//coupling_char, FORM='FORMATTED', &
667                        POSITION='APPEND' )
668
669       CASE ( 85 )
670
671          IF ( myid_char == '' )  THEN
672             OPEN ( 85, FILE='PARTICLE_DATA'//TRIM(coupling_char)//myid_char, &
673                        FORM='UNFORMATTED', POSITION='APPEND' )
674          ELSE
675             IF ( myid == 0  .AND.  .NOT. openfile(85)%opened_before )  THEN
676                CALL local_system( 'mkdir  PARTICLE_DATA' // coupling_char )
677             ENDIF
678#if defined( __parallel )
679!
680!--          Set a barrier in order to allow that thereafter all other
681!--          processors in the directory created by PE0 can open their file
682             CALL MPI_BARRIER( comm2d, ierr )
683#endif
684             OPEN ( 85, FILE='PARTICLE_DATA'//TRIM( coupling_char )//'/'// &
685                        myid_char,                                         &
686                        FORM='UNFORMATTED', POSITION='APPEND' )
687          ENDIF
688
689          IF ( .NOT. openfile(85)%opened_before )  THEN
690             WRITE ( 85 )  run_description_header
691!
692!--          Attention: change version number whenever the output format on
693!--                     unit 85 is changed (see also in routine advec_particles)
694             rtext = 'data format version 3.0'
695             WRITE ( 85 )  rtext
696             WRITE ( 85 )  number_of_particle_groups, &
697                           max_number_of_particle_groups
698             WRITE ( 85 )  particle_groups
699          ENDIF
700
701#if defined( __netcdf )
702       CASE ( 101, 111 )
703!
704!--       Set filename depending on unit number
705          IF ( file_id == 101 )  THEN
706             filename = 'DATA_2D_XY_NETCDF' // coupling_char
707             av = 0
708          ELSE
709             filename = 'DATA_2D_XY_AV_NETCDF' // coupling_char
710             av = 1
711          ENDIF
712!
713!--       Inquire, if there is a NetCDF file from a previuos run. This should
714!--       be opened for extension, if its dimensions and variables match the
715!--       actual run.
716          INQUIRE( FILE=filename, EXIST=netcdf_extend )
717
718          IF ( netcdf_extend )  THEN
719!
720!--          Open an existing NetCDF file for output
721#if defined( __netcdf4 )
722             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xy(av), &
723                                  COMM = comm2d, INFO = MPI_INFO_NULL )
724#else
725             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xy(av) )
726#endif
727
728             CALL handle_netcdf_error( 'check_open', 20 )
729!
730!--          Read header information and set all ids. If there is a mismatch
731!--          between the previuos and the actual run, netcdf_extend is returned
732!--          as .FALSE.
733             CALL define_netcdf_header( 'xy', netcdf_extend, av )
734
735!
736!--          Remove the local file, if it can not be extended
737             IF ( .NOT. netcdf_extend )  THEN
738                nc_stat = NF90_CLOSE( id_set_xy(av) )
739                CALL handle_netcdf_error( 'check_open', 21 )
740                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
741             ENDIF
742
743          ENDIF         
744
745          IF ( .NOT. netcdf_extend )  THEN
746!
747!--          Create a new NetCDF output file with requested NetCDF format
748             IF ( netcdf_data_format == 1 )  THEN
749!
750!--             Classic NetCDF format
751                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xy(av) )
752
753             ELSEIF ( netcdf_data_format == 2 )  THEN
754!
755!--             64bit-offset format
756                nc_stat = NF90_CREATE( filename,                               &
757                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
758                                       id_set_xy(av) )
759
760#if defined( __netcdf4 )
761             ELSEIF ( netcdf_data_format == 3 )  THEN
762!
763!--             NetCDF4/HDF5 format
764                nc_stat = NF90_CREATE( filename,                               &
765                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
766                                       id_set_xy(av), COMM = comm2d,           &
767                                       INFO = MPI_INFO_NULL )
768
769             ELSEIF ( netcdf_data_format == 4 )  THEN
770!
771!--             NetCDF4/HDF5 format with classic model flag
772                nc_stat = NF90_CREATE( filename,                               &
773                                       OR( NF90_NOCLOBBER,                     &
774                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
775                                       id_set_xy(av), COMM = comm2d,           &
776                                       INFO = MPI_INFO_NULL )
777#endif
778             ENDIF
779
780             CALL handle_netcdf_error( 'check_open', 22 )
781
782!
783!--          Define the header
784             CALL define_netcdf_header( 'xy', netcdf_extend, av )
785
786!
787!--          In case of parallel NetCDF output, create flag file which tells
788!--          combine_plot_fields that nothing is to do.
789             IF ( myid == 0  .AND.  netcdf_data_format > 2 )  THEN
790                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XY' )
791                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
792                CLOSE( 99 )
793             ENDIF
794
795          ENDIF
796
797       CASE ( 102, 112 )
798!
799!--       Set filename depending on unit number
800          IF ( file_id == 102 )  THEN
801             filename = 'DATA_2D_XZ_NETCDF' // coupling_char
802             av = 0
803          ELSE
804             filename = 'DATA_2D_XZ_AV_NETCDF' // coupling_char
805             av = 1
806          ENDIF
807!
808!--       Inquire, if there is a NetCDF file from a previuos run. This should
809!--       be opened for extension, if its dimensions and variables match the
810!--       actual run.
811          INQUIRE( FILE=filename, EXIST=netcdf_extend )
812
813          IF ( netcdf_extend )  THEN
814!
815!--          Open an existing NetCDF file for output
816#if defined( __netcdf4 )
817             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xz(av), &
818                                  COMM = comm2d, INFO = MPI_INFO_NULL )
819#else
820             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xz(av) )
821#endif
822             CALL handle_netcdf_error( 'check_open', 23 )
823!
824!--          Read header information and set all ids. If there is a mismatch
825!--          between the previuos and the actual run, netcdf_extend is returned
826!--          as .FALSE.
827             CALL define_netcdf_header( 'xz', netcdf_extend, av )
828
829!
830!--          Remove the local file, if it can not be extended
831             IF ( .NOT. netcdf_extend )  THEN
832                nc_stat = NF90_CLOSE( id_set_xz(av) )
833                CALL handle_netcdf_error( 'check_open', 24 )
834                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
835             ENDIF
836
837          ENDIF         
838
839          IF ( .NOT. netcdf_extend )  THEN
840!
841!--          Create a new NetCDF output file with requested NetCDF format
842             IF ( netcdf_data_format == 1 )  THEN
843!
844!--             Classic NetCDF format
845                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xz(av) )
846
847             ELSEIF ( netcdf_data_format == 2 )  THEN
848!
849!--             64bit-offset format
850                nc_stat = NF90_CREATE( filename,                               &
851                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
852                                       id_set_xz(av) )
853
854#if defined( __netcdf4 )
855             ELSEIF ( netcdf_data_format == 3 )  THEN
856!
857!--             NetCDF4/HDF5 format
858                nc_stat = NF90_CREATE( filename,                               &
859                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
860                                       id_set_xz(av), COMM = comm2d,           &
861                                       INFO = MPI_INFO_NULL )
862
863             ELSEIF ( netcdf_data_format == 4 )  THEN
864!
865!--             NetCDF4/HDF5 format with classic model flag
866                nc_stat = NF90_CREATE( filename,                               &
867                                       OR( NF90_NOCLOBBER,                     &
868                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
869                                       id_set_xz(av), COMM = comm2d,           &
870                                       INFO = MPI_INFO_NULL )
871#endif
872             ENDIF
873
874             CALL handle_netcdf_error( 'check_open', 25 )
875
876!
877!--          Define the header
878             CALL define_netcdf_header( 'xz', netcdf_extend, av )
879
880!
881!--          In case of parallel NetCDF output, create flag file which tells
882!--          combine_plot_fields that nothing is to do.
883             IF ( myid == 0  .AND.  netcdf_data_format > 2 )  THEN
884                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XZ' )
885                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
886                CLOSE( 99 )
887             ENDIF
888
889          ENDIF
890
891       CASE ( 103, 113 )
892!
893!--       Set filename depending on unit number
894          IF ( file_id == 103 )  THEN
895             filename = 'DATA_2D_YZ_NETCDF' // coupling_char
896             av = 0
897          ELSE
898             filename = 'DATA_2D_YZ_AV_NETCDF' // coupling_char
899             av = 1
900          ENDIF
901!
902!--       Inquire, if there is a NetCDF file from a previuos run. This should
903!--       be opened for extension, if its dimensions and variables match the
904!--       actual run.
905          INQUIRE( FILE=filename, EXIST=netcdf_extend )
906
907          IF ( netcdf_extend )  THEN
908!
909!--          Open an existing NetCDF file for output
910#if defined( __netcdf4 )
911             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_yz(av), &
912                                  COMM = comm2d, INFO = MPI_INFO_NULL )
913#else
914             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_yz(av) )
915#endif
916             CALL handle_netcdf_error( 'check_open', 26 )
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 define_netcdf_header( 'yz', netcdf_extend, av )
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_yz(av) )
927                CALL handle_netcdf_error( 'check_open', 27 )
928                IF ( myid == 0 )  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             IF ( netcdf_data_format == 1 )  THEN
937!
938!--             Classic NetCDF format
939                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_yz(av) )
940
941             ELSEIF ( netcdf_data_format == 2 )  THEN
942!
943!--             64bit-offset format
944                nc_stat = NF90_CREATE( filename,                               &
945                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
946                                       id_set_yz(av) )
947
948#if defined( __netcdf4 )
949             ELSEIF ( netcdf_data_format == 3 )  THEN
950!
951!--             NetCDF4/HDF5 format
952                nc_stat = NF90_CREATE( filename,                               &
953                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
954                                       id_set_yz(av), COMM = comm2d,           &
955                                       INFO = MPI_INFO_NULL )
956
957             ELSEIF ( netcdf_data_format == 4 )  THEN
958!
959!--             NetCDF4/HDF5 format with classic model flag
960                nc_stat = NF90_CREATE( filename,                               &
961                                       OR( NF90_NOCLOBBER,                     &
962                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
963                                       id_set_yz(av), COMM = comm2d,           &
964                                       INFO = MPI_INFO_NULL )
965#endif
966             ENDIF
967
968             CALL handle_netcdf_error( 'check_open', 28 )
969
970!
971!--          Define the header
972             CALL define_netcdf_header( 'yz', netcdf_extend, av )
973
974!
975!--          In case of parallel NetCDF output, create flag file which tells
976!--          combine_plot_fields that nothing is to do.
977             IF ( myid == 0  .AND.  netcdf_data_format > 2 )  THEN
978                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_YZ' )
979                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
980                CLOSE( 99 )
981             ENDIF
982
983          ENDIF
984
985       CASE ( 104 )
986!
987!--       Set filename
988          filename = 'DATA_1D_PR_NETCDF' // coupling_char
989
990!
991!--       Inquire, if there is a NetCDF file from a previuos run. This should
992!--       be opened for extension, if its variables match the actual run.
993          INQUIRE( FILE=filename, EXIST=netcdf_extend )
994
995          IF ( netcdf_extend )  THEN
996!
997!--          Open an existing NetCDF file for output
998             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_pr )
999             CALL handle_netcdf_error( 'check_open', 29 )
1000!
1001!--          Read header information and set all ids. If there is a mismatch
1002!--          between the previuos and the actual run, netcdf_extend is returned
1003!--          as .FALSE.
1004             CALL define_netcdf_header( 'pr', netcdf_extend, 0 )
1005
1006!
1007!--          Remove the local file, if it can not be extended
1008             IF ( .NOT. netcdf_extend )  THEN
1009                nc_stat = NF90_CLOSE( id_set_pr )
1010                CALL handle_netcdf_error( 'check_open', 30 )
1011                CALL local_system( 'rm ' // TRIM( filename ) )
1012             ENDIF
1013
1014          ENDIF         
1015
1016          IF ( .NOT. netcdf_extend )  THEN
1017!
1018!--          Create a new NetCDF output file
1019             IF ( netcdf_data_format > 1 )  THEN
1020                nc_stat = NF90_CREATE( filename,                               &
1021                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
1022                                       id_set_pr )
1023             ELSE
1024                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_pr )
1025             ENDIF
1026             CALL handle_netcdf_error( 'check_open', 31 )
1027!
1028!--          Define the header
1029             CALL define_netcdf_header( 'pr', netcdf_extend, 0 )
1030
1031          ENDIF
1032
1033       CASE ( 105 )
1034!
1035!--       Set filename
1036          filename = 'DATA_1D_TS_NETCDF' // coupling_char
1037
1038!
1039!--       Inquire, if there is a NetCDF file from a previuos run. This should
1040!--       be opened for extension, if its variables match the actual run.
1041          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1042
1043          IF ( netcdf_extend )  THEN
1044!
1045!--          Open an existing NetCDF file for output
1046             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_ts )
1047             CALL handle_netcdf_error( 'check_open', 32 )
1048!
1049!--          Read header information and set all ids. If there is a mismatch
1050!--          between the previuos and the actual run, netcdf_extend is returned
1051!--          as .FALSE.
1052             CALL define_netcdf_header( 'ts', netcdf_extend, 0 )
1053
1054!
1055!--          Remove the local file, if it can not be extended
1056             IF ( .NOT. netcdf_extend )  THEN
1057                nc_stat = NF90_CLOSE( id_set_ts )
1058                CALL handle_netcdf_error( 'check_open', 33 )
1059                CALL local_system( 'rm ' // TRIM( filename ) )
1060             ENDIF
1061
1062          ENDIF         
1063
1064          IF ( .NOT. netcdf_extend )  THEN
1065!
1066!--          Create a new NetCDF output file
1067             IF ( netcdf_data_format > 1 )  THEN
1068                nc_stat = NF90_CREATE( filename,                               &
1069                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
1070                                       id_set_ts )
1071             ELSE
1072                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_ts )
1073             ENDIF
1074             CALL handle_netcdf_error( 'check_open', 34 )
1075!
1076!--          Define the header
1077             CALL define_netcdf_header( 'ts', netcdf_extend, 0 )
1078
1079          ENDIF
1080
1081
1082       CASE ( 106, 116 )
1083!
1084!--       Set filename depending on unit number
1085          IF ( file_id == 106 )  THEN
1086             filename = 'DATA_3D_NETCDF' // coupling_char
1087             av = 0
1088          ELSE
1089             filename = 'DATA_3D_AV_NETCDF' // coupling_char
1090             av = 1
1091          ENDIF
1092!
1093!--       Inquire, if there is a NetCDF file from a previous run. This should
1094!--       be opened for extension, if its dimensions and variables match the
1095!--       actual run.
1096          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1097
1098          IF ( netcdf_extend )  THEN
1099!
1100!--          Open an existing NetCDF file for output
1101#if defined( __netcdf4 )
1102             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_3d(av), &
1103                                  COMM = comm2d, INFO = MPI_INFO_NULL )
1104#else
1105             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_3d(av) )
1106#endif
1107             CALL handle_netcdf_error( 'check_open', 35 )
1108!
1109!--          Read header information and set all ids. If there is a mismatch
1110!--          between the previuos and the actual run, netcdf_extend is returned
1111!--          as .FALSE.
1112             CALL define_netcdf_header( '3d', netcdf_extend, av )
1113
1114!
1115!--          Remove the local file, if it can not be extended
1116             IF ( .NOT. netcdf_extend )  THEN
1117                nc_stat = NF90_CLOSE( id_set_3d(av) )
1118                CALL handle_netcdf_error( 'check_open', 36 )
1119                CALL local_system('rm ' // TRIM( filename ) )
1120             ENDIF
1121
1122          ENDIF         
1123
1124          IF ( .NOT. netcdf_extend )  THEN
1125!
1126!--          Create a new NetCDF output file with requested NetCDF format
1127             IF ( netcdf_data_format == 1 )  THEN
1128!
1129!--             Classic NetCDF format
1130                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_3d(av) )
1131
1132             ELSEIF ( netcdf_data_format == 2 )  THEN
1133!
1134!--             64bit-offset format
1135                nc_stat = NF90_CREATE( filename,                               &
1136                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
1137                                       id_set_3d(av) )
1138
1139#if defined( __netcdf4 )
1140             ELSEIF ( netcdf_data_format == 3 )  THEN
1141!
1142!--             NetCDF4/HDF5 format
1143                nc_stat = NF90_CREATE( filename,                               &
1144                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
1145                                       id_set_3d(av), COMM = comm2d,           &
1146                                       INFO = MPI_INFO_NULL )
1147
1148             ELSEIF ( netcdf_data_format == 4 )  THEN
1149!
1150!--             NetCDF4/HDF5 format with classic model flag
1151                nc_stat = NF90_CREATE( filename,                               &
1152                                       OR( NF90_NOCLOBBER,                     &
1153                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
1154                                       id_set_3d(av), COMM = comm2d,           &
1155                                       INFO = MPI_INFO_NULL )
1156#endif
1157             ENDIF
1158
1159             CALL handle_netcdf_error( 'check_open', 37 )
1160
1161!
1162!--          Define the header
1163             CALL define_netcdf_header( '3d', netcdf_extend, av )
1164
1165!
1166!--          In case of parallel NetCDF output, create flag file which tells
1167!--          combine_plot_fields that nothing is to do.
1168             IF ( myid == 0  .AND.  netcdf_data_format > 2 )  THEN
1169                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_3D' )
1170                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
1171                CLOSE( 99 )
1172             ENDIF
1173
1174          ENDIF
1175
1176
1177       CASE ( 107 )
1178!
1179!--       Set filename
1180          filename = 'DATA_1D_SP_NETCDF' // coupling_char
1181
1182!
1183!--       Inquire, if there is a NetCDF file from a previuos run. This should
1184!--       be opened for extension, if its variables match the actual run.
1185          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1186
1187          IF ( netcdf_extend )  THEN
1188!
1189!--          Open an existing NetCDF file for output
1190             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_sp )
1191             CALL handle_netcdf_error( 'check_open', 38 )
1192
1193!
1194!--          Read header information and set all ids. If there is a mismatch
1195!--          between the previuos and the actual run, netcdf_extend is returned
1196!--          as .FALSE.
1197             CALL define_netcdf_header( 'sp', netcdf_extend, 0 )
1198
1199!
1200!--          Remove the local file, if it can not be extended
1201             IF ( .NOT. netcdf_extend )  THEN
1202                nc_stat = NF90_CLOSE( id_set_sp )
1203                CALL handle_netcdf_error( 'check_open', 39 )
1204                CALL local_system( 'rm ' // TRIM( filename ) )
1205             ENDIF
1206
1207          ENDIF         
1208
1209          IF ( .NOT. netcdf_extend )  THEN
1210!
1211!--          Create a new NetCDF output file
1212             IF ( netcdf_data_format > 1 )  THEN
1213                nc_stat = NF90_CREATE( filename,                               &
1214                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
1215                                       id_set_sp )
1216             ELSE
1217                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_sp )
1218             ENDIF
1219             CALL handle_netcdf_error( 'check_open', 40 )
1220!
1221!--          Define the header
1222             CALL define_netcdf_header( 'sp', netcdf_extend, 0 )
1223
1224          ENDIF
1225
1226
1227       CASE ( 108 )
1228
1229          IF ( myid_char == '' )  THEN
1230             filename = 'DATA_PRT_NETCDF' // coupling_char
1231          ELSE
1232             filename = 'DATA_PRT_NETCDF' // TRIM( coupling_char ) // '/' // &
1233                        myid_char
1234          ENDIF
1235!
1236!--       Inquire, if there is a NetCDF file from a previuos run. This should
1237!--       be opened for extension, if its variables match the actual run.
1238          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1239
1240          IF ( netcdf_extend )  THEN
1241!
1242!--          Open an existing NetCDF file for output
1243             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_prt )
1244             CALL handle_netcdf_error( 'check_open', 41 )
1245!
1246!--          Read header information and set all ids. If there is a mismatch
1247!--          between the previuos and the actual run, netcdf_extend is returned
1248!--          as .FALSE.
1249             CALL define_netcdf_header( 'pt', netcdf_extend, 0 )
1250
1251!
1252!--          Remove the local file, if it can not be extended
1253             IF ( .NOT. netcdf_extend )  THEN
1254                nc_stat = NF90_CLOSE( id_set_prt )
1255                CALL handle_netcdf_error( 'check_open', 42 )
1256                CALL local_system( 'rm ' // filename )
1257             ENDIF
1258
1259          ENDIF         
1260
1261          IF ( .NOT. netcdf_extend )  THEN
1262
1263!
1264!--          For runs on multiple processors create the subdirectory
1265             IF ( myid_char /= '' )  THEN
1266                IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before ) &
1267                THEN    ! needs modification in case of non-extendable sets
1268                   CALL local_system( 'mkdir  DATA_PRT_NETCDF' // &
1269                                       TRIM( coupling_char ) // '/' )
1270                ENDIF
1271#if defined( __parallel )
1272!
1273!--             Set a barrier in order to allow that all other processors in the
1274!--             directory created by PE0 can open their file
1275                CALL MPI_BARRIER( comm2d, ierr )
1276#endif
1277             ENDIF
1278
1279!
1280!--          Create a new NetCDF output file with requested NetCDF format
1281             IF ( netcdf_data_format == 1 )  THEN
1282!
1283!--             Classic NetCDF format
1284                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_prt )
1285
1286             ELSEIF ( netcdf_data_format == 2 )  THEN
1287!
1288!--             64bit-offset format
1289                nc_stat = NF90_CREATE( filename,                               &
1290                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
1291                                       id_set_prt )
1292
1293#if defined( __netcdf4 )
1294             ELSEIF ( netcdf_data_format == 3 )  THEN
1295!
1296!--             NetCDF4/HDF5 format, but no parallel output into a single file!
1297                nc_stat = NF90_CREATE( filename,                               &
1298                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
1299                                       id_set_prt )
1300
1301             ELSEIF ( netcdf_data_format == 4 )  THEN
1302!
1303!--             NetCDF4/HDF5 format with classic model flag, but no parallel
1304!--             output into a single file!
1305                nc_stat = NF90_CREATE( filename,                               &
1306                                       OR( NF90_NOCLOBBER,                     &
1307                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
1308                                       id_set_prt )
1309#endif
1310             ENDIF
1311
1312             CALL handle_netcdf_error( 'check_open', 43 ) 
1313
1314!
1315!--          Define the header
1316             CALL define_netcdf_header( 'pt', netcdf_extend, 0 )
1317
1318          ENDIF
1319
1320       CASE ( 109 )
1321!
1322!--       Set filename
1323          filename = 'DATA_1D_PTS_NETCDF' // coupling_char
1324
1325!
1326!--       Inquire, if there is a NetCDF file from a previuos run. This should
1327!--       be opened for extension, if its variables match the actual run.
1328          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1329
1330          IF ( netcdf_extend )  THEN
1331!
1332!--          Open an existing NetCDF file for output
1333             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_pts )
1334             CALL handle_netcdf_error( 'check_open', 393 )
1335!
1336!--          Read header information and set all ids. If there is a mismatch
1337!--          between the previuos and the actual run, netcdf_extend is returned
1338!--          as .FALSE.
1339             CALL define_netcdf_header( 'ps', netcdf_extend, 0 )
1340
1341!
1342!--          Remove the local file, if it can not be extended
1343             IF ( .NOT. netcdf_extend )  THEN
1344                nc_stat = NF90_CLOSE( id_set_pts )
1345                CALL handle_netcdf_error( 'check_open', 394 )
1346                CALL local_system( 'rm ' // TRIM( filename ) )
1347             ENDIF
1348
1349          ENDIF         
1350
1351          IF ( .NOT. netcdf_extend )  THEN
1352!
1353!--          Create a new NetCDF output file
1354             IF ( netcdf_data_format > 1 )  THEN
1355                nc_stat = NF90_CREATE( filename,                               &
1356                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
1357                                       id_set_pts )
1358             ELSE
1359                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_pts )
1360             ENDIF
1361             CALL handle_netcdf_error( 'check_open', 395 )
1362!
1363!--          Define the header
1364             CALL define_netcdf_header( 'ps', netcdf_extend, 0 )
1365
1366          ENDIF
1367
1368       CASE ( 121:160 )
1369!
1370!--       Set filename depending on unit number
1371          IF ( file_id <= 140 )  THEN
1372             mid = file_id - 120
1373             WRITE ( mask_char,'(I2.2)')  mid
1374             filename = 'DATA_MASK_' // mask_char // '_NETCDF' // coupling_char
1375             av = 0
1376          ELSE
1377             mid = file_id - 140
1378             WRITE ( mask_char,'(I2.2)')  mid
1379             filename = 'DATA_MASK_' // mask_char // '_AV_NETCDF' // &
1380                  coupling_char
1381             av = 1
1382          ENDIF
1383!
1384!--       Inquire, if there is a NetCDF file from a previuos run. This should
1385!--       be opened for extension, if its dimensions and variables match the
1386!--       actual run.
1387          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1388
1389          IF ( netcdf_extend )  THEN
1390!
1391!--          Open an existing NetCDF file for output
1392#if defined( __netcdf4 )
1393             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_mask(mid,av), &
1394                                  COMM = comm2d, INFO = MPI_INFO_NULL )
1395#else
1396             nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_mask(mid,av) )
1397#endif
1398             CALL handle_netcdf_error( 'check_open', 9998 )
1399!
1400!--          Read header information and set all ids. If there is a mismatch
1401!--          between the previuos and the actual run, netcdf_extend is returned
1402!--          as .FALSE.
1403             CALL define_netcdf_header( 'ma', netcdf_extend, file_id )
1404
1405!
1406!--          Remove the local file, if it can not be extended
1407             IF ( .NOT. netcdf_extend )  THEN
1408                nc_stat = NF90_CLOSE( id_set_mask(mid,av) )
1409                CALL handle_netcdf_error( 'check_open', 9998 )
1410                CALL local_system('rm ' // TRIM( filename ) )
1411             ENDIF
1412
1413          ENDIF         
1414
1415          IF ( .NOT. netcdf_extend )  THEN
1416!
1417!--          Create a new NetCDF output file with requested NetCDF format
1418             IF ( netcdf_data_format == 1 )  THEN
1419!
1420!--             Classic NetCDF format
1421                nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, &
1422                                       id_set_mask(mid,av) )
1423
1424             ELSEIF ( netcdf_data_format == 2 )  THEN
1425!
1426!--             64bit-offset format
1427                nc_stat = NF90_CREATE( filename,                               &
1428                                       OR( NF90_NOCLOBBER, NF90_64BIT_OFFSET ),&
1429                                       id_set_mask(mid,av) )
1430
1431
1432#if defined( __netcdf4 )
1433             ELSEIF ( netcdf_data_format == 3 )  THEN
1434!
1435!--             NetCDF4/HDF5 format
1436                nc_stat = NF90_CREATE( filename,                               &
1437                                       OR( NF90_NOCLOBBER, NF90_NETCDF4 ),     &
1438                                       id_set_mask(mid,av), COMM = comm2d,     &
1439                                       INFO = MPI_INFO_NULL )
1440
1441             ELSEIF ( netcdf_data_format == 4 )  THEN
1442!
1443!--             NetCDF4/HDF5 format with classic model flag
1444                nc_stat = NF90_CREATE( filename,                               &
1445                                       OR( NF90_NOCLOBBER,                     &
1446                                        OR( NF90_CLASSIC_MODEL, NF90_HDF5 ) ), &
1447                                       id_set_mask(mid,av), COMM = comm2d,     &
1448                                       INFO = MPI_INFO_NULL )
1449#endif
1450             ENDIF
1451
1452             CALL handle_netcdf_error( 'check_open', 9998 )
1453!
1454!--          Define the header
1455             CALL define_netcdf_header( 'ma', netcdf_extend, file_id )
1456
1457          ENDIF
1458
1459
1460#else
1461
1462       CASE ( 101:109, 111:113, 116, 121:160 )
1463
1464!
1465!--       Nothing is done in case of missing netcdf support
1466          RETURN
1467
1468#endif
1469
1470       CASE DEFAULT
1471
1472          WRITE( message_string, * ) 'no OPEN-statement for file-id ',file_id
1473          CALL message( 'check_open', 'PA0172', 2, 2, -1, 6, 1 )
1474
1475    END SELECT
1476
1477!
1478!-- Set open flag
1479    openfile(file_id)%opened = .TRUE.
1480
1481!
1482!-- Formats
14833300 FORMAT ('#'/                                                   &
1484             'coord 1  file=',A,'  filetype=unformatted'/           &
1485             'coord 2  file=',A,'  filetype=unformatted  skip=',I6/ &
1486             'coord 3  file=',A,'  filetype=unformatted  skip=',I6/ &
1487             '#')
14884000 FORMAT ('# ',A)
14895000 FORMAT ('# ',A/                                                          &
1490             '#1 E'/'#2 E*'/'#3 dt'/'#4 u*'/'#5 th*'/'#6 umax'/'#7 vmax'/     &
1491             '#8 wmax'/'#9 div_new'/'#10 div_old'/'#11 z_i_wpt'/'#12 z_i_pt'/ &
1492             '#13 w*'/'#14 w''pt''0'/'#15 w''pt'''/'#16 wpt'/'#17 pt(0)'/     &
1493             '#18 pt(zp)'/'#19 splptx'/'#20 splpty'/'#21 splptz')
14948000 FORMAT (A/                                                            &
1495             '  step    time  # of parts   lPE sent/recv  rPE sent/recv  ',&
1496             'sPE sent/recv  nPE sent/recv  max # of parts'/               &
1497             103('-'))
1498
1499 END SUBROUTINE check_open
Note: See TracBrowser for help on using the repository browser.