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

Last change on this file since 2958 was 2957, checked in by Giersch, 6 years ago

Sky view factors will always be read from file now in case of automatic restarts, corrected error message in case of writing sky view factors

  • Property svn:keywords set to Id
File size: 43.3 KB
RevLine 
[1682]1!> @file check_open.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]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!
[2696]14! You should have received a copy of the GNU General Public License along with
[1036]15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
[2718]17! Copyright 1997-2018 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[247]20! Current revisions:
[1]21! -----------------
[1805]22!
[2516]23!
[1321]24! Former revisions:
25! -----------------
26! $Id: check_open.f90 2957 2018-04-11 08:48:06Z suehring $
[2957]27! Error message has been corrected in case of writing sky view factors
28!
29! 2906 2018-03-19 08:56:40Z Giersch
[2906]30! CASE 88 and 89 has been added for the input/output of sky view factors
31!
32! 2718 2018-01-02 08:49:38Z maronga
[2716]33! Corrected "Former revisions" section
34!
35! 2696 2017-12-14 17:12:51Z kanani
36! Change in file header (GPL part)
37!
38! 2669 2017-12-06 16:03:27Z raasch
[2669]39! file name extension for masked data files is changed to "_M##" and is now
40! appended at the end of the filename,
41! file ids not used any more have been removed
42!
43! 2516 2017-10-04 11:03:04Z suehring
[2516]44! Remove tabs
45!
46! 2514 2017-10-04 09:52:37Z suehring
[2512]47! upper bounds of cross section and 3d output changed from nx+1,ny+1 to nx,ny
48! no output of ghost layer data
49! iso2d-related parts removed
50!
51! 2300 2017-06-29 13:31:14Z raasch
[2300]52! -host
53!
54! 2298 2017-06-29 09:28:18Z raasch
[2298]55! -return_addres, return_username, avs_coor_file_..., avs_data_file_...,
56! cross_ts_numbers, cross_ts_number_count
[1321]57!
[2298]58! 2101 2017-01-05 16:42:31Z suehring
59!
[2064]60! 2063 2016-11-10 17:14:35Z raasch
61! bugfix: opening of PROGRESS file moved out of the NetCDF block
62!
[2041]63! 2040 2016-10-26 16:58:09Z gronemeier
[2040]64! Removed open of file 'PLOTTS_DATA' ( CASE(50:59) ) as it is no longer needed
65!
[2001]66! 2000 2016-08-20 18:09:15Z knoop
67! Forced header and separation lines into 80 columns
68!
[1989]69! 1988 2016-08-10 14:49:06Z gronemeier
70! informative message added if files cannot be opened in newly created directory
71!
[1987]72! 1986 2016-08-10 14:07:17Z gronemeier
73! Bugfix: check if output can be opened in newly created directory. If not
74! wait one second and try again.
75!
[1975]76! 1974 2016-07-26 08:43:25Z gronemeier
77! Bugfix: MPI barriers after deleting non-extendable files must only be called
78! in case of parallel I/O
79!
[1958]80! 1957 2016-07-07 10:43:48Z suehring
81! flight module added
82!
[1805]83! 1804 2016-04-05 16:30:18Z maronga
84! Removed code for parameter file check (__check)
85!
[1784]86! 1783 2016-03-06 18:36:17Z raasch
87! name change of netcdf routines and module + related changes
88!
[1780]89! 1779 2016-03-03 08:01:28Z raasch
90! coupling_char is trimmed at every place it occurs, because it can have
91! different length now
92!
[1746]93! 1745 2016-02-05 13:06:51Z gronemeier
94! Bugfix: added MPI barrier after deleting existing non-extendable file by PE0
95!
[1683]96! 1682 2015-10-07 23:56:08Z knoop
97! Code annotations made doxygen readable
98!
[1552]99! 1551 2015-03-03 14:18:16Z maronga
100! Removed redundant output for combine_plot_fields
101!
[1469]102! 1468 2014-09-24 14:06:57Z maronga
103! Adapted for use on up to 6-digit processor cores
104! Added file unit 117 (PROGRESS)
105!
[1360]106! 1359 2014-04-11 17:15:14Z hoffmann
107! Format of particle exchange statistics extended to reasonable numbers of     
108! particles.
109!
[1354]110! 1353 2014-04-08 15:21:23Z heinze
111! REAL constants provided with KIND-attribute,
112! declaration for unused variables xkoor, ykoor, zkoor removed
113!
[1329]114! 1327 2014-03-21 11:00:16Z raasch
115! parts concerning iso2d and avs output removed
116!
[1321]117! 1320 2014-03-20 08:40:49Z raasch
[1320]118! ONLY-attribute added to USE-statements,
119! kind-parameters added to all INTEGER and REAL declaration statements,
120! kinds are defined in new module kinds,
121! old module precision_kind is removed,
122! revision history before 2012 removed,
123! comment fields (!:) to be used for variable explanations added to
124! all variable declaration statements
[1]125!
[1107]126! 1106 2013-03-04 05:31:38Z raasch
127! array_kind renamed precision_kind
128!
[1093]129! 1092 2013-02-02 11:24:22Z raasch
130! unused variables removed
131!
[1037]132! 1036 2012-10-22 13:43:42Z raasch
133! code put under GPL (PALM 3.9)
134!
[1035]135! 1031 2012-10-19 14:35:30Z raasch
136! netCDF4 without parallel file support implemented,
137! opening of netCDF files are done by new routines create_netcdf_file and
138! open_write_netcdf_file
139!
[965]140! 964 2012-07-26 09:14:24Z raasch
141! old profil-units (40:49) removed,
142! append feature removed from unit 14
143!
[850]144! 849 2012-03-15 10:35:09Z raasch
145! comment changed
146!
[810]147! 809 2012-01-30 13:32:58Z maronga
148! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives
149!
[808]150! 807 2012-01-25 11:53:51Z maronga
151! New cpp directive "__check" implemented which is used by check_namelist_files
152!
[1]153! Revision 1.1  1997/08/11 06:10:55  raasch
154! Initial revision
155!
156!
157! Description:
158! ------------
[1682]159!> Check if file unit is open. If not, open file and, if necessary, write a
160!> header or start other initializing actions, respectively.
[1]161!------------------------------------------------------------------------------!
[1682]162SUBROUTINE check_open( file_id )
163 
[1]164
[1320]165    USE arrays_3d,                                                             &
166        ONLY:  zu
167
168    USE control_parameters,                                                    &
[2300]169        ONLY:  coupling_char, data_output_2d_on_each_pe, max_masks,            &
[2298]170               message_string, mid, nz_do3d, openfile, run_description_header, &
171               runnr
[1320]172
173    USE grid_variables,                                                        &
174        ONLY:  dx, dy
175
176    USE indices,                                                               &
[1551]177        ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nyng, nys, nysg, nz, nzb, nzt 
[1320]178
179    USE kinds
180
[1783]181#if defined( __netcdf )
182    USE NETCDF
183#endif
[1320]184
[1783]185    USE netcdf_interface,                                                      &
[1957]186        ONLY:  id_set_fl, id_set_mask, id_set_pr, id_set_prt, id_set_pts,      &
187               id_set_sp, id_set_ts, id_set_xy, id_set_xz, id_set_yz,          &
188               id_set_3d, nc_stat, netcdf_create_file, netcdf_data_format,     &
189               netcdf_define_header, netcdf_handle_error, netcdf_open_write_file
[1783]190
[1320]191    USE particle_attributes,                                                   &
192        ONLY:  max_number_of_particle_groups, number_of_particle_groups,       &
193               particle_groups
194
[1]195    USE pegrid
196
[1986]197    USE posix_calls_from_fortran,                                              &
198        ONLY:  fortran_sleep
199
[1320]200
[1]201    IMPLICIT NONE
202
[2669]203    CHARACTER (LEN=4)   ::  mask_char               !<
[1682]204    CHARACTER (LEN=2)   ::  suffix                  !<
205    CHARACTER (LEN=30)  ::  filename                !<
206    CHARACTER (LEN=80)  ::  rtext                   !<
207    CHARACTER (LEN=100) ::  line                    !<
[1]208
[1682]209    INTEGER(iwp) ::  av          !<
210    INTEGER(iwp) ::  file_id     !<
211    INTEGER(iwp) ::  i           !<
[1986]212    INTEGER(iwp) ::  ioerr       !< IOSTAT flag for IO-commands ( 0 = no error )
[1682]213    INTEGER(iwp) ::  j           !<
214    INTEGER(iwp) ::  k           !<
[1320]215   
[2512]216    LOGICAL ::  netcdf_extend    !<
[1]217
218!
219!-- Immediate return if file already open
220    IF ( openfile(file_id)%opened )  RETURN
221
222!
223!-- Only certain files are allowed to be re-opened
224!-- NOTE: some of the other files perhaps also could be re-opened, but it
225!--       has not been checked so far, if it works!
226    IF ( openfile(file_id)%opened_before )  THEN
227       SELECT CASE ( file_id )
[2669]228          CASE ( 13, 14, 21, 22, 23, 80, 85, 117 )
[1]229             IF ( file_id == 14 .AND. openfile(file_id)%opened_before )  THEN
[1320]230                message_string = 're-open of unit ' //                         &
[274]231                                 '14 is not verified. Please check results!'
[247]232                CALL message( 'check_open', 'PA0165', 0, 1, 0, 6, 0 )       
[1]233             ENDIF
[143]234
[1]235          CASE DEFAULT
[1320]236             WRITE( message_string, * ) 're-opening of file-id ', file_id,     &
[274]237                                        ' is not allowed'
[247]238             CALL message( 'check_open', 'PA0166', 0, 1, 0, 6, 0 )   
239               
[1]240             RETURN
[143]241
[1]242       END SELECT
243    ENDIF
244
245!
246!-- Check if file may be opened on the relevant PE
247    SELECT CASE ( file_id )
248
[2669]249       CASE ( 15, 16, 17, 18, 19, 50:59, 104:105, 107, 109, 117 )
[2514]250     
[493]251          IF ( myid /= 0 )  THEN
[1320]252             WRITE( message_string, * ) 'opening file-id ',file_id,            &
[493]253                                        ' not allowed for PE ',myid
254             CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
255          ENDIF
256
[564]257       CASE ( 101:103, 106, 111:113, 116, 201:200+2*max_masks )
[493]258
[1031]259          IF ( netcdf_data_format < 5 )  THEN
[247]260         
[410]261             IF ( myid /= 0 )  THEN
[1320]262                WRITE( message_string, * ) 'opening file-id ',file_id,         &
[410]263                                           ' not allowed for PE ',myid
264                CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
265             ENDIF
[2514]266     
[493]267          ENDIF
[1]268
269       CASE ( 21, 22, 23 )
270
271          IF ( .NOT.  data_output_2d_on_each_pe )  THEN
272             IF ( myid /= 0 )  THEN
[1320]273                WRITE( message_string, * ) 'opening file-id ',file_id,         &
[247]274                                           ' not allowed for PE ',myid
[277]275                CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
[247]276             END IF
[1]277          ENDIF
278
[2669]279       CASE ( 90:99 )
[1]280
281!
282!--       File-ids that are used temporarily in other routines
[1320]283          WRITE( message_string, * ) 'opening file-id ',file_id,               &
[274]284                                    ' is not allowed since it is used otherwise'
[247]285          CALL message( 'check_open', 'PA0168', 0, 1, 0, 6, 0 ) 
286         
[1]287    END SELECT
288
289!
290!-- Open relevant files
291    SELECT CASE ( file_id )
292
293       CASE ( 11 )
294
[1779]295          OPEN ( 11, FILE='PARIN'//TRIM( coupling_char ), FORM='FORMATTED',    &
[102]296                     STATUS='OLD' )
[1]297
298       CASE ( 13 )
299
300          IF ( myid_char == '' )  THEN
[1779]301             OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//myid_char,        &
[102]302                        FORM='UNFORMATTED', STATUS='OLD' )
[1]303          ELSE
[143]304!
[1468]305!--          First opening of unit 13 openes file _000000 on all PEs because
306!--          only this file contains the global variables
[143]307             IF ( .NOT. openfile(file_id)%opened_before )  THEN
[1779]308                OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//'/_000000',    &
[143]309                           FORM='UNFORMATTED', STATUS='OLD' )
310             ELSE
[1779]311                OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//'/'//          &
312                           myid_char, FORM='UNFORMATTED', STATUS='OLD' )
[143]313             ENDIF
[1]314          ENDIF
315
316       CASE ( 14 )
317
318          IF ( myid_char == '' )  THEN
[1779]319             OPEN ( 14, FILE='BINOUT'//TRIM( coupling_char )//myid_char,       &
[102]320                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]321          ELSE
322             IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
[1779]323                CALL local_system( 'mkdir  BINOUT' // TRIM( coupling_char ) )
[1]324             ENDIF
[1804]325#if defined( __parallel )
[1]326!
327!--          Set a barrier in order to allow that all other processors in the
328!--          directory created by PE0 can open their file
329             CALL MPI_BARRIER( comm2d, ierr )
330#endif
[1986]331             ioerr = 1
332             DO WHILE ( ioerr /= 0 )
333                OPEN ( 14, FILE='BINOUT'//TRIM(coupling_char)//'/'//myid_char, &
334                           FORM='UNFORMATTED', IOSTAT=ioerr )
[1988]335                IF ( ioerr /= 0 )  THEN
336                   WRITE( 9, * )  '*** could not open "BINOUT'//         &
337                                  TRIM(coupling_char)//'/'//myid_char//  &
338                                  '"! Trying again in 1 sec.'
339                   CALL fortran_sleep( 1 )
340                ENDIF
[1986]341             ENDDO
342
[1]343          ENDIF
344
345       CASE ( 15 )
346
[1779]347          OPEN ( 15, FILE='RUN_CONTROL'//TRIM( coupling_char ),                &
348                     FORM='FORMATTED' )
[1]349
350       CASE ( 16 )
351
[1779]352          OPEN ( 16, FILE='LIST_PROFIL'//TRIM( coupling_char ),                &
353                     FORM='FORMATTED' )
[1]354
355       CASE ( 17 )
356
[1779]357          OPEN ( 17, FILE='LIST_PROFIL_1D'//TRIM( coupling_char ),             &
358                     FORM='FORMATTED' )
[1]359
360       CASE ( 18 )
361
[1779]362          OPEN ( 18, FILE='CPU_MEASURES'//TRIM( coupling_char ),               &
363                     FORM='FORMATTED' )
[1]364
365       CASE ( 19 )
366
[1779]367          OPEN ( 19, FILE='HEADER'//TRIM( coupling_char ), FORM='FORMATTED' )
[1]368
369       CASE ( 20 )
370
371          IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
[1779]372             CALL local_system( 'mkdir  DATA_LOG' // TRIM( coupling_char ) )
[1]373          ENDIF
374          IF ( myid_char == '' )  THEN
[1779]375             OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/_000000',    &
[102]376                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]377          ELSE
[1804]378#if defined( __parallel )
[1]379!
380!--          Set a barrier in order to allow that all other processors in the
381!--          directory created by PE0 can open their file
382             CALL MPI_BARRIER( comm2d, ierr )
383#endif
[1986]384             ioerr = 1
385             DO WHILE ( ioerr /= 0 )
386                OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/'//       &
387                           myid_char, FORM='UNFORMATTED', POSITION='APPEND',   &
388                           IOSTAT=ioerr )
[1988]389                IF ( ioerr /= 0 )  THEN
390                   WRITE( 9, * )  '*** could not open "DATA_LOG'//         &
391                                  TRIM( coupling_char )//'/'//myid_char//  &
392                                  '"! Trying again in 1 sec.'
393                   CALL fortran_sleep( 1 )
394                ENDIF
[1986]395             ENDDO
396
[1]397          ENDIF
398
399       CASE ( 21 )
400
401          IF ( data_output_2d_on_each_pe )  THEN
[1320]402             OPEN ( 21, FILE='PLOT2D_XY'//TRIM( coupling_char )//myid_char,    &
[102]403                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]404          ELSE
[1779]405             OPEN ( 21, FILE='PLOT2D_XY'//TRIM( coupling_char ),                       &
[102]406                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]407          ENDIF
408
409          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
410!
[2512]411!--          Write index bounds of total domain for combine_plot_fields
[1]412             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
[2512]413                WRITE (21)   0, nx,  0, ny
[1]414             ENDIF
415
416          ENDIF
417
418       CASE ( 22 )
419
420          IF ( data_output_2d_on_each_pe )  THEN
[1320]421             OPEN ( 22, FILE='PLOT2D_XZ'//TRIM( coupling_char )//myid_char,    &
[102]422                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]423          ELSE
[1779]424             OPEN ( 22, FILE='PLOT2D_XZ'//TRIM( coupling_char ),               &
425                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]426          ENDIF
427
428          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
429!
[2512]430!--          Write index bounds of total domain for combine_plot_fields
[1]431             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
[2512]432                WRITE (22)   0, nx, 0, nz+1    ! output part
[1]433             ENDIF
434
435          ENDIF
436
437       CASE ( 23 )
438
439          IF ( data_output_2d_on_each_pe )  THEN
[1320]440             OPEN ( 23, FILE='PLOT2D_YZ'//TRIM( coupling_char )//myid_char,    &
[102]441                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]442          ELSE
[1779]443             OPEN ( 23, FILE='PLOT2D_YZ'//TRIM( coupling_char ),               &
444                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]445          ENDIF
446
447          IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
448!
[2512]449!--          Write index bounds of total domain for combine_plot_fields
[1]450             IF ( data_output_2d_on_each_pe  .AND.  myid_char /= '' )  THEN
[2512]451                WRITE (23)   0, ny, 0, nz+1    ! output part
[1]452             ENDIF
453
454          ENDIF
455
456       CASE ( 30 )
457
[1320]458          OPEN ( 30, FILE='PLOT3D_DATA'//TRIM( coupling_char )//myid_char,     &
[102]459                     FORM='UNFORMATTED' )
[1]460!
[2512]461!--       Specifications for combine_plot_fields
[1]462          IF ( myid == 0 )  THEN
463#if defined( __parallel )
[2512]464             WRITE ( 30 )  0, nx, 0, ny, 0, nz_do3d
[1]465#endif
466          ENDIF
467
468       CASE ( 80 )
469
470          IF ( myid_char == '' )  THEN
[105]471             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM(coupling_char)//myid_char, &
[102]472                        FORM='FORMATTED', POSITION='APPEND' )
[1]473          ELSE
474             IF ( myid == 0  .AND.  .NOT. openfile(80)%opened_before )  THEN
[1779]475                CALL local_system( 'mkdir  PARTICLE_INFOS' //                  &
476                                   TRIM( coupling_char ) )
[1]477             ENDIF
[1804]478#if defined( __parallel )
[1]479!
480!--          Set a barrier in order to allow that thereafter all other
481!--          processors in the directory created by PE0 can open their file.
482!--          WARNING: The following barrier will lead to hanging jobs, if
483!--                   check_open is first called from routine
484!--                   allocate_prt_memory!
485             IF ( .NOT. openfile(80)%opened_before )  THEN
486                CALL MPI_BARRIER( comm2d, ierr )
487             ENDIF
488#endif
[1320]489             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM( coupling_char )//'/'//    &
490                             myid_char,                                        &
[102]491                        FORM='FORMATTED', POSITION='APPEND' )
[1]492          ENDIF
493
494          IF ( .NOT. openfile(80)%opened_before )  THEN
495             WRITE ( 80, 8000 )  TRIM( run_description_header )
496          ENDIF
497
498       CASE ( 85 )
499
500          IF ( myid_char == '' )  THEN
[1320]501             OPEN ( 85, FILE='PARTICLE_DATA'//TRIM(coupling_char)//myid_char,  &
[102]502                        FORM='UNFORMATTED', POSITION='APPEND' )
[1]503          ELSE
504             IF ( myid == 0  .AND.  .NOT. openfile(85)%opened_before )  THEN
[1779]505                CALL local_system( 'mkdir  PARTICLE_DATA' //                   &
506                                   TRIM( coupling_char ) )
[1]507             ENDIF
[1804]508#if defined( __parallel )
[1]509!
510!--          Set a barrier in order to allow that thereafter all other
511!--          processors in the directory created by PE0 can open their file
512             CALL MPI_BARRIER( comm2d, ierr )
513#endif
[1986]514             ioerr = 1
515             DO WHILE ( ioerr /= 0 )
516                OPEN ( 85, FILE='PARTICLE_DATA'//TRIM( coupling_char )//'/'//  &
517                           myid_char,                                          &
518                           FORM='UNFORMATTED', POSITION='APPEND', IOSTAT=ioerr )
[1988]519                IF ( ioerr /= 0 )  THEN
[2906]520                   WRITE( 9, * )  '*** could not open "PARTICLE_DATA'//        &
521                                  TRIM( coupling_char )//'/'//myid_char//      &
[1988]522                                  '"! Trying again in 1 sec.'
523                   CALL fortran_sleep( 1 )
524                ENDIF
[1986]525             ENDDO
526
[1]527          ENDIF
528
529          IF ( .NOT. openfile(85)%opened_before )  THEN
530             WRITE ( 85 )  run_description_header
531!
532!--          Attention: change version number whenever the output format on
[849]533!--                     unit 85 is changed (see also in routine
534!--                     lpm_data_output_particles)
[1359]535             rtext = 'data format version 3.1'
[1]536             WRITE ( 85 )  rtext
[1320]537             WRITE ( 85 )  number_of_particle_groups,                          &
[1]538                           max_number_of_particle_groups
539             WRITE ( 85 )  particle_groups
[1359]540             WRITE ( 85 )  nxl, nxr, nys, nyn, nzb, nzt, nbgp
[1]541          ENDIF
542
[2063]543!
[2906]544!--    File where sky-view factors and further required data is stored will be
545!--    read
546       CASE ( 88 )
547
548          IF (numprocs_previous_run /= numprocs) THEN
549             WRITE( message_string, * ) 'A different number of processors',    &
550                                        ' between the run that has written',   &
551                                        ' the svf data and the one that will ',&
552                                        ' read it is not allowed' 
553             CALL message( 'check_open', 'PA0484', 1, 2, 0, 6, 0 )
554          ENDIF
555
556          IF ( myid_char == '' )  THEN
557             OPEN ( 88, FILE='SVFIN'//TRIM( coupling_char )//myid_char,        &
558                        FORM='UNFORMATTED', STATUS='OLD', IOSTAT=ioerr )
559          ELSE
560
561             OPEN ( 88, FILE='SVFIN'//TRIM( coupling_char )//'/'//myid_char,   &
562                        FORM='UNFORMATTED', STATUS='OLD', IOSTAT=ioerr )
563          ENDIF
564
565!
566!--    File where sky-view factors and further required data is stored will be
567!--    created
568       CASE ( 89 )
569
570          IF ( myid_char == '' )  THEN
571             OPEN ( 89, FILE='SVFOUT'//TRIM( coupling_char )//myid_char,       &
572                        FORM='UNFORMATTED', STATUS='NEW' )
573          ELSE
574             IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
575                CALL local_system( 'mkdir  SVFOUT' // TRIM( coupling_char ) )
576             ENDIF
577#if defined( __parallel )
578!
579!--          Set a barrier in order to allow that all other processors in the
580!--          directory created by PE0 can open their file
581             CALL MPI_BARRIER( comm2d, ierr )
582#endif
583             ioerr = 1
584             DO WHILE ( ioerr /= 0 )
585                OPEN ( 89, FILE='SVFOUT'//TRIM(coupling_char)//'/'//myid_char, &
586                           FORM='UNFORMATTED', STATUS='NEW', IOSTAT=ioerr )
587                IF ( ioerr /= 0 )  THEN
[2957]588                   WRITE( 9, * )  '*** could not open "SVFOUT'//               &
589                                  TRIM(coupling_char)//'/'//myid_char//        &
[2906]590                                  '"! Trying again in 1 sec.'
591                   CALL fortran_sleep( 1 )
592                ENDIF
593             ENDDO
594
595          ENDIF
596
597!
[2063]598!--    Progress file that is used by the PALM watchdog
599       CASE ( 117 )
600
601          OPEN ( 117, FILE='PROGRESS'//TRIM( coupling_char ),                  &
602                      STATUS='REPLACE', FORM='FORMATTED' )
603
[1]604#if defined( __netcdf )
605       CASE ( 101, 111 )
606!
607!--       Set filename depending on unit number
608          IF ( file_id == 101 )  THEN
[1779]609             filename = 'DATA_2D_XY_NETCDF' // TRIM( coupling_char )
[1]610             av = 0
611          ELSE
[1779]612             filename = 'DATA_2D_XY_AV_NETCDF' // TRIM( coupling_char )
[1]613             av = 1
614          ENDIF
615!
[1031]616!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]617!--       be opened for extension, if its dimensions and variables match the
618!--       actual run.
619          INQUIRE( FILE=filename, EXIST=netcdf_extend )
620          IF ( netcdf_extend )  THEN
621!
[1031]622!--          Open an existing netCDF file for output
[1783]623             CALL netcdf_open_write_file( filename, id_set_xy(av), .TRUE., 20 )
[1]624!
625!--          Read header information and set all ids. If there is a mismatch
626!--          between the previuos and the actual run, netcdf_extend is returned
627!--          as .FALSE.
[1783]628             CALL netcdf_define_header( 'xy', netcdf_extend, av )
[1]629
630!
631!--          Remove the local file, if it can not be extended
632             IF ( .NOT. netcdf_extend )  THEN
633                nc_stat = NF90_CLOSE( id_set_xy(av) )
[1783]634                CALL netcdf_handle_error( 'check_open', 21 )
[493]635                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1804]636#if defined( __parallel )
[1745]637!
638!--             Set a barrier in order to assure that PE0 deleted the old file
[1974]639!--             before any other processor tries to open a new file.
640!--             Barrier is only needed in case of parallel I/O
641                IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
[1745]642#endif
[1]643             ENDIF
644
[1745]645          ENDIF
[1]646
647          IF ( .NOT. netcdf_extend )  THEN
648!
[1031]649!--          Create a new netCDF output file with requested netCDF format
[1783]650             CALL netcdf_create_file( filename, id_set_xy(av), .TRUE., 22 )
[493]651
652!
[1]653!--          Define the header
[1783]654             CALL netcdf_define_header( 'xy', netcdf_extend, av )
[1]655
[493]656!
[1031]657!--          In case of parallel netCDF output, create flag file which tells
[493]658!--          combine_plot_fields that nothing is to do.
[1031]659             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
[493]660                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XY' )
661                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
662                CLOSE( 99 )
663             ENDIF
664
[1]665          ENDIF
666
667       CASE ( 102, 112 )
668!
669!--       Set filename depending on unit number
670          IF ( file_id == 102 )  THEN
[1779]671             filename = 'DATA_2D_XZ_NETCDF' // TRIM( coupling_char )
[1]672             av = 0
673          ELSE
[1779]674             filename = 'DATA_2D_XZ_AV_NETCDF' // TRIM( coupling_char )
[1]675             av = 1
676          ENDIF
677!
[1031]678!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]679!--       be opened for extension, if its dimensions and variables match the
680!--       actual run.
681          INQUIRE( FILE=filename, EXIST=netcdf_extend )
682
683          IF ( netcdf_extend )  THEN
684!
[1031]685!--          Open an existing netCDF file for output
[1783]686             CALL netcdf_open_write_file( filename, id_set_xz(av), .TRUE., 23 )
[1]687!
688!--          Read header information and set all ids. If there is a mismatch
689!--          between the previuos and the actual run, netcdf_extend is returned
690!--          as .FALSE.
[1783]691             CALL netcdf_define_header( 'xz', netcdf_extend, av )
[1]692
693!
694!--          Remove the local file, if it can not be extended
695             IF ( .NOT. netcdf_extend )  THEN
696                nc_stat = NF90_CLOSE( id_set_xz(av) )
[1783]697                CALL netcdf_handle_error( 'check_open', 24 )
[493]698                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1804]699#if defined( __parallel )
[1745]700!
701!--             Set a barrier in order to assure that PE0 deleted the old file
702!--             before any other processor tries to open a new file
[1974]703!--             Barrier is only needed in case of parallel I/O
704                IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
[1745]705#endif
[1]706             ENDIF
707
[1745]708          ENDIF
[1]709
710          IF ( .NOT. netcdf_extend )  THEN
711!
[1031]712!--          Create a new netCDF output file with requested netCDF format
[1783]713             CALL netcdf_create_file( filename, id_set_xz(av), .TRUE., 25 )
[493]714
715!
[1]716!--          Define the header
[1783]717             CALL netcdf_define_header( 'xz', netcdf_extend, av )
[1]718
[493]719!
[1031]720!--          In case of parallel netCDF output, create flag file which tells
[493]721!--          combine_plot_fields that nothing is to do.
[1031]722             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
[493]723                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XZ' )
724                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
725                CLOSE( 99 )
726             ENDIF
727
[1]728          ENDIF
729
730       CASE ( 103, 113 )
731!
732!--       Set filename depending on unit number
733          IF ( file_id == 103 )  THEN
[1779]734             filename = 'DATA_2D_YZ_NETCDF' // TRIM( coupling_char )
[1]735             av = 0
736          ELSE
[1779]737             filename = 'DATA_2D_YZ_AV_NETCDF' // TRIM( coupling_char )
[1]738             av = 1
739          ENDIF
740!
[1031]741!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]742!--       be opened for extension, if its dimensions and variables match the
743!--       actual run.
744          INQUIRE( FILE=filename, EXIST=netcdf_extend )
745
746          IF ( netcdf_extend )  THEN
747!
[1031]748!--          Open an existing netCDF file for output
[1783]749             CALL netcdf_open_write_file( filename, id_set_yz(av), .TRUE., 26 )
[1]750!
751!--          Read header information and set all ids. If there is a mismatch
752!--          between the previuos and the actual run, netcdf_extend is returned
753!--          as .FALSE.
[1783]754             CALL netcdf_define_header( 'yz', netcdf_extend, av )
[1]755
756!
757!--          Remove the local file, if it can not be extended
758             IF ( .NOT. netcdf_extend )  THEN
759                nc_stat = NF90_CLOSE( id_set_yz(av) )
[1783]760                CALL netcdf_handle_error( 'check_open', 27 )
[493]761                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1804]762#if defined( __parallel )
[1745]763!
764!--             Set a barrier in order to assure that PE0 deleted the old file
765!--             before any other processor tries to open a new file
[1974]766!--             Barrier is only needed in case of parallel I/O
767                IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
[1745]768#endif
[1]769             ENDIF
770
[1745]771          ENDIF
[1]772
773          IF ( .NOT. netcdf_extend )  THEN
774!
[1031]775!--          Create a new netCDF output file with requested netCDF format
[1783]776             CALL netcdf_create_file( filename, id_set_yz(av), .TRUE., 28 )
[493]777
778!
[1]779!--          Define the header
[1783]780             CALL netcdf_define_header( 'yz', netcdf_extend, av )
[1]781
[493]782!
[1031]783!--          In case of parallel netCDF output, create flag file which tells
[493]784!--          combine_plot_fields that nothing is to do.
[1031]785             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
[493]786                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_YZ' )
787                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
788                CLOSE( 99 )
789             ENDIF
790
[1]791          ENDIF
792
793       CASE ( 104 )
794!
[102]795!--       Set filename
[1779]796          filename = 'DATA_1D_PR_NETCDF' // TRIM( coupling_char )
[102]797
798!
[1031]799!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]800!--       be opened for extension, if its variables match the actual run.
[102]801          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1]802
803          IF ( netcdf_extend )  THEN
804!
[1031]805!--          Open an existing netCDF file for output
[1783]806             CALL netcdf_open_write_file( filename, id_set_pr, .FALSE., 29 )
[1]807!
808!--          Read header information and set all ids. If there is a mismatch
809!--          between the previuos and the actual run, netcdf_extend is returned
810!--          as .FALSE.
[1783]811             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
[1]812
813!
814!--          Remove the local file, if it can not be extended
815             IF ( .NOT. netcdf_extend )  THEN
816                nc_stat = NF90_CLOSE( id_set_pr )
[1783]817                CALL netcdf_handle_error( 'check_open', 30 )
[102]818                CALL local_system( 'rm ' // TRIM( filename ) )
[1]819             ENDIF
820
821          ENDIF         
822
823          IF ( .NOT. netcdf_extend )  THEN
824!
[1031]825!--          Create a new netCDF output file with requested netCDF format
[1783]826             CALL netcdf_create_file( filename, id_set_pr, .FALSE., 31 )
[1]827!
828!--          Define the header
[1783]829             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
[1]830
831          ENDIF
832
833       CASE ( 105 )
834!
[102]835!--       Set filename
[1779]836          filename = 'DATA_1D_TS_NETCDF' // TRIM( coupling_char )
[102]837
838!
[1031]839!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]840!--       be opened for extension, if its variables match the actual run.
[102]841          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1]842
843          IF ( netcdf_extend )  THEN
844!
[1031]845!--          Open an existing netCDF file for output
[1783]846             CALL netcdf_open_write_file( filename, id_set_ts, .FALSE., 32 )
[1]847!
848!--          Read header information and set all ids. If there is a mismatch
849!--          between the previuos and the actual run, netcdf_extend is returned
850!--          as .FALSE.
[1783]851             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
[1]852
853!
854!--          Remove the local file, if it can not be extended
855             IF ( .NOT. netcdf_extend )  THEN
856                nc_stat = NF90_CLOSE( id_set_ts )
[1783]857                CALL netcdf_handle_error( 'check_open', 33 )
[102]858                CALL local_system( 'rm ' // TRIM( filename ) )
[1]859             ENDIF
860
861          ENDIF         
862
863          IF ( .NOT. netcdf_extend )  THEN
864!
[1031]865!--          Create a new netCDF output file with requested netCDF format
[1783]866             CALL netcdf_create_file( filename, id_set_ts, .FALSE., 34 )
[1]867!
868!--          Define the header
[1783]869             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
[1]870
871          ENDIF
872
873
874       CASE ( 106, 116 )
875!
876!--       Set filename depending on unit number
877          IF ( file_id == 106 )  THEN
[1779]878             filename = 'DATA_3D_NETCDF' // TRIM( coupling_char )
[1]879             av = 0
880          ELSE
[1779]881             filename = 'DATA_3D_AV_NETCDF' // TRIM( coupling_char )
[1]882             av = 1
883          ENDIF
884!
[1031]885!--       Inquire, if there is a netCDF file from a previous run. This should
[1]886!--       be opened for extension, if its dimensions and variables match the
887!--       actual run.
888          INQUIRE( FILE=filename, EXIST=netcdf_extend )
889
890          IF ( netcdf_extend )  THEN
891!
[1031]892!--          Open an existing netCDF file for output
[1783]893             CALL netcdf_open_write_file( filename, id_set_3d(av), .TRUE., 35 )
[1]894!
895!--          Read header information and set all ids. If there is a mismatch
896!--          between the previuos and the actual run, netcdf_extend is returned
897!--          as .FALSE.
[1783]898             CALL netcdf_define_header( '3d', netcdf_extend, av )
[1]899
900!
901!--          Remove the local file, if it can not be extended
902             IF ( .NOT. netcdf_extend )  THEN
903                nc_stat = NF90_CLOSE( id_set_3d(av) )
[1783]904                CALL netcdf_handle_error( 'check_open', 36 )
[1745]905                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
[1804]906#if defined( __parallel )
[1745]907!
908!--             Set a barrier in order to assure that PE0 deleted the old file
909!--             before any other processor tries to open a new file
[1974]910!--             Barrier is only needed in case of parallel I/O
911                IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
[1745]912#endif
[1]913             ENDIF
914
[1745]915          ENDIF
[1]916
917          IF ( .NOT. netcdf_extend )  THEN
918!
[1031]919!--          Create a new netCDF output file with requested netCDF format
[1783]920             CALL netcdf_create_file( filename, id_set_3d(av), .TRUE., 37 )
[493]921
922!
[1]923!--          Define the header
[1783]924             CALL netcdf_define_header( '3d', netcdf_extend, av )
[1]925
[493]926!
[1031]927!--          In case of parallel netCDF output, create flag file which tells
[493]928!--          combine_plot_fields that nothing is to do.
[1031]929             IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
[493]930                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_3D' )
931                WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
932                CLOSE( 99 )
933             ENDIF
934
[1]935          ENDIF
936
937
938       CASE ( 107 )
939!
[102]940!--       Set filename
[1779]941          filename = 'DATA_1D_SP_NETCDF' // TRIM( coupling_char )
[102]942
943!
[1031]944!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]945!--       be opened for extension, if its variables match the actual run.
[102]946          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1]947
948          IF ( netcdf_extend )  THEN
949!
[1031]950!--          Open an existing netCDF file for output
[1783]951             CALL netcdf_open_write_file( filename, id_set_sp, .FALSE., 38 )
[263]952
[1]953!
954!--          Read header information and set all ids. If there is a mismatch
955!--          between the previuos and the actual run, netcdf_extend is returned
956!--          as .FALSE.
[1783]957             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
[1]958
959!
960!--          Remove the local file, if it can not be extended
961             IF ( .NOT. netcdf_extend )  THEN
962                nc_stat = NF90_CLOSE( id_set_sp )
[1783]963                CALL netcdf_handle_error( 'check_open', 39 )
[102]964                CALL local_system( 'rm ' // TRIM( filename ) )
[1]965             ENDIF
966
967          ENDIF         
968
969          IF ( .NOT. netcdf_extend )  THEN
970!
[1031]971!--          Create a new netCDF output file with requested netCDF format
[1783]972             CALL netcdf_create_file( filename, id_set_sp, .FALSE., 40 )
[1]973!
974!--          Define the header
[1783]975             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
[1]976
977          ENDIF
978
979
980       CASE ( 108 )
981
982          IF ( myid_char == '' )  THEN
[1779]983             filename = 'DATA_PRT_NETCDF' // TRIM( coupling_char )
[1]984          ELSE
[1320]985             filename = 'DATA_PRT_NETCDF' // TRIM( coupling_char ) // '/' //   &
[105]986                        myid_char
[1]987          ENDIF
988!
[1031]989!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]990!--       be opened for extension, if its variables match the actual run.
991          INQUIRE( FILE=filename, EXIST=netcdf_extend )
992
993          IF ( netcdf_extend )  THEN
994!
[1031]995!--          Open an existing netCDF file for output
[1783]996             CALL netcdf_open_write_file( filename, id_set_prt, .FALSE., 41 )
[1]997!
998!--          Read header information and set all ids. If there is a mismatch
999!--          between the previuos and the actual run, netcdf_extend is returned
1000!--          as .FALSE.
[1783]1001             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
[1]1002
1003!
1004!--          Remove the local file, if it can not be extended
1005             IF ( .NOT. netcdf_extend )  THEN
1006                nc_stat = NF90_CLOSE( id_set_prt )
[1783]1007                CALL netcdf_handle_error( 'check_open', 42 )
[1745]1008                CALL local_system( 'rm ' // TRIM( filename ) )
[1]1009             ENDIF
1010
1011          ENDIF         
1012
1013          IF ( .NOT. netcdf_extend )  THEN
1014
1015!
1016!--          For runs on multiple processors create the subdirectory
1017             IF ( myid_char /= '' )  THEN
[1320]1018                IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  &
[1]1019                THEN    ! needs modification in case of non-extendable sets
[1320]1020                   CALL local_system( 'mkdir  DATA_PRT_NETCDF' //              &
[105]1021                                       TRIM( coupling_char ) // '/' )
[1]1022                ENDIF
[1804]1023#if defined( __parallel )
[807]1024!
[1]1025!--             Set a barrier in order to allow that all other processors in the
1026!--             directory created by PE0 can open their file
1027                CALL MPI_BARRIER( comm2d, ierr )
1028#endif
1029             ENDIF
1030
1031!
[1031]1032!--          Create a new netCDF output file with requested netCDF format
[1783]1033             CALL netcdf_create_file( filename, id_set_prt, .FALSE., 43 )
[519]1034
1035!
[1]1036!--          Define the header
[1783]1037             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
[1]1038
1039          ENDIF
1040
1041       CASE ( 109 )
1042!
[102]1043!--       Set filename
[1779]1044          filename = 'DATA_1D_PTS_NETCDF' // TRIM( coupling_char )
[102]1045
1046!
[1031]1047!--       Inquire, if there is a netCDF file from a previuos run. This should
[1]1048!--       be opened for extension, if its variables match the actual run.
[102]1049          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1]1050
1051          IF ( netcdf_extend )  THEN
1052!
[1031]1053!--          Open an existing netCDF file for output
[1783]1054             CALL netcdf_open_write_file( filename, id_set_pts, .FALSE., 393 )
[1]1055!
1056!--          Read header information and set all ids. If there is a mismatch
1057!--          between the previuos and the actual run, netcdf_extend is returned
1058!--          as .FALSE.
[1783]1059             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
[1]1060
1061!
1062!--          Remove the local file, if it can not be extended
1063             IF ( .NOT. netcdf_extend )  THEN
1064                nc_stat = NF90_CLOSE( id_set_pts )
[1783]1065                CALL netcdf_handle_error( 'check_open', 394 )
[102]1066                CALL local_system( 'rm ' // TRIM( filename ) )
[1]1067             ENDIF
1068
1069          ENDIF         
1070
1071          IF ( .NOT. netcdf_extend )  THEN
1072!
[1031]1073!--          Create a new netCDF output file with requested netCDF format
[1783]1074             CALL netcdf_create_file( filename, id_set_pts, .FALSE., 395 )
[1]1075!
1076!--          Define the header
[1783]1077             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
[1]1078
1079          ENDIF
[410]1080
[1468]1081!
[1957]1082!--    nc-file for virtual flight measurements
1083       CASE ( 199 )
1084!
1085!--       Set filename
1086          filename = 'DATA_1D_FL_NETCDF' // TRIM( coupling_char )
[1468]1087
[1957]1088!
1089!--       Inquire, if there is a netCDF file from a previuos run. This should
1090!--       be opened for extension, if its variables match the actual run.
1091          INQUIRE( FILE=filename, EXIST=netcdf_extend )
[1468]1092
[1957]1093          IF ( netcdf_extend )  THEN
1094!
1095!--          Open an existing netCDF file for output
1096             CALL netcdf_open_write_file( filename, id_set_fl, .FALSE., 532 )
1097!
1098!--          Read header information and set all ids. If there is a mismatch
1099!--          between the previuos and the actual run, netcdf_extend is returned
1100!--          as .FALSE.
1101             CALL netcdf_define_header( 'fl', netcdf_extend, 0 )
1102
1103!
1104!--          Remove the local file, if it can not be extended
1105             IF ( .NOT. netcdf_extend )  THEN
1106                nc_stat = NF90_CLOSE( id_set_fl )
1107                CALL netcdf_handle_error( 'check_open', 533 )
1108                CALL local_system( 'rm ' // TRIM( filename ) )
1109             ENDIF
1110
1111          ENDIF         
1112
1113          IF ( .NOT. netcdf_extend )  THEN
1114!
1115!--          Create a new netCDF output file with requested netCDF format
1116             CALL netcdf_create_file( filename, id_set_fl, .FALSE., 534 )
1117!
1118!--          Define the header
1119             CALL netcdf_define_header( 'fl', netcdf_extend, 0 )
1120
1121          ENDIF
1122
1123
[564]1124       CASE ( 201:200+2*max_masks )
[410]1125!
1126!--       Set filename depending on unit number
[564]1127          IF ( file_id <= 200+max_masks )  THEN
1128             mid = file_id - 200
[2669]1129             WRITE ( mask_char,'(A2,I2.2)')  '_M', mid
1130             filename = 'DATA_MASK_NETCDF' // TRIM( coupling_char ) //         &
1131                        mask_char
[410]1132             av = 0
1133          ELSE
[564]1134             mid = file_id - (200+max_masks)
[2669]1135             WRITE ( mask_char,'(A2,I2.2)')  '_M', mid
1136             filename = 'DATA_MASK_AV_NETCDF' // TRIM( coupling_char ) //      &
1137                        mask_char
[410]1138             av = 1
1139          ENDIF
1140!
[1031]1141!--       Inquire, if there is a netCDF file from a previuos run. This should
[410]1142!--       be opened for extension, if its dimensions and variables match the
1143!--       actual run.
1144          INQUIRE( FILE=filename, EXIST=netcdf_extend )
1145
1146          IF ( netcdf_extend )  THEN
1147!
[1031]1148!--          Open an existing netCDF file for output
[1783]1149             CALL netcdf_open_write_file( filename, id_set_mask(mid,av),       &
[1031]1150                                          .TRUE., 456 )
[410]1151!
1152!--          Read header information and set all ids. If there is a mismatch
1153!--          between the previuos and the actual run, netcdf_extend is returned
1154!--          as .FALSE.
[1783]1155             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
[1]1156
[410]1157!
1158!--          Remove the local file, if it can not be extended
1159             IF ( .NOT. netcdf_extend )  THEN
1160                nc_stat = NF90_CLOSE( id_set_mask(mid,av) )
[1783]1161                CALL netcdf_handle_error( 'check_open', 457 )
[410]1162                CALL local_system('rm ' // TRIM( filename ) )
1163             ENDIF
[1]1164
[410]1165          ENDIF         
1166
1167          IF ( .NOT. netcdf_extend )  THEN
[1]1168!
[1031]1169!--          Create a new netCDF output file with requested netCDF format
[1783]1170             CALL netcdf_create_file( filename, id_set_mask(mid,av), .TRUE., 458 )
[493]1171!
[410]1172!--          Define the header
[1783]1173             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
[410]1174
1175          ENDIF
1176
1177
1178#else
1179
[564]1180       CASE ( 101:109, 111:113, 116, 201:200+2*max_masks )
[410]1181
1182!
[1]1183!--       Nothing is done in case of missing netcdf support
1184          RETURN
1185
1186#endif
1187
1188       CASE DEFAULT
1189
[247]1190          WRITE( message_string, * ) 'no OPEN-statement for file-id ',file_id
[277]1191          CALL message( 'check_open', 'PA0172', 2, 2, -1, 6, 1 )
[1]1192
1193    END SELECT
1194
1195!
1196!-- Set open flag
1197    openfile(file_id)%opened = .TRUE.
1198
1199!
1200!-- Formats
[1320]12013300 FORMAT ('#'/                                                              &
1202             'coord 1  file=',A,'  filetype=unformatted'/                      &
1203             'coord 2  file=',A,'  filetype=unformatted  skip=',I6/            &
1204             'coord 3  file=',A,'  filetype=unformatted  skip=',I6/            &
[1]1205             '#')
12064000 FORMAT ('# ',A)
[1320]12075000 FORMAT ('# ',A/                                                           &
1208             '#1 E'/'#2 E*'/'#3 dt'/'#4 u*'/'#5 th*'/'#6 umax'/'#7 vmax'/      &
1209             '#8 wmax'/'#9 div_new'/'#10 div_old'/'#11 z_i_wpt'/'#12 z_i_pt'/  &
1210             '#13 w*'/'#14 w''pt''0'/'#15 w''pt'''/'#16 wpt'/'#17 pt(0)'/      &
[1]1211             '#18 pt(zp)'/'#19 splptx'/'#20 splpty'/'#21 splptz')
[1320]12128000 FORMAT (A/                                                                &
[1359]1213             '  step    time    # of parts     lPE sent/recv  rPE sent/recv  ',&
1214             'sPE sent/recv  nPE sent/recv    max # of parts  '/               &
1215             109('-'))
[1]1216
1217 END SUBROUTINE check_open
Note: See TracBrowser for help on using the repository browser.