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