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

Last change on this file since 565 was 565, checked in by helmke, 13 years ago

last commit documented

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