Index: palm/trunk/SOURCE/init_masks.f90
===================================================================
--- palm/trunk/SOURCE/init_masks.f90	(revision 4521)
+++ palm/trunk/SOURCE/init_masks.f90	(revision 4648)
@@ -1,52 +1,53 @@
 !> @file init_masks.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4521 2020-05-06 11:39:49Z schwenkel
 ! Rename variable
-! 
+!
 ! 4502 2020-04-17 16:14:16Z schwenkel
 ! Implementation of ice microphysics
-! 
+!
 ! 4444 2020-03-05 15:59:50Z raasch
 ! bugfix: cpp-directives for serial mode added
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 4069 2019-07-01 14:05:51Z Giersch
-! Masked output running index mid has been introduced as a local variable to 
-! avoid runtime error (Loop variable has been modified) in time_integration 
-! 
+! Masked output running index mid has been introduced as a local variable to avoid runtime error
+! (Loop variable has been modified) in time_integration
+!
 ! 3766 2019-02-26 16:23:41Z raasch
 ! unused variables removed
-! 
+!
 ! 3687 2019-01-22 10:42:06Z knoop
 ! unused variables removed
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
-! Move the control parameter "salsa" from salsa_mod to control_parameters 
-! (M. Kurppa)
+! Move the control parameter "salsa" from salsa_mod to control_parameters (M. Kurppa)
 !
 ! 410 2009-12-04 17:05:40Z letzel
@@ -57,42 +58,38 @@
 ! ------------
 !> Initialize masked data output
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_masks
 
-    USE arrays_3d,                                                             &
+    USE arrays_3d,                                                                                 &
         ONLY:  zu, zw
 
-    USE bulk_cloud_model_mod,                                                  &
-        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert,   &
-              microphysics_ice_phase
-
-    USE control_parameters,                                                    &
-        ONLY:  constant_diffusion, cloud_droplets,                             &
-               data_output_masks, data_output_masks_user,                      &
-               doav, doav_n, domask, domask_no, dz, dz_stretch_level_start,    &
-               humidity, mask, masks, mask_scale, mask_i,                      &
-               mask_i_global, mask_j, mask_j_global, mask_k, mask_k_global,    &
-               mask_k_over_surface,                                            &
-               mask_loop, mask_size, mask_size_l, mask_start_l,                &
-               mask_surface, mask_x,                                           &
-               mask_x_loop, mask_xyz_dimension, mask_y, mask_y_loop, mask_z,   &
-               mask_z_loop, max_masks,  message_string,                        &
-               passive_scalar, ocean_mode, varnamelength
-
-    USE grid_variables,                                                        &
+    USE bulk_cloud_model_mod,                                                                      &
+        ONLY: bulk_cloud_model, microphysics_ice_phase, microphysics_morrison,                     &
+              microphysics_seifert
+
+
+    USE control_parameters,                                                                        &
+        ONLY:  constant_diffusion, cloud_droplets, data_output_masks, data_output_masks_user, doav,&
+               doav_n, domask, domask_no, dz, dz_stretch_level_start, humidity, mask, masks,       &
+               mask_scale, mask_i, mask_i_global, mask_j, mask_j_global, mask_k, mask_k_global,    &
+               mask_k_over_surface, mask_loop, mask_size, mask_size_l, mask_start_l, mask_surface, &
+               mask_x, mask_x_loop, mask_xyz_dimension, mask_y, mask_y_loop, mask_z, mask_z_loop,  &
+               max_masks,  message_string, passive_scalar, ocean_mode, varnamelength
+
+    USE grid_variables,                                                                            &
         ONLY:  dx, dy
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nx, nxl, nxr, ny, nyn, nys, nz, nzb, nzt
 
     USE kinds
 
-    USE module_interface,                                                      &
+    USE module_interface,                                                                          &
         ONLY:  module_interface_init_masks
 
-    USE netcdf_interface,                                                      &
+    USE netcdf_interface,                                                                          &
         ONLY:  domask_unit, netcdf_data_format
 
