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