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

Last change on this file since 1780 was 1780, checked in by raasch, 8 years ago

last commit documented

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