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

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

last commit documented

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