SUBROUTINE init_masks !------------------------------------------------------------------------------! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: init_masks.f90 596 2010-11-12 09:57:10Z letzel $ ! ! 595 2010-11-12 09:52:10Z helmke ! Calculation of z locations for masked output changed ! ! 564 2010-09-30 13:18:59Z helmke ! assignment of mask_xyz_loop added, palm message identifiers of masked output ! changed ! ! 557 2010-09-07 14:50:07Z weinreis ! bugfix message string in set_mask_locations ! ! 553 2010-09-01 14:09:06Z weinreis ! parameters for masked output are replaced by arrays ! ! 493 2010-03-01 08:30:24Z raasch ! netcdf_format_mask* and format_parallel_io replaced by netcdf_data_format ! ! 410 2009-12-04 17:05:40Z letzel ! Initial revision ! ! ! Description: ! ------------ ! Initialize masked data output !------------------------------------------------------------------------------! USE arrays_3d USE control_parameters USE grid_variables USE indices USE netcdf_control USE particle_attributes USE pegrid IMPLICIT NONE CHARACTER (LEN=6) :: var CHARACTER (LEN=7) :: unit CHARACTER (LEN=10), DIMENSION(max_masks,100) :: do_mask, do_mask_user INTEGER :: i, ilen, ind(6), ind_array(1), j, k, n, sender INTEGER, DIMENSION(:), ALLOCATABLE :: tmp_array LOGICAL :: found ! !-- Allocation and initialization ALLOCATE( tmp_array( MAX(nx,ny,nz)+1 ) ) ALLOCATE( mask_i(max_masks,nxr-nxl+1), & mask_j(max_masks,nyn-nys+1), & mask_k(max_masks,nzt-nzb+1) ) ! !-- internal mask arrays ("mask,dimension,selection") ALLOCATE( mask(max_masks,3,mask_xyz_dimension), & mask_loop(max_masks,3,3) ) ! !-- Parallel mask output not yet tested IF ( netcdf_data_format > 2 ) THEN message_string = 'NetCDF file formats '// & '3 (NetCDF 4) and 4 (NetCDF 4 Classic model)'// & '&are currently not supported (not yet tested).' CALL message( 'init_masks', 'PA0328', 1, 2, 0, 6, 0 ) ENDIF ! !-- Store data output parameters for masked data output in few shared arrays DO mid = 1, masks do_mask (mid,:) = data_output_masks(mid,:) do_mask_user(mid,:) = data_output_masks_user(mid,:) mask (mid,1,:) = mask_x(mid,:) mask (mid,2,:) = mask_y(mid,:) mask (mid,3,:) = mask_z(mid,:) IF ( mask_x_loop(mid,1) == -1.0 .AND. mask_x_loop(mid,2) == -1.0 & .AND. mask_x_loop(mid,3) == -1.0 ) THEN mask_loop(mid,1,1:2) = -1.0 mask_loop(mid,1,3) = 0.0 ELSE mask_loop(mid,1,:) = mask_x_loop(mid,:) ENDIF IF ( mask_y_loop(mid,1) == -1.0 .AND. mask_y_loop(mid,2) == -1.0 & .AND. mask_y_loop(mid,3) == -1.0 ) THEN mask_loop(mid,2,1:2) = -1.0 mask_loop(mid,2,3) = 0.0 ELSE mask_loop(mid,2,:) = mask_y_loop(mid,:) ENDIF IF ( mask_z_loop(mid,1) == -1.0 .AND. mask_z_loop(mid,2) == -1.0 & .AND. mask_z_loop(mid,3) == -1.0 ) THEN mask_loop(mid,3,1:2) = -1.0 mask_loop(mid,3,3) = 0.0 ELSE mask_loop(mid,3,:) = mask_z_loop(mid,:) ENDIF ENDDO mask_i = -1; mask_j = -1; mask_k = -1 ! !-- Global arrays are required by define_netcdf_header. IF ( myid == 0 .OR. netcdf_data_format > 2 ) THEN ALLOCATE( mask_i_global(max_masks,nx+1), & mask_j_global(max_masks,ny+1), & mask_k_global(max_masks,nz+1) ) mask_i_global = -1; mask_j_global = -1; mask_k_global = -1 ENDIF ! !-- Determine variable names for each mask DO mid = 1, masks ! !-- Append user-defined data output variables to the standard data output IF ( do_mask_user(mid,1) /= ' ' ) THEN i = 1 DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) i = i + 1 ENDDO j = 1 DO WHILE ( do_mask_user(mid,j) /= ' ' .AND. j <= 100 ) IF ( i > 100 ) THEN WRITE ( message_string, * ) 'number of output quantitities ', & 'given by data_output_mask and data_output_mask_user ', & 'exceeds the limit of 100' CALL message( 'init_masks', 'PA0329', 1, 2, 0, 6, 0 ) ENDIF do_mask(mid,i) = do_mask_user(mid,j) i = i + 1 j = j + 1 ENDDO ENDIF ! !-- Check and set steering parameters for mask data output and averaging i = 1 DO WHILE ( do_mask(mid,i) /= ' ' .AND. i <= 100 ) ! !-- Check for data averaging ilen = LEN_TRIM( do_mask(mid,i) ) j = 0 ! no data averaging IF ( ilen > 3 ) THEN IF ( do_mask(mid,i)(ilen-2:ilen) == '_av' ) THEN j = 1 ! data averaging do_mask(mid,i) = do_mask(mid,i)(1:ilen-3) ENDIF ENDIF var = TRIM( do_mask(mid,i) ) ! !-- Check for allowed value and set units SELECT CASE ( TRIM( var ) ) CASE ( 'e' ) IF ( constant_diffusion ) THEN WRITE ( message_string, * ) 'output of "', TRIM( var ), & '" requires constant_diffusion = .FALSE.' CALL message( 'init_masks', 'PA0103', 1, 2, 0, 6, 0 ) ENDIF unit = 'm2/s2' CASE ( 'pc', 'pr' ) IF ( .NOT. particle_advection ) THEN WRITE ( message_string, * ) 'output of "', TRIM( var ), & '" requires a "particles_par"-NAMELIST in the ', & 'parameter file (PARIN)' CALL message( 'init_masks', 'PA0104', 1, 2, 0, 6, 0 ) ENDIF IF ( TRIM( var ) == 'pc' ) unit = 'number' IF ( TRIM( var ) == 'pr' ) unit = 'm' CASE ( 'q', 'vpt' ) IF ( .NOT. humidity ) THEN WRITE ( message_string, * ) 'output of "', TRIM( var ), & '" requires humidity = .TRUE.' CALL message( 'init_masks', 'PA0105', 1, 2, 0, 6, 0 ) ENDIF IF ( TRIM( var ) == 'q' ) unit = 'kg/kg' IF ( TRIM( var ) == 'vpt' ) unit = 'K' CASE ( 'ql' ) IF ( .NOT. ( cloud_physics .OR. cloud_droplets ) ) THEN WRITE ( message_string, * ) 'output of "', TRIM( var ), & '" requires cloud_physics = .TRUE. or cloud_droplets', & ' = .TRUE.' CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) ENDIF unit = 'kg/kg' CASE ( 'ql_c', 'ql_v', 'ql_vp' ) IF ( .NOT. cloud_droplets ) THEN WRITE ( message_string, * ) 'output of "', TRIM( var ), & '" requires cloud_droplets = .TRUE.' CALL message( 'init_masks', 'PA0107', 1, 2, 0, 6, 0 ) ENDIF IF ( TRIM( var ) == 'ql_c' ) unit = 'kg/kg' IF ( TRIM( var ) == 'ql_v' ) unit = 'm3' IF ( TRIM( var ) == 'ql_vp' ) unit = 'none' CASE ( 'qv' ) IF ( .NOT. cloud_physics ) THEN WRITE ( message_string, * ) 'output of "', TRIM( var ), & '" requires cloud_physics = .TRUE.' CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) ENDIF unit = 'kg/kg' CASE ( 'rho' ) IF ( .NOT. ocean ) THEN WRITE ( message_string, * ) 'output of "', TRIM( var ), & '" requires ocean = .TRUE.' CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) ENDIF unit = 'kg/m3' CASE ( 's' ) IF ( .NOT. passive_scalar ) THEN WRITE ( message_string, * ) 'output of "', TRIM( var ), & '" requires passive_scalar = .TRUE.' CALL message( 'init_masks', 'PA0110', 1, 2, 0, 6, 0 ) ENDIF unit = 'conc' CASE ( 'sa' ) IF ( .NOT. ocean ) THEN WRITE ( message_string, * ) 'output of "', TRIM( var ), & '" requires ocean = .TRUE.' CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 ) ENDIF unit = 'psu' CASE ( 'u*', 't*', 'lwp*', 'pra*', 'prr*', 'z0*' ) WRITE ( message_string, * ) 'illegal value for data_',& 'output: "', TRIM( var ), '" is only allowed', & 'for horizontal cross section' CALL message( 'init_masks', 'PA0111', 1, 2, 0, 6, 0 ) ! IF ( TRIM( var ) == 'lwp*' .AND. .NOT. cloud_physics ) THEN ! WRITE ( message_string, * ) 'output of "', TRIM( var ), & ! '" requires cloud_physics = .TRUE.' ! CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 ) ! ENDIF ! IF ( TRIM( var ) == 'pra*' .AND. .NOT. precipitation ) THEN ! WRITE ( message_string, * ) 'output of "', TRIM( var ), & ! '" requires precipitation = .TRUE.' ! CALL message( 'init_masks', 'PA0112', 1, 2, 0, 6, 0 ) ! ENDIF ! IF ( TRIM( var ) == 'pra*' .AND. j == 1 ) THEN ! WRITE ( message_string, * ) 'temporal averaging of ', & ! ' precipitation amount "', TRIM( var ), & ! '" not possible' ! CALL message( 'init_masks', 'PA0113', 1, 2, 0, 6, 0 ) ! ENDIF ! IF ( TRIM( var ) == 'prr*' .AND. .NOT. precipitation ) THEN ! WRITE ( message_string, * ) 'output of "', TRIM( var ), & ! '" requires precipitation = .TRUE.' ! CALL message( 'init_masks', 'PA0112', 1, 2, 0, 6, 0 ) ! ENDIF ! ! IF ( TRIM( var ) == 'u*' ) unit = 'm/s' ! IF ( TRIM( var ) == 't*' ) unit = 'K' ! IF ( TRIM( var ) == 'lwp*' ) unit = 'kg/kg*m' ! IF ( TRIM( var ) == 'pra*' ) unit = 'mm' ! IF ( TRIM( var ) == 'prr*' ) unit = 'mm/s' ! IF ( TRIM( var ) == 'z0*' ) unit = 'm' CASE ( 'p', 'pt', 'u', 'v', 'w' ) IF ( TRIM( var ) == 'p' ) unit = 'Pa' IF ( TRIM( var ) == 'pt' ) unit = 'K' IF ( TRIM( var ) == 'u' ) unit = 'm/s' IF ( TRIM( var ) == 'v' ) unit = 'm/s' IF ( TRIM( var ) == 'w' ) unit = 'm/s' CONTINUE CASE DEFAULT CALL user_check_data_output( var, unit ) IF ( unit == 'illegal' ) THEN IF ( do_mask_user(mid,1) /= ' ' ) THEN WRITE ( message_string, * ) 'illegal value for data_',& 'output or data_output_user: "', & TRIM( do_mask(mid,i) ), '"' CALL message( 'init_masks', 'PA0114', 1, 2, 0, 6, 0 ) ELSE WRITE ( message_string, * ) 'illegal value for data_',& 'output: "', TRIM( do_mask(mid,i) ), '"' CALL message( 'init_masks', 'PA0330', 1, 2, 0, 6, 0 ) ENDIF ENDIF END SELECT ! !-- Set the internal steering parameters appropriately domask_no(mid,j) = domask_no(mid,j) + 1 domask(mid,j,domask_no(mid,j)) = do_mask(mid,i) domask_unit(mid,j,domask_no(mid,j)) = unit IF ( j == 1 ) THEN ! !-- Check, if variable is already subject to averaging found = .FALSE. DO k = 1, doav_n IF ( TRIM( doav(k) ) == TRIM( var ) ) found = .TRUE. ENDDO IF ( .NOT. found ) THEN doav_n = doav_n + 1 doav(doav_n) = var ENDIF ENDIF i = i + 1 ENDDO ! do_mask(mid,i) ENDDO ! mid ! !-- Determine mask locations for each mask DO mid = 1, masks ! !-- Set local masks for each subdomain along all three dimensions CALL set_mask_locations( 1, dx, 'dx', nx, 'nx', nxl, nxr ) CALL set_mask_locations( 2, dy, 'dy', ny, 'ny', nys, nyn ) CALL set_mask_locations( 3, dz, 'dz', nz, 'nz', nzb, nzt ) ! !-- Set global masks along all three dimensions (required by !-- define_netcdf_header). #if defined( __parallel ) ! !-- PE0 receives partial arrays from all processors of the respective mask !-- and outputs them. Here a barrier has to be set, because otherwise !-- "-MPI- FATAL: Remote protocol queue full" may occur. CALL MPI_BARRIER( comm2d, ierr ) IF ( myid == 0 ) THEN ! !-- Local arrays can be relocated directly. mask_i_global(mid,mask_start_l(mid,1): & mask_start_l(mid,1)+mask_size_l(mid,1)-1) = & mask_i(mid,:mask_size_l(mid,1)) mask_j_global(mid,mask_start_l(mid,2): & mask_start_l(mid,2)+mask_size_l(mid,2)-1) = & mask_j(mid,:mask_size_l(mid,2)) mask_k_global(mid,mask_start_l(mid,3): & mask_start_l(mid,3)+mask_size_l(mid,3)-1) = & mask_k(mid,:mask_size_l(mid,3)) ! !-- Receive data from all other PEs. DO n = 1, numprocs-1 ! !-- Receive index limits first, then arrays. !-- Index limits are received in arbitrary order from the PEs. CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0, & comm2d, status, ierr ) ! !-- Not all PEs have data for the mask. IF ( ind(1) /= -9999 ) THEN sender = status(MPI_SOURCE) CALL MPI_RECV( tmp_array(ind(1)), ind(2)-ind(1)+1, & MPI_INTEGER, sender, 1, comm2d, status, ierr ) mask_i_global(mid,ind(1):ind(2)) = tmp_array(ind(1):ind(2)) CALL MPI_RECV( tmp_array(ind(3)), ind(4)-ind(3)+1, & MPI_INTEGER, sender, 2, comm2d, status, ierr ) mask_j_global(mid,ind(3):ind(4)) = tmp_array(ind(3):ind(4)) CALL MPI_RECV( tmp_array(ind(5)), ind(6)-ind(5)+1, & MPI_INTEGER, sender, 3, comm2d, status, ierr ) mask_k_global(mid,ind(5):ind(6)) = tmp_array(ind(5):ind(6)) ENDIF ENDDO ELSE ! !-- If at least part of the mask resides on the PE, send the index limits !-- for the target array, otherwise send -9999 to PE0. IF ( mask_size_l(mid,1) > 0 .AND. mask_size_l(mid,2) > 0 .AND. & mask_size_l(mid,3) > 0 ) & THEN ind(1) = mask_start_l(mid,1) ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1 ind(3) = mask_start_l(mid,2) ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1 ind(5) = mask_start_l(mid,3) ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1 ELSE ind(1) = -9999; ind(2) = -9999 ind(3) = -9999; ind(4) = -9999 ind(5) = -9999; ind(6) = -9999 ENDIF CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr ) ! !-- If applicable, send data to PE0. IF ( ind(1) /= -9999 ) THEN tmp_array(:mask_size_l(mid,1)) = mask_i(mid,:mask_size_l(mid,1)) CALL MPI_SEND( tmp_array(1), mask_size_l(mid,1), & MPI_INTEGER, 0, 1, comm2d, ierr ) tmp_array(:mask_size_l(mid,2)) = mask_j(mid,:mask_size_l(mid,2)) CALL MPI_SEND( tmp_array(1), mask_size_l(mid,2), & MPI_INTEGER, 0, 2, comm2d, ierr ) tmp_array(:mask_size_l(mid,3)) = mask_k(mid,:mask_size_l(mid,3)) CALL MPI_SEND( tmp_array(1), mask_size_l(mid,3), & MPI_INTEGER, 0, 3, comm2d, ierr ) ENDIF ENDIF ! !-- A barrier has to be set, because otherwise some PEs may proceed too fast !-- so that PE0 may receive wrong data on tag 0. CALL MPI_BARRIER( comm2d, ierr ) IF ( netcdf_data_format > 2 ) THEN CALL MPI_BCAST( mask_i_global(mid,:), nx+1, MPI_INTEGER, 0, comm2d, & ierr ) CALL MPI_BCAST( mask_j_global(mid,:), ny+1, MPI_INTEGER, 0, comm2d, & ierr ) CALL MPI_BCAST( mask_k_global(mid,:), nz+1, MPI_INTEGER, 0, comm2d, & ierr ) ENDIF #else ! !-- Local arrays can be relocated directly. mask_i_global(mid,:) = mask_i(mid,:) mask_j_global(mid,:) = mask_j(mid,:) mask_k_global(mid,:) = mask_k(mid,:) #endif ENDDO ! mid DEALLOCATE( tmp_array ) ! !-- Internal mask arrays cannot be deallocated on PE 0 because they are !-- required for header output on PE 0. IF ( myid /= 0 ) DEALLOCATE( mask, mask_loop ) CONTAINS SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, & lb, ub ) !------------------------------------------------------------------------------! ! ! Description: ! ------------ ! Set local mask for each subdomain along 'dim' direction. !------------------------------------------------------------------------------! IMPLICIT NONE CHARACTER (LEN=2) :: dxyz_string, nxyz_string INTEGER :: count, count_l, dim, m, loop_begin, loop_end, loop_stride, & lb, nxyz, ub REAL :: dxyz, ddxyz, tmp1, tmp2 count = 0; count_l = 0; ddxyz = 1.0 / dxyz; tmp1 = 0.0; tmp2 = 0.0 IF ( mask(mid,dim,1) >= 0.0 ) THEN ! !-- use predefined mask_* array DO WHILE ( mask(mid,dim,count+1) >= 0.0 ) count = count + 1 IF ( dim == 1 .OR. dim == 2 ) THEN m = NINT( mask(mid,dim,count) * mask_scale(dim) * ddxyz ) ELSEIF ( dim == 3 ) THEN ind_array = & MINLOC( ABS( mask(mid,dim,count) * mask_scale(dim) - zu ) ) m = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 ENDIF IF ( m > nxyz ) THEN WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' ) & m,' in mask ',mid,' along dimension ',dim, & ' exceeds ',nxyz_string,' = ',nxyz CALL message( 'init_masks', 'PA0331', 1, 2, 0, 6, 0 ) ENDIF IF ( m >= lb .AND. m <= ub ) THEN IF ( count_l == 0 ) mask_start_l(mid,dim) = count count_l = count_l + 1 IF ( dim == 1 ) THEN mask_i(mid,count_l) = m ELSEIF ( dim == 2 ) THEN mask_j(mid,count_l) = m ELSEIF ( dim == 3 ) THEN mask_k(mid,count_l) = m ENDIF ENDIF IF ( count == mask_xyz_dimension ) EXIT ENDDO mask_size(mid,dim) = count mask_size_l(mid,dim) = count_l ELSE ! !-- use predefined mask_loop_* array, or use the default (all grid points !-- along this direction) IF ( mask_loop(mid,dim,1) < 0.0 ) THEN tmp1 = mask_loop(mid,dim,1) mask_loop(mid,dim,1) = 0.0 ! (default) ENDIF IF ( dim == 1 .OR. dim == 2 ) THEN IF ( mask_loop(mid,dim,2) < 0.0 ) THEN tmp2 = mask_loop(mid,dim,2) mask_loop(mid,dim,2) = nxyz*dxyz / mask_scale(dim) ! (default) ENDIF IF ( MAXVAL( mask_loop(mid,dim,1:2) ) & > nxyz * dxyz / mask_scale(dim) ) THEN WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),5A,I1,A,F9.3)' ) & 'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), & ' and/or mask_loop(',mid,',',dim,',2)=', & mask_loop(mid,dim,2),'&exceed ', & nxyz_string,'*',dxyz_string,'/mask_scale(',dim,')=', & nxyz*dxyz/mask_scale(dim) CALL message( 'init_masks', 'PA0332', 1, 2, 0, 6, 0 ) ENDIF loop_begin = NINT( mask_loop(mid,dim,1) * mask_scale(dim) * ddxyz ) loop_end = NINT( mask_loop(mid,dim,2) * mask_scale(dim) * ddxyz ) loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz ) ELSEIF ( dim == 3 ) THEN IF ( mask_loop(mid,dim,2) < 0.0 ) THEN tmp2 = mask_loop(mid,dim,2) mask_loop(mid,dim,2) = zu(nz) / mask_scale(dim) ! (default) ENDIF IF ( MAXVAL( mask_loop(mid,dim,1:2) ) & > zu(nz) / mask_scale(dim) ) THEN WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),A,I1,A,F9.3)' ) & 'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), & ' and/or mask_loop(',mid,',',dim,',2)=', & mask_loop(mid,dim,2),'&exceed zu(nz)/mask_scale(',dim, & ')=',zu(nz)/mask_scale(dim) CALL message( 'init_masks', 'PA0333', 1, 2, 0, 6, 0 ) ENDIF ind_array = & MINLOC( ABS( mask_loop(mid,dim,1) * mask_scale(dim) - zu ) ) loop_begin = & ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 ind_array = & MINLOC( ABS( mask_loop(mid,dim,2) * mask_scale(dim) - zu ) ) loop_end = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 ! !-- The following line assumes a constant vertical grid spacing within !-- the vertical mask range; it fails for vertical grid stretching. !-- Maybe revise later. Issue warning but continue execution. loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz ) IF ( mask_loop(mid,dim,2) * mask_scale(dim) > dz_stretch_level ) & THEN WRITE ( message_string, '(A,I3,A,I1,A,F9.3,A,F8.2,3A)' ) & 'mask_loop(',mid,',',dim,',2)=', mask_loop(mid,dim,2),& ' exceeds dz_stretch_level=',dz_stretch_level, & '.&Vertical mask locations will not ', & 'match the desired heights&within the stretching ', & 'region. Recommendation: use mask instead of mask_loop.' CALL message( 'init_masks', 'PA0334', 0, 1, 0, 6, 0 ) ENDIF ENDIF ! !-- If necessary, reset mask_loop(mid,dim,1) and mask_loop(mid,dim,2). IF ( tmp1 < 0.0 ) mask_loop(mid,dim,1) = tmp1 IF ( tmp2 < 0.0 ) mask_loop(mid,dim,2) = tmp2 ! !-- The default stride +/-1 (every grid point) applies if !-- mask_loop(mid,dim,3) is not specified (its default is zero). IF ( loop_stride == 0 ) THEN IF ( loop_end >= loop_begin ) THEN loop_stride = 1 ELSE loop_stride = -1 ENDIF ENDIF DO m = loop_begin, loop_end, loop_stride count = count + 1 IF ( m >= lb .AND. m <= ub ) THEN IF ( count_l == 0 ) mask_start_l(mid,dim) = count count_l = count_l + 1 IF ( dim == 1 ) THEN mask_i(mid,count_l) = m ELSEIF ( dim == 2 ) THEN mask_j(mid,count_l) = m ELSEIF ( dim == 3 ) THEN mask_k(mid,count_l) = m ENDIF ENDIF ENDDO mask_size(mid,dim) = count mask_size_l(mid,dim) = count_l ENDIF END SUBROUTINE set_mask_locations END SUBROUTINE init_masks