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