-    USE particle_attributes,                                                   &
+    USE particle_attributes,                                                                       &
         ONLY:  particle_advection
 
@@ -103,5 +100,5 @@
     CHARACTER (LEN=varnamelength) ::  var  !< contains variable name
     CHARACTER (LEN=7)             ::  unit !< contains unit of variable
-    
+
     CHARACTER (LEN=varnamelength), DIMENSION(max_masks,100) ::  do_mask      !< list of output variables
     CHARACTER (LEN=varnamelength), DIMENSION(max_masks,100) ::  do_mask_user !< list of user-specified output variables
@@ -120,5 +117,5 @@
     INTEGER(iwp) ::  sender       !< PE id of sending PE
 #endif
-    
+
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  tmp_array !< temporary 1D array
 
@@ -126,7 +123,7 @@
 
 !
-!-- Initial values are explicitly set here due to a bug in the Cray compiler
-!-- in case of assignments of initial values in declaration statements for
-!-- arrays with more than 9999 elements (appears with -eD only)
+!-- Initial values are explicitly set here due to a bug in the Cray compiler in case of assignments
+!-- of initial values in declaration statements for arrays with more than 9999 elements
+!-- (appears with -eD only)
     domask = ' '
 
@@ -135,19 +132,17 @@
     ALLOCATE( tmp_array( MAX(nx,ny,nz)+2 ) )
 
-    ALLOCATE( mask_i(max_masks,nxr-nxl+2), &
-              mask_j(max_masks,nyn-nys+2), &
+    ALLOCATE( mask_i(max_masks,nxr-nxl+2),                                                         &
+              mask_j(max_masks,nyn-nys+2),                                                         &
               mask_k(max_masks,nzt-nzb+2) )
 !
 !-- 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 supported. In check_parameters data format 
-!-- is restricted and is switched back to non-parallel output. Therefore the
-!-- following error can not occur at the moment.
+    ALLOCATE( mask(max_masks,3,mask_xyz_dimension), mask_loop(max_masks,3,3) )
+
+!
+!-- Parallel mask output not yet supported. In check_parameters data format is restricted and is
+!-- switched back to non-parallel output. Therefore the following error can not occur at the moment.
     IF ( netcdf_data_format > 4 )  THEN
-       message_string = 'netCDF file formats '//                               &
-                        '5 and 6 (with parallel I/O support)'//                &
+       message_string = 'netCDF file formats '//                                                   &
+                        '5 and 6 (with parallel I/O support)'//                                    &
                         ' are currently not supported.'
        CALL message( 'init_masks', 'PA0328', 1, 2, 0, 6, 0 )
@@ -157,10 +152,10 @@
 !-- 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,1,:) = mask_x(mid,:)
        mask      (mid,2,:) = mask_y(mid,:)
-       mask      (mid,3,:) = mask_z(mid,:) 
+       mask      (mid,3,:) = mask_z(mid,:)
 !
 !--    Flag a mask as terrain following
@@ -169,6 +164,6 @@
        ENDIF
 
-       IF ( mask_x_loop(mid,1) == -1.0_wp  .AND.  mask_x_loop(mid,2) == -1.0_wp&
-            .AND.  mask_x_loop(mid,3) == -1.0_wp )  THEN
+       IF ( mask_x_loop(mid,1) == -1.0_wp  .AND.  mask_x_loop(mid,2) == -1.0_wp  .AND.             &
+            mask_x_loop(mid,3) == -1.0_wp )  THEN
           mask_loop(mid,1,1:2) = -1.0_wp
           mask_loop(mid,1,3)   =  0.0_wp
@@ -176,6 +171,6 @@
           mask_loop(mid,1,:) = mask_x_loop(mid,:)
        ENDIF
-       IF ( mask_y_loop(mid,1) == -1.0_wp  .AND.  mask_y_loop(mid,2) == -1.0_wp&
-            .AND.  mask_y_loop(mid,3) == -1.0_wp )  THEN
+       IF ( mask_y_loop(mid,1) == -1.0_wp  .AND.  mask_y_loop(mid,2) == -1.0_wp  .AND.             &
+            mask_y_loop(mid,3) == -1.0_wp )  THEN
           mask_loop(mid,2,1:2) = -1.0_wp
           mask_loop(mid,2,3)   =  0.0_wp
