[298] | 1 | SUBROUTINE init_masks |
---|
| 2 | |
---|
| 3 | !------------------------------------------------------------------------------! |
---|
[484] | 4 | ! Current revisions: |
---|
[298] | 5 | ! ----------------- |
---|
| 6 | ! |
---|
| 7 | ! |
---|
| 8 | ! Former revisions: |
---|
| 9 | ! ----------------- |
---|
| 10 | ! $Id: init_masks.f90 494 2010-03-01 12:23:32Z heinze $ |
---|
| 11 | ! |
---|
[494] | 12 | ! 493 2010-03-01 08:30:24Z raasch |
---|
| 13 | ! netcdf_format_mask* and format_parallel_io replaced by netcdf_data_format |
---|
| 14 | ! |
---|
[449] | 15 | ! 410 2009-12-04 17:05:40Z letzel |
---|
| 16 | ! Initial revision |
---|
[298] | 17 | ! |
---|
[449] | 18 | ! |
---|
[298] | 19 | ! Description: |
---|
| 20 | ! ------------ |
---|
| 21 | ! Initialize masked data output |
---|
| 22 | !------------------------------------------------------------------------------! |
---|
| 23 | |
---|
| 24 | USE arrays_3d |
---|
| 25 | USE control_parameters |
---|
| 26 | USE grid_variables |
---|
| 27 | USE indices |
---|
| 28 | USE netcdf_control |
---|
| 29 | USE particle_attributes |
---|
| 30 | USE pegrid |
---|
| 31 | |
---|
| 32 | IMPLICIT NONE |
---|
| 33 | |
---|
| 34 | CHARACTER (LEN=6) :: var |
---|
| 35 | CHARACTER (LEN=7) :: unit |
---|
| 36 | CHARACTER (LEN=10), DIMENSION(max_masks,100) :: do_mask, do_mask_user |
---|
| 37 | |
---|
| 38 | INTEGER :: i, ilen, ind(6), ind_array(1), j, k, n, sender |
---|
| 39 | INTEGER, DIMENSION(:), ALLOCATABLE :: tmp_array |
---|
| 40 | |
---|
| 41 | LOGICAL :: found |
---|
| 42 | ! |
---|
| 43 | !-- Allocation and initialization |
---|
| 44 | ALLOCATE( tmp_array( MAX(nx,ny,nz)+1 ) ) |
---|
| 45 | |
---|
| 46 | ALLOCATE( mask_i(max_masks,nxr-nxl+1), & |
---|
| 47 | mask_j(max_masks,nyn-nys+1), & |
---|
| 48 | mask_k(max_masks,nzt-nzb+1) ) |
---|
| 49 | ! |
---|
| 50 | !-- internal mask arrays ("mask,dimension,selection") |
---|
| 51 | ALLOCATE( mask(max_masks,3,mask_xyz_dimension), & |
---|
| 52 | mask_loop(max_masks,3,3) ) |
---|
[493] | 53 | |
---|
[298] | 54 | ! |
---|
[493] | 55 | !-- Parallel mask output not yet tested |
---|
| 56 | IF ( netcdf_data_format > 2 ) THEN |
---|
| 57 | message_string = 'NetCDF file formats '// & |
---|
| 58 | '3 (NetCDF 4) and 4 (NetCDF 4 Classic model)'// & |
---|
| 59 | '&are currently not supported (not yet tested).' |
---|
[298] | 60 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 61 | ENDIF |
---|
| 62 | ! |
---|
| 63 | !-- Store data output parameters for masked data output in few shared arrays |
---|
| 64 | do_mask( 1,:) = data_output_mask_01; do_mask( 2,:) = data_output_mask_02 |
---|
| 65 | do_mask( 3,:) = data_output_mask_03; do_mask( 4,:) = data_output_mask_04 |
---|
| 66 | do_mask( 5,:) = data_output_mask_05; do_mask( 6,:) = data_output_mask_06 |
---|
| 67 | do_mask( 7,:) = data_output_mask_07; do_mask( 8,:) = data_output_mask_08 |
---|
| 68 | do_mask( 9,:) = data_output_mask_09; do_mask(10,:) = data_output_mask_10 |
---|
| 69 | do_mask(11,:) = data_output_mask_11; do_mask(12,:) = data_output_mask_12 |
---|
| 70 | do_mask(13,:) = data_output_mask_13; do_mask(14,:) = data_output_mask_14 |
---|
| 71 | do_mask(15,:) = data_output_mask_15; do_mask(16,:) = data_output_mask_16 |
---|
| 72 | do_mask(17,:) = data_output_mask_17; do_mask(18,:) = data_output_mask_18 |
---|
| 73 | do_mask(19,:) = data_output_mask_19; do_mask(20,:) = data_output_mask_20 |
---|
| 74 | do_mask_user( 1,:) = data_output_mask_user_01 |
---|
| 75 | do_mask_user( 2,:) = data_output_mask_user_02 |
---|
| 76 | do_mask_user( 3,:) = data_output_mask_user_03 |
---|
| 77 | do_mask_user( 4,:) = data_output_mask_user_04 |
---|
| 78 | do_mask_user( 5,:) = data_output_mask_user_05 |
---|
| 79 | do_mask_user( 6,:) = data_output_mask_user_06 |
---|
| 80 | do_mask_user( 7,:) = data_output_mask_user_07 |
---|
| 81 | do_mask_user( 8,:) = data_output_mask_user_08 |
---|
| 82 | do_mask_user( 9,:) = data_output_mask_user_09 |
---|
| 83 | do_mask_user(10,:) = data_output_mask_user_10 |
---|
| 84 | do_mask_user(11,:) = data_output_mask_user_11 |
---|
| 85 | do_mask_user(12,:) = data_output_mask_user_12 |
---|
| 86 | do_mask_user(13,:) = data_output_mask_user_13 |
---|
| 87 | do_mask_user(14,:) = data_output_mask_user_14 |
---|
| 88 | do_mask_user(15,:) = data_output_mask_user_15 |
---|
| 89 | do_mask_user(16,:) = data_output_mask_user_16 |
---|
| 90 | do_mask_user(17,:) = data_output_mask_user_17 |
---|
| 91 | do_mask_user(18,:) = data_output_mask_user_18 |
---|
| 92 | do_mask_user(19,:) = data_output_mask_user_19 |
---|
| 93 | do_mask_user(20,:) = data_output_mask_user_20 |
---|
| 94 | mask( 1,1,:) = mask_01_x; mask( 2,1,:) = mask_02_x |
---|
| 95 | mask( 3,1,:) = mask_03_x; mask( 4,1,:) = mask_04_x |
---|
| 96 | mask( 5,1,:) = mask_05_x; mask( 6,1,:) = mask_06_x |
---|
| 97 | mask( 7,1,:) = mask_07_x; mask( 8,1,:) = mask_08_x |
---|
| 98 | mask( 9,1,:) = mask_09_x; mask(10,1,:) = mask_10_x |
---|
| 99 | mask(11,1,:) = mask_11_x; mask(12,1,:) = mask_12_x |
---|
| 100 | mask(13,1,:) = mask_13_x; mask(14,1,:) = mask_14_x |
---|
| 101 | mask(15,1,:) = mask_15_x; mask(16,1,:) = mask_16_x |
---|
| 102 | mask(17,1,:) = mask_17_x; mask(18,1,:) = mask_18_x |
---|
| 103 | mask(19,1,:) = mask_19_x; mask(20,1,:) = mask_20_x |
---|
| 104 | mask( 1,2,:) = mask_01_y; mask( 2,2,:) = mask_02_y |
---|
| 105 | mask( 3,2,:) = mask_03_y; mask( 4,2,:) = mask_04_y |
---|
| 106 | mask( 5,2,:) = mask_05_y; mask( 6,2,:) = mask_06_y |
---|
| 107 | mask( 7,2,:) = mask_07_y; mask( 8,2,:) = mask_08_y |
---|
| 108 | mask( 9,2,:) = mask_09_y; mask(10,2,:) = mask_10_y |
---|
| 109 | mask(11,2,:) = mask_11_y; mask(12,2,:) = mask_12_y |
---|
| 110 | mask(13,2,:) = mask_13_y; mask(14,2,:) = mask_14_y |
---|
| 111 | mask(15,2,:) = mask_15_y; mask(16,2,:) = mask_16_y |
---|
| 112 | mask(17,2,:) = mask_17_y; mask(18,2,:) = mask_18_y |
---|
| 113 | mask(19,2,:) = mask_19_y; mask(20,2,:) = mask_20_y |
---|
| 114 | mask( 1,3,:) = mask_01_z; mask( 2,3,:) = mask_02_z |
---|
| 115 | mask( 3,3,:) = mask_03_z; mask( 4,3,:) = mask_04_z |
---|
| 116 | mask( 5,3,:) = mask_05_z; mask( 6,3,:) = mask_06_z |
---|
| 117 | mask( 7,3,:) = mask_07_z; mask( 8,3,:) = mask_08_z |
---|
| 118 | mask( 9,3,:) = mask_09_z; mask(10,3,:) = mask_10_z |
---|
| 119 | mask(11,3,:) = mask_11_z; mask(12,3,:) = mask_12_z |
---|
| 120 | mask(13,3,:) = mask_13_z; mask(14,3,:) = mask_14_z |
---|
| 121 | mask(15,3,:) = mask_15_z; mask(16,3,:) = mask_16_z |
---|
| 122 | mask(17,3,:) = mask_17_z; mask(18,3,:) = mask_18_z |
---|
| 123 | mask(19,3,:) = mask_19_z; mask(20,3,:) = mask_20_z |
---|
| 124 | mask_loop( 1,1,:) = mask_01_x_loop; mask_loop( 2,1,:) = mask_02_x_loop |
---|
| 125 | mask_loop( 3,1,:) = mask_03_x_loop; mask_loop( 4,1,:) = mask_04_x_loop |
---|
| 126 | mask_loop( 5,1,:) = mask_05_x_loop; mask_loop( 6,1,:) = mask_06_x_loop |
---|
| 127 | mask_loop( 7,1,:) = mask_07_x_loop; mask_loop( 8,1,:) = mask_08_x_loop |
---|
| 128 | mask_loop( 9,1,:) = mask_09_x_loop; mask_loop(10,1,:) = mask_10_x_loop |
---|
| 129 | mask_loop(11,1,:) = mask_11_x_loop; mask_loop(12,1,:) = mask_12_x_loop |
---|
| 130 | mask_loop(13,1,:) = mask_13_x_loop; mask_loop(14,1,:) = mask_14_x_loop |
---|
| 131 | mask_loop(15,1,:) = mask_15_x_loop; mask_loop(16,1,:) = mask_16_x_loop |
---|
| 132 | mask_loop(17,1,:) = mask_17_x_loop; mask_loop(18,1,:) = mask_18_x_loop |
---|
| 133 | mask_loop(19,1,:) = mask_19_x_loop; mask_loop(20,1,:) = mask_20_x_loop |
---|
| 134 | mask_loop( 1,2,:) = mask_01_y_loop; mask_loop( 2,2,:) = mask_02_y_loop |
---|
| 135 | mask_loop( 3,2,:) = mask_03_y_loop; mask_loop( 4,2,:) = mask_04_y_loop |
---|
| 136 | mask_loop( 5,2,:) = mask_05_y_loop; mask_loop( 6,2,:) = mask_06_y_loop |
---|
| 137 | mask_loop( 7,2,:) = mask_07_y_loop; mask_loop( 8,2,:) = mask_08_y_loop |
---|
| 138 | mask_loop( 9,2,:) = mask_09_y_loop; mask_loop(10,2,:) = mask_10_y_loop |
---|
| 139 | mask_loop(11,2,:) = mask_11_y_loop; mask_loop(12,2,:) = mask_12_y_loop |
---|
| 140 | mask_loop(13,2,:) = mask_13_y_loop; mask_loop(14,2,:) = mask_14_y_loop |
---|
| 141 | mask_loop(15,2,:) = mask_15_y_loop; mask_loop(16,2,:) = mask_16_y_loop |
---|
| 142 | mask_loop(17,2,:) = mask_17_y_loop; mask_loop(18,2,:) = mask_18_y_loop |
---|
| 143 | mask_loop(19,2,:) = mask_19_y_loop; mask_loop(20,2,:) = mask_20_y_loop |
---|
| 144 | mask_loop( 1,3,:) = mask_01_z_loop; mask_loop( 2,3,:) = mask_02_z_loop |
---|
| 145 | mask_loop( 3,3,:) = mask_03_z_loop; mask_loop( 4,3,:) = mask_04_z_loop |
---|
| 146 | mask_loop( 5,3,:) = mask_05_z_loop; mask_loop( 6,3,:) = mask_06_z_loop |
---|
| 147 | mask_loop( 7,3,:) = mask_07_z_loop; mask_loop( 8,3,:) = mask_08_z_loop |
---|
| 148 | mask_loop( 9,3,:) = mask_09_z_loop; mask_loop(10,3,:) = mask_10_z_loop |
---|
| 149 | mask_loop(11,3,:) = mask_11_z_loop; mask_loop(12,3,:) = mask_12_z_loop |
---|
| 150 | mask_loop(13,3,:) = mask_13_z_loop; mask_loop(14,3,:) = mask_14_z_loop |
---|
| 151 | mask_loop(15,3,:) = mask_15_z_loop; mask_loop(16,3,:) = mask_16_z_loop |
---|
| 152 | mask_loop(17,3,:) = mask_17_z_loop; mask_loop(18,3,:) = mask_18_z_loop |
---|
| 153 | mask_loop(19,3,:) = mask_19_z_loop; mask_loop(20,3,:) = mask_20_z_loop |
---|
| 154 | mask_i = -1; mask_j = -1; mask_k = -1 |
---|
| 155 | ! |
---|
| 156 | !-- Global arrays are required by define_netcdf_header. |
---|
[493] | 157 | IF ( myid == 0 .OR. netcdf_data_format > 2 ) THEN |
---|
[298] | 158 | ALLOCATE( mask_i_global(max_masks,nx+1), & |
---|
| 159 | mask_j_global(max_masks,ny+1), & |
---|
| 160 | mask_k_global(max_masks,nz+1) ) |
---|
| 161 | mask_i_global = -1; mask_j_global = -1; mask_k_global = -1 |
---|
| 162 | ENDIF |
---|
| 163 | |
---|
| 164 | ! |
---|
| 165 | !-- Determine variable names for each mask |
---|
| 166 | DO mid = 1, masks |
---|
| 167 | ! |
---|
| 168 | !-- Append user-defined data output variables to the standard data output |
---|
| 169 | IF ( do_mask_user(mid,1) /= ' ' ) THEN |
---|
| 170 | i = 1 |
---|
| 171 | DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) |
---|
| 172 | i = i + 1 |
---|
| 173 | ENDDO |
---|
| 174 | j = 1 |
---|
| 175 | DO WHILE ( do_mask_user(mid,j) /= ' ' .AND. j <= 100 ) |
---|
| 176 | IF ( i > 100 ) THEN |
---|
| 177 | WRITE ( message_string, * ) 'number of output quantitities ', & |
---|
| 178 | 'given by data_output_mask and data_output_mask_user ', & |
---|
| 179 | 'exceeds the limit of 100' |
---|
| 180 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 181 | ENDIF |
---|
| 182 | do_mask(mid,i) = do_mask_user(mid,j) |
---|
| 183 | i = i + 1 |
---|
| 184 | j = j + 1 |
---|
| 185 | ENDDO |
---|
| 186 | ENDIF |
---|
| 187 | |
---|
| 188 | ! |
---|
| 189 | !-- Check and set steering parameters for mask data output and averaging |
---|
| 190 | i = 1 |
---|
| 191 | DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) |
---|
| 192 | ! |
---|
| 193 | !-- Check for data averaging |
---|
| 194 | ilen = LEN_TRIM( do_mask(mid,i) ) |
---|
| 195 | j = 0 ! no data averaging |
---|
| 196 | IF ( ilen > 3 ) THEN |
---|
| 197 | IF ( do_mask(mid,i)(ilen-2:ilen) == '_av' ) THEN |
---|
| 198 | j = 1 ! data averaging |
---|
| 199 | do_mask(mid,i) = do_mask(mid,i)(1:ilen-3) |
---|
| 200 | ENDIF |
---|
| 201 | ENDIF |
---|
| 202 | var = TRIM( do_mask(mid,i) ) |
---|
| 203 | ! |
---|
| 204 | !-- Check for allowed value and set units |
---|
| 205 | SELECT CASE ( TRIM( var ) ) |
---|
| 206 | |
---|
| 207 | CASE ( 'e' ) |
---|
| 208 | IF ( constant_diffusion ) THEN |
---|
| 209 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 210 | '" requires constant_diffusion = .FALSE.' |
---|
| 211 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 212 | ENDIF |
---|
| 213 | unit = 'm2/s2' |
---|
| 214 | |
---|
| 215 | CASE ( 'pc', 'pr' ) |
---|
| 216 | IF ( .NOT. particle_advection ) THEN |
---|
| 217 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 218 | '" requires a "particles_par"-NAMELIST in the ', & |
---|
| 219 | 'parameter file (PARIN)' |
---|
| 220 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 221 | ENDIF |
---|
| 222 | IF ( TRIM( var ) == 'pc' ) unit = 'number' |
---|
| 223 | IF ( TRIM( var ) == 'pr' ) unit = 'm' |
---|
| 224 | |
---|
| 225 | CASE ( 'q', 'vpt' ) |
---|
| 226 | IF ( .NOT. humidity ) THEN |
---|
| 227 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 228 | '" requires humidity = .TRUE.' |
---|
| 229 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 230 | ENDIF |
---|
| 231 | IF ( TRIM( var ) == 'q' ) unit = 'kg/kg' |
---|
| 232 | IF ( TRIM( var ) == 'vpt' ) unit = 'K' |
---|
| 233 | |
---|
| 234 | CASE ( 'ql' ) |
---|
| 235 | IF ( .NOT. ( cloud_physics .OR. cloud_droplets ) ) THEN |
---|
| 236 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 237 | '" requires cloud_physics = .TRUE. or cloud_droplets', & |
---|
| 238 | ' = .TRUE.' |
---|
| 239 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 240 | ENDIF |
---|
| 241 | unit = 'kg/kg' |
---|
| 242 | |
---|
| 243 | CASE ( 'ql_c', 'ql_v', 'ql_vp' ) |
---|
| 244 | IF ( .NOT. cloud_droplets ) THEN |
---|
| 245 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 246 | '" requires cloud_droplets = .TRUE.' |
---|
| 247 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 248 | ENDIF |
---|
| 249 | IF ( TRIM( var ) == 'ql_c' ) unit = 'kg/kg' |
---|
| 250 | IF ( TRIM( var ) == 'ql_v' ) unit = 'm3' |
---|
| 251 | IF ( TRIM( var ) == 'ql_vp' ) unit = 'none' |
---|
| 252 | |
---|
| 253 | CASE ( 'qv' ) |
---|
| 254 | IF ( .NOT. cloud_physics ) THEN |
---|
| 255 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 256 | '" requires cloud_physics = .TRUE.' |
---|
| 257 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 258 | ENDIF |
---|
| 259 | unit = 'kg/kg' |
---|
| 260 | |
---|
| 261 | CASE ( 'rho' ) |
---|
| 262 | IF ( .NOT. ocean ) THEN |
---|
| 263 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 264 | '" requires ocean = .TRUE.' |
---|
| 265 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 266 | ENDIF |
---|
| 267 | unit = 'kg/m3' |
---|
| 268 | |
---|
| 269 | CASE ( 's' ) |
---|
| 270 | IF ( .NOT. passive_scalar ) THEN |
---|
| 271 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 272 | '" requires passive_scalar = .TRUE.' |
---|
| 273 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 274 | ENDIF |
---|
| 275 | unit = 'conc' |
---|
| 276 | |
---|
| 277 | CASE ( 'sa' ) |
---|
| 278 | IF ( .NOT. ocean ) THEN |
---|
| 279 | WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 280 | '" requires ocean = .TRUE.' |
---|
| 281 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 282 | ENDIF |
---|
| 283 | unit = 'psu' |
---|
| 284 | |
---|
| 285 | CASE ( 'u*', 't*', 'lwp*', 'pra*', 'prr*', 'z0*' ) |
---|
| 286 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
| 287 | 'output: "', TRIM( var ), '" is only allowed', & |
---|
| 288 | 'for horizontal cross section' |
---|
| 289 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 290 | ! IF ( TRIM( var ) == 'lwp*' .AND. .NOT. cloud_physics ) THEN |
---|
| 291 | ! WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 292 | ! '" requires cloud_physics = .TRUE.' |
---|
| 293 | ! CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 294 | ! ENDIF |
---|
| 295 | ! IF ( TRIM( var ) == 'pra*' .AND. .NOT. precipitation ) THEN |
---|
| 296 | ! WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 297 | ! '" requires precipitation = .TRUE.' |
---|
| 298 | ! CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 299 | ! ENDIF |
---|
| 300 | ! IF ( TRIM( var ) == 'pra*' .AND. j == 1 ) THEN |
---|
| 301 | ! WRITE ( message_string, * ) 'temporal averaging of ', & |
---|
| 302 | ! ' precipitation amount "', TRIM( var ), & |
---|
| 303 | ! '" not possible' |
---|
| 304 | ! CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 305 | ! ENDIF |
---|
| 306 | ! IF ( TRIM( var ) == 'prr*' .AND. .NOT. precipitation ) THEN |
---|
| 307 | ! WRITE ( message_string, * ) 'output of "', TRIM( var ), & |
---|
| 308 | ! '" requires precipitation = .TRUE.' |
---|
| 309 | ! CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 310 | ! ENDIF |
---|
| 311 | ! |
---|
| 312 | ! IF ( TRIM( var ) == 'u*' ) unit = 'm/s' |
---|
| 313 | ! IF ( TRIM( var ) == 't*' ) unit = 'K' |
---|
| 314 | ! IF ( TRIM( var ) == 'lwp*' ) unit = 'kg/kg*m' |
---|
| 315 | ! IF ( TRIM( var ) == 'pra*' ) unit = 'mm' |
---|
| 316 | ! IF ( TRIM( var ) == 'prr*' ) unit = 'mm/s' |
---|
| 317 | ! IF ( TRIM( var ) == 'z0*' ) unit = 'm' |
---|
| 318 | |
---|
| 319 | CASE ( 'p', 'pt', 'u', 'v', 'w' ) |
---|
| 320 | IF ( TRIM( var ) == 'p' ) unit = 'Pa' |
---|
| 321 | IF ( TRIM( var ) == 'pt' ) unit = 'K' |
---|
| 322 | IF ( TRIM( var ) == 'u' ) unit = 'm/s' |
---|
| 323 | IF ( TRIM( var ) == 'v' ) unit = 'm/s' |
---|
| 324 | IF ( TRIM( var ) == 'w' ) unit = 'm/s' |
---|
| 325 | CONTINUE |
---|
| 326 | |
---|
| 327 | CASE DEFAULT |
---|
| 328 | CALL user_check_data_output( var, unit ) |
---|
| 329 | |
---|
| 330 | IF ( unit == 'illegal' ) THEN |
---|
| 331 | IF ( do_mask_user(mid,1) /= ' ' ) THEN |
---|
| 332 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
| 333 | 'output or data_output_user: "', & |
---|
| 334 | TRIM( do_mask(mid,i) ), '"' |
---|
| 335 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 336 | ELSE |
---|
| 337 | WRITE ( message_string, * ) 'illegal value for data_',& |
---|
| 338 | 'output: "', TRIM( do_mask(mid,i) ), '"' |
---|
| 339 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 340 | ENDIF |
---|
| 341 | ENDIF |
---|
| 342 | |
---|
| 343 | END SELECT |
---|
| 344 | ! |
---|
| 345 | !-- Set the internal steering parameters appropriately |
---|
| 346 | domask_no(mid,j) = domask_no(mid,j) + 1 |
---|
| 347 | domask(mid,j,domask_no(mid,j)) = do_mask(mid,i) |
---|
| 348 | domask_unit(mid,j,domask_no(mid,j)) = unit |
---|
| 349 | |
---|
| 350 | IF ( j == 1 ) THEN |
---|
| 351 | ! |
---|
| 352 | !-- Check, if variable is already subject to averaging |
---|
| 353 | found = .FALSE. |
---|
| 354 | DO k = 1, doav_n |
---|
| 355 | IF ( TRIM( doav(k) ) == TRIM( var ) ) found = .TRUE. |
---|
| 356 | ENDDO |
---|
| 357 | |
---|
| 358 | IF ( .NOT. found ) THEN |
---|
| 359 | doav_n = doav_n + 1 |
---|
| 360 | doav(doav_n) = var |
---|
| 361 | ENDIF |
---|
| 362 | ENDIF |
---|
| 363 | |
---|
| 364 | i = i + 1 |
---|
| 365 | |
---|
| 366 | ENDDO ! do_mask(mid,i) |
---|
| 367 | ENDDO ! mid |
---|
| 368 | |
---|
| 369 | |
---|
| 370 | ! |
---|
| 371 | !-- Determine mask locations for each mask |
---|
| 372 | DO mid = 1, masks |
---|
| 373 | ! |
---|
| 374 | !-- Set local masks for each subdomain along all three dimensions |
---|
| 375 | CALL set_mask_locations( 1, dx, 'dx', nx, 'nx', nxl, nxr ) |
---|
| 376 | CALL set_mask_locations( 2, dy, 'dy', ny, 'ny', nys, nyn ) |
---|
| 377 | CALL set_mask_locations( 3, dz, 'dz', nz, 'nz', nzb, nzt ) |
---|
| 378 | ! |
---|
| 379 | !-- Set global masks along all three dimensions (required by |
---|
| 380 | !-- define_netcdf_header). |
---|
| 381 | #if defined( __parallel ) |
---|
| 382 | ! |
---|
| 383 | !-- PE0 receives partial arrays from all processors of the respective mask |
---|
| 384 | !-- and outputs them. Here a barrier has to be set, because otherwise |
---|
| 385 | !-- "-MPI- FATAL: Remote protocol queue full" may occur. |
---|
| 386 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 387 | |
---|
| 388 | IF ( myid == 0 ) THEN |
---|
| 389 | ! |
---|
| 390 | !-- Local arrays can be relocated directly. |
---|
| 391 | mask_i_global(mid,mask_start_l(mid,1): & |
---|
| 392 | mask_start_l(mid,1)+mask_size_l(mid,1)-1) = & |
---|
| 393 | mask_i(mid,:mask_size_l(mid,1)) |
---|
| 394 | mask_j_global(mid,mask_start_l(mid,2): & |
---|
| 395 | mask_start_l(mid,2)+mask_size_l(mid,2)-1) = & |
---|
| 396 | mask_j(mid,:mask_size_l(mid,2)) |
---|
| 397 | mask_k_global(mid,mask_start_l(mid,3): & |
---|
| 398 | mask_start_l(mid,3)+mask_size_l(mid,3)-1) = & |
---|
| 399 | mask_k(mid,:mask_size_l(mid,3)) |
---|
| 400 | ! |
---|
| 401 | !-- Receive data from all other PEs. |
---|
| 402 | DO n = 1, numprocs-1 |
---|
| 403 | ! |
---|
| 404 | !-- Receive index limits first, then arrays. |
---|
| 405 | !-- Index limits are received in arbitrary order from the PEs. |
---|
| 406 | CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0, & |
---|
| 407 | comm2d, status, ierr ) |
---|
| 408 | ! |
---|
| 409 | !-- Not all PEs have data for the mask. |
---|
| 410 | IF ( ind(1) /= -9999 ) THEN |
---|
| 411 | sender = status(MPI_SOURCE) |
---|
| 412 | CALL MPI_RECV( tmp_array(ind(1)), ind(2)-ind(1)+1, & |
---|
[363] | 413 | MPI_INTEGER, sender, 1, comm2d, status, ierr ) |
---|
[298] | 414 | mask_i_global(mid,ind(1):ind(2)) = tmp_array(ind(1):ind(2)) |
---|
| 415 | CALL MPI_RECV( tmp_array(ind(3)), ind(4)-ind(3)+1, & |
---|
[363] | 416 | MPI_INTEGER, sender, 2, comm2d, status, ierr ) |
---|
[298] | 417 | mask_j_global(mid,ind(3):ind(4)) = tmp_array(ind(3):ind(4)) |
---|
| 418 | CALL MPI_RECV( tmp_array(ind(5)), ind(6)-ind(5)+1, & |
---|
[363] | 419 | MPI_INTEGER, sender, 3, comm2d, status, ierr ) |
---|
[298] | 420 | mask_k_global(mid,ind(5):ind(6)) = tmp_array(ind(5):ind(6)) |
---|
| 421 | ENDIF |
---|
| 422 | ENDDO |
---|
| 423 | |
---|
| 424 | ELSE |
---|
| 425 | ! |
---|
| 426 | !-- If at least part of the mask resides on the PE, send the index limits |
---|
| 427 | !-- for the target array, otherwise send -9999 to PE0. |
---|
| 428 | IF ( mask_size_l(mid,1) > 0 .AND. mask_size_l(mid,2) > 0 .AND. & |
---|
| 429 | mask_size_l(mid,3) > 0 ) & |
---|
| 430 | THEN |
---|
| 431 | ind(1) = mask_start_l(mid,1) |
---|
| 432 | ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1 |
---|
| 433 | ind(3) = mask_start_l(mid,2) |
---|
| 434 | ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1 |
---|
| 435 | ind(5) = mask_start_l(mid,3) |
---|
| 436 | ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1 |
---|
| 437 | ELSE |
---|
| 438 | ind(1) = -9999; ind(2) = -9999 |
---|
| 439 | ind(3) = -9999; ind(4) = -9999 |
---|
| 440 | ind(5) = -9999; ind(6) = -9999 |
---|
| 441 | ENDIF |
---|
| 442 | CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr ) |
---|
| 443 | ! |
---|
| 444 | !-- If applicable, send data to PE0. |
---|
| 445 | IF ( ind(1) /= -9999 ) THEN |
---|
| 446 | tmp_array(:mask_size_l(mid,1)) = mask_i(mid,:mask_size_l(mid,1)) |
---|
| 447 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,1), & |
---|
[363] | 448 | MPI_INTEGER, 0, 1, comm2d, ierr ) |
---|
[298] | 449 | tmp_array(:mask_size_l(mid,2)) = mask_j(mid,:mask_size_l(mid,2)) |
---|
| 450 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,2), & |
---|
[363] | 451 | MPI_INTEGER, 0, 2, comm2d, ierr ) |
---|
[298] | 452 | tmp_array(:mask_size_l(mid,3)) = mask_k(mid,:mask_size_l(mid,3)) |
---|
| 453 | CALL MPI_SEND( tmp_array(1), mask_size_l(mid,3), & |
---|
[363] | 454 | MPI_INTEGER, 0, 3, comm2d, ierr ) |
---|
[298] | 455 | ENDIF |
---|
| 456 | ENDIF |
---|
| 457 | ! |
---|
| 458 | !-- A barrier has to be set, because otherwise some PEs may proceed too fast |
---|
| 459 | !-- so that PE0 may receive wrong data on tag 0. |
---|
| 460 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
[409] | 461 | |
---|
[493] | 462 | IF ( netcdf_data_format > 2 ) THEN |
---|
[409] | 463 | |
---|
[493] | 464 | CALL MPI_BCAST( mask_i_global(mid,:), nx+1, MPI_INTEGER, 0, comm2d, & |
---|
| 465 | ierr ) |
---|
| 466 | CALL MPI_BCAST( mask_j_global(mid,:), ny+1, MPI_INTEGER, 0, comm2d, & |
---|
| 467 | ierr ) |
---|
| 468 | CALL MPI_BCAST( mask_k_global(mid,:), nz+1, MPI_INTEGER, 0, comm2d, & |
---|
| 469 | ierr ) |
---|
[409] | 470 | |
---|
| 471 | ENDIF |
---|
[298] | 472 | |
---|
| 473 | #else |
---|
| 474 | ! |
---|
| 475 | !-- Local arrays can be relocated directly. |
---|
| 476 | mask_i_global(mid,:) = mask_i(mid,:) |
---|
| 477 | mask_j_global(mid,:) = mask_j(mid,:) |
---|
| 478 | mask_k_global(mid,:) = mask_k(mid,:) |
---|
| 479 | #endif |
---|
| 480 | ENDDO ! mid |
---|
| 481 | |
---|
| 482 | DEALLOCATE( tmp_array ) |
---|
| 483 | ! |
---|
| 484 | !-- Internal mask arrays cannot be deallocated on PE 0 because they are |
---|
| 485 | !-- required for header output on PE 0. |
---|
| 486 | IF ( myid /= 0 ) DEALLOCATE( mask, mask_loop ) |
---|
| 487 | |
---|
| 488 | CONTAINS |
---|
[493] | 489 | |
---|
[298] | 490 | SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, & |
---|
| 491 | lb, ub ) |
---|
| 492 | !------------------------------------------------------------------------------! |
---|
| 493 | ! |
---|
| 494 | ! Description: |
---|
| 495 | ! ------------ |
---|
| 496 | ! Set local mask for each subdomain along 'dim' direction. |
---|
| 497 | !------------------------------------------------------------------------------! |
---|
| 498 | |
---|
| 499 | IMPLICIT NONE |
---|
| 500 | |
---|
| 501 | CHARACTER (LEN=2) :: dxyz_string, nxyz_string |
---|
| 502 | INTEGER :: count, count_l, dim, m, loop_begin, loop_end, loop_stride, & |
---|
| 503 | lb, nxyz, ub |
---|
| 504 | REAL :: dxyz, ddxyz, tmp1, tmp2 |
---|
| 505 | |
---|
| 506 | count = 0; count_l = 0; ddxyz = 1.0 / dxyz; tmp1 = 0.0; tmp2 = 0.0 |
---|
| 507 | |
---|
| 508 | IF ( mask(mid,dim,1) >= 0.0 ) THEN |
---|
| 509 | ! |
---|
| 510 | !-- use predefined mask_* array |
---|
| 511 | DO WHILE ( mask(mid,dim,count+1) >= 0.0 ) |
---|
| 512 | count = count + 1 |
---|
| 513 | IF ( dim == 1 .OR. dim == 2 ) THEN |
---|
[303] | 514 | m = NINT( mask(mid,dim,count) * mask_scale(dim) * ddxyz ) |
---|
[298] | 515 | ELSEIF ( dim == 3 ) THEN |
---|
| 516 | ind_array = & |
---|
[303] | 517 | MINLOC( ABS( mask(mid,dim,count) * mask_scale(dim) - zw ) ) |
---|
[298] | 518 | m = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 |
---|
| 519 | ENDIF |
---|
| 520 | IF ( m > nxyz ) THEN |
---|
[303] | 521 | WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' ) & |
---|
| 522 | m,' in mask ',mid,' along dimension ',dim, & |
---|
| 523 | ' exceeds ',nxyz_string,' = ',nxyz |
---|
[298] | 524 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 525 | ENDIF |
---|
| 526 | IF ( m >= lb .AND. m <= ub ) THEN |
---|
| 527 | IF ( count_l == 0 ) mask_start_l(mid,dim) = count |
---|
| 528 | count_l = count_l + 1 |
---|
| 529 | IF ( dim == 1 ) THEN |
---|
| 530 | mask_i(mid,count_l) = m |
---|
| 531 | ELSEIF ( dim == 2 ) THEN |
---|
| 532 | mask_j(mid,count_l) = m |
---|
| 533 | ELSEIF ( dim == 3 ) THEN |
---|
| 534 | mask_k(mid,count_l) = m |
---|
| 535 | ENDIF |
---|
| 536 | ENDIF |
---|
| 537 | IF ( count == mask_xyz_dimension ) EXIT |
---|
| 538 | ENDDO |
---|
| 539 | mask_size(mid,dim) = count |
---|
| 540 | mask_size_l(mid,dim) = count_l |
---|
| 541 | |
---|
| 542 | ELSE |
---|
| 543 | ! |
---|
| 544 | !-- use predefined mask_loop_* array, or use the default (all grid points |
---|
| 545 | !-- along this direction) |
---|
| 546 | IF ( mask_loop(mid,dim,1) < 0.0 ) THEN |
---|
| 547 | tmp1 = mask_loop(mid,dim,1) |
---|
| 548 | mask_loop(mid,dim,1) = 0.0 ! (default) |
---|
| 549 | ENDIF |
---|
| 550 | IF ( dim == 1 .OR. dim == 2 ) THEN |
---|
| 551 | IF ( mask_loop(mid,dim,2) < 0.0 ) THEN |
---|
| 552 | tmp2 = mask_loop(mid,dim,2) |
---|
[303] | 553 | mask_loop(mid,dim,2) = nxyz*dxyz / mask_scale(dim) ! (default) |
---|
[298] | 554 | ENDIF |
---|
| 555 | IF ( MAXVAL( mask_loop(mid,dim,1:2) ) & |
---|
[303] | 556 | > nxyz * dxyz / mask_scale(dim) ) THEN |
---|
| 557 | WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),5A,I1,A,F9.3)' ) & |
---|
| 558 | 'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), & |
---|
| 559 | ' and/or mask_loop(',mid,',',dim,',2)=', & |
---|
| 560 | mask_loop(mid,dim,2),'&exceed ', & |
---|
| 561 | nxyz_string,'*',dxyz_string,'/mask_scale(',dim,')=', & |
---|
| 562 | nxyz*dxyz/mask_scale(dim) |
---|
[298] | 563 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 564 | ENDIF |
---|
[303] | 565 | loop_begin = NINT( mask_loop(mid,dim,1) * mask_scale(dim) * ddxyz ) |
---|
| 566 | loop_end = NINT( mask_loop(mid,dim,2) * mask_scale(dim) * ddxyz ) |
---|
| 567 | loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz ) |
---|
[298] | 568 | ELSEIF ( dim == 3 ) THEN |
---|
| 569 | IF ( mask_loop(mid,dim,2) < 0.0 ) THEN |
---|
| 570 | tmp2 = mask_loop(mid,dim,2) |
---|
[303] | 571 | mask_loop(mid,dim,2) = zw(nz) / mask_scale(dim) ! (default) |
---|
[298] | 572 | ENDIF |
---|
| 573 | IF ( MAXVAL( mask_loop(mid,dim,1:2) ) & |
---|
[303] | 574 | > zw(nz) / mask_scale(dim) ) THEN |
---|
| 575 | WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),A,I1,A,F9.3)' ) & |
---|
| 576 | 'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), & |
---|
| 577 | ' and/or mask_loop(',mid,',',dim,',2)=', & |
---|
| 578 | mask_loop(mid,dim,2),'&exceed zw(nz)/mask_scale(',dim, & |
---|
| 579 | ')=',zw(nz)/mask_scale(dim) |
---|
[298] | 580 | CALL message( 'init_masks', 'PA9998', 1, 2, 0, 6, 0 ) |
---|
| 581 | ENDIF |
---|
[303] | 582 | ind_array = & |
---|
| 583 | MINLOC( ABS( mask_loop(mid,dim,1) * mask_scale(dim) - zw ) ) |
---|
[298] | 584 | loop_begin = & |
---|
[303] | 585 | ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 |
---|
| 586 | ind_array = & |
---|
| 587 | MINLOC( ABS( mask_loop(mid,dim,2) * mask_scale(dim) - zw ) ) |
---|
[298] | 588 | loop_end = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 |
---|
| 589 | ! |
---|
[303] | 590 | !-- The following line assumes a constant vertical grid spacing within |
---|
| 591 | !-- the vertical mask range; it fails for vertical grid stretching. |
---|
| 592 | !-- Maybe revise later. Issue warning but continue execution. |
---|
| 593 | loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz ) |
---|
| 594 | |
---|
| 595 | IF ( mask_loop(mid,dim,2) * mask_scale(dim) > dz_stretch_level ) & |
---|
| 596 | THEN |
---|
| 597 | WRITE ( message_string, '(A,I3,A,I1,A,F9.3,A,F8.2,3A)' ) & |
---|
| 598 | 'mask_loop(',mid,dim,',2)=', mask_loop(mid,dim,2),& |
---|
| 599 | ' exceeds dz_stretch_level=',dz_stretch_level, & |
---|
| 600 | '.&Vertical mask locations will not ', & |
---|
| 601 | 'match the desired heights&within the stretching ', & |
---|
| 602 | 'region. Recommendation: use mask instead of mask_loop.' |
---|
| 603 | CALL message( 'init_masks', 'PA9998', 0, 1, 0, 6, 0 ) |
---|
| 604 | ENDIF |
---|
| 605 | |
---|
[298] | 606 | ENDIF |
---|
| 607 | ! |
---|
| 608 | !-- If necessary, reset mask_loop(mid,dim,1) and mask_loop(mid,dim,2). |
---|
| 609 | IF ( tmp1 < 0.0 ) mask_loop(mid,dim,1) = tmp1 |
---|
| 610 | IF ( tmp2 < 0.0 ) mask_loop(mid,dim,2) = tmp2 |
---|
| 611 | ! |
---|
| 612 | !-- The default stride +/-1 (every grid point) applies if |
---|
| 613 | !-- mask_loop(mid,dim,3) is not specified (its default is zero). |
---|
| 614 | IF ( loop_stride == 0 ) THEN |
---|
| 615 | IF ( loop_end >= loop_begin ) THEN |
---|
| 616 | loop_stride = 1 |
---|
| 617 | ELSE |
---|
| 618 | loop_stride = -1 |
---|
| 619 | ENDIF |
---|
| 620 | ENDIF |
---|
| 621 | DO m = loop_begin, loop_end, loop_stride |
---|
| 622 | count = count + 1 |
---|
| 623 | IF ( m >= lb .AND. m <= ub ) THEN |
---|
| 624 | IF ( count_l == 0 ) mask_start_l(mid,dim) = count |
---|
| 625 | count_l = count_l + 1 |
---|
| 626 | IF ( dim == 1 ) THEN |
---|
| 627 | mask_i(mid,count_l) = m |
---|
| 628 | ELSEIF ( dim == 2 ) THEN |
---|
| 629 | mask_j(mid,count_l) = m |
---|
| 630 | ELSEIF ( dim == 3 ) THEN |
---|
| 631 | mask_k(mid,count_l) = m |
---|
| 632 | ENDIF |
---|
| 633 | ENDIF |
---|
| 634 | ENDDO |
---|
| 635 | mask_size(mid,dim) = count |
---|
| 636 | mask_size_l(mid,dim) = count_l |
---|
| 637 | ENDIF |
---|
| 638 | |
---|
| 639 | END SUBROUTINE set_mask_locations |
---|
| 640 | |
---|
| 641 | END SUBROUTINE init_masks |
---|