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

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

New:
---
Output in NetCDF4-format. New d3par-parameter netcdf_data_format.

(check_open, check_parameters, close_file, data_output_2d, data_output_3d, header, modules, netcdf, parin)

Modules to be loaded for compilation (mbuild) or job execution (mrun)
can be given in the configuration file using variable modules. Example:

%modules ifort/11.0.069:netcdf lcsgih parallel

This method replaces the (undocumented) mpilib-variable.

WARNING: All fixed settings of modules in the scripts mbuild, mrun, and subjob
have been removed! Please set the modules variable appropriately in your
configuration file. (mbuild, mrun, subjob)

Changed:


Parameters netcdf_64bit and netcdf_64bit_3d have been removed. Use
netcdf_data_format = 2 for choosing the classic 64bit-offset format (this is
the default). The offset-format can not be set independently for the
3d-output-data any more.

Parameters netcdf_format_mask, netcdf_format_mask_av, and variables
nc_format_mask, format_parallel_io removed. They are replaced by the new
parameter netcdf_data_format. (check_open, close_file,
data_output_mask, header, init_masks, modules, parin)

Errors:


bugfix in trunk/UTIL/Makefile: forgot to compile for interpret_config

Bugfix: timeseries data have to be collected by PE0 (user_statistics)

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