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

Last change on this file since 1036 was 1036, checked in by raasch, 11 years ago

code has been put under the GNU General Public License (v3)

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