[1691] | 1 | !> @file data_output_mask.f90 |
---|
[1320] | 2 | !--------------------------------------------------------------------------------! |
---|
| 3 | ! This file is part of PALM. |
---|
| 4 | ! |
---|
| 5 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 6 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 7 | ! either version 3 of the License, or (at your option) any later version. |
---|
| 8 | ! |
---|
| 9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 10 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 11 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 12 | ! |
---|
| 13 | ! You should have received a copy of the GNU General Public License along with |
---|
| 14 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 15 | ! |
---|
[1818] | 16 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
[1320] | 17 | !--------------------------------------------------------------------------------! |
---|
| 18 | ! |
---|
| 19 | ! Current revisions: |
---|
| 20 | ! ----------------- |
---|
[1961] | 21 | ! |
---|
| 22 | ! |
---|
[1320] | 23 | ! Former revisions: |
---|
| 24 | ! ----------------- |
---|
| 25 | ! $Id: data_output_mask.f90 1961 2016-07-12 16:37:58Z suehring $ |
---|
| 26 | ! |
---|
[1961] | 27 | ! 1960 2016-07-12 16:34:24Z suehring |
---|
| 28 | ! Separate humidity and passive scalar |
---|
| 29 | ! |
---|
[1784] | 30 | ! 2016-03-06 18:36:17Z raasch |
---|
| 31 | ! name change of netcdf routines and module + related changes, |
---|
| 32 | ! switch back of netcdf data format moved from time integration routine to here |
---|
| 33 | ! |
---|
[1960] | 34 | ! 1691 2015-10-26 16:17:44Z maronga |
---|
[1692] | 35 | ! Added output of radiative heating rates for RRTMG |
---|
| 36 | ! |
---|
[1691] | 37 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 38 | ! Code annotations made doxygen readable |
---|
| 39 | ! |
---|
| 40 | ! 1585 2015-04-30 07:05:52Z maronga |
---|
[1586] | 41 | ! Added support for RRTMG |
---|
| 42 | ! |
---|
[1585] | 43 | ! 1438 2014-07-22 14:14:06Z heinze |
---|
[1439] | 44 | ! +nr, qc, qr |
---|
| 45 | ! |
---|
[1438] | 46 | ! 1359 2014-04-11 17:15:14Z hoffmann |
---|
[1360] | 47 | ! New particle structure integrated. |
---|
| 48 | ! |
---|
[1359] | 49 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
[1354] | 50 | ! REAL constants provided with KIND-attribute |
---|
| 51 | ! |
---|
[1353] | 52 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
[1329] | 53 | ! |
---|
| 54 | ! |
---|
[1321] | 55 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
| 56 | ! ONLY-attribute added to USE-statements, |
---|
| 57 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 58 | ! kinds are defined in new module kinds, |
---|
| 59 | ! revision history before 2012 removed, |
---|
| 60 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 61 | ! all variable declaration statements |
---|
| 62 | ! |
---|
[1320] | 63 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
| 64 | ! barrier argument removed from cpu_log, |
---|
| 65 | ! module interfaces removed |
---|
| 66 | ! |
---|
| 67 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 68 | ! unused variables removed |
---|
| 69 | ! |
---|
| 70 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 71 | ! code put under GPL (PALM 3.9) |
---|
| 72 | ! |
---|
| 73 | ! 1031 2012-10-19 14:35:30Z raasch |
---|
| 74 | ! netCDF4 without parallel file support implemented |
---|
| 75 | ! |
---|
| 76 | ! 1007 2012-09-19 14:30:36Z franke |
---|
| 77 | ! Bugfix: calculation of pr must depend on the particle weighting factor, |
---|
| 78 | ! missing calculation of ql_vp added |
---|
| 79 | ! |
---|
| 80 | ! 410 2009-12-04 17:05:40Z letzel |
---|
| 81 | ! Initial version |
---|
| 82 | ! |
---|
| 83 | ! Description: |
---|
| 84 | ! ------------ |
---|
[1682] | 85 | !> Masked data output in netCDF format for current mask (current value of mid). |
---|
[1320] | 86 | !------------------------------------------------------------------------------! |
---|
[1682] | 87 | SUBROUTINE data_output_mask( av ) |
---|
[1320] | 88 | |
---|
[1691] | 89 | |
---|
[1682] | 90 | |
---|
[1320] | 91 | #if defined( __netcdf ) |
---|
| 92 | USE arrays_3d, & |
---|
[1960] | 93 | ONLY: e, nr, p, pt, q, qc, ql, ql_c, ql_v, qr, rho, s, sa, tend, u, & |
---|
[1438] | 94 | v, vpt, w |
---|
[1320] | 95 | |
---|
| 96 | USE averaging, & |
---|
[1438] | 97 | ONLY: e_av, lpt_av, nr_av, p_av, pc_av, pr_av, pt_av, q_av, qc_av, & |
---|
| 98 | ql_av, ql_c_av, ql_v_av, ql_vp_av, qv_av, qr_av, rho_av, s_av, & |
---|
| 99 | sa_av, u_av, v_av, vpt_av, w_av |
---|
[1320] | 100 | |
---|
| 101 | USE cloud_parameters, & |
---|
| 102 | ONLY: l_d_cp, pt_d_t |
---|
| 103 | |
---|
| 104 | USE control_parameters, & |
---|
[1783] | 105 | ONLY: cloud_physics, domask, domask_no, domask_time_count, mask_i, & |
---|
| 106 | mask_j, mask_k, mask_size, mask_size_l, mask_start_l, & |
---|
| 107 | max_masks, message_string, mid, nz_do3d, simulated_time |
---|
[1320] | 108 | USE cpulog, & |
---|
| 109 | ONLY: cpu_log, log_point |
---|
[1438] | 110 | |
---|
[1320] | 111 | USE indices, & |
---|
| 112 | ONLY: nbgp, nxl, nxr, nyn, nys, nzb, nzt |
---|
| 113 | |
---|
| 114 | USE kinds |
---|
| 115 | |
---|
[1783] | 116 | USE NETCDF |
---|
[1320] | 117 | |
---|
[1783] | 118 | USE netcdf_interface, & |
---|
| 119 | ONLY: id_set_mask, id_var_domask, id_var_time_mask, nc_stat, & |
---|
| 120 | netcdf_data_format, netcdf_handle_error |
---|
[1320] | 121 | |
---|
| 122 | USE particle_attributes, & |
---|
[1359] | 123 | ONLY: grid_particles, number_of_particles, particles, & |
---|
| 124 | particle_advection_start, prt_count |
---|
[1320] | 125 | |
---|
| 126 | USE pegrid |
---|
| 127 | |
---|
[1585] | 128 | USE radiation_model_mod, & |
---|
| 129 | ONLY: rad_lw_in, rad_lw_in_av, rad_lw_out, rad_lw_out_av, & |
---|
[1691] | 130 | rad_lw_cs_hr, rad_lw_cs_hr_av, rad_lw_hr, rad_lw_hr_av, & |
---|
| 131 | rad_sw_in, rad_sw_in_av, rad_sw_out, rad_sw_out_av, & |
---|
| 132 | rad_sw_cs_hr, rad_sw_cs_hr_av, rad_sw_hr, rad_sw_hr_av |
---|
[1585] | 133 | |
---|
[1691] | 134 | |
---|
[1320] | 135 | IMPLICIT NONE |
---|
| 136 | |
---|
[1682] | 137 | INTEGER(iwp) :: av !< |
---|
| 138 | INTEGER(iwp) :: ngp !< |
---|
| 139 | INTEGER(iwp) :: i !< |
---|
| 140 | INTEGER(iwp) :: if !< |
---|
| 141 | INTEGER(iwp) :: j !< |
---|
| 142 | INTEGER(iwp) :: k !< |
---|
| 143 | INTEGER(iwp) :: n !< |
---|
[1783] | 144 | INTEGER(iwp) :: netcdf_data_format_save !< |
---|
[1682] | 145 | INTEGER(iwp) :: psi !< |
---|
| 146 | INTEGER(iwp) :: sender !< |
---|
| 147 | INTEGER(iwp) :: ind(6) !< |
---|
[1320] | 148 | |
---|
[1682] | 149 | LOGICAL :: found !< |
---|
| 150 | LOGICAL :: resorted !< |
---|
[1320] | 151 | |
---|
[1682] | 152 | REAL(wp) :: mean_r !< |
---|
| 153 | REAL(wp) :: s_r2 !< |
---|
| 154 | REAL(wp) :: s_r3 !< |
---|
[1320] | 155 | |
---|
[1682] | 156 | REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: local_pf !< |
---|
[1320] | 157 | #if defined( __parallel ) |
---|
[1682] | 158 | REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: total_pf !< |
---|
[1320] | 159 | #endif |
---|
[1682] | 160 | REAL(wp), DIMENSION(:,:,:), POINTER :: to_be_resorted !< |
---|
[1320] | 161 | |
---|
| 162 | ! |
---|
| 163 | !-- Return, if nothing to output |
---|
| 164 | IF ( domask_no(mid,av) == 0 ) RETURN |
---|
| 165 | |
---|
| 166 | CALL cpu_log (log_point(49),'data_output_mask','start') |
---|
| 167 | |
---|
| 168 | ! |
---|
[1783] | 169 | !-- Parallel netcdf output is not tested so far for masked data, hence |
---|
| 170 | !-- netcdf_data_format is switched back to non-paralell output. |
---|
| 171 | netcdf_data_format_save = netcdf_data_format |
---|
| 172 | IF ( netcdf_data_format == 5 ) netcdf_data_format = 3 |
---|
| 173 | IF ( netcdf_data_format == 6 ) netcdf_data_format = 4 |
---|
| 174 | |
---|
| 175 | ! |
---|
[1320] | 176 | !-- Open output file. |
---|
[1327] | 177 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1320] | 178 | CALL check_open( 200+mid+av*max_masks ) |
---|
| 179 | ENDIF |
---|
| 180 | |
---|
| 181 | ! |
---|
| 182 | !-- Allocate total and local output arrays. |
---|
| 183 | #if defined( __parallel ) |
---|
| 184 | IF ( myid == 0 ) THEN |
---|
| 185 | ALLOCATE( total_pf(mask_size(mid,1),mask_size(mid,2),mask_size(mid,3)) ) |
---|
| 186 | ENDIF |
---|
| 187 | #endif |
---|
| 188 | ALLOCATE( local_pf(mask_size_l(mid,1),mask_size_l(mid,2), & |
---|
| 189 | mask_size_l(mid,3)) ) |
---|
| 190 | |
---|
| 191 | ! |
---|
| 192 | !-- Update the netCDF time axis. |
---|
| 193 | domask_time_count(mid,av) = domask_time_count(mid,av) + 1 |
---|
[1327] | 194 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1320] | 195 | nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), id_var_time_mask(mid,av), & |
---|
| 196 | (/ simulated_time /), & |
---|
| 197 | start = (/ domask_time_count(mid,av) /), & |
---|
| 198 | count = (/ 1 /) ) |
---|
[1783] | 199 | CALL netcdf_handle_error( 'data_output_mask', 460 ) |
---|
[1320] | 200 | ENDIF |
---|
| 201 | |
---|
| 202 | ! |
---|
| 203 | !-- Loop over all variables to be written. |
---|
| 204 | if = 1 |
---|
| 205 | |
---|
| 206 | DO WHILE ( domask(mid,av,if)(1:1) /= ' ' ) |
---|
| 207 | ! |
---|
| 208 | !-- Reallocate local_pf on PE 0 since its shape changes during MPI exchange |
---|
| 209 | IF ( netcdf_data_format < 5 .AND. myid == 0 .AND. if > 1 ) THEN |
---|
| 210 | DEALLOCATE( local_pf ) |
---|
| 211 | ALLOCATE( local_pf(mask_size_l(mid,1),mask_size_l(mid,2), & |
---|
| 212 | mask_size_l(mid,3)) ) |
---|
| 213 | ENDIF |
---|
| 214 | ! |
---|
| 215 | !-- Store the variable chosen. |
---|
| 216 | resorted = .FALSE. |
---|
| 217 | SELECT CASE ( TRIM( domask(mid,av,if) ) ) |
---|
| 218 | |
---|
| 219 | CASE ( 'e' ) |
---|
| 220 | IF ( av == 0 ) THEN |
---|
| 221 | to_be_resorted => e |
---|
| 222 | ELSE |
---|
| 223 | to_be_resorted => e_av |
---|
| 224 | ENDIF |
---|
| 225 | |
---|
| 226 | CASE ( 'lpt' ) |
---|
| 227 | IF ( av == 0 ) THEN |
---|
| 228 | to_be_resorted => pt |
---|
| 229 | ELSE |
---|
| 230 | to_be_resorted => lpt_av |
---|
| 231 | ENDIF |
---|
| 232 | |
---|
[1438] | 233 | CASE ( 'nr' ) |
---|
| 234 | IF ( av == 0 ) THEN |
---|
| 235 | to_be_resorted => nr |
---|
| 236 | ELSE |
---|
| 237 | to_be_resorted => nr_av |
---|
| 238 | ENDIF |
---|
| 239 | |
---|
[1320] | 240 | CASE ( 'p' ) |
---|
| 241 | IF ( av == 0 ) THEN |
---|
| 242 | to_be_resorted => p |
---|
| 243 | ELSE |
---|
| 244 | to_be_resorted => p_av |
---|
| 245 | ENDIF |
---|
| 246 | |
---|
| 247 | CASE ( 'pc' ) ! particle concentration (requires ghostpoint exchange) |
---|
| 248 | IF ( av == 0 ) THEN |
---|
| 249 | tend = prt_count |
---|
| 250 | CALL exchange_horiz( tend, nbgp ) |
---|
| 251 | DO i = 1, mask_size_l(mid,1) |
---|
| 252 | DO j = 1, mask_size_l(mid,2) |
---|
| 253 | DO k = 1, mask_size_l(mid,3) |
---|
| 254 | local_pf(i,j,k) = tend(mask_k(mid,k), & |
---|
| 255 | mask_j(mid,j),mask_i(mid,i)) |
---|
| 256 | ENDDO |
---|
| 257 | ENDDO |
---|
| 258 | ENDDO |
---|
| 259 | resorted = .TRUE. |
---|
| 260 | ELSE |
---|
| 261 | CALL exchange_horiz( pc_av, nbgp ) |
---|
| 262 | to_be_resorted => pc_av |
---|
| 263 | ENDIF |
---|
| 264 | |
---|
[1359] | 265 | CASE ( 'pr' ) ! mean particle radius (effective radius) |
---|
[1320] | 266 | IF ( av == 0 ) THEN |
---|
[1359] | 267 | IF ( simulated_time >= particle_advection_start ) THEN |
---|
| 268 | DO i = nxl, nxr |
---|
| 269 | DO j = nys, nyn |
---|
| 270 | DO k = nzb, nz_do3d |
---|
| 271 | number_of_particles = prt_count(k,j,i) |
---|
| 272 | IF (number_of_particles <= 0) CYCLE |
---|
| 273 | particles => grid_particles(k,j,i)%particles(1:number_of_particles) |
---|
| 274 | s_r2 = 0.0_wp |
---|
| 275 | s_r3 = 0.0_wp |
---|
| 276 | DO n = 1, number_of_particles |
---|
| 277 | IF ( particles(n)%particle_mask ) THEN |
---|
| 278 | s_r2 = s_r2 + grid_particles(k,j,i)%particles(n)%radius**2 * & |
---|
| 279 | grid_particles(k,j,i)%particles(n)%weight_factor |
---|
| 280 | s_r3 = s_r3 + grid_particles(k,j,i)%particles(n)%radius**3 * & |
---|
| 281 | grid_particles(k,j,i)%particles(n)%weight_factor |
---|
| 282 | ENDIF |
---|
| 283 | ENDDO |
---|
| 284 | IF ( s_r2 > 0.0_wp ) THEN |
---|
| 285 | mean_r = s_r3 / s_r2 |
---|
| 286 | ELSE |
---|
| 287 | mean_r = 0.0_wp |
---|
| 288 | ENDIF |
---|
| 289 | tend(k,j,i) = mean_r |
---|
[1320] | 290 | ENDDO |
---|
| 291 | ENDDO |
---|
| 292 | ENDDO |
---|
[1359] | 293 | CALL exchange_horiz( tend, nbgp ) |
---|
| 294 | ELSE |
---|
| 295 | tend = 0.0_wp |
---|
| 296 | ENDIF |
---|
[1320] | 297 | DO i = 1, mask_size_l(mid,1) |
---|
| 298 | DO j = 1, mask_size_l(mid,2) |
---|
| 299 | DO k = 1, mask_size_l(mid,3) |
---|
| 300 | local_pf(i,j,k) = tend(mask_k(mid,k), & |
---|
| 301 | mask_j(mid,j),mask_i(mid,i)) |
---|
| 302 | ENDDO |
---|
| 303 | ENDDO |
---|
| 304 | ENDDO |
---|
| 305 | resorted = .TRUE. |
---|
| 306 | ELSE |
---|
| 307 | CALL exchange_horiz( pr_av, nbgp ) |
---|
| 308 | to_be_resorted => pr_av |
---|
| 309 | ENDIF |
---|
| 310 | |
---|
| 311 | CASE ( 'pt' ) |
---|
| 312 | IF ( av == 0 ) THEN |
---|
| 313 | IF ( .NOT. cloud_physics ) THEN |
---|
| 314 | to_be_resorted => pt |
---|
| 315 | ELSE |
---|
| 316 | DO i = 1, mask_size_l(mid,1) |
---|
| 317 | DO j = 1, mask_size_l(mid,2) |
---|
| 318 | DO k = 1, mask_size_l(mid,3) |
---|
| 319 | local_pf(i,j,k) = & |
---|
| 320 | pt(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) & |
---|
| 321 | + l_d_cp * pt_d_t(mask_k(mid,k)) * & |
---|
| 322 | ql(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) |
---|
| 323 | ENDDO |
---|
| 324 | ENDDO |
---|
| 325 | ENDDO |
---|
| 326 | resorted = .TRUE. |
---|
| 327 | ENDIF |
---|
| 328 | ELSE |
---|
| 329 | to_be_resorted => pt_av |
---|
| 330 | ENDIF |
---|
| 331 | |
---|
| 332 | CASE ( 'q' ) |
---|
| 333 | IF ( av == 0 ) THEN |
---|
| 334 | to_be_resorted => q |
---|
| 335 | ELSE |
---|
| 336 | to_be_resorted => q_av |
---|
| 337 | ENDIF |
---|
| 338 | |
---|
[1438] | 339 | CASE ( 'qc' ) |
---|
| 340 | IF ( av == 0 ) THEN |
---|
| 341 | to_be_resorted => qc |
---|
| 342 | ELSE |
---|
| 343 | to_be_resorted => qc_av |
---|
| 344 | ENDIF |
---|
| 345 | |
---|
[1320] | 346 | CASE ( 'ql' ) |
---|
| 347 | IF ( av == 0 ) THEN |
---|
| 348 | to_be_resorted => ql |
---|
| 349 | ELSE |
---|
| 350 | to_be_resorted => ql_av |
---|
| 351 | ENDIF |
---|
| 352 | |
---|
| 353 | CASE ( 'ql_c' ) |
---|
| 354 | IF ( av == 0 ) THEN |
---|
| 355 | to_be_resorted => ql_c |
---|
| 356 | ELSE |
---|
| 357 | to_be_resorted => ql_c_av |
---|
| 358 | ENDIF |
---|
| 359 | |
---|
| 360 | CASE ( 'ql_v' ) |
---|
| 361 | IF ( av == 0 ) THEN |
---|
| 362 | to_be_resorted => ql_v |
---|
| 363 | ELSE |
---|
| 364 | to_be_resorted => ql_v_av |
---|
| 365 | ENDIF |
---|
| 366 | |
---|
| 367 | CASE ( 'ql_vp' ) |
---|
| 368 | IF ( av == 0 ) THEN |
---|
[1359] | 369 | IF ( simulated_time >= particle_advection_start ) THEN |
---|
| 370 | DO i = nxl, nxr |
---|
| 371 | DO j = nys, nyn |
---|
| 372 | DO k = nzb, nz_do3d |
---|
| 373 | number_of_particles = prt_count(k,j,i) |
---|
| 374 | IF (number_of_particles <= 0) CYCLE |
---|
| 375 | particles => grid_particles(k,j,i)%particles(1:number_of_particles) |
---|
| 376 | DO n = 1, number_of_particles |
---|
| 377 | IF ( particles(n)%particle_mask ) THEN |
---|
| 378 | tend(k,j,i) = tend(k,j,i) + & |
---|
[1320] | 379 | particles(n)%weight_factor / & |
---|
| 380 | prt_count(k,j,i) |
---|
[1359] | 381 | ENDIF |
---|
| 382 | ENDDO |
---|
[1320] | 383 | ENDDO |
---|
| 384 | ENDDO |
---|
| 385 | ENDDO |
---|
[1359] | 386 | CALL exchange_horiz( tend, nbgp ) |
---|
| 387 | ELSE |
---|
| 388 | tend = 0.0_wp |
---|
| 389 | ENDIF |
---|
[1320] | 390 | DO i = 1, mask_size_l(mid,1) |
---|
| 391 | DO j = 1, mask_size_l(mid,2) |
---|
| 392 | DO k = 1, mask_size_l(mid,3) |
---|
| 393 | local_pf(i,j,k) = tend(mask_k(mid,k), & |
---|
| 394 | mask_j(mid,j),mask_i(mid,i)) |
---|
| 395 | ENDDO |
---|
| 396 | ENDDO |
---|
| 397 | ENDDO |
---|
| 398 | resorted = .TRUE. |
---|
| 399 | ELSE |
---|
| 400 | CALL exchange_horiz( ql_vp_av, nbgp ) |
---|
| 401 | to_be_resorted => ql_vp_av |
---|
| 402 | ENDIF |
---|
| 403 | |
---|
| 404 | CASE ( 'qv' ) |
---|
| 405 | IF ( av == 0 ) THEN |
---|
| 406 | DO i = 1, mask_size_l(mid,1) |
---|
| 407 | DO j = 1, mask_size_l(mid,2) |
---|
| 408 | DO k = 1, mask_size_l(mid,3) |
---|
| 409 | local_pf(i,j,k) = & |
---|
| 410 | q(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) - & |
---|
| 411 | ql(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) |
---|
| 412 | ENDDO |
---|
| 413 | ENDDO |
---|
| 414 | ENDDO |
---|
| 415 | resorted = .TRUE. |
---|
| 416 | ELSE |
---|
| 417 | to_be_resorted => qv_av |
---|
| 418 | ENDIF |
---|
| 419 | |
---|
[1438] | 420 | CASE ( 'qr' ) |
---|
| 421 | IF ( av == 0 ) THEN |
---|
| 422 | to_be_resorted => qr |
---|
| 423 | ELSE |
---|
| 424 | to_be_resorted => qr_av |
---|
| 425 | ENDIF |
---|
| 426 | |
---|
[1691] | 427 | CASE ( 'rad_lw_in' ) |
---|
| 428 | IF ( av == 0 ) THEN |
---|
| 429 | to_be_resorted => rad_lw_in |
---|
| 430 | ELSE |
---|
| 431 | to_be_resorted => rad_lw_in_av |
---|
| 432 | ENDIF |
---|
| 433 | |
---|
| 434 | CASE ( 'rad_lw_out' ) |
---|
| 435 | IF ( av == 0 ) THEN |
---|
| 436 | to_be_resorted => rad_lw_out |
---|
| 437 | ELSE |
---|
| 438 | to_be_resorted => rad_lw_out_av |
---|
| 439 | ENDIF |
---|
| 440 | |
---|
| 441 | CASE ( 'rad_lw_cs_hr' ) |
---|
| 442 | IF ( av == 0 ) THEN |
---|
| 443 | to_be_resorted => rad_lw_cs_hr |
---|
| 444 | ELSE |
---|
| 445 | to_be_resorted => rad_lw_cs_hr_av |
---|
| 446 | ENDIF |
---|
| 447 | |
---|
| 448 | CASE ( 'rad_lw_hr' ) |
---|
| 449 | IF ( av == 0 ) THEN |
---|
| 450 | to_be_resorted => rad_lw_hr |
---|
| 451 | ELSE |
---|
| 452 | to_be_resorted => rad_lw_hr_av |
---|
| 453 | ENDIF |
---|
| 454 | |
---|
[1585] | 455 | CASE ( 'rad_sw_in' ) |
---|
| 456 | IF ( av == 0 ) THEN |
---|
| 457 | to_be_resorted => rad_sw_in |
---|
| 458 | ELSE |
---|
| 459 | to_be_resorted => rad_sw_in_av |
---|
| 460 | ENDIF |
---|
| 461 | |
---|
| 462 | CASE ( 'rad_sw_out' ) |
---|
| 463 | IF ( av == 0 ) THEN |
---|
| 464 | to_be_resorted => rad_sw_out |
---|
| 465 | ELSE |
---|
| 466 | to_be_resorted => rad_sw_out_av |
---|
| 467 | ENDIF |
---|
| 468 | |
---|
[1691] | 469 | CASE ( 'rad_sw_cs_hr' ) |
---|
[1585] | 470 | IF ( av == 0 ) THEN |
---|
[1691] | 471 | to_be_resorted => rad_sw_cs_hr |
---|
[1585] | 472 | ELSE |
---|
[1691] | 473 | to_be_resorted => rad_sw_cs_hr_av |
---|
[1585] | 474 | ENDIF |
---|
| 475 | |
---|
[1691] | 476 | CASE ( 'rad_sw_hr' ) |
---|
[1585] | 477 | IF ( av == 0 ) THEN |
---|
[1691] | 478 | to_be_resorted => rad_sw_hr |
---|
[1585] | 479 | ELSE |
---|
[1691] | 480 | to_be_resorted => rad_sw_hr_av |
---|
[1585] | 481 | ENDIF |
---|
| 482 | |
---|
[1320] | 483 | CASE ( 'rho' ) |
---|
| 484 | IF ( av == 0 ) THEN |
---|
| 485 | to_be_resorted => rho |
---|
| 486 | ELSE |
---|
| 487 | to_be_resorted => rho_av |
---|
| 488 | ENDIF |
---|
| 489 | |
---|
| 490 | CASE ( 's' ) |
---|
| 491 | IF ( av == 0 ) THEN |
---|
[1960] | 492 | to_be_resorted => s |
---|
[1320] | 493 | ELSE |
---|
| 494 | to_be_resorted => s_av |
---|
| 495 | ENDIF |
---|
| 496 | |
---|
| 497 | CASE ( 'sa' ) |
---|
| 498 | IF ( av == 0 ) THEN |
---|
| 499 | to_be_resorted => sa |
---|
| 500 | ELSE |
---|
| 501 | to_be_resorted => sa_av |
---|
| 502 | ENDIF |
---|
| 503 | |
---|
| 504 | CASE ( 'u' ) |
---|
| 505 | IF ( av == 0 ) THEN |
---|
| 506 | to_be_resorted => u |
---|
| 507 | ELSE |
---|
| 508 | to_be_resorted => u_av |
---|
| 509 | ENDIF |
---|
| 510 | |
---|
| 511 | CASE ( 'v' ) |
---|
| 512 | IF ( av == 0 ) THEN |
---|
| 513 | to_be_resorted => v |
---|
| 514 | ELSE |
---|
| 515 | to_be_resorted => v_av |
---|
| 516 | ENDIF |
---|
| 517 | |
---|
| 518 | CASE ( 'vpt' ) |
---|
| 519 | IF ( av == 0 ) THEN |
---|
| 520 | to_be_resorted => vpt |
---|
| 521 | ELSE |
---|
| 522 | to_be_resorted => vpt_av |
---|
| 523 | ENDIF |
---|
| 524 | |
---|
| 525 | CASE ( 'w' ) |
---|
| 526 | IF ( av == 0 ) THEN |
---|
| 527 | to_be_resorted => w |
---|
| 528 | ELSE |
---|
| 529 | to_be_resorted => w_av |
---|
| 530 | ENDIF |
---|
| 531 | |
---|
| 532 | CASE DEFAULT |
---|
| 533 | ! |
---|
| 534 | !-- User defined quantity |
---|
| 535 | CALL user_data_output_mask(av, domask(mid,av,if), found, local_pf ) |
---|
| 536 | resorted = .TRUE. |
---|
| 537 | |
---|
| 538 | IF ( .NOT. found ) THEN |
---|
| 539 | WRITE ( message_string, * ) 'no output available for: ', & |
---|
| 540 | TRIM( domask(mid,av,if) ) |
---|
| 541 | CALL message( 'data_output_mask', 'PA0327', 0, 0, 0, 6, 0 ) |
---|
| 542 | ENDIF |
---|
| 543 | |
---|
| 544 | END SELECT |
---|
| 545 | |
---|
| 546 | ! |
---|
| 547 | !-- Resort the array to be output, if not done above |
---|
| 548 | IF ( .NOT. resorted ) THEN |
---|
| 549 | DO i = 1, mask_size_l(mid,1) |
---|
| 550 | DO j = 1, mask_size_l(mid,2) |
---|
| 551 | DO k = 1, mask_size_l(mid,3) |
---|
| 552 | local_pf(i,j,k) = to_be_resorted(mask_k(mid,k), & |
---|
| 553 | mask_j(mid,j),mask_i(mid,i)) |
---|
| 554 | ENDDO |
---|
| 555 | ENDDO |
---|
| 556 | ENDDO |
---|
| 557 | ENDIF |
---|
| 558 | |
---|
| 559 | ! |
---|
| 560 | !-- I/O block. I/O methods are implemented |
---|
| 561 | !-- (1) for parallel execution |
---|
| 562 | !-- a. with netCDF 4 parallel I/O-enabled library |
---|
| 563 | !-- b. with netCDF 3 library |
---|
| 564 | !-- (2) for serial execution. |
---|
| 565 | !-- The choice of method depends on the correct setting of preprocessor |
---|
| 566 | !-- directives __parallel and __netcdf4_parallel as well as on the parameter |
---|
| 567 | !-- netcdf_data_format. |
---|
| 568 | #if defined( __parallel ) |
---|
| 569 | #if defined( __netcdf4_parallel ) |
---|
| 570 | IF ( netcdf_data_format > 4 ) THEN |
---|
| 571 | ! |
---|
| 572 | !-- (1) a. Parallel I/O using netCDF 4 (not yet tested) |
---|
| 573 | nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), & |
---|
| 574 | id_var_domask(mid,av,if), & |
---|
| 575 | local_pf, & |
---|
| 576 | start = (/ mask_start_l(mid,1), mask_start_l(mid,2), & |
---|
| 577 | mask_start_l(mid,3), domask_time_count(mid,av) /), & |
---|
| 578 | count = (/ mask_size_l(mid,1), mask_size_l(mid,2), & |
---|
| 579 | mask_size_l(mid,3), 1 /) ) |
---|
[1783] | 580 | CALL netcdf_handle_error( 'data_output_mask', 461 ) |
---|
[1320] | 581 | ELSE |
---|
| 582 | #endif |
---|
| 583 | ! |
---|
| 584 | !-- (1) b. Conventional I/O only through PE0 |
---|
| 585 | !-- PE0 receives partial arrays from all processors of the respective mask |
---|
| 586 | !-- and outputs them. Here a barrier has to be set, because otherwise |
---|
| 587 | !-- "-MPI- FATAL: Remote protocol queue full" may occur. |
---|
| 588 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 589 | |
---|
| 590 | ngp = mask_size_l(mid,1) * mask_size_l(mid,2) * mask_size_l(mid,3) |
---|
| 591 | IF ( myid == 0 ) THEN |
---|
| 592 | ! |
---|
| 593 | !-- Local array can be relocated directly. |
---|
| 594 | total_pf( & |
---|
| 595 | mask_start_l(mid,1):mask_start_l(mid,1)+mask_size_l(mid,1)-1, & |
---|
| 596 | mask_start_l(mid,2):mask_start_l(mid,2)+mask_size_l(mid,2)-1, & |
---|
| 597 | mask_start_l(mid,3):mask_start_l(mid,3)+mask_size_l(mid,3)-1 ) & |
---|
| 598 | = local_pf |
---|
| 599 | ! |
---|
| 600 | !-- Receive data from all other PEs. |
---|
| 601 | DO n = 1, numprocs-1 |
---|
| 602 | ! |
---|
| 603 | !-- Receive index limits first, then array. |
---|
| 604 | !-- Index limits are received in arbitrary order from the PEs. |
---|
| 605 | CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0, & |
---|
| 606 | comm2d, status, ierr ) |
---|
| 607 | ! |
---|
| 608 | !-- Not all PEs have data for the mask |
---|
| 609 | IF ( ind(1) /= -9999 ) THEN |
---|
| 610 | ngp = ( ind(2)-ind(1)+1 ) * (ind(4)-ind(3)+1 ) * & |
---|
| 611 | ( ind(6)-ind(5)+1 ) |
---|
| 612 | sender = status(MPI_SOURCE) |
---|
| 613 | DEALLOCATE( local_pf ) |
---|
| 614 | ALLOCATE(local_pf(ind(1):ind(2),ind(3):ind(4),ind(5):ind(6))) |
---|
| 615 | CALL MPI_RECV( local_pf(ind(1),ind(3),ind(5)), ngp, & |
---|
| 616 | MPI_REAL, sender, 1, comm2d, status, ierr ) |
---|
| 617 | total_pf(ind(1):ind(2),ind(3):ind(4),ind(5):ind(6)) & |
---|
| 618 | = local_pf |
---|
| 619 | ENDIF |
---|
| 620 | ENDDO |
---|
| 621 | |
---|
| 622 | nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), & |
---|
| 623 | id_var_domask(mid,av,if), total_pf, & |
---|
| 624 | start = (/ 1, 1, 1, domask_time_count(mid,av) /), & |
---|
| 625 | count = (/ mask_size(mid,1), mask_size(mid,2), & |
---|
| 626 | mask_size(mid,3), 1 /) ) |
---|
[1783] | 627 | CALL netcdf_handle_error( 'data_output_mask', 462 ) |
---|
[1320] | 628 | |
---|
| 629 | ELSE |
---|
| 630 | ! |
---|
| 631 | !-- If at least part of the mask resides on the PE, send the index |
---|
| 632 | !-- limits for the target array, otherwise send -9999 to PE0. |
---|
| 633 | IF ( mask_size_l(mid,1) > 0 .AND. mask_size_l(mid,2) > 0 .AND. & |
---|
| 634 | mask_size_l(mid,3) > 0 ) & |
---|
| 635 | THEN |
---|
| 636 | ind(1) = mask_start_l(mid,1) |
---|
| 637 | ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1 |
---|
| 638 | ind(3) = mask_start_l(mid,2) |
---|
| 639 | ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1 |
---|
| 640 | ind(5) = mask_start_l(mid,3) |
---|
| 641 | ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1 |
---|
| 642 | ELSE |
---|
| 643 | ind(1) = -9999; ind(2) = -9999 |
---|
| 644 | ind(3) = -9999; ind(4) = -9999 |
---|
| 645 | ind(5) = -9999; ind(6) = -9999 |
---|
| 646 | ENDIF |
---|
| 647 | CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr ) |
---|
| 648 | ! |
---|
| 649 | !-- If applicable, send data to PE0. |
---|
| 650 | IF ( ind(1) /= -9999 ) THEN |
---|
| 651 | CALL MPI_SEND( local_pf(1,1,1), ngp, MPI_REAL, 0, 1, comm2d, & |
---|
| 652 | ierr ) |
---|
| 653 | ENDIF |
---|
| 654 | ENDIF |
---|
| 655 | ! |
---|
| 656 | !-- A barrier has to be set, because otherwise some PEs may proceed too |
---|
| 657 | !-- fast so that PE0 may receive wrong data on tag 0. |
---|
| 658 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 659 | #if defined( __netcdf4_parallel ) |
---|
| 660 | ENDIF |
---|
| 661 | #endif |
---|
| 662 | #else |
---|
| 663 | ! |
---|
| 664 | !-- (2) For serial execution of PALM, the single processor (PE0) holds all |
---|
| 665 | !-- data and writes them directly to file. |
---|
| 666 | nc_stat = NF90_PUT_VAR( id_set_mask(mid,av), & |
---|
| 667 | id_var_domask(mid,av,if), & |
---|
| 668 | local_pf, & |
---|
| 669 | start = (/ 1, 1, 1, domask_time_count(mid,av) /), & |
---|
| 670 | count = (/ mask_size_l(mid,1), mask_size_l(mid,2), & |
---|
| 671 | mask_size_l(mid,3), 1 /) ) |
---|
[1783] | 672 | CALL netcdf_handle_error( 'data_output_mask', 463 ) |
---|
[1320] | 673 | #endif |
---|
| 674 | |
---|
| 675 | if = if + 1 |
---|
| 676 | |
---|
| 677 | ENDDO |
---|
| 678 | |
---|
| 679 | ! |
---|
| 680 | !-- Deallocate temporary arrays. |
---|
| 681 | DEALLOCATE( local_pf ) |
---|
| 682 | #if defined( __parallel ) |
---|
| 683 | IF ( myid == 0 ) THEN |
---|
| 684 | DEALLOCATE( total_pf ) |
---|
| 685 | ENDIF |
---|
| 686 | #endif |
---|
| 687 | |
---|
[1783] | 688 | ! |
---|
| 689 | !-- Switch back to original format given by user (see beginning of this routine) |
---|
| 690 | netcdf_data_format = netcdf_data_format_save |
---|
[1320] | 691 | |
---|
| 692 | CALL cpu_log( log_point(49), 'data_output_mask', 'stop' ) |
---|
| 693 | #endif |
---|
| 694 | |
---|
| 695 | END SUBROUTINE data_output_mask |
---|