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

Last change on this file since 1745 was 1745, checked in by gronemeier, 8 years ago

Bugfix:calculation of time levels for parallel NetCDF output

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