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

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

Code annotations made doxygen readable

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