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

Last change on this file since 1166 was 1037, checked in by raasch, 11 years ago

last commit documented

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