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