1 | PROGRAM combine_plot_fields |
---|
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: combine_plot_fields.f90 1395 2014-05-06 10:23:40Z keck $ |
---|
27 | ! |
---|
28 | ! 1394 2014-05-06 10:17:31Z keck |
---|
29 | ! KIND-attribute added to all INTEGER and REAL declaration statements |
---|
30 | ! |
---|
31 | ! 1046 2012-11-09 14:38:45Z maronga |
---|
32 | ! code put under GPL (PALM 3.9) |
---|
33 | ! |
---|
34 | ! 691 2011-03-04 08:45:30Z maronga |
---|
35 | ! Bugfix: check for precursor ocean runs, removed typo |
---|
36 | ! |
---|
37 | ! 493 2010-03-01 08:30:24Z raasch |
---|
38 | ! Exit in case of already complete NetCDF data (due to parallel output in PALM) |
---|
39 | ! cpu measurements included |
---|
40 | ! |
---|
41 | ! 210 2008-11-06 08:54:02Z raasch |
---|
42 | ! Size of pf3d adjusted to the required output size (1 gridpoint less, along |
---|
43 | ! all three dimensions), because output of a subset of the data |
---|
44 | ! (pf3d(nxa:nxe...) in the NF90_PUT_VAR statement caused segmentation fault |
---|
45 | ! with the INTEL compiler. |
---|
46 | ! Subdomain data are read into temporary arrays pf_tmp/pf3d_tmp in order to |
---|
47 | ! avoid INTEL compiler warnings about (automatic) creation of temporary arrays |
---|
48 | ! Bugfix: three misplaced #endif directives |
---|
49 | ! |
---|
50 | ! 114 2007-10-10 00:03:15Z raasch |
---|
51 | ! Bugfix: model_string needed a default value |
---|
52 | ! |
---|
53 | ! Aug 07 Loop for processing of output by coupled runs, id_string does not |
---|
54 | ! contain modus any longer |
---|
55 | ! |
---|
56 | ! 18/01/06 Output of time-averaged data |
---|
57 | ! |
---|
58 | ! 25/05/05 Errors removed |
---|
59 | ! |
---|
60 | ! 26/04/05 Output in NetCDF format, iso2d and avs output only if parameter |
---|
61 | ! file exists |
---|
62 | ! |
---|
63 | ! 31/10/01 All comments and messages translated into English |
---|
64 | ! |
---|
65 | ! 23/02/99 Keine Bearbeitung komprimierter 3D-Daten |
---|
66 | ! Ursprungsversion vom 28/07/97 |
---|
67 | ! |
---|
68 | ! |
---|
69 | ! Description: |
---|
70 | ! ------------ |
---|
71 | ! This routine combines data of the PALM-subdomains into one file. In PALM |
---|
72 | ! every processor element opens its own file and writes 2D- or 3D-binary-data |
---|
73 | ! into it (different files are opened for xy-, xz-, yz-cross-sections and |
---|
74 | ! 3D-data). For plotting or analyzing these PE-data have to be collected and |
---|
75 | ! to be put into single files, which is done by this routine. |
---|
76 | ! Output format is NetCDF. Additionally, a data are output in a binary format |
---|
77 | ! readable by ISO2D-software (cross-sections) and by AVS (3D-data). |
---|
78 | !------------------------------------------------------------------------------! |
---|
79 | |
---|
80 | #if defined( __netcdf ) |
---|
81 | USE netcdf |
---|
82 | #endif |
---|
83 | |
---|
84 | IMPLICIT NONE |
---|
85 | |
---|
86 | ! |
---|
87 | !-- Local variables |
---|
88 | CHARACTER (LEN=2) :: modus, model_string |
---|
89 | CHARACTER (LEN=4) :: id_string |
---|
90 | CHARACTER (LEN=10) :: dimname, var_name |
---|
91 | CHARACTER (LEN=40) :: filename |
---|
92 | |
---|
93 | CHARACTER (LEN=2000), DIMENSION(0:1) :: var_list |
---|
94 | |
---|
95 | INTEGER, PARAMETER :: iwp = 4, spk = SELECTED_REAL_KIND( 6 ), wp = 8 |
---|
96 | |
---|
97 | INTEGER(iwp) :: av, danz, i, id, j, k, model, models, nc_stat, & |
---|
98 | nxa, nxag, nxe, nxeg, nya, nyag, nye, nyeg, & |
---|
99 | nza, nzag, nze, nzeg, pos, time_step, & |
---|
100 | xa, xe, xxa, xxe, ya, ye, yya, yye, za, ze, zza, zze |
---|
101 | |
---|
102 | #if defined( __lc ) || defined( __decalpha ) |
---|
103 | INTEGER(8) :: count, count_rate |
---|
104 | #elif defined( __nec ) |
---|
105 | INTEGER(iwp) :: count, count_rate |
---|
106 | #elif defined( __ibm ) |
---|
107 | INTEGER(8) :: IRTC |
---|
108 | #endif |
---|
109 | |
---|
110 | INTEGER(iwp), DIMENSION(0:1) :: current_level, current_var, & |
---|
111 | fanz, id_set, id_var_time, num_var |
---|
112 | INTEGER(iwp), DIMENSION(4) :: id_dims_loc |
---|
113 | INTEGER(iwp), DIMENSION(0:1,4) :: id_dims |
---|
114 | INTEGER(iwp), DIMENSION(0:1,1000) :: id_var, levels |
---|
115 | |
---|
116 | LOGICAL :: avs_output, compressed, found, iso2d_output, netcdf_output, & |
---|
117 | netcdf_parallel, netcdf_0, netcdf_1 |
---|
118 | |
---|
119 | REAL(wp) :: cpu_start_time, cpu_end_time, dx, simulated_time |
---|
120 | REAL(wp), DIMENSION(:), ALLOCATABLE :: eta, ho, hu |
---|
121 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: pf, pf_tmp |
---|
122 | REAL(spk), DIMENSION(:,:,:), ALLOCATABLE :: pf3d, pf3d_tmp |
---|
123 | |
---|
124 | PRINT*, '' |
---|
125 | PRINT*, '' |
---|
126 | PRINT*, '*** combine_plot_fields ***' |
---|
127 | |
---|
128 | ! |
---|
129 | !-- Find out if a coupled run has been carried out |
---|
130 | INQUIRE( FILE='COUPLING_PORT_OPENED', EXIST=found ) |
---|
131 | IF ( found ) THEN |
---|
132 | models = 2 |
---|
133 | PRINT*, ' coupled run' |
---|
134 | ELSE |
---|
135 | models = 1 |
---|
136 | PRINT*, ' uncoupled run' |
---|
137 | ENDIF |
---|
138 | |
---|
139 | ! |
---|
140 | !-- Find out if a precursor ocean run has been carried out |
---|
141 | INQUIRE( FILE='PRECURSOR_OCEAN', EXIST=found ) |
---|
142 | IF ( found ) THEN |
---|
143 | model_string = '_O' |
---|
144 | PRINT*, ' precursor ocean run' |
---|
145 | ELSE |
---|
146 | model_string = '' |
---|
147 | ENDIF |
---|
148 | |
---|
149 | ! |
---|
150 | !-- Do everything for each model |
---|
151 | DO model = 1, models |
---|
152 | ! |
---|
153 | !-- Set the model string used to identify the filenames |
---|
154 | IF ( models == 2 ) THEN |
---|
155 | PRINT*, '' |
---|
156 | PRINT*, '*** combine_plot_fields ***' |
---|
157 | IF ( model == 2 ) THEN |
---|
158 | model_string = '_O' |
---|
159 | PRINT*, ' now combining ocean data' |
---|
160 | PRINT*, ' ========================' |
---|
161 | ELSE |
---|
162 | PRINT*, ' now combining atmosphere data' |
---|
163 | PRINT*, ' =============================' |
---|
164 | ENDIF |
---|
165 | ENDIF |
---|
166 | ! |
---|
167 | !-- 2D-arrays for ISO2D |
---|
168 | !-- Main loop for the three different cross-sections, starting with |
---|
169 | !-- xy-section |
---|
170 | modus = 'XY' |
---|
171 | PRINT*, '' |
---|
172 | DO WHILE ( modus == 'XY' .OR. modus == 'XZ' .OR. modus == 'YZ' ) |
---|
173 | ! |
---|
174 | !-- Take current time |
---|
175 | #if defined( __lc ) || defined( __decalpha ) || defined( __nec ) |
---|
176 | CALL SYSTEM_CLOCK( count, count_rate ) |
---|
177 | cpu_start_time = REAL( count ) / REAL( count_rate ) |
---|
178 | #elif defined( __ibm ) |
---|
179 | cpu_start_time = IRTC( ) * 1E-9 |
---|
180 | #else |
---|
181 | PRINT*, '+++ INFORMATIVE: no time measurement defined on this host' |
---|
182 | #endif |
---|
183 | |
---|
184 | netcdf_parallel = .FALSE. |
---|
185 | ! |
---|
186 | !-- Check, if file from PE0 exists. If it does not exist, PALM did not |
---|
187 | !-- create any output for this cross-section. |
---|
188 | danz = 0 |
---|
189 | WRITE (id_string,'(I4.4)') danz |
---|
190 | INQUIRE ( & |
---|
191 | FILE='PLOT2D_'//modus//TRIM( model_string )//'_'//id_string, & |
---|
192 | EXIST=found ) |
---|
193 | ! |
---|
194 | !-- Find out the number of files (equal to the number of PEs which |
---|
195 | !-- have been used in PALM) and open them |
---|
196 | DO WHILE ( found ) |
---|
197 | |
---|
198 | OPEN ( danz+110, & |
---|
199 | FILE='PLOT2D_'//modus//TRIM( model_string )//'_'//id_string, & |
---|
200 | FORM='UNFORMATTED' ) |
---|
201 | danz = danz + 1 |
---|
202 | WRITE (id_string,'(I4.4)') danz |
---|
203 | INQUIRE ( & |
---|
204 | FILE='PLOT2D_'//modus//TRIM( model_string )//'_'//id_string, & |
---|
205 | EXIST=found ) |
---|
206 | |
---|
207 | ENDDO |
---|
208 | |
---|
209 | ! |
---|
210 | !-- Inquire whether an iso2d parameter file exists |
---|
211 | INQUIRE( FILE='PLOT2D_'//modus//'_GLOBAL'//TRIM( model_string ), & |
---|
212 | EXIST=iso2d_output ) |
---|
213 | |
---|
214 | ! |
---|
215 | !-- Inquire whether a NetCDF file exists |
---|
216 | INQUIRE( FILE='DATA_2D_'//modus//'_NETCDF'//TRIM( model_string ), & |
---|
217 | EXIST=netcdf_0 ) |
---|
218 | |
---|
219 | ! |
---|
220 | !-- Inquire whether a NetCDF file for time-averaged data exists |
---|
221 | INQUIRE( FILE='DATA_2D_'//modus//'_AV_NETCDF'//TRIM( model_string ),& |
---|
222 | EXIST=netcdf_1 ) |
---|
223 | |
---|
224 | IF ( netcdf_0 .OR. netcdf_1 ) THEN |
---|
225 | netcdf_output = .TRUE. |
---|
226 | ! |
---|
227 | !-- Inquire whether the NetCDF file is already complete (parallel |
---|
228 | !-- output) |
---|
229 | INQUIRE( FILE='NO_COMBINE_PLOT_FIELDS_'//modus, & |
---|
230 | EXIST=netcdf_parallel ) |
---|
231 | IF ( netcdf_parallel ) THEN |
---|
232 | netcdf_parallel = .TRUE. |
---|
233 | ELSE |
---|
234 | netcdf_parallel = .FALSE. |
---|
235 | ENDIF |
---|
236 | ELSE |
---|
237 | netcdf_output = .FALSE. |
---|
238 | ENDIF |
---|
239 | |
---|
240 | ! |
---|
241 | !-- Info-output |
---|
242 | PRINT*, '' |
---|
243 | PRINT*, '*** combine_plot_fields ***' |
---|
244 | #if defined( __netcdf ) |
---|
245 | IF ( netcdf_output ) THEN |
---|
246 | IF ( netcdf_parallel ) THEN |
---|
247 | PRINT*, ' NetCDF ' // modus // '-data are in one file ', & |
---|
248 | '(NetCDF4-format) - merging not neccessary' |
---|
249 | ELSE |
---|
250 | PRINT*, ' NetCDF output enabled' |
---|
251 | ENDIF |
---|
252 | ENDIF |
---|
253 | #else |
---|
254 | IF ( netcdf_output ) THEN |
---|
255 | PRINT*, '--- Sorry, no NetCDF support on this host' |
---|
256 | netcdf_output = .FALSE. |
---|
257 | ENDIF |
---|
258 | #endif |
---|
259 | IF ( .NOT. netcdf_parallel ) THEN |
---|
260 | IF ( danz /= 0 ) THEN |
---|
261 | PRINT*, ' ',modus,'-section: ', danz, ' file(s) found' |
---|
262 | ELSE |
---|
263 | PRINT*, ' no ', modus, '-section data available' |
---|
264 | ENDIF |
---|
265 | ENDIF |
---|
266 | |
---|
267 | IF ( netcdf_output .AND. .NOT. netcdf_parallel .AND. danz /= 0 ) & |
---|
268 | THEN |
---|
269 | #if defined( __netcdf ) |
---|
270 | DO av = 0, 1 |
---|
271 | |
---|
272 | IF ( av == 0 .AND. .NOT. netcdf_0 ) CYCLE |
---|
273 | IF ( av == 1 .AND. .NOT. netcdf_1 ) CYCLE |
---|
274 | |
---|
275 | ! |
---|
276 | !-- Open NetCDF dataset |
---|
277 | IF ( av == 0 ) THEN |
---|
278 | filename = 'DATA_2D_'//modus//'_NETCDF' & |
---|
279 | //TRIM( model_string ) |
---|
280 | ELSE |
---|
281 | filename = 'DATA_2D_'//modus//'_AV_NETCDF' & |
---|
282 | //TRIM( model_string ) |
---|
283 | ENDIF |
---|
284 | nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set(av) ) |
---|
285 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 1 ) |
---|
286 | |
---|
287 | ! |
---|
288 | !-- Get the list of variables (order of variables corresponds with |
---|
289 | !-- the order of data on the binary file) |
---|
290 | var_list(av) = ' ' ! GET_ATT does not assign trailing blanks |
---|
291 | nc_stat = NF90_GET_ATT( id_set(av), NF90_GLOBAL, 'VAR_LIST', & |
---|
292 | var_list(av) ) |
---|
293 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 2 ) |
---|
294 | |
---|
295 | ! |
---|
296 | !-- Inquire id of the time coordinate variable |
---|
297 | nc_stat = NF90_INQ_VARID( id_set(av), 'time', id_var_time(av) ) |
---|
298 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 3 ) |
---|
299 | |
---|
300 | ! |
---|
301 | !-- Count number of variables; there is one more semicolon in the |
---|
302 | !-- string than variable names |
---|
303 | num_var(av) = -1 |
---|
304 | DO i = 1, LEN( var_list(av) ) |
---|
305 | IF ( var_list(av)(i:i) == ';' ) num_var(av) = num_var(av) +1 |
---|
306 | ENDDO |
---|
307 | |
---|
308 | ! |
---|
309 | !-- Extract the variable names from the list and inquire their |
---|
310 | !-- NetCDF IDs |
---|
311 | pos = INDEX( var_list(av), ';' ) |
---|
312 | ! |
---|
313 | !-- Loop over all variables |
---|
314 | DO i = 1, num_var(av) |
---|
315 | |
---|
316 | ! |
---|
317 | !-- Extract variable name from list |
---|
318 | var_list(av) = var_list(av)(pos+1:) |
---|
319 | pos = INDEX( var_list(av), ';' ) |
---|
320 | var_name = var_list(av)(1:pos-1) |
---|
321 | |
---|
322 | ! |
---|
323 | !-- Get variable ID from name |
---|
324 | nc_stat = NF90_INQ_VARID( id_set(av), TRIM( var_name ), & |
---|
325 | id_var(av,i) ) |
---|
326 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 4 ) |
---|
327 | |
---|
328 | ! |
---|
329 | !-- Get number of x/y/z levels for that variable |
---|
330 | nc_stat = NF90_INQUIRE_VARIABLE( id_set(av), id_var(av,i), & |
---|
331 | dimids = id_dims_loc ) |
---|
332 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 5 ) |
---|
333 | id_dims(av,:) = id_dims_loc |
---|
334 | |
---|
335 | ! |
---|
336 | !-- Inquire dimension ID |
---|
337 | DO j = 1, 4 |
---|
338 | nc_stat = NF90_INQUIRE_DIMENSION( id_set(av), & |
---|
339 | id_dims(av,j), dimname, levels(av,i) ) |
---|
340 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 6 ) |
---|
341 | |
---|
342 | IF ( modus == 'XY' .AND. INDEX(dimname, 'z') /= 0 ) EXIT |
---|
343 | IF ( modus == 'XZ' .AND. INDEX(dimname, 'y') /= 0 ) EXIT |
---|
344 | IF ( modus == 'YZ' .AND. INDEX(dimname, 'x') /= 0 ) EXIT |
---|
345 | ENDDO |
---|
346 | |
---|
347 | ENDDO |
---|
348 | |
---|
349 | ENDDO ! av = 0, 1 |
---|
350 | |
---|
351 | #endif |
---|
352 | ENDIF |
---|
353 | |
---|
354 | ! |
---|
355 | !-- Read the arrays, as long as the end of the file is reached |
---|
356 | IF ( .NOT. netcdf_parallel ) THEN |
---|
357 | |
---|
358 | fanz = 0 |
---|
359 | current_level = 1 |
---|
360 | current_var = 999999999 |
---|
361 | |
---|
362 | DO WHILE ( danz /= 0 ) |
---|
363 | |
---|
364 | ! |
---|
365 | !-- Loop over all files (reading data of the subdomains) |
---|
366 | DO id = 0, danz-1 |
---|
367 | ! |
---|
368 | !-- File from PE0 contains special information at the beginning, |
---|
369 | !-- concerning the lower and upper indices of the total-domain |
---|
370 | !-- used in PALM (nxag, nxeg, nyag, nyeg) and the lower and |
---|
371 | !-- upper indices of the array to be writte by this routine |
---|
372 | !-- (nxa, nxe, nya, nye). Usually in the horizontal directions |
---|
373 | !-- nxag=-1 and nxa=0 while all other variables have the same |
---|
374 | !-- value (i.e. nxeg=nxe). |
---|
375 | !-- Allocate necessary arrays, open the output file and write |
---|
376 | !-- the coordinate informations needed by ISO2D. |
---|
377 | IF ( id == 0 .AND. fanz(0) == 0 .AND. fanz(1) == 0 ) THEN |
---|
378 | READ ( id+110 ) nxag, nxeg, nyag, nyeg |
---|
379 | READ ( id+110 ) nxa, nxe, nya, nye |
---|
380 | ALLOCATE ( eta(nya:nye), ho(nxa:nxe), hu(nxa:nxe), & |
---|
381 | pf(nxag:nxeg,nyag:nyeg) ) |
---|
382 | READ ( id+110 ) dx, eta, hu, ho |
---|
383 | |
---|
384 | IF ( iso2d_output ) THEN |
---|
385 | OPEN ( 2, FILE='PLOT2D_'//modus//TRIM( model_string ),& |
---|
386 | FORM='UNFORMATTED' ) |
---|
387 | WRITE ( 2 ) dx, eta, hu, ho |
---|
388 | ENDIF |
---|
389 | ENDIF |
---|
390 | ! |
---|
391 | !-- Read output time |
---|
392 | IF ( netcdf_output .AND. id == 0 ) THEN |
---|
393 | IF ( netcdf_1 ) THEN |
---|
394 | READ ( id+110, END=998 ) simulated_time, time_step, av |
---|
395 | ELSE |
---|
396 | ! |
---|
397 | !-- For compatibility with earlier PALM versions |
---|
398 | READ ( id+110, END=998 ) simulated_time, time_step |
---|
399 | av = 0 |
---|
400 | ENDIF |
---|
401 | ENDIF |
---|
402 | ! |
---|
403 | !-- Read subdomain indices |
---|
404 | READ ( id+110, END=998 ) xa, xe, ya, ye |
---|
405 | ! |
---|
406 | !-- IF the PE made no output (in case that no part of the |
---|
407 | !-- cross-section is situated on this PE), indices have the |
---|
408 | !-- value -1 |
---|
409 | IF ( .NOT. ( xa == -1 .AND. xe == -1 .AND. & |
---|
410 | ya == -1 .AND. ye == -1 ) ) THEN |
---|
411 | ! |
---|
412 | !-- Read the subdomain grid-point values |
---|
413 | ALLOCATE( pf_tmp(xa:xe,ya:ye) ) |
---|
414 | READ ( id+110 ) pf_tmp |
---|
415 | pf(xa:xe,ya:ye) = pf_tmp |
---|
416 | DEALLOCATE( pf_tmp ) |
---|
417 | ENDIF |
---|
418 | IF ( id == 0 ) fanz(av) = fanz(av) + 1 |
---|
419 | |
---|
420 | ENDDO |
---|
421 | ! |
---|
422 | !-- Write the data of the total domain cross-section |
---|
423 | IF ( iso2d_output ) WRITE ( 2 ) pf(nxa:nxe,nya:nye) |
---|
424 | |
---|
425 | ! |
---|
426 | !-- Write same data in NetCDF format |
---|
427 | IF ( netcdf_output ) THEN |
---|
428 | #if defined( __netcdf ) |
---|
429 | ! |
---|
430 | !-- Check if a new time step has begun; if yes write data to |
---|
431 | !-- time axis |
---|
432 | IF ( current_var(av) > num_var(av) ) THEN |
---|
433 | current_var(av) = 1 |
---|
434 | nc_stat = NF90_PUT_VAR( id_set(av), id_var_time(av), & |
---|
435 | (/ simulated_time /), & |
---|
436 | start = (/ time_step /), & |
---|
437 | count = (/ 1 /) ) |
---|
438 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 7 ) |
---|
439 | ENDIF |
---|
440 | |
---|
441 | ! |
---|
442 | !-- Now write the data; this is mode dependent |
---|
443 | SELECT CASE ( modus ) |
---|
444 | |
---|
445 | CASE ( 'XY' ) |
---|
446 | nc_stat = NF90_PUT_VAR( id_set(av), & |
---|
447 | id_var(av,current_var(av)), & |
---|
448 | pf(nxa:nxe,nya:nye), & |
---|
449 | start = (/ 1, 1, current_level(av), time_step /), & |
---|
450 | count = (/ nxe-nxa+1, nye-nya+1, 1, 1 /) ) |
---|
451 | IF ( nc_stat /= NF90_NOERR ) THEN |
---|
452 | CALL handle_netcdf_error( 8 ) |
---|
453 | ENDIF |
---|
454 | |
---|
455 | CASE ( 'XZ' ) |
---|
456 | nc_stat = NF90_PUT_VAR( id_set(av), & |
---|
457 | id_var(av,current_var(av)), & |
---|
458 | pf(nxa:nxe,nya:nye), & |
---|
459 | start = (/ 1, current_level(av), 1, time_step /), & |
---|
460 | count = (/ nxe-nxa+1, 1, nye-nya+1, 1 /) ) |
---|
461 | IF ( nc_stat /= NF90_NOERR ) THEN |
---|
462 | CALL handle_netcdf_error( 9 ) |
---|
463 | ENDIF |
---|
464 | |
---|
465 | CASE ( 'YZ' ) |
---|
466 | nc_stat = NF90_PUT_VAR( id_set(av), & |
---|
467 | id_var(av,current_var(av)), & |
---|
468 | pf(nxa:nxe,nya:nye), & |
---|
469 | start = (/ current_level(av), 1, 1, time_step /), & |
---|
470 | count = (/ 1, nxe-nxa+1, nye-nya+1, 1 /) ) |
---|
471 | IF ( nc_stat /= NF90_NOERR ) THEN |
---|
472 | CALL handle_netcdf_error( 10 ) |
---|
473 | ENDIF |
---|
474 | |
---|
475 | END SELECT |
---|
476 | |
---|
477 | ! |
---|
478 | !-- Data is written, check if max level is reached |
---|
479 | current_level(av) = current_level(av) + 1 |
---|
480 | IF ( current_level(av) > levels(av,current_var(av)) ) THEN |
---|
481 | current_level(av) = 1 |
---|
482 | current_var(av) = current_var(av) + 1 |
---|
483 | ENDIF |
---|
484 | |
---|
485 | #endif |
---|
486 | ENDIF |
---|
487 | |
---|
488 | ENDDO |
---|
489 | |
---|
490 | ENDIF |
---|
491 | |
---|
492 | 998 IF ( danz /= 0 .AND. .NOT. netcdf_parallel ) THEN |
---|
493 | ! |
---|
494 | !-- Print the number of the arrays processed |
---|
495 | WRITE (*,'(16X,I4,A)') fanz(0)+fanz(1), ' array(s) processed' |
---|
496 | IF ( fanz(1) /= 0 ) THEN |
---|
497 | WRITE (*,'(16X,I4,A)') fanz(1), ' array(s) are time-averaged' |
---|
498 | ENDIF |
---|
499 | |
---|
500 | ! |
---|
501 | !-- Close all files and deallocate arrays |
---|
502 | DO id = 0, danz-1 |
---|
503 | CLOSE ( id+110 ) |
---|
504 | ENDDO |
---|
505 | CLOSE ( 2 ) |
---|
506 | DEALLOCATE ( eta, ho, hu, pf ) |
---|
507 | |
---|
508 | ! |
---|
509 | !-- Close the NetCDF file |
---|
510 | IF ( netcdf_output ) THEN |
---|
511 | #if defined( __netcdf ) |
---|
512 | IF ( netcdf_0 ) THEN |
---|
513 | nc_stat = NF90_CLOSE( id_set(0) ) |
---|
514 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 11 ) |
---|
515 | ENDIF |
---|
516 | IF ( netcdf_1 ) THEN |
---|
517 | nc_stat = NF90_CLOSE( id_set(1) ) |
---|
518 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 12 ) |
---|
519 | ENDIF |
---|
520 | #endif |
---|
521 | ENDIF |
---|
522 | ENDIF |
---|
523 | |
---|
524 | ! |
---|
525 | !-- Output required cpu time |
---|
526 | IF ( danz /= 0 .AND. .NOT. netcdf_parallel ) THEN |
---|
527 | #if defined( __lc ) || defined( __decalpha ) || defined( __nec ) |
---|
528 | CALL SYSTEM_CLOCK( count, count_rate ) |
---|
529 | cpu_end_time = REAL( count ) / REAL( count_rate ) |
---|
530 | WRITE (*,'(5X,A,F9.3,A)') 'Required cpu-time: ', & |
---|
531 | cpu_end_time-cpu_start_time, ' sec' |
---|
532 | #elif defined( __ibm ) |
---|
533 | cpu_end_time = IRTC( ) * 1E-9 |
---|
534 | WRITE (*,'(5X,A,F9.3,A)') 'Required cpu-time: ', & |
---|
535 | cpu_end_time-cpu_start_time, ' sec' |
---|
536 | #else |
---|
537 | CONTINUE |
---|
538 | #endif |
---|
539 | ENDIF |
---|
540 | |
---|
541 | ! |
---|
542 | !-- Choose the next cross-section |
---|
543 | SELECT CASE ( modus ) |
---|
544 | CASE ( 'XY' ) |
---|
545 | modus = 'XZ' |
---|
546 | CASE ( 'XZ' ) |
---|
547 | modus = 'YZ' |
---|
548 | CASE ( 'YZ' ) |
---|
549 | modus = 'no' |
---|
550 | END SELECT |
---|
551 | |
---|
552 | ENDDO |
---|
553 | |
---|
554 | |
---|
555 | ! |
---|
556 | !-- Combine the 3D-arrays |
---|
557 | netcdf_parallel = .FALSE. |
---|
558 | |
---|
559 | ! |
---|
560 | !-- Info-output |
---|
561 | PRINT*, ' ' |
---|
562 | PRINT*, '*** combine_plot_fields ***' |
---|
563 | |
---|
564 | ! |
---|
565 | !-- Take current time |
---|
566 | #if defined( __lc ) || defined( __decalpha ) || defined( __nec ) |
---|
567 | CALL SYSTEM_CLOCK( count, count_rate ) |
---|
568 | cpu_start_time = REAL( count ) / REAL( count_rate ) |
---|
569 | #elif defined( __ibm ) |
---|
570 | cpu_start_time = IRTC( ) * 1E-9 |
---|
571 | #else |
---|
572 | PRINT*, '+++ INFORMATIVE: no time measurement defined on this host' |
---|
573 | #endif |
---|
574 | |
---|
575 | ! |
---|
576 | !-- Inquire whether an avs fld file exists |
---|
577 | INQUIRE( FILE='PLOT3D_FLD'//TRIM( model_string ), EXIST=avs_output ) |
---|
578 | |
---|
579 | ! |
---|
580 | !-- Inquire whether a NetCDF file exists |
---|
581 | INQUIRE( FILE='DATA_3D_NETCDF'//TRIM( model_string ), EXIST=netcdf_0 ) |
---|
582 | |
---|
583 | ! |
---|
584 | !-- Inquire whether a NetCDF file for time-averaged data exists |
---|
585 | INQUIRE( FILE='DATA_3D_AV_NETCDF'//TRIM( model_string ), EXIST=netcdf_1 ) |
---|
586 | |
---|
587 | IF ( netcdf_0 .OR. netcdf_1 ) THEN |
---|
588 | netcdf_output = .TRUE. |
---|
589 | ! |
---|
590 | !-- Inquire whether the NetCDF file is already complete (parallel output) |
---|
591 | INQUIRE( FILE='NO_COMBINE_PLOT_FIELDS_3D', EXIST=netcdf_parallel ) |
---|
592 | IF ( netcdf_parallel ) THEN |
---|
593 | netcdf_parallel = .TRUE. |
---|
594 | ELSE |
---|
595 | netcdf_parallel = .FALSE. |
---|
596 | ENDIF |
---|
597 | ELSE |
---|
598 | netcdf_output = .FALSE. |
---|
599 | ENDIF |
---|
600 | |
---|
601 | ! |
---|
602 | !-- Check, if file from PE0 exists; not neccessary in case of parallel |
---|
603 | !-- PALM output |
---|
604 | IF ( .NOT. netcdf_parallel ) THEN |
---|
605 | danz = 0 |
---|
606 | WRITE (id_string,'(I4.4)') danz |
---|
607 | INQUIRE ( & |
---|
608 | FILE='PLOT3D_DATA'//TRIM( model_string )//'_'//TRIM( id_string ), & |
---|
609 | EXIST=found ) |
---|
610 | ELSE |
---|
611 | found = .FALSE. |
---|
612 | ENDIF |
---|
613 | |
---|
614 | ! |
---|
615 | !-- Combination only works, if data are not compressed. In that case, |
---|
616 | !-- PALM created a flag file (PLOT3D_COMPRESSED) |
---|
617 | INQUIRE ( FILE='PLOT3D_COMPRESSED'//TRIM( model_string ), & |
---|
618 | EXIST=compressed ) |
---|
619 | |
---|
620 | ! |
---|
621 | !-- Find out the number of files and open them |
---|
622 | DO WHILE ( found .AND. .NOT. compressed ) |
---|
623 | |
---|
624 | OPEN ( danz+110, & |
---|
625 | FILE='PLOT3D_DATA'//TRIM( model_string )//'_'//TRIM(id_string), & |
---|
626 | FORM='UNFORMATTED') |
---|
627 | danz = danz + 1 |
---|
628 | WRITE (id_string,'(I4.4)') danz |
---|
629 | INQUIRE ( & |
---|
630 | FILE='PLOT3D_DATA'//TRIM( model_string )//'_'//TRIM(id_string), & |
---|
631 | EXIST=found ) |
---|
632 | |
---|
633 | ENDDO |
---|
634 | |
---|
635 | #if defined( __netcdf ) |
---|
636 | IF ( netcdf_output ) THEN |
---|
637 | IF ( netcdf_parallel ) THEN |
---|
638 | PRINT*, ' NetCDF data are in one file (NetCDF4-format)', & |
---|
639 | ' - merging not neccessary' |
---|
640 | ELSE |
---|
641 | PRINT*, ' NetCDF output enabled' |
---|
642 | ENDIF |
---|
643 | ENDIF |
---|
644 | #else |
---|
645 | IF ( netcdf_output ) THEN |
---|
646 | PRINT*, '--- Sorry, no NetCDF support on this host' |
---|
647 | netcdf_output = .FALSE. |
---|
648 | ENDIF |
---|
649 | #endif |
---|
650 | IF ( .NOT. netcdf_parallel ) THEN |
---|
651 | IF ( danz /= 0 ) THEN |
---|
652 | PRINT*, ' 3D-data: ', danz, ' file(s) found' |
---|
653 | ELSE |
---|
654 | IF ( found .AND. compressed ) THEN |
---|
655 | PRINT*, '+++ no 3D-data processing, since data are compressed' |
---|
656 | ELSE |
---|
657 | PRINT*, ' no 3D-data file available' |
---|
658 | ENDIF |
---|
659 | ENDIF |
---|
660 | ENDIF |
---|
661 | |
---|
662 | IF ( netcdf_output .AND. .NOT. netcdf_parallel .AND. danz /= 0 ) THEN |
---|
663 | #if defined( __netcdf ) |
---|
664 | DO av = 0, 1 |
---|
665 | |
---|
666 | IF ( av == 0 .AND. .NOT. netcdf_0 ) CYCLE |
---|
667 | IF ( av == 1 .AND. .NOT. netcdf_1 ) CYCLE |
---|
668 | |
---|
669 | ! |
---|
670 | !-- Open NetCDF dataset |
---|
671 | IF ( av == 0 ) THEN |
---|
672 | filename = 'DATA_3D_NETCDF'//TRIM( model_string ) |
---|
673 | ELSE |
---|
674 | filename = 'DATA_3D_AV_NETCDF'//TRIM( model_string ) |
---|
675 | ENDIF |
---|
676 | nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set(av) ) |
---|
677 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 13 ) |
---|
678 | |
---|
679 | |
---|
680 | ! |
---|
681 | !-- Get the list of variables (order of variables corresponds with the |
---|
682 | !-- order of data on the binary file) |
---|
683 | var_list(av) = ' ' ! GET_ATT does not assign trailing blanks |
---|
684 | nc_stat = NF90_GET_ATT( id_set(av), NF90_GLOBAL, 'VAR_LIST', & |
---|
685 | var_list(av) ) |
---|
686 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 14 ) |
---|
687 | |
---|
688 | ! |
---|
689 | !-- Inquire id of the time coordinate variable |
---|
690 | nc_stat = NF90_INQ_VARID( id_set(av), 'time', id_var_time(av) ) |
---|
691 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 15 ) |
---|
692 | |
---|
693 | ! |
---|
694 | !-- Count number of variables; there is one more semicolon in the |
---|
695 | !-- string than variable names |
---|
696 | num_var(av) = -1 |
---|
697 | DO i = 1, LEN( var_list(av) ) |
---|
698 | IF ( var_list(av)(i:i) == ';' ) num_var(av) = num_var(av) + 1 |
---|
699 | ENDDO |
---|
700 | |
---|
701 | ! |
---|
702 | !-- Extract the variable names from the list and inquire their NetCDF |
---|
703 | !-- IDs |
---|
704 | pos = INDEX( var_list(av), ';' ) |
---|
705 | ! |
---|
706 | !-- Loop over all variables |
---|
707 | DO i = 1, num_var(av) |
---|
708 | |
---|
709 | ! |
---|
710 | !-- Extract variable name from list |
---|
711 | var_list(av) = var_list(av)(pos+1:) |
---|
712 | pos = INDEX( var_list(av), ';' ) |
---|
713 | var_name = var_list(av)(1:pos-1) |
---|
714 | |
---|
715 | ! |
---|
716 | !-- Get variable ID from name |
---|
717 | nc_stat = NF90_INQ_VARID( id_set(av), TRIM( var_name ), & |
---|
718 | id_var(av,i) ) |
---|
719 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 16 ) |
---|
720 | |
---|
721 | ENDDO |
---|
722 | |
---|
723 | ENDDO ! av=0,1 |
---|
724 | |
---|
725 | #endif |
---|
726 | ENDIF |
---|
727 | |
---|
728 | ! |
---|
729 | !-- Read arrays, until the end of the file is reached |
---|
730 | IF ( .NOT. netcdf_parallel ) THEN |
---|
731 | |
---|
732 | current_var = 999999999 |
---|
733 | fanz = 0 |
---|
734 | DO WHILE ( danz /= 0 ) |
---|
735 | |
---|
736 | ! |
---|
737 | !-- Loop over all files |
---|
738 | DO id = 0, danz-1 |
---|
739 | ! |
---|
740 | !-- File from PE0 contains special information at the beginning, |
---|
741 | !-- concerning the lower and upper indices of the total-domain used |
---|
742 | !-- in PALM (nxag, nxeg, nyag, nyeg, nzag, nzeg) and the lower and |
---|
743 | !-- upper indices of the array to be written by this routine (nxa, |
---|
744 | !-- nxe, nya, nye, nza, nze). Usually nxag=-1 and nxa=0, nyag=-1 |
---|
745 | !-- and nya=0, nzeg=nz and nze=nz_plot3d. |
---|
746 | !-- Allocate necessary array and open the output file. |
---|
747 | IF ( id == 0 .AND. fanz(0) == 0 .AND. fanz(1) == 0 ) THEN |
---|
748 | READ ( id+110 ) nxag, nxeg, nyag, nyeg, nzag, nzeg |
---|
749 | READ ( id+110 ) nxa, nxe, nya, nye, nza, nze |
---|
750 | ALLOCATE ( pf3d(nxa:nxe,nya:nye,nza:nze) ) |
---|
751 | IF ( avs_output ) THEN |
---|
752 | OPEN ( 2, FILE='PLOT3D_DATA'//TRIM( model_string ), & |
---|
753 | FORM='UNFORMATTED' ) |
---|
754 | ENDIF |
---|
755 | ENDIF |
---|
756 | |
---|
757 | ! |
---|
758 | !-- Read output time |
---|
759 | IF ( netcdf_output .AND. id == 0 ) THEN |
---|
760 | IF ( netcdf_1 ) THEN |
---|
761 | READ ( id+110, END=999 ) simulated_time, time_step, av |
---|
762 | ELSE |
---|
763 | ! |
---|
764 | !-- For compatibility with earlier PALM versions |
---|
765 | READ ( id+110, END=999 ) simulated_time, time_step |
---|
766 | av = 0 |
---|
767 | ENDIF |
---|
768 | ENDIF |
---|
769 | |
---|
770 | ! |
---|
771 | !-- Read subdomain indices and grid point values |
---|
772 | READ ( id+110, END=999 ) xa, xe, ya, ye, za, ze |
---|
773 | ALLOCATE( pf3d_tmp(xa:xe,ya:ye,za:ze) ) |
---|
774 | READ ( id+110 ) pf3d_tmp |
---|
775 | |
---|
776 | xxa = MAX( nxa, xa ) |
---|
777 | xxe = MIN( nxe, xe ) |
---|
778 | yya = MAX( nya, ya ) |
---|
779 | yye = MIN( nye, ye ) |
---|
780 | zza = MAX( nza, za ) |
---|
781 | zze = MIN( nze, ze ) |
---|
782 | DO k = zza, zze |
---|
783 | DO j = yya, yye |
---|
784 | DO i = xxa, xxe |
---|
785 | pf3d(i,j,k) = pf3d_tmp(i,j,k) |
---|
786 | ENDDO |
---|
787 | ENDDO |
---|
788 | ENDDO |
---|
789 | |
---|
790 | DEALLOCATE( pf3d_tmp ) |
---|
791 | IF ( id == 0 ) fanz(av) = fanz(av) + 1 |
---|
792 | |
---|
793 | ENDDO |
---|
794 | |
---|
795 | ! |
---|
796 | !-- Write data of the total domain |
---|
797 | IF ( avs_output ) WRITE ( 2 ) pf3d(nxa:nxe,nya:nye,nza:nze) |
---|
798 | |
---|
799 | ! |
---|
800 | !-- Write same data in NetCDF format |
---|
801 | IF ( netcdf_output ) THEN |
---|
802 | #if defined( __netcdf ) |
---|
803 | ! |
---|
804 | !-- Check if a new time step has begun; if yes write data to time |
---|
805 | !-- axis |
---|
806 | IF ( current_var(av) > num_var(av) ) THEN |
---|
807 | current_var(av) = 1 |
---|
808 | nc_stat = NF90_PUT_VAR( id_set(av), id_var_time(av), & |
---|
809 | (/ simulated_time /),& |
---|
810 | start = (/ time_step /), count = (/ 1 /) ) |
---|
811 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 17 ) |
---|
812 | ENDIF |
---|
813 | |
---|
814 | ! |
---|
815 | !-- Now write the data |
---|
816 | nc_stat = NF90_PUT_VAR( id_set(av), id_var(av,current_var(av)),& |
---|
817 | pf3d, start = (/ 1, 1, 1, time_step /),& |
---|
818 | count = (/ nxe-nxa+1, nye-nya+1, nze-nza+1, 1 /) ) |
---|
819 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 18 ) |
---|
820 | |
---|
821 | current_var(av) = current_var(av) + 1 |
---|
822 | |
---|
823 | #endif |
---|
824 | ENDIF |
---|
825 | |
---|
826 | ENDDO |
---|
827 | |
---|
828 | ENDIF |
---|
829 | |
---|
830 | 999 IF ( danz /= 0 .AND. .NOT. netcdf_parallel ) THEN |
---|
831 | ! |
---|
832 | !-- Print the number of arrays processed |
---|
833 | WRITE (*,'(16X,I4,A)') fanz(0)+fanz(1), ' array(s) processed' |
---|
834 | IF ( fanz(1) /= 0 ) THEN |
---|
835 | WRITE (*,'(16X,I4,A)') fanz(1), ' array(s) are time-averaged' |
---|
836 | ENDIF |
---|
837 | ! |
---|
838 | !-- Close all files and deallocate array |
---|
839 | DO id = 0, danz-1 |
---|
840 | CLOSE ( id+110 ) |
---|
841 | ENDDO |
---|
842 | CLOSE ( 2 ) |
---|
843 | DEALLOCATE ( pf3d ) |
---|
844 | ! |
---|
845 | !-- Close the NetCDF file |
---|
846 | IF ( netcdf_output ) THEN |
---|
847 | #if defined( __netcdf ) |
---|
848 | IF ( netcdf_0 ) THEN |
---|
849 | nc_stat = NF90_CLOSE( id_set(0) ) |
---|
850 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 19 ) |
---|
851 | ENDIF |
---|
852 | IF ( netcdf_1 ) THEN |
---|
853 | nc_stat = NF90_CLOSE( id_set(1) ) |
---|
854 | IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 20 ) |
---|
855 | ENDIF |
---|
856 | #endif |
---|
857 | ENDIF |
---|
858 | |
---|
859 | ! |
---|
860 | !-- Output required cpu time |
---|
861 | #if defined( __lc ) || defined( __decalpha ) || defined( __nec ) |
---|
862 | CALL SYSTEM_CLOCK( count, count_rate ) |
---|
863 | cpu_end_time = REAL( count ) / REAL( count_rate ) |
---|
864 | WRITE (*,'(5X,A,F9.3,A)') 'Required cpu-time: ', & |
---|
865 | cpu_end_time-cpu_start_time, ' sec' |
---|
866 | #elif defined( __ibm ) |
---|
867 | cpu_end_time = IRTC( ) * 1E-9 |
---|
868 | WRITE (*,'(5X,A,F9.3,A)') 'Required cpu-time: ', & |
---|
869 | cpu_end_time-cpu_start_time, ' sec' |
---|
870 | #endif |
---|
871 | |
---|
872 | ENDIF |
---|
873 | |
---|
874 | ENDDO ! models |
---|
875 | |
---|
876 | |
---|
877 | CONTAINS |
---|
878 | |
---|
879 | |
---|
880 | SUBROUTINE handle_netcdf_error( errno ) |
---|
881 | ! |
---|
882 | !-- Prints out a text message corresponding to the current NetCDF status |
---|
883 | |
---|
884 | IMPLICIT NONE |
---|
885 | |
---|
886 | INTEGER, INTENT(IN) :: errno |
---|
887 | |
---|
888 | #if defined( __netcdf ) |
---|
889 | IF ( nc_stat /= NF90_NOERR ) THEN |
---|
890 | PRINT*, '+++ combine_plot_fields netcdf: ', av, errno, & |
---|
891 | TRIM( nf90_strerror( nc_stat ) ) |
---|
892 | ENDIF |
---|
893 | #endif |
---|
894 | |
---|
895 | END SUBROUTINE handle_netcdf_error |
---|
896 | |
---|
897 | |
---|
898 | END PROGRAM combine_plot_fields |
---|
899 | |
---|
900 | |
---|
901 | |
---|