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

Last change on this file since 2001 was 2001, checked in by knoop, 8 years ago

last commit documented

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