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