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

Last change on this file since 1551 was 1551, checked in by maronga, 9 years ago

land surface model released

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