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

Last change on this file since 184 was 146, checked in by raasch, 16 years ago

further updates for turbulent inflow: PE-grid change for restart is working

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