source: palm/trunk/SOURCE/init_masks.f90 @ 996

Last change on this file since 996 was 996, checked in by raasch, 12 years ago

parameter use_prior_plot1d_parameters removed; little reformatting

  • Property svn:keywords set to Id
File size: 23.1 KB
RevLine 
[298]1 SUBROUTINE init_masks
2
3!------------------------------------------------------------------------------!
[484]4! Current revisions:
[298]5! -----------------
[996]6! little reformatting
[298]7!
8! Former revisions:
9! -----------------
10! $Id: init_masks.f90 996 2012-09-07 10:41:47Z raasch $
11!
[979]12! 978 2012-08-09 08:28:32Z fricke
13! +z0h*
14!
[810]15! 809 2012-01-30 13:32:58Z maronga
16! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives
17!
[808]18! 807 2012-01-25 11:53:51Z maronga
19! New cpp directive "__check" implemented which is used by check_namelist_files
20!
[772]21! 771 2011-10-27 10:56:21Z heinze
22! +lpt
23!
[596]24! 595 2010-11-12 09:52:10Z helmke
25! Calculation of z locations for masked output changed
26!
[565]27! 564 2010-09-30 13:18:59Z helmke
28! assignment of mask_xyz_loop added, palm message identifiers of masked output
29! changed
30!
[558]31! 557 2010-09-07 14:50:07Z weinreis
32! bugfix message string in set_mask_locations
33!
[554]34! 553 2010-09-01 14:09:06Z weinreis
35! parameters for masked output are replaced by arrays
36!
[494]37! 493 2010-03-01 08:30:24Z raasch
38! netcdf_format_mask* and format_parallel_io replaced by netcdf_data_format
39!
[449]40! 410 2009-12-04 17:05:40Z letzel
41! Initial revision
[298]42!
[449]43!
[298]44! Description:
45! ------------
46! Initialize masked data output
47!------------------------------------------------------------------------------!
48
49    USE arrays_3d
50    USE control_parameters
51    USE grid_variables
52    USE indices
53    USE netcdf_control
54    USE particle_attributes
55    USE pegrid
56
57    IMPLICIT NONE
58
59    CHARACTER (LEN=6)   ::  var
60    CHARACTER (LEN=7)   ::  unit
61    CHARACTER (LEN=10), DIMENSION(max_masks,100) ::  do_mask, do_mask_user
62
63    INTEGER :: i, ilen, ind(6), ind_array(1), j, k, n, sender
64    INTEGER, DIMENSION(:), ALLOCATABLE ::  tmp_array
65
66    LOGICAL ::  found
67!
68!-- Allocation and initialization
69    ALLOCATE( tmp_array( MAX(nx,ny,nz)+1 ) )
70
71    ALLOCATE( mask_i(max_masks,nxr-nxl+1), &
72              mask_j(max_masks,nyn-nys+1), &
73              mask_k(max_masks,nzt-nzb+1) )
74!
75!-- internal mask arrays ("mask,dimension,selection")
76    ALLOCATE( mask(max_masks,3,mask_xyz_dimension), &
77              mask_loop(max_masks,3,3) )
[493]78   
[298]79!
[493]80!-- Parallel mask output not yet tested
81    IF ( netcdf_data_format > 2 )  THEN
[996]82       message_string = 'netCDF file formats '//                         &
83                        '3 (netCDF 4) and 4 (netCDF 4 Classic model)'//  &
[493]84                        '&are currently not supported (not yet tested).'
[564]85       CALL message( 'init_masks', 'PA0328', 1, 2, 0, 6, 0 )
[298]86    ENDIF
[553]87
[298]88!
89!-- Store data output parameters for masked data output in few shared arrays
[996]90    DO  mid = 1, masks
[564]91   
[553]92       do_mask     (mid,:) = data_output_masks(mid,:)
93       do_mask_user(mid,:) = data_output_masks_user(mid,:)
94       mask      (mid,1,:) = mask_x(mid,:) 
95       mask      (mid,2,:) = mask_y(mid,:)
96       mask      (mid,3,:) = mask_z(mid,:) 
[564]97       
[996]98       IF ( mask_x_loop(mid,1) == -1.0  .AND.  mask_x_loop(mid,2) == -1.0  &
99            .AND.  mask_x_loop(mid,3) == -1.0 )  THEN
100          mask_loop(mid,1,1:2) = -1.0
[564]101          mask_loop(mid,1,3) = 0.0
102       ELSE
103          mask_loop(mid,1,:) = mask_x_loop(mid,:)
104       ENDIF
[996]105       IF ( mask_y_loop(mid,1) == -1.0  .AND.  mask_y_loop(mid,2) == -1.0  &
106            .AND.  mask_y_loop(mid,3) == -1.0 )  THEN
107          mask_loop(mid,2,1:2) = -1.0
[564]108          mask_loop(mid,2,3) = 0.0
109       ELSE
110          mask_loop(mid,2,:) = mask_y_loop(mid,:)
111       ENDIF
[996]112       IF ( mask_z_loop(mid,1) == -1.0  .AND.  mask_z_loop(mid,2) == -1.0  &
113            .AND.  mask_z_loop(mid,3) == -1.0 )  THEN
114          mask_loop(mid,3,1:2) = -1.0
[564]115          mask_loop(mid,3,3) = 0.0
116       ELSE
117          mask_loop(mid,3,:) = mask_z_loop(mid,:)
118       ENDIF
119       
[553]120    ENDDO
121   
[298]122    mask_i = -1; mask_j = -1; mask_k = -1
[553]123   
[298]124!
125!-- Global arrays are required by define_netcdf_header.
[493]126    IF ( myid == 0  .OR.  netcdf_data_format > 2 )  THEN
[298]127       ALLOCATE( mask_i_global(max_masks,nx+1), &
128                 mask_j_global(max_masks,ny+1), &
129                 mask_k_global(max_masks,nz+1) )
130       mask_i_global = -1; mask_j_global = -1; mask_k_global = -1
131    ENDIF
132
133!
134!-- Determine variable names for each mask
135    DO  mid = 1, masks
136!
137!--    Append user-defined data output variables to the standard data output
138       IF ( do_mask_user(mid,1) /= ' ' )  THEN
139          i = 1
140          DO  WHILE ( do_mask(mid,i) /= ' '  .AND.  i <= 100 )
141             i = i + 1
142          ENDDO
143          j = 1
144          DO  WHILE ( do_mask_user(mid,j) /= ' '  .AND.  j <= 100 )
145             IF ( i > 100 )  THEN
146                WRITE ( message_string, * ) 'number of output quantitities ', &
147                     'given by data_output_mask and data_output_mask_user ', &
148                     'exceeds the limit of 100'
[564]149                CALL message( 'init_masks', 'PA0329', 1, 2, 0, 6, 0 )
[298]150             ENDIF
151             do_mask(mid,i) = do_mask_user(mid,j)
152             i = i + 1
153             j = j + 1
154          ENDDO
155       ENDIF
156
157!
158!--    Check and set steering parameters for mask data output and averaging
159       i   = 1
[996]160       DO WHILE ( do_mask(mid,i) /= ' '  .AND.  i <= 100 )
[298]161!
162!--       Check for data averaging
163          ilen = LEN_TRIM( do_mask(mid,i) )
164          j = 0                                              ! no data averaging
165          IF ( ilen > 3 )  THEN
166             IF ( do_mask(mid,i)(ilen-2:ilen) == '_av' )  THEN
167                j = 1                                           ! data averaging
168                do_mask(mid,i) = do_mask(mid,i)(1:ilen-3)
169             ENDIF
170          ENDIF
171          var = TRIM( do_mask(mid,i) )
172!
173!--       Check for allowed value and set units
174          SELECT CASE ( TRIM( var ) )
175
176             CASE ( 'e' )
177                IF ( constant_diffusion )  THEN
178                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
179                        '" requires constant_diffusion = .FALSE.'
[564]180                   CALL message( 'init_masks', 'PA0103', 1, 2, 0, 6, 0 )
[298]181                ENDIF
182                unit = 'm2/s2'
183
[771]184             CASE ( 'lpt' )
185                IF ( .NOT. cloud_physics )  THEN
186                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
187                        '" requires cloud_physics = .TRUE.'
[773]188                   CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
[771]189                ENDIF
190                unit = 'K'
191
[298]192             CASE ( 'pc', 'pr' )
193                IF ( .NOT. particle_advection )  THEN
194                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
195                        '" requires a "particles_par"-NAMELIST in the ', &
196                        'parameter file (PARIN)'
[564]197                   CALL message( 'init_masks', 'PA0104', 1, 2, 0, 6, 0 )
[298]198                ENDIF
199                IF ( TRIM( var ) == 'pc' )  unit = 'number'
200                IF ( TRIM( var ) == 'pr' )  unit = 'm'
201
202             CASE ( 'q', 'vpt' )
203                IF ( .NOT. humidity )  THEN
204                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
205                        '" requires humidity = .TRUE.'
[564]206                   CALL message( 'init_masks', 'PA0105', 1, 2, 0, 6, 0 )
[298]207                ENDIF
208                IF ( TRIM( var ) == 'q'   )  unit = 'kg/kg'
209                IF ( TRIM( var ) == 'vpt' )  unit = 'K'
210
211             CASE ( 'ql' )
212                IF ( .NOT. ( cloud_physics  .OR.  cloud_droplets ) )  THEN
213                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
214                        '" requires cloud_physics = .TRUE. or cloud_droplets', &
215                        ' = .TRUE.'
[564]216                   CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
[298]217                ENDIF
218                unit = 'kg/kg'
219
220             CASE ( 'ql_c', 'ql_v', 'ql_vp' )
221                IF ( .NOT. cloud_droplets )  THEN
222                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
223                        '" requires cloud_droplets = .TRUE.'
[564]224                   CALL message( 'init_masks', 'PA0107', 1, 2, 0, 6, 0 )
[298]225                ENDIF
226                IF ( TRIM( var ) == 'ql_c'  )  unit = 'kg/kg'
227                IF ( TRIM( var ) == 'ql_v'  )  unit = 'm3'
228                IF ( TRIM( var ) == 'ql_vp' )  unit = 'none'
229
230             CASE ( 'qv' )
231                IF ( .NOT. cloud_physics )  THEN
232                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
233                        '" requires cloud_physics = .TRUE.'
[564]234                   CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
[298]235                ENDIF
236                unit = 'kg/kg'
237
238             CASE ( 'rho' )
239                IF ( .NOT. ocean )  THEN
240                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
241                        '" requires ocean = .TRUE.'
[564]242                   CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 )
[298]243                ENDIF
244                unit = 'kg/m3'
245
246             CASE ( 's' )
247                IF ( .NOT. passive_scalar )  THEN
248                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
249                        '" requires passive_scalar = .TRUE.'
[564]250                   CALL message( 'init_masks', 'PA0110', 1, 2, 0, 6, 0 )
[298]251                ENDIF
252                unit = 'conc'
253
254             CASE ( 'sa' )
255                IF ( .NOT. ocean )  THEN
256                   WRITE ( message_string, * ) 'output of "', TRIM( var ), &
257                        '" requires ocean = .TRUE.'
[564]258                   CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 )
[298]259                ENDIF
260                unit = 'psu'
261
[978]262             CASE ( 'u*', 't*', 'lwp*', 'pra*', 'prr*', 'z0*', 'z0h*' )
[298]263                WRITE ( message_string, * ) 'illegal value for data_',&
264                     'output: "', TRIM( var ), '" is only allowed', &
265                     'for horizontal cross section'
[564]266                CALL message( 'init_masks', 'PA0111', 1, 2, 0, 6, 0 )
[298]267
268             CASE ( 'p', 'pt', 'u', 'v', 'w' )
269                IF ( TRIM( var ) == 'p'  )  unit = 'Pa'
270                IF ( TRIM( var ) == 'pt' )  unit = 'K'
271                IF ( TRIM( var ) == 'u'  )  unit = 'm/s'
272                IF ( TRIM( var ) == 'v'  )  unit = 'm/s'
273                IF ( TRIM( var ) == 'w'  )  unit = 'm/s'
274                CONTINUE
275
276             CASE DEFAULT
277                CALL user_check_data_output( var, unit )
278
279                IF ( unit == 'illegal' )  THEN
280                   IF ( do_mask_user(mid,1) /= ' ' )  THEN
281                      WRITE ( message_string, * ) 'illegal value for data_',&
282                           'output or data_output_user: "', &
283                           TRIM( do_mask(mid,i) ), '"'
[564]284                      CALL message( 'init_masks', 'PA0114', 1, 2, 0, 6, 0 )
[298]285                   ELSE
286                      WRITE ( message_string, * ) 'illegal value for data_',&
287                           'output: "', TRIM( do_mask(mid,i) ), '"'
[564]288                      CALL message( 'init_masks', 'PA0330', 1, 2, 0, 6, 0 )
[298]289                   ENDIF
290                ENDIF
291
292          END SELECT
293!
294!--       Set the internal steering parameters appropriately
295          domask_no(mid,j)                    = domask_no(mid,j) + 1
296          domask(mid,j,domask_no(mid,j))      = do_mask(mid,i)
297          domask_unit(mid,j,domask_no(mid,j)) = unit
298
299          IF ( j == 1 )  THEN
300!
301!--          Check, if variable is already subject to averaging
302             found = .FALSE.
303             DO  k = 1, doav_n
304                IF ( TRIM( doav(k) ) == TRIM( var ) )  found = .TRUE.
305             ENDDO
306
307             IF ( .NOT. found )  THEN
308                doav_n = doav_n + 1
309                doav(doav_n) = var
310             ENDIF
311          ENDIF
312
313          i = i + 1
314
315       ENDDO   ! do_mask(mid,i)
316    ENDDO   ! mid
317
318
319!
320!-- Determine mask locations for each mask
321    DO  mid = 1, masks
322!
323!--    Set local masks for each subdomain along all three dimensions
324       CALL set_mask_locations( 1, dx, 'dx', nx, 'nx', nxl, nxr )
325       CALL set_mask_locations( 2, dy, 'dy', ny, 'ny', nys, nyn )
326       CALL set_mask_locations( 3, dz, 'dz', nz, 'nz', nzb, nzt )
327!
328!--    Set global masks along all three dimensions (required by
329!--    define_netcdf_header).
[809]330#if defined( __parallel ) && ! defined ( __check )
[298]331!
332!--    PE0 receives partial arrays from all processors of the respective mask
333!--    and outputs them. Here a barrier has to be set, because otherwise
334!--    "-MPI- FATAL: Remote protocol queue full" may occur.
[807]335
[298]336       CALL MPI_BARRIER( comm2d, ierr )
337
338       IF ( myid == 0 )  THEN
339!
340!--       Local arrays can be relocated directly.
341          mask_i_global(mid,mask_start_l(mid,1): &
342                       mask_start_l(mid,1)+mask_size_l(mid,1)-1) = &
343                       mask_i(mid,:mask_size_l(mid,1))
344          mask_j_global(mid,mask_start_l(mid,2): &
345                       mask_start_l(mid,2)+mask_size_l(mid,2)-1) = &
346                       mask_j(mid,:mask_size_l(mid,2))
347          mask_k_global(mid,mask_start_l(mid,3): &
348                       mask_start_l(mid,3)+mask_size_l(mid,3)-1) = &
349                       mask_k(mid,:mask_size_l(mid,3))
350!
351!--       Receive data from all other PEs.
352          DO  n = 1, numprocs-1
353!
354!--          Receive index limits first, then arrays.
355!--          Index limits are received in arbitrary order from the PEs.
356             CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0,  &
357                  comm2d, status, ierr )
358!
359!--          Not all PEs have data for the mask.
360             IF ( ind(1) /= -9999 )  THEN
361                sender = status(MPI_SOURCE)
362                CALL MPI_RECV( tmp_array(ind(1)), ind(2)-ind(1)+1,  &
[363]363                               MPI_INTEGER, sender, 1, comm2d, status, ierr )
[298]364                mask_i_global(mid,ind(1):ind(2)) = tmp_array(ind(1):ind(2))
365                CALL MPI_RECV( tmp_array(ind(3)), ind(4)-ind(3)+1,  &
[363]366                               MPI_INTEGER, sender, 2, comm2d, status, ierr )
[298]367                mask_j_global(mid,ind(3):ind(4)) = tmp_array(ind(3):ind(4))
368                CALL MPI_RECV( tmp_array(ind(5)), ind(6)-ind(5)+1,  &
[363]369                               MPI_INTEGER, sender, 3, comm2d, status, ierr )
[298]370                mask_k_global(mid,ind(5):ind(6)) = tmp_array(ind(5):ind(6))
371             ENDIF
372          ENDDO
373
374       ELSE
375!
376!--       If at least part of the mask resides on the PE, send the index limits
377!--       for the target array, otherwise send -9999 to PE0.
[996]378          IF ( mask_size_l(mid,1) > 0  .AND.  mask_size_l(mid,2) > 0  .AND.  &
379               mask_size_l(mid,3) > 0  )  THEN
[298]380             ind(1) = mask_start_l(mid,1)
381             ind(2) = mask_start_l(mid,1) + mask_size_l(mid,1) - 1
382             ind(3) = mask_start_l(mid,2)
383             ind(4) = mask_start_l(mid,2) + mask_size_l(mid,2) - 1
384             ind(5) = mask_start_l(mid,3)
385             ind(6) = mask_start_l(mid,3) + mask_size_l(mid,3) - 1
386          ELSE
387             ind(1) = -9999; ind(2) = -9999
388             ind(3) = -9999; ind(4) = -9999
389             ind(5) = -9999; ind(6) = -9999
390          ENDIF
391          CALL MPI_SEND( ind(1), 6, MPI_INTEGER, 0, 0, comm2d, ierr )
392!
393!--       If applicable, send data to PE0.
394          IF ( ind(1) /= -9999 )  THEN
395             tmp_array(:mask_size_l(mid,1)) = mask_i(mid,:mask_size_l(mid,1))
396             CALL MPI_SEND( tmp_array(1), mask_size_l(mid,1),  &
[363]397                            MPI_INTEGER, 0, 1, comm2d, ierr )
[298]398             tmp_array(:mask_size_l(mid,2)) = mask_j(mid,:mask_size_l(mid,2))
399             CALL MPI_SEND( tmp_array(1), mask_size_l(mid,2),  &
[363]400                            MPI_INTEGER, 0, 2, comm2d, ierr )
[298]401             tmp_array(:mask_size_l(mid,3)) = mask_k(mid,:mask_size_l(mid,3))
402             CALL MPI_SEND( tmp_array(1), mask_size_l(mid,3),  &
[363]403                            MPI_INTEGER, 0, 3, comm2d, ierr )
[298]404          ENDIF
405       ENDIF
406!
407!--    A barrier has to be set, because otherwise some PEs may proceed too fast
408!--    so that PE0 may receive wrong data on tag 0.
409       CALL MPI_BARRIER( comm2d, ierr )
[409]410       
[493]411       IF ( netcdf_data_format > 2 )  THEN 
[409]412         
[493]413          CALL MPI_BCAST( mask_i_global(mid,:), nx+1, MPI_INTEGER, 0, comm2d, &
414                          ierr )
415          CALL MPI_BCAST( mask_j_global(mid,:), ny+1, MPI_INTEGER, 0, comm2d, &
416                          ierr )
417          CALL MPI_BCAST( mask_k_global(mid,:), nz+1, MPI_INTEGER, 0, comm2d, &
418                          ierr ) 
[409]419         
420       ENDIF
[298]421
[809]422#elif ! defined ( __parallel )
[298]423!
424!--    Local arrays can be relocated directly.
425       mask_i_global(mid,:) = mask_i(mid,:)
426       mask_j_global(mid,:) = mask_j(mid,:)
427       mask_k_global(mid,:) = mask_k(mid,:)
428#endif
429    ENDDO   ! mid
430
431    DEALLOCATE( tmp_array )
432!
433!-- Internal mask arrays cannot be deallocated on PE 0 because they are
434!-- required for header output on PE 0.
435    IF ( myid /= 0 )  DEALLOCATE( mask, mask_loop )
436
437 CONTAINS
[493]438
[298]439    SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, &
440                                   lb, ub )
441!------------------------------------------------------------------------------!
442!
443! Description:
444! ------------
445! Set local mask for each subdomain along 'dim' direction.
446!------------------------------------------------------------------------------!
447
448       IMPLICIT NONE
449
450       CHARACTER (LEN=2) :: dxyz_string, nxyz_string
451       INTEGER  ::  count, count_l, dim, m, loop_begin, loop_end, loop_stride, &
452                    lb, nxyz, ub
453       REAL     ::  dxyz, ddxyz, tmp1, tmp2
454
455       count = 0;  count_l = 0;  ddxyz = 1.0 / dxyz;  tmp1 = 0.0;  tmp2 = 0.0
456
457       IF ( mask(mid,dim,1) >= 0.0 )  THEN
458!
459!--       use predefined mask_* array
460          DO  WHILE ( mask(mid,dim,count+1) >= 0.0 )
461             count = count + 1
462             IF ( dim == 1 .OR. dim == 2 )  THEN
[303]463                m = NINT( mask(mid,dim,count) * mask_scale(dim) * ddxyz )
[298]464             ELSEIF ( dim == 3 )  THEN
465                ind_array =  &
[595]466                     MINLOC( ABS( mask(mid,dim,count) * mask_scale(dim) - zu ) )
[298]467                m = ind_array(1) - 1 + nzb  ! MINLOC uses lower array bound 1
468             ENDIF
469             IF ( m > nxyz )  THEN
[303]470                WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' )  &
471                     m,' in mask ',mid,' along dimension ',dim,  &
472                     ' exceeds ',nxyz_string,' = ',nxyz
[564]473                CALL message( 'init_masks', 'PA0331', 1, 2, 0, 6, 0 )
[298]474             ENDIF
475             IF ( m >= lb .AND. m <= ub )  THEN
476                IF ( count_l == 0 )  mask_start_l(mid,dim) = count
477                count_l = count_l + 1
478                IF ( dim == 1 )  THEN
479                   mask_i(mid,count_l) = m
480                ELSEIF ( dim == 2 )  THEN
481                   mask_j(mid,count_l) = m
482                ELSEIF ( dim == 3 )  THEN
483                   mask_k(mid,count_l) = m
484                ENDIF
485             ENDIF
486             IF ( count == mask_xyz_dimension )  EXIT
487          ENDDO
488          mask_size(mid,dim)   = count
489          mask_size_l(mid,dim) = count_l
490
491       ELSE
492!
493!--       use predefined mask_loop_* array, or use the default (all grid points
494!--       along this direction)
495          IF ( mask_loop(mid,dim,1) < 0.0 )  THEN
496             tmp1 = mask_loop(mid,dim,1)
497             mask_loop(mid,dim,1) = 0.0   ! (default)
498          ENDIF
499          IF ( dim == 1 .OR. dim == 2 )  THEN
500             IF ( mask_loop(mid,dim,2) < 0.0 )  THEN
501                tmp2 = mask_loop(mid,dim,2)
[303]502                mask_loop(mid,dim,2) = nxyz*dxyz / mask_scale(dim)   ! (default)
[298]503             ENDIF
504             IF ( MAXVAL( mask_loop(mid,dim,1:2) )  &
[303]505                  > nxyz * dxyz / mask_scale(dim) )  THEN
506                WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),5A,I1,A,F9.3)' ) &
507                     'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), &
508                     ' and/or mask_loop(',mid,',',dim,',2)=', &
509                     mask_loop(mid,dim,2),'&exceed ', &
510                     nxyz_string,'*',dxyz_string,'/mask_scale(',dim,')=', &
511                     nxyz*dxyz/mask_scale(dim)
[564]512                CALL message( 'init_masks', 'PA0332', 1, 2, 0, 6, 0 )
[298]513             ENDIF
[303]514             loop_begin  = NINT( mask_loop(mid,dim,1) * mask_scale(dim) * ddxyz )
515             loop_end    = NINT( mask_loop(mid,dim,2) * mask_scale(dim) * ddxyz )
516             loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz )
[298]517          ELSEIF ( dim == 3 )  THEN
518             IF ( mask_loop(mid,dim,2) < 0.0 )  THEN
519                tmp2 = mask_loop(mid,dim,2)
[595]520                mask_loop(mid,dim,2) = zu(nz) / mask_scale(dim)   ! (default)
[298]521             ENDIF
522             IF ( MAXVAL( mask_loop(mid,dim,1:2) )  &
[595]523                  > zu(nz) / mask_scale(dim) )  THEN
[303]524                WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),A,I1,A,F9.3)' ) &
525                     'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1), &
526                     ' and/or mask_loop(',mid,',',dim,',2)=', &
[595]527                     mask_loop(mid,dim,2),'&exceed zu(nz)/mask_scale(',dim, &
528                     ')=',zu(nz)/mask_scale(dim)
[564]529                CALL message( 'init_masks', 'PA0333', 1, 2, 0, 6, 0 )
[298]530             ENDIF
[303]531             ind_array =  &
[595]532                  MINLOC( ABS( mask_loop(mid,dim,1) * mask_scale(dim) - zu ) )
[298]533             loop_begin =  &
[303]534                  ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1
535             ind_array =  &
[595]536                  MINLOC( ABS( mask_loop(mid,dim,2) * mask_scale(dim) - zu ) )
[298]537             loop_end = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1
538!
[303]539!--          The following line assumes a constant vertical grid spacing within
540!--          the vertical mask range; it fails for vertical grid stretching.
541!--          Maybe revise later. Issue warning but continue execution.
542             loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz )
543
544             IF ( mask_loop(mid,dim,2) * mask_scale(dim) > dz_stretch_level )  &
545                  THEN
[557]546                WRITE ( message_string, '(A,I3,A,I1,A,F9.3,A,F8.2,3A)' ) &
547                     'mask_loop(',mid,',',dim,',2)=', mask_loop(mid,dim,2),&
[303]548                     ' exceeds dz_stretch_level=',dz_stretch_level, &
549                     '.&Vertical mask locations will not ', &
550                     'match the desired heights&within the stretching ', &
551                     'region. Recommendation: use mask instead of mask_loop.'
[564]552                CALL message( 'init_masks', 'PA0334', 0, 1, 0, 6, 0 )
[303]553             ENDIF
554
[298]555          ENDIF
556!
557!--       If necessary, reset mask_loop(mid,dim,1) and mask_loop(mid,dim,2).
558          IF ( tmp1 < 0.0 )  mask_loop(mid,dim,1) = tmp1
559          IF ( tmp2 < 0.0 )  mask_loop(mid,dim,2) = tmp2
560!
561!--       The default stride +/-1 (every grid point) applies if
562!--       mask_loop(mid,dim,3) is not specified (its default is zero).
563          IF ( loop_stride == 0 )  THEN
564             IF ( loop_end >= loop_begin )  THEN
565                loop_stride =  1
566             ELSE
567                loop_stride = -1
568             ENDIF
569          ENDIF
570          DO  m = loop_begin, loop_end, loop_stride
571             count = count + 1
[996]572             IF ( m >= lb  .AND.  m <= ub )  THEN
[298]573                IF ( count_l == 0 )  mask_start_l(mid,dim) = count
574                count_l = count_l + 1
575                IF ( dim == 1 )  THEN
576                   mask_i(mid,count_l) = m
577                ELSEIF ( dim == 2 )  THEN
578                   mask_j(mid,count_l) = m
579                ELSEIF ( dim == 3 )  THEN
580                   mask_k(mid,count_l) = m
581                ENDIF
582             ENDIF
583          ENDDO
584          mask_size(mid,dim)   = count
585          mask_size_l(mid,dim) = count_l
586       ENDIF
587
588    END SUBROUTINE set_mask_locations
589
590 END SUBROUTINE init_masks
Note: See TracBrowser for help on using the repository browser.