@@ -183,6 +178,6 @@
           mask_loop(mid,2,:) = mask_y_loop(mid,:)
        ENDIF
-       IF ( mask_z_loop(mid,1) == -1.0_wp  .AND.  mask_z_loop(mid,2) == -1.0_wp&
-            .AND.  mask_z_loop(mid,3) == -1.0_wp )  THEN
+       IF ( mask_z_loop(mid,1) == -1.0_wp  .AND.  mask_z_loop(mid,2) == -1.0_wp  .AND.             &
+            mask_z_loop(mid,3) == -1.0_wp )  THEN
           mask_loop(mid,3,1:2) = -1.0_wp
           mask_loop(mid,3,3)   =  0.0_wp
@@ -190,14 +185,14 @@
           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 > 4 )  THEN
-       ALLOCATE( mask_i_global(max_masks,nx+2), &
-                 mask_j_global(max_masks,ny+2), &
+       ALLOCATE( mask_i_global(max_masks,nx+2),                                                    &
+                 mask_j_global(max_masks,ny+2),                                                    &
                  mask_k_global(max_masks,nz+2) )
        mask_i_global = -1; mask_j_global = -1; mask_k_global = -1
@@ -217,7 +212,7 @@
           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'
+                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
@@ -249,6 +244,6 @@
              CASE ( 'e' )
                 IF ( constant_diffusion )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires constant_diffusion = .FALSE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires constant_diffusion = .FALSE.'
                    CALL message( 'init_masks', 'PA0103', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -257,6 +252,6 @@
              CASE ( 'thetal' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -265,10 +260,9 @@
              CASE ( 'nc' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
-                 ELSEIF ( .NOT. microphysics_morrison ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                         'requires  = morrison'
+                ELSEIF ( .NOT. microphysics_morrison )  THEN
+                   message_string = 'output of "' // TRIM( var ) // '" ' // 'requires  = morrison'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -277,10 +271,10 @@
              CASE ( 'ni' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
-                 ELSEIF ( .NOT. microphysics_ice_phase ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                         'requires  microphysics_ice_phase = .TRUE.'
+                 ELSEIF ( .NOT. microphysics_ice_phase )  THEN
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires  microphysics_ice_phase = .TRUE.'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -289,10 +283,10 @@
              CASE ( 'nr' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
-                 ELSEIF ( .NOT. microphysics_seifert ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '"' //     &
-                         'requires cloud_scheme = seifert_beheng'
+                ELSEIF ( .NOT. microphysics_seifert )  THEN
+                   message_string = 'output of "' // TRIM( var ) // '"' //                         &
+                                    'requires cloud_scheme = seifert_beheng'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -301,7 +295,7 @@
              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)'
+                   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
@@ -311,6 +305,6 @@
              CASE ( 'q', 'thetav' )
                 IF ( .NOT. humidity )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires humidity = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires humidity = .TRUE.'
                    CALL message( 'init_masks', 'PA0105', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -320,6 +314,6 @@
              CASE ( 'qc' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   message_string = 'output of "' // TRIM( var ) // '"' //     &
-                            'requires bulk_cloud_model = .TRUE.'
+                   message_string = 'output of "' // TRIM( var ) // '"' //                         &
+                                    'requires bulk_cloud_model = .TRUE.'
                    CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -328,7 +322,7 @@
              CASE ( 'ql' )
                 IF ( .NOT. ( bulk_cloud_model  .OR.  cloud_droplets ) )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE. or ',            &
-                        'cloud_droplets = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE. or ',         &
+                                               'cloud_droplets = .TRUE.'
                    CALL message( 'init_masks', 'PA0106', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -337,6 +331,6 @@
              CASE ( 'ql_c', 'ql_v', 'ql_vp' )
                 IF ( .NOT. cloud_droplets )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires cloud_droplets = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires cloud_droplets = .TRUE.'
                    CALL message( 'init_masks', 'PA0107', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -347,6 +341,6 @@
              CASE ( 'qv' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                        '                      " requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -355,10 +349,10 @@
              CASE ( 'qi' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                            'requires bulk_cloud_model = .TRUE.'
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires bulk_cloud_model = .TRUE.'
                    CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
                 ELSEIF ( .NOT. microphysics_ice_phase ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                            'requires microphysics_ice_phase = .TRUE.'
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires microphysics_ice_phase = .TRUE.'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -367,10 +361,10 @@
              CASE ( 'qr' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                            'requires bulk_cloud_model = .TRUE.'
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires bulk_cloud_model = .TRUE.'
                    CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
                 ELSEIF ( .NOT. microphysics_seifert ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                            'requires cloud_scheme = seifert_beheng'
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires cloud_scheme = seifert_beheng'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -379,6 +373,6 @@
              CASE ( 'rho_sea_water' )
                 IF ( .NOT. ocean_mode )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires ocean mode'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires ocean mode'
                    CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -387,6 +381,6 @@
              CASE ( 's' )
                 IF ( .NOT. passive_scalar )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires passive_scalar = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires passive_scalar = .TRUE.'
                    CALL message( 'init_masks', 'PA0110', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -395,6 +389,5 @@
              CASE ( 'sa' )
                 IF ( .NOT. ocean_mode )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires ocean mode'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ), '" requires ocean mode'
                    CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -402,7 +395,6 @@
 
              CASE ( 'us*', 't*', 'lwp*', 'pra*', 'prr*', 'z0*', 'z0h*' )
-                WRITE ( message_string, * ) 'illegal value for data_',         &
-                     'output: "', TRIM( var ), '" is only allowed',            &
-                     'for horizontal cross section'
+                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 )
 
@@ -422,11 +414,11 @@
                 IF ( unit == 'illegal' )  THEN
                    IF ( do_mask_user(mid,1) /= ' ' )  THEN
-                      WRITE ( message_string, * ) 'illegal value for data_',   &
-                           'output_masks or data_output_masks_user: "',        &
-                           TRIM( do_mask(mid,i) ), '"'
+                      WRITE ( message_string, * ) 'illegal value for data_',                       &
+                                                  'output_masks or data_output_masks_user: "',     &
+                                                  TRIM( do_mask(mid,i) ), '"'
                       CALL message( 'init_masks', 'PA0018', 1, 2, 0, 6, 0 )
                    ELSE
-                      WRITE ( message_string, * ) 'illegal value for data_',   &
-                           ' output_masks : "', TRIM( do_mask(mid,i) ), '"'
+                      WRITE ( message_string, * ) 'illegal value for data_',                       &
+                                                  ' output_masks : "', TRIM( do_mask(mid,i) ), '"'
                       CALL message( 'init_masks', 'PA0330', 1, 2, 0, 6, 0 )
                    ENDIF
@@ -471,13 +463,12 @@
        ELSE
 !
-!--       Set vertical mask locations and size in case of terrain-following
-!--       output
+!--       Set vertical mask locations and size in case of terrain-following output
           count = 0
           DO  WHILE ( mask_k_over_surface(mid, count+1) >= 0 )
              m = mask_k_over_surface(mid, count+1)
              IF ( m > nz+1 )  THEN
-                WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' )               &
-                     m,' in mask ',mid,' along dimension ', 3,                 &
-                     ' exceeds (nz+1) = ',nz+1
+                WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' )  m, ' in mask ', mid,             &
+                                                                  ' along dimension ', 3,          &
+                                                                  ' exceeds (nz+1) = ', nz+1
                 CALL message( 'init_masks', 'PA0331', 1, 2, 0, 6, 0 )
              ENDIF
@@ -491,11 +482,10 @@
        ENDIF
 !
-!--    Set global masks along all three dimensions (required by
-!--    define_netcdf_header).
+!--    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.
+!--    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 )
@@ -519,18 +509,17 @@
 !--          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 )
+             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 )
+                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 )
+                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 )
+                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
@@ -539,7 +528,7 @@
        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.  &
+!--       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)
@@ -559,28 +548,22 @@
           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 )
+             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 )
+             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 )
+             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.
+!--    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 > 4 )  THEN
-         
-          CALL MPI_BCAST( mask_i_global(mid,:), nx+2, MPI_INTEGER, 0, comm2d, &
-                          ierr )
-          CALL MPI_BCAST( mask_j_global(mid,:), ny+2, MPI_INTEGER, 0, comm2d, &
-                          ierr )
-          CALL MPI_BCAST( mask_k_global(mid,:), nz+2, MPI_INTEGER, 0, comm2d, &
-                          ierr ) 
-     
+
+          CALL MPI_BCAST( mask_i_global(mid,:), nx+2, MPI_INTEGER, 0, comm2d, ierr )
+          CALL MPI_BCAST( mask_j_global(mid,:), ny+2, MPI_INTEGER, 0, comm2d, ierr )
+          CALL MPI_BCAST( mask_k_global(mid,:), nz+2, MPI_INTEGER, 0, comm2d, ierr )
+
        ENDIF
 
@@ -596,17 +579,16 @@
     DEALLOCATE( tmp_array )
 !
-!-- Internal mask arrays cannot be deallocated on PE 0 because they are
-!-- required for header output on PE 0.
+!-- 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
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Set local mask for each subdomain along 'dim' direction.
-!------------------------------------------------------------------------------!
-    SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, &
-                                   lb, ub )
+!--------------------------------------------------------------------------------------------------!
+    SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, lb, ub )
 
        IMPLICIT NONE
@@ -614,5 +596,5 @@
        CHARACTER (LEN=2) ::  dxyz_string !<
        CHARACTER (LEN=2) ::  nxyz_string !<
-       
+
        INTEGER(iwp)  ::  count       !<
        INTEGER(iwp)  ::  count_l     !<
@@ -625,5 +607,5 @@
        INTEGER(iwp)  ::  nxyz        !<
        INTEGER(iwp)  ::  ub          !<
-       
+
        REAL(wp)      ::  dxyz  !<
        REAL(wp)      ::  ddxyz !<
@@ -631,6 +613,6 @@
        REAL(wp)      ::  tmp2  !<
 
-       count = 0;  count_l = 0  
-       ddxyz = 1.0_wp / dxyz  
+       count = 0;  count_l = 0
+       ddxyz = 1.0_wp / dxyz
        tmp1  = 0.0_wp
        tmp2  = 0.0_wp
@@ -638,8 +620,8 @@
        IF ( mask(mid,dim,1) >= 0.0_wp )  THEN
 !
-!--       use predefined mask_* array
+!--       Use predefined mask_* array
           DO  WHILE ( mask(mid,dim,count+1) >= 0.0_wp )
              count = count + 1
-             IF ( dim == 1 .OR. dim == 2 )  THEN
+             IF ( dim == 1  .OR.  dim == 2 )  THEN
                 m = NINT( mask(mid,dim,count) * mask_scale(dim) * ddxyz - 0.5_wp )
                 IF ( m < 0 )  m = 0  ! avoid negative values
@@ -650,11 +632,11 @@
              ENDIF
              IF ( m > (nxyz+1) )  THEN
-                WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' )               &
-                     m,' in mask ',mid,' along dimension ',dim,                &
-                     ' exceeds (',nxyz_string,'+1) = ',nxyz+1
+                WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' )  m, ' in mask ', mid,             &
+                                                                  ' along dimension ' ,dim,        &
+                                                                  ' exceeds (' ,nxyz_string,       &
+                                                                  '+1) = ', nxyz+1
                 CALL message( 'init_masks', 'PA0331', 1, 2, 0, 6, 0 )
              ENDIF
-             IF ( ( m >= lb .AND. m <= ub ) .OR.     &
-                  ( m == (nxyz+1) .AND. ub == nxyz )  )  THEN
+             IF ( ( m >= lb  .AND.  m <= ub )  .OR.  ( m == (nxyz+1)  .AND.  ub == nxyz )  )  THEN
                 IF ( count_l == 0 )  mask_start_l(mid,dim) = count
                 count_l = count_l + 1
@@ -674,6 +656,6 @@
        ELSE
 !
-!--       use predefined mask_loop_* array, or use the default (all grid points
-!--       along this direction)
+!--       Use predefined mask_loop_* array, or use the default (all grid points along this
+!--       direction)
           IF ( mask_loop(mid,dim,1) < 0.0_wp )  THEN
              tmp1 = mask_loop(mid,dim,1)
@@ -687,18 +669,14 @@
              IF ( MAXVAL( mask_loop(mid,dim,1:2) )  &
                   > (nxyz+1) * 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,'+1)*',dxyz_string,'/mask_scale(',dim,')=',   &
+                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,'+1)*',dxyz_string,'/mask_scale(',dim,')=',          &
                      (nxyz+1)*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 - 0.5_wp )
-             loop_end    = NINT( mask_loop(mid,dim,2) * mask_scale(dim)        &
-                  * ddxyz - 0.5_wp )
-             loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim)        &
-                  * ddxyz )
+             loop_begin  = NINT( mask_loop(mid,dim,1) * mask_scale(dim) * ddxyz - 0.5_wp )
+             loop_end    = NINT( mask_loop(mid,dim,2) * mask_scale(dim) * ddxyz - 0.5_wp )
+             loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz )
              IF ( loop_begin == -1 )  loop_begin = 0  ! avoid negative values
           ELSEIF ( dim == 3 )  THEN
@@ -707,36 +685,29 @@
                 mask_loop(mid,dim,2) = zu(nz+1) / mask_scale(dim)   ! (default)
              ENDIF
-             IF ( MAXVAL( mask_loop(mid,dim,1:2) )  &
-                  > zu(nz+1) / 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+1)/mask_scale(',dim,  &
-                     ')=',zu(nz+1)/mask_scale(dim)
+             IF ( MAXVAL( mask_loop(mid,dim,1:2) ) > zu(nz+1) / 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+1)/mask_scale(', dim, ')=',zu(nz+1)/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. ABS(...)
-!--          within the IF statement is necessary because the default value of
-!--          dz_stretch_level_start is -9999999.9_wp.
+             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. ABS(...) within the IF
+!--          statement is necessary because the default value of dz_stretch_level_start is
+!--          -9999999.9_wp.
              loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz )
 
-             IF ( mask_loop(mid,dim,2) * mask_scale(dim) >                     &
-                  ABS( dz_stretch_level_start(1) ) )  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_start(1),   &
-                     '.&Vertical mask locations will not ',                    &
-                     'match the desired heights within the stretching ',       &
-                     'region.'
+             IF ( mask_loop(mid,dim,2) * mask_scale(dim) > ABS( dz_stretch_level_start(1) ) )  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_start(1),                     &
+                      '.&Vertical mask locations will not ',                                       &
+                      'match the desired heights within the stretching ', 'region.'
                 CALL message( 'init_masks', 'PA0334', 0, 1, 0, 6, 0 )
              ENDIF
@@ -748,6 +719,6 @@
           IF ( tmp2 < 0.0_wp )  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).
+!--       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
@@ -759,6 +730,5 @@
           DO  m = loop_begin, loop_end, loop_stride
              count = count + 1
-             IF ( ( m >= lb  .AND.  m <= ub ) .OR.   &
-                  ( m == (nxyz+1) .AND. ub == nxyz )  )  THEN
+             IF ( ( m >= lb  .AND.  m <= ub ) .OR.  ( m == (nxyz+1) .AND. ub == nxyz )  )  THEN
                 IF ( count_l == 0 )  mask_start_l(mid,dim) = count
                 count_l = count_l + 1
