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

Last change on this file since 1346 was 1329, checked in by raasch, 10 years ago

last commit documented

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