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

Last change on this file since 964 was 964, checked in by raasch, 12 years ago

old profil-parameters (cross_xtext, cross_normalized_x, etc. ) and respective code removed
(check_open, check_parameters, close_file, data_output_profiles, data_output_spectra, header, modules, parin)

reformatting (netcdf)

append feature removed from unit 14 (check_open)

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