1 | !> @file data_output_3d.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of the PALM model system. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
6 | ! terms of the GNU General Public License as published by the Free Software |
---|
7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
8 | ! 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-2020 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ------------------ |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: data_output_3d.f90 4444 2020-03-05 15:59:50Z forkel $ |
---|
27 | ! bugfix: cpp-directives for serial mode added |
---|
28 | ! |
---|
29 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
30 | ! Introduction of wall_flags_total_0, which currently sets bits based on static |
---|
31 | ! topography information used in wall_flags_static_0 |
---|
32 | ! |
---|
33 | ! 4329 2019-12-10 15:46:36Z motisi |
---|
34 | ! Renamed wall_flags_0 to wall_flags_static_0 |
---|
35 | ! |
---|
36 | ! 4182 2019-08-22 15:20:23Z scharf |
---|
37 | ! Corrected "Former revisions" section |
---|
38 | ! |
---|
39 | ! 4162 2019-08-16 05:54:29Z raasch |
---|
40 | ! bugfix for r4155 |
---|
41 | ! |
---|
42 | ! 4155 2019-08-14 06:25:18Z raasch |
---|
43 | ! bugfix for 3d-output in serial mode (ghost points must not be written) |
---|
44 | ! |
---|
45 | ! 4127 2019-07-30 14:47:10Z suehring |
---|
46 | ! Adjustment for top boundary index for plant-canopy model outputs |
---|
47 | ! (merge from branch resler) |
---|
48 | ! |
---|
49 | ! 4048 2019-06-21 21:00:21Z knoop |
---|
50 | ! Moved tcm_data_output_3d to module_interface |
---|
51 | ! |
---|
52 | ! 4039 2019-06-18 10:32:41Z suehring |
---|
53 | ! modularize diagnostic output |
---|
54 | ! |
---|
55 | ! 3994 2019-05-22 18:08:09Z suehring |
---|
56 | ! output of turbulence intensity added |
---|
57 | ! |
---|
58 | ! 3987 2019-05-22 09:52:13Z kanani |
---|
59 | ! Introduce alternative switch for debug output during timestepping |
---|
60 | ! |
---|
61 | ! 3885 2019-04-11 11:29:34Z kanani |
---|
62 | ! Changes related to global restructuring of location messages and introduction |
---|
63 | ! of additional debug messages |
---|
64 | ! |
---|
65 | ! 3814 2019-03-26 08:40:31Z pavelkrc |
---|
66 | ! unused variables removed |
---|
67 | ! |
---|
68 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
69 | ! Bugfix: use time_since_reference_point instead of simulated_time (relevant |
---|
70 | ! when using wall/soil spinup) |
---|
71 | ! |
---|
72 | ! Revision 1.1 1997/09/03 06:29:36 raasch |
---|
73 | ! Initial revision |
---|
74 | ! |
---|
75 | ! |
---|
76 | ! Description: |
---|
77 | ! ------------ |
---|
78 | !> Output of the 3D-arrays in netCDF and/or AVS format. |
---|
79 | !------------------------------------------------------------------------------! |
---|
80 | SUBROUTINE data_output_3d( av ) |
---|
81 | |
---|
82 | |
---|
83 | USE arrays_3d, & |
---|
84 | ONLY: d_exner, e, p, pt, q, ql, ql_c, ql_v, s, tend, u, v, vpt, w |
---|
85 | |
---|
86 | USE averaging |
---|
87 | |
---|
88 | USE basic_constants_and_equations_mod, & |
---|
89 | ONLY: lv_d_cp |
---|
90 | |
---|
91 | USE bulk_cloud_model_mod, & |
---|
92 | ONLY: bulk_cloud_model |
---|
93 | |
---|
94 | USE control_parameters, & |
---|
95 | ONLY: debug_output_timestep, do3d, do3d_no, do3d_time_count, & |
---|
96 | land_surface, message_string, ntdim_3d, nz_do3d, plant_canopy, & |
---|
97 | psolver, time_since_reference_point, urban_surface, & |
---|
98 | varnamelength |
---|
99 | |
---|
100 | #if defined( __parallel ) |
---|
101 | USE control_parameters, & |
---|
102 | ONLY: io_blocks, io_group |
---|
103 | #endif |
---|
104 | |
---|
105 | USE cpulog, & |
---|
106 | ONLY: log_point, cpu_log |
---|
107 | |
---|
108 | USE indices, & |
---|
109 | ONLY: nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt, & |
---|
110 | wall_flags_total_0 |
---|
111 | |
---|
112 | #if ! defined( __parallel ) |
---|
113 | USE indices, & |
---|
114 | ONLY: nx, ny |
---|
115 | #endif |
---|
116 | |
---|
117 | USE kinds |
---|
118 | |
---|
119 | USE land_surface_model_mod, & |
---|
120 | ONLY: lsm_data_output_3d, nzb_soil, nzt_soil |
---|
121 | |
---|
122 | USE module_interface, & |
---|
123 | ONLY: module_interface_data_output_3d |
---|
124 | |
---|
125 | #if defined( __netcdf ) |
---|
126 | USE NETCDF |
---|
127 | #endif |
---|
128 | |
---|
129 | USE netcdf_interface, & |
---|
130 | ONLY: fill_value, id_set_3d, id_var_do3d, id_var_time_3d, nc_stat, & |
---|
131 | netcdf_data_format, netcdf_handle_error |
---|
132 | |
---|
133 | USE particle_attributes, & |
---|
134 | ONLY: grid_particles, number_of_particles, particles, & |
---|
135 | particle_advection_start, prt_count |
---|
136 | |
---|
137 | USE pegrid |
---|
138 | |
---|
139 | USE plant_canopy_model_mod, & |
---|
140 | ONLY: pch_index |
---|
141 | |
---|
142 | USE radiation_model_mod, & |
---|
143 | ONLY: nz_urban_b, nz_urban_t |
---|
144 | |
---|
145 | USE urban_surface_mod, & |
---|
146 | ONLY: usm_data_output_3d |
---|
147 | |
---|
148 | |
---|
149 | IMPLICIT NONE |
---|
150 | |
---|
151 | INTEGER(iwp) :: av !< flag for (non-)average output |
---|
152 | INTEGER(iwp) :: flag_nr !< number of masking flag |
---|
153 | INTEGER(iwp) :: i !< loop index |
---|
154 | INTEGER(iwp) :: ivar !< variable index |
---|
155 | INTEGER(iwp) :: j !< loop index |
---|
156 | INTEGER(iwp) :: k !< loop index |
---|
157 | INTEGER(iwp) :: n !< loop index |
---|
158 | INTEGER(iwp) :: nzb_do !< vertical lower limit for data output |
---|
159 | INTEGER(iwp) :: nzt_do !< vertical upper limit for data output |
---|
160 | |
---|
161 | LOGICAL :: found !< true if output variable was found |
---|
162 | LOGICAL :: resorted !< true if variable is resorted |
---|
163 | |
---|
164 | REAL(wp) :: mean_r !< mean particle radius |
---|
165 | REAL(wp) :: s_r2 !< sum( particle-radius**2 ) |
---|
166 | REAL(wp) :: s_r3 !< sum( particle-radius**3 ) |
---|
167 | |
---|
168 | REAL(sp), DIMENSION(:,:,:), ALLOCATABLE :: local_pf !< output array |
---|
169 | |
---|
170 | REAL(wp), DIMENSION(:,:,:), POINTER :: to_be_resorted !< pointer to array which shall be output |
---|
171 | |
---|
172 | CHARACTER (LEN=varnamelength) :: trimvar !< TRIM of output-variable string |
---|
173 | |
---|
174 | ! |
---|
175 | !-- Return, if nothing to output |
---|
176 | IF ( do3d_no(av) == 0 ) RETURN |
---|
177 | |
---|
178 | IF ( debug_output_timestep ) CALL debug_message( 'data_output_3d', 'start' ) |
---|
179 | |
---|
180 | CALL cpu_log (log_point(14),'data_output_3d','start') |
---|
181 | |
---|
182 | ! |
---|
183 | !-- Open output file. |
---|
184 | !-- For classic or 64bit netCDF output on more than one PE, each PE opens its |
---|
185 | !-- own file and writes the data of its subdomain in binary format. After the |
---|
186 | !-- run, these files are combined to one NetCDF file by combine_plot_fields. |
---|
187 | !-- For netCDF4/HDF5 output, data is written in parallel into one file. |
---|
188 | IF ( netcdf_data_format < 5 ) THEN |
---|
189 | #if defined( __parallel ) |
---|
190 | CALL check_open( 30 ) |
---|
191 | #endif |
---|
192 | IF ( myid == 0 ) CALL check_open( 106+av*10 ) |
---|
193 | ELSE |
---|
194 | CALL check_open( 106+av*10 ) |
---|
195 | ENDIF |
---|
196 | |
---|
197 | ! |
---|
198 | !-- For parallel netcdf output the time axis must be limited. Return, if this |
---|
199 | !-- limit is exceeded. This could be the case, if the simulated time exceeds |
---|
200 | !-- the given end time by the length of the given output interval. |
---|
201 | IF ( netcdf_data_format > 4 ) THEN |
---|
202 | IF ( do3d_time_count(av) + 1 > ntdim_3d(av) ) THEN |
---|
203 | WRITE ( message_string, * ) 'Output of 3d data is not given at t=', & |
---|
204 | time_since_reference_point, 's because the maximum ', & |
---|
205 | 'number of output time levels is ', & |
---|
206 | 'exceeded.' |
---|
207 | CALL message( 'data_output_3d', 'PA0387', 0, 1, 0, 6, 0 ) |
---|
208 | CALL cpu_log( log_point(14), 'data_output_3d', 'stop' ) |
---|
209 | RETURN |
---|
210 | ENDIF |
---|
211 | ENDIF |
---|
212 | |
---|
213 | ! |
---|
214 | !-- Update the netCDF time axis |
---|
215 | !-- In case of parallel output, this is only done by PE0 to increase the |
---|
216 | !-- performance. |
---|
217 | #if defined( __netcdf ) |
---|
218 | do3d_time_count(av) = do3d_time_count(av) + 1 |
---|
219 | IF ( myid == 0 ) THEN |
---|
220 | nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_time_3d(av), & |
---|
221 | (/ time_since_reference_point /), & |
---|
222 | start = (/ do3d_time_count(av) /), & |
---|
223 | count = (/ 1 /) ) |
---|
224 | CALL netcdf_handle_error( 'data_output_3d', 376 ) |
---|
225 | ENDIF |
---|
226 | #endif |
---|
227 | |
---|
228 | ! |
---|
229 | !-- Loop over all variables to be written. |
---|
230 | ivar = 1 |
---|
231 | |
---|
232 | DO WHILE ( do3d(av,ivar)(1:1) /= ' ' ) |
---|
233 | |
---|
234 | ! |
---|
235 | !-- Initiate found flag and resorting flag |
---|
236 | found = .FALSE. |
---|
237 | resorted = .FALSE. |
---|
238 | trimvar = TRIM( do3d(av,ivar) ) |
---|
239 | |
---|
240 | ! |
---|
241 | !-- Temporary solution to account for data output within the new urban |
---|
242 | !-- surface model (urban_surface_mod.f90), see also SELECT CASE ( trimvar ). |
---|
243 | !-- Store the array chosen on the temporary array. |
---|
244 | nzb_do = nzb |
---|
245 | ! |
---|
246 | !-- Set top index for 3D output. Note in case of plant-canopy model |
---|
247 | !-- these index is determined by pch_index. |
---|
248 | IF ( plant_canopy .AND. trimvar(1:4) == 'pcm_' ) THEN |
---|
249 | nzt_do = pch_index |
---|
250 | ELSE |
---|
251 | nzt_do = nz_do3d |
---|
252 | ENDIF |
---|
253 | |
---|
254 | ! |
---|
255 | !-- Allocate a temporary array with the desired output dimensions. |
---|
256 | ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) ) |
---|
257 | ! |
---|
258 | !-- Before each output, set array local_pf to fill value |
---|
259 | local_pf = fill_value |
---|
260 | ! |
---|
261 | !-- Set masking flag for topography for not resorted arrays |
---|
262 | flag_nr = 0 |
---|
263 | |
---|
264 | SELECT CASE ( trimvar ) |
---|
265 | |
---|
266 | CASE ( 'e' ) |
---|
267 | IF ( av == 0 ) THEN |
---|
268 | to_be_resorted => e |
---|
269 | ELSE |
---|
270 | IF ( .NOT. ALLOCATED( e_av ) ) THEN |
---|
271 | ALLOCATE( e_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
272 | e_av = REAL( fill_value, KIND = wp ) |
---|
273 | ENDIF |
---|
274 | to_be_resorted => e_av |
---|
275 | ENDIF |
---|
276 | |
---|
277 | CASE ( 'thetal' ) |
---|
278 | IF ( av == 0 ) THEN |
---|
279 | to_be_resorted => pt |
---|
280 | ELSE |
---|
281 | IF ( .NOT. ALLOCATED( lpt_av ) ) THEN |
---|
282 | ALLOCATE( lpt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
283 | lpt_av = REAL( fill_value, KIND = wp ) |
---|
284 | ENDIF |
---|
285 | to_be_resorted => lpt_av |
---|
286 | ENDIF |
---|
287 | |
---|
288 | CASE ( 'p' ) |
---|
289 | IF ( av == 0 ) THEN |
---|
290 | IF ( psolver /= 'sor' ) CALL exchange_horiz( p, nbgp ) |
---|
291 | to_be_resorted => p |
---|
292 | ELSE |
---|
293 | IF ( .NOT. ALLOCATED( p_av ) ) THEN |
---|
294 | ALLOCATE( p_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
295 | p_av = REAL( fill_value, KIND = wp ) |
---|
296 | ENDIF |
---|
297 | IF ( psolver /= 'sor' ) CALL exchange_horiz( p_av, nbgp ) |
---|
298 | to_be_resorted => p_av |
---|
299 | ENDIF |
---|
300 | |
---|
301 | CASE ( 'pc' ) ! particle concentration (requires ghostpoint exchange) |
---|
302 | IF ( av == 0 ) THEN |
---|
303 | IF ( time_since_reference_point >= particle_advection_start ) THEN |
---|
304 | tend = prt_count |
---|
305 | ELSE |
---|
306 | tend = 0.0_wp |
---|
307 | ENDIF |
---|
308 | DO i = nxl, nxr |
---|
309 | DO j = nys, nyn |
---|
310 | DO k = nzb_do, nzt_do |
---|
311 | local_pf(i,j,k) = tend(k,j,i) |
---|
312 | ENDDO |
---|
313 | ENDDO |
---|
314 | ENDDO |
---|
315 | resorted = .TRUE. |
---|
316 | ELSE |
---|
317 | IF ( .NOT. ALLOCATED( pc_av ) ) THEN |
---|
318 | ALLOCATE( pc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
319 | pc_av = REAL( fill_value, KIND = wp ) |
---|
320 | ENDIF |
---|
321 | to_be_resorted => pc_av |
---|
322 | ENDIF |
---|
323 | |
---|
324 | CASE ( 'pr' ) ! mean particle radius (effective radius) |
---|
325 | IF ( av == 0 ) THEN |
---|
326 | IF ( time_since_reference_point >= particle_advection_start ) THEN |
---|
327 | DO i = nxl, nxr |
---|
328 | DO j = nys, nyn |
---|
329 | DO k = nzb_do, nzt_do |
---|
330 | number_of_particles = prt_count(k,j,i) |
---|
331 | IF (number_of_particles <= 0) CYCLE |
---|
332 | particles => grid_particles(k,j,i)%particles(1:number_of_particles) |
---|
333 | s_r2 = 0.0_wp |
---|
334 | s_r3 = 0.0_wp |
---|
335 | DO n = 1, number_of_particles |
---|
336 | IF ( particles(n)%particle_mask ) THEN |
---|
337 | s_r2 = s_r2 + particles(n)%radius**2 * & |
---|
338 | particles(n)%weight_factor |
---|
339 | s_r3 = s_r3 + particles(n)%radius**3 * & |
---|
340 | particles(n)%weight_factor |
---|
341 | ENDIF |
---|
342 | ENDDO |
---|
343 | IF ( s_r2 > 0.0_wp ) THEN |
---|
344 | mean_r = s_r3 / s_r2 |
---|
345 | ELSE |
---|
346 | mean_r = 0.0_wp |
---|
347 | ENDIF |
---|
348 | tend(k,j,i) = mean_r |
---|
349 | ENDDO |
---|
350 | ENDDO |
---|
351 | ENDDO |
---|
352 | ELSE |
---|
353 | tend = 0.0_wp |
---|
354 | ENDIF |
---|
355 | DO i = nxl, nxr |
---|
356 | DO j = nys, nyn |
---|
357 | DO k = nzb_do, nzt_do |
---|
358 | local_pf(i,j,k) = tend(k,j,i) |
---|
359 | ENDDO |
---|
360 | ENDDO |
---|
361 | ENDDO |
---|
362 | resorted = .TRUE. |
---|
363 | ELSE |
---|
364 | IF ( .NOT. ALLOCATED( pr_av ) ) THEN |
---|
365 | ALLOCATE( pr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
366 | pr_av = REAL( fill_value, KIND = wp ) |
---|
367 | ENDIF |
---|
368 | to_be_resorted => pr_av |
---|
369 | ENDIF |
---|
370 | |
---|
371 | CASE ( 'theta' ) |
---|
372 | IF ( av == 0 ) THEN |
---|
373 | IF ( .NOT. bulk_cloud_model ) THEN |
---|
374 | to_be_resorted => pt |
---|
375 | ELSE |
---|
376 | DO i = nxl, nxr |
---|
377 | DO j = nys, nyn |
---|
378 | DO k = nzb_do, nzt_do |
---|
379 | local_pf(i,j,k) = pt(k,j,i) + lv_d_cp * & |
---|
380 | d_exner(k) * & |
---|
381 | ql(k,j,i) |
---|
382 | ENDDO |
---|
383 | ENDDO |
---|
384 | ENDDO |
---|
385 | resorted = .TRUE. |
---|
386 | ENDIF |
---|
387 | ELSE |
---|
388 | IF ( .NOT. ALLOCATED( pt_av ) ) THEN |
---|
389 | ALLOCATE( pt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
390 | pt_av = REAL( fill_value, KIND = wp ) |
---|
391 | ENDIF |
---|
392 | to_be_resorted => pt_av |
---|
393 | ENDIF |
---|
394 | |
---|
395 | CASE ( 'q' ) |
---|
396 | IF ( av == 0 ) THEN |
---|
397 | to_be_resorted => q |
---|
398 | ELSE |
---|
399 | IF ( .NOT. ALLOCATED( q_av ) ) THEN |
---|
400 | ALLOCATE( q_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
401 | q_av = REAL( fill_value, KIND = wp ) |
---|
402 | ENDIF |
---|
403 | to_be_resorted => q_av |
---|
404 | ENDIF |
---|
405 | |
---|
406 | CASE ( 'ql' ) |
---|
407 | IF ( av == 0 ) THEN |
---|
408 | to_be_resorted => ql |
---|
409 | ELSE |
---|
410 | IF ( .NOT. ALLOCATED( ql_av ) ) THEN |
---|
411 | ALLOCATE( ql_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
412 | ql_av = REAL( fill_value, KIND = wp ) |
---|
413 | ENDIF |
---|
414 | to_be_resorted => ql_av |
---|
415 | ENDIF |
---|
416 | |
---|
417 | CASE ( 'ql_c' ) |
---|
418 | IF ( av == 0 ) THEN |
---|
419 | to_be_resorted => ql_c |
---|
420 | ELSE |
---|
421 | IF ( .NOT. ALLOCATED( ql_c_av ) ) THEN |
---|
422 | ALLOCATE( ql_c_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
423 | ql_c_av = REAL( fill_value, KIND = wp ) |
---|
424 | ENDIF |
---|
425 | to_be_resorted => ql_c_av |
---|
426 | ENDIF |
---|
427 | |
---|
428 | CASE ( 'ql_v' ) |
---|
429 | IF ( av == 0 ) THEN |
---|
430 | to_be_resorted => ql_v |
---|
431 | ELSE |
---|
432 | IF ( .NOT. ALLOCATED( ql_v_av ) ) THEN |
---|
433 | ALLOCATE( ql_v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
434 | ql_v_av = REAL( fill_value, KIND = wp ) |
---|
435 | ENDIF |
---|
436 | to_be_resorted => ql_v_av |
---|
437 | ENDIF |
---|
438 | |
---|
439 | CASE ( 'ql_vp' ) |
---|
440 | IF ( av == 0 ) THEN |
---|
441 | IF ( time_since_reference_point >= particle_advection_start ) THEN |
---|
442 | DO i = nxl, nxr |
---|
443 | DO j = nys, nyn |
---|
444 | DO k = nzb_do, nzt_do |
---|
445 | number_of_particles = prt_count(k,j,i) |
---|
446 | IF (number_of_particles <= 0) CYCLE |
---|
447 | particles => grid_particles(k,j,i)%particles(1:number_of_particles) |
---|
448 | DO n = 1, number_of_particles |
---|
449 | IF ( particles(n)%particle_mask ) THEN |
---|
450 | tend(k,j,i) = tend(k,j,i) + & |
---|
451 | particles(n)%weight_factor / & |
---|
452 | prt_count(k,j,i) |
---|
453 | ENDIF |
---|
454 | ENDDO |
---|
455 | ENDDO |
---|
456 | ENDDO |
---|
457 | ENDDO |
---|
458 | ELSE |
---|
459 | tend = 0.0_wp |
---|
460 | ENDIF |
---|
461 | DO i = nxl, nxr |
---|
462 | DO j = nys, nyn |
---|
463 | DO k = nzb_do, nzt_do |
---|
464 | local_pf(i,j,k) = tend(k,j,i) |
---|
465 | ENDDO |
---|
466 | ENDDO |
---|
467 | ENDDO |
---|
468 | resorted = .TRUE. |
---|
469 | ELSE |
---|
470 | IF ( .NOT. ALLOCATED( ql_vp_av ) ) THEN |
---|
471 | ALLOCATE( ql_vp_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
472 | ql_vp_av = REAL( fill_value, KIND = wp ) |
---|
473 | ENDIF |
---|
474 | to_be_resorted => ql_vp_av |
---|
475 | ENDIF |
---|
476 | |
---|
477 | CASE ( 'qv' ) |
---|
478 | IF ( av == 0 ) THEN |
---|
479 | DO i = nxl, nxr |
---|
480 | DO j = nys, nyn |
---|
481 | DO k = nzb_do, nzt_do |
---|
482 | local_pf(i,j,k) = q(k,j,i) - ql(k,j,i) |
---|
483 | ENDDO |
---|
484 | ENDDO |
---|
485 | ENDDO |
---|
486 | resorted = .TRUE. |
---|
487 | ELSE |
---|
488 | IF ( .NOT. ALLOCATED( qv_av ) ) THEN |
---|
489 | ALLOCATE( qv_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
490 | qv_av = REAL( fill_value, KIND = wp ) |
---|
491 | ENDIF |
---|
492 | to_be_resorted => qv_av |
---|
493 | ENDIF |
---|
494 | |
---|
495 | CASE ( 's' ) |
---|
496 | IF ( av == 0 ) THEN |
---|
497 | to_be_resorted => s |
---|
498 | ELSE |
---|
499 | IF ( .NOT. ALLOCATED( s_av ) ) THEN |
---|
500 | ALLOCATE( s_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
501 | s_av = REAL( fill_value, KIND = wp ) |
---|
502 | ENDIF |
---|
503 | to_be_resorted => s_av |
---|
504 | ENDIF |
---|
505 | |
---|
506 | CASE ( 'u' ) |
---|
507 | flag_nr = 1 |
---|
508 | IF ( av == 0 ) THEN |
---|
509 | to_be_resorted => u |
---|
510 | ELSE |
---|
511 | IF ( .NOT. ALLOCATED( u_av ) ) THEN |
---|
512 | ALLOCATE( u_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
513 | u_av = REAL( fill_value, KIND = wp ) |
---|
514 | ENDIF |
---|
515 | to_be_resorted => u_av |
---|
516 | ENDIF |
---|
517 | |
---|
518 | CASE ( 'v' ) |
---|
519 | flag_nr = 2 |
---|
520 | IF ( av == 0 ) THEN |
---|
521 | to_be_resorted => v |
---|
522 | ELSE |
---|
523 | IF ( .NOT. ALLOCATED( v_av ) ) THEN |
---|
524 | ALLOCATE( v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
525 | v_av = REAL( fill_value, KIND = wp ) |
---|
526 | ENDIF |
---|
527 | to_be_resorted => v_av |
---|
528 | ENDIF |
---|
529 | |
---|
530 | CASE ( 'thetav' ) |
---|
531 | IF ( av == 0 ) THEN |
---|
532 | to_be_resorted => vpt |
---|
533 | ELSE |
---|
534 | IF ( .NOT. ALLOCATED( vpt_av ) ) THEN |
---|
535 | ALLOCATE( vpt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
536 | vpt_av = REAL( fill_value, KIND = wp ) |
---|
537 | ENDIF |
---|
538 | to_be_resorted => vpt_av |
---|
539 | ENDIF |
---|
540 | |
---|
541 | CASE ( 'w' ) |
---|
542 | flag_nr = 3 |
---|
543 | IF ( av == 0 ) THEN |
---|
544 | to_be_resorted => w |
---|
545 | ELSE |
---|
546 | IF ( .NOT. ALLOCATED( w_av ) ) THEN |
---|
547 | ALLOCATE( w_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
548 | w_av = REAL( fill_value, KIND = wp ) |
---|
549 | ENDIF |
---|
550 | to_be_resorted => w_av |
---|
551 | ENDIF |
---|
552 | |
---|
553 | CASE DEFAULT |
---|
554 | ! |
---|
555 | !-- Quantities of other modules |
---|
556 | IF ( .NOT. found ) THEN |
---|
557 | CALL module_interface_data_output_3d( & |
---|
558 | av, trimvar, found, local_pf, & |
---|
559 | fill_value, resorted, nzb_do, nzt_do & |
---|
560 | ) |
---|
561 | ENDIF |
---|
562 | |
---|
563 | ! |
---|
564 | !-- Temporary workaround: ToDo: refactor local_pf allocation |
---|
565 | IF ( .NOT. found .AND. urban_surface .AND. trimvar(1:4) == 'usm_' ) THEN |
---|
566 | ! |
---|
567 | !-- For urban model quantities, it is required to re-allocate local_pf |
---|
568 | nzb_do = nz_urban_b |
---|
569 | nzt_do = nz_urban_t |
---|
570 | |
---|
571 | DEALLOCATE ( local_pf ) |
---|
572 | ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) ) |
---|
573 | local_pf = fill_value |
---|
574 | |
---|
575 | CALL usm_data_output_3d( av, trimvar, found, local_pf, & |
---|
576 | nzb_do, nzt_do ) |
---|
577 | resorted = .TRUE. |
---|
578 | |
---|
579 | ! |
---|
580 | !-- If no soil model variable was found, re-allocate local_pf |
---|
581 | IF ( .NOT. found ) THEN |
---|
582 | nzb_do = nzb |
---|
583 | nzt_do = nz_do3d |
---|
584 | |
---|
585 | DEALLOCATE ( local_pf ) |
---|
586 | ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) ) |
---|
587 | ENDIF |
---|
588 | |
---|
589 | ENDIF |
---|
590 | |
---|
591 | ! |
---|
592 | !-- Temporary workaround: ToDo: refactor local_pf allocation |
---|
593 | IF ( .NOT. found .AND. land_surface ) THEN |
---|
594 | ! |
---|
595 | !-- For soil model quantities, it is required to re-allocate local_pf |
---|
596 | nzb_do = nzb_soil |
---|
597 | nzt_do = nzt_soil |
---|
598 | |
---|
599 | DEALLOCATE ( local_pf ) |
---|
600 | ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) ) |
---|
601 | local_pf = fill_value |
---|
602 | |
---|
603 | CALL lsm_data_output_3d( av, trimvar, found, local_pf ) |
---|
604 | resorted = .TRUE. |
---|
605 | |
---|
606 | ! |
---|
607 | !-- If no soil model variable was found, re-allocate local_pf |
---|
608 | IF ( .NOT. found ) THEN |
---|
609 | nzb_do = nzb |
---|
610 | nzt_do = nz_do3d |
---|
611 | |
---|
612 | DEALLOCATE ( local_pf ) |
---|
613 | ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) ) |
---|
614 | ENDIF |
---|
615 | |
---|
616 | ENDIF |
---|
617 | |
---|
618 | IF ( .NOT. found ) THEN |
---|
619 | message_string = 'no output available for: ' // & |
---|
620 | TRIM( do3d(av,ivar) ) |
---|
621 | CALL message( 'data_output_3d', 'PA0182', 0, 0, 0, 6, 0 ) |
---|
622 | ENDIF |
---|
623 | |
---|
624 | END SELECT |
---|
625 | |
---|
626 | ! |
---|
627 | !-- Resort the array to be output, if not done above |
---|
628 | IF ( .NOT. resorted ) THEN |
---|
629 | DO i = nxl, nxr |
---|
630 | DO j = nys, nyn |
---|
631 | DO k = nzb_do, nzt_do |
---|
632 | local_pf(i,j,k) = MERGE( & |
---|
633 | to_be_resorted(k,j,i), & |
---|
634 | REAL( fill_value, KIND = wp ), & |
---|
635 | BTEST( wall_flags_total_0(k,j,i), flag_nr ) ) |
---|
636 | ENDDO |
---|
637 | ENDDO |
---|
638 | ENDDO |
---|
639 | ENDIF |
---|
640 | |
---|
641 | ! |
---|
642 | !-- Output of the 3D-array |
---|
643 | #if defined( __parallel ) |
---|
644 | IF ( netcdf_data_format < 5 ) THEN |
---|
645 | ! |
---|
646 | !-- Non-parallel netCDF output. Data is output in parallel in |
---|
647 | !-- FORTRAN binary format here, and later collected into one file by |
---|
648 | !-- combine_plot_fields |
---|
649 | IF ( myid == 0 ) THEN |
---|
650 | WRITE ( 30 ) time_since_reference_point, & |
---|
651 | do3d_time_count(av), av |
---|
652 | ENDIF |
---|
653 | DO i = 0, io_blocks-1 |
---|
654 | IF ( i == io_group ) THEN |
---|
655 | WRITE ( 30 ) nxl, nxr, nys, nyn, nzb_do, nzt_do |
---|
656 | WRITE ( 30 ) local_pf(:,:,nzb_do:nzt_do) |
---|
657 | ENDIF |
---|
658 | |
---|
659 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
660 | |
---|
661 | ENDDO |
---|
662 | |
---|
663 | ELSE |
---|
664 | #if defined( __netcdf ) |
---|
665 | ! |
---|
666 | !-- Parallel output in netCDF4/HDF5 format. |
---|
667 | ! IF ( nxr == nx .AND. nyn /= ny ) THEN |
---|
668 | ! nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar), & |
---|
669 | ! local_pf(nxl:nxr+1,nys:nyn,nzb_do:nzt_do), & |
---|
670 | ! start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /), & |
---|
671 | ! count = (/ nxr-nxl+2, nyn-nys+1, nzt_do-nzb_do+1, 1 /) ) |
---|
672 | ! ELSEIF ( nxr /= nx .AND. nyn == ny ) THEN |
---|
673 | ! nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar), & |
---|
674 | ! local_pf(nxl:nxr,nys:nyn+1,nzb_do:nzt_do), & |
---|
675 | ! start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /), & |
---|
676 | ! count = (/ nxr-nxl+1, nyn-nys+2, nzt_do-nzb_do+1, 1 /) ) |
---|
677 | ! ELSEIF ( nxr == nx .AND. nyn == ny ) THEN |
---|
678 | ! nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar), & |
---|
679 | ! local_pf(nxl:nxr+1,nys:nyn+1,nzb_do:nzt_do ), & |
---|
680 | ! start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /), & |
---|
681 | ! count = (/ nxr-nxl+2, nyn-nys+2, nzt_do-nzb_do+1, 1 /) ) |
---|
682 | ! ELSE |
---|
683 | nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar), & |
---|
684 | local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do), & |
---|
685 | start = (/ nxl+1, nys+1, nzb_do+1, do3d_time_count(av) /), & |
---|
686 | count = (/ nxr-nxl+1, nyn-nys+1, nzt_do-nzb_do+1, 1 /) ) |
---|
687 | ! ENDIF |
---|
688 | CALL netcdf_handle_error( 'data_output_3d', 386 ) |
---|
689 | #endif |
---|
690 | ENDIF |
---|
691 | #else |
---|
692 | #if defined( __netcdf ) |
---|
693 | nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,ivar), & |
---|
694 | local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do), & |
---|
695 | start = (/ 1, 1, 1, do3d_time_count(av) /), & |
---|
696 | count = (/ nx+1, ny+1, nzt_do-nzb_do+1, 1 /) ) |
---|
697 | CALL netcdf_handle_error( 'data_output_3d', 446 ) |
---|
698 | #endif |
---|
699 | #endif |
---|
700 | |
---|
701 | ivar = ivar + 1 |
---|
702 | |
---|
703 | ! |
---|
704 | !-- Deallocate temporary array |
---|
705 | DEALLOCATE ( local_pf ) |
---|
706 | |
---|
707 | ENDDO |
---|
708 | |
---|
709 | CALL cpu_log( log_point(14), 'data_output_3d', 'stop' ) |
---|
710 | |
---|
711 | IF ( debug_output_timestep ) CALL debug_message( 'data_output_3d', 'end' ) |
---|
712 | |
---|
713 | |
---|
714 | END SUBROUTINE data_output_3d |
---|