Index: palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90
===================================================================
--- palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 4559)
+++ palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 4562)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Parts of r4559 re-formatted
+! 
+! 4559 2020-06-11 08:51:48Z raasch
 ! File re-formatted to follow the PALM coding standard
 !
@@ -1375,6 +1378,6 @@
 !--             Lund rotation following Eq. 17 in Xie and Castro (2008).
 !--             Additional factors are added to improve the variance of v and w
-                dist_yz(k,j,1) = MIN( a11(k) * fu_yz(k,j), 3.0_wp ) * MERGE( 1.0_wp, 0.0_wp,       &
-                                 BTEST( wall_flags_total_0(k,j,i), 1 ) )
+                dist_yz(k,j,1) = MIN( a11(k) * fu_yz(k,j), 3.0_wp ) *                              &
+                                 MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 1 ) )
              ENDDO
           ENDDO
@@ -1393,6 +1396,6 @@
                 dist_yz(k,j,3) = MIN( ( SQRT( a33(k) / MAXVAL( a33 ) ) * 1.3_wp ) *                &
                                       ( a31(k) * fu_yz(k,j) + a32(k) * fv_yz(k,j) + a33(k)         &
-                                        * fw_yz(k,j) ), 3.0_wp ) *  MERGE( 1.0_wp, 0.0_wp,         &
-                                        BTEST( wall_flags_total_0(k,j,i), 3 ) )
+                                        * fw_yz(k,j) ), 3.0_wp ) *                                 &
+                                      MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 3 ) )
              ENDDO
           ENDDO
@@ -1412,14 +1415,14 @@
           IF ( myidx == id_stg_right )  i = nxr+1
 
-          mc_factor_l(1) = SUM( dist_yz(nzb:nzt,nys:nyn,1) * MERGE( 1.0_wp, 0.0_wp,                &
-                           BTEST( wall_flags_total_0(nzb:nzt,nys:nyn,i), 1 ) ) )
+          mc_factor_l(1) = SUM( dist_yz(nzb:nzt,nys:nyn,1) *                                       &
+                       MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(nzb:nzt,nys:nyn,i), 1 ) ) )
 
           IF ( myidx == id_stg_left  )  i = nxl-1
           IF ( myidx == id_stg_right )  i = nxr+1
 
-          mc_factor_l(2) = SUM( dist_yz(nzb:nzt,nysv:nyn,2) * MERGE( 1.0_wp, 0.0_wp,               &
-                           BTEST( wall_flags_total_0(nzb:nzt,nysv:nyn,i), 2 ) ) )
-          mc_factor_l(3) = SUM( dist_yz(nzb:nzt,nys:nyn,3) * MERGE( 1.0_wp, 0.0_wp,                &
-                           BTEST( wall_flags_total_0(nzb:nzt,nys:nyn,i), 3 ) ) )
+          mc_factor_l(2) = SUM( dist_yz(nzb:nzt,nysv:nyn,2) *                                      &
+                       MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(nzb:nzt,nysv:nyn,i), 2 ) ) )
+          mc_factor_l(3) = SUM( dist_yz(nzb:nzt,nys:nyn,3) *                                       &
+                       MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(nzb:nzt,nys:nyn,i), 3 ) ) )
 
 #if defined( __parallel )
@@ -1435,6 +1438,6 @@
           IF ( myidx == id_stg_right )  i = nxr+1
 
-          dist_yz(:,nys:nyn,1) = ( dist_yz(:,nys:nyn,1) - mc_factor(1) ) * MERGE( 1.0_wp, 0.0_wp,  &
-                                 BTEST( wall_flags_total_0(:,nys:nyn,i), 1 ) )
+          dist_yz(:,nys:nyn,1) = ( dist_yz(:,nys:nyn,1) - mc_factor(1) ) *                         &
+                                MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(:,nys:nyn,i), 1 ) )
 
 
@@ -1442,9 +1445,9 @@
           IF ( myidx == id_stg_right )  i = nxr+1
 
-          dist_yz(:,nys:nyn,2) = ( dist_yz(:,nys:nyn,2) - mc_factor(2) ) * MERGE( 1.0_wp, 0.0_wp,  &
-                                 BTEST( wall_flags_total_0(:,nys:nyn,i), 2 ) )
-
-          dist_yz(:,nys:nyn,3) = ( dist_yz(:,nys:nyn,3) - mc_factor(3) ) * MERGE( 1.0_wp, 0.0_wp,  &
-                                 BTEST( wall_flags_total_0(:,nys:nyn,i), 3 ) )
+          dist_yz(:,nys:nyn,2) = ( dist_yz(:,nys:nyn,2) - mc_factor(2) ) *                         &
+                                MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(:,nys:nyn,i), 2 ) )
+
+          dist_yz(:,nys:nyn,3) = ( dist_yz(:,nys:nyn,3) - mc_factor(3) ) *                         &
+                                MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(:,nys:nyn,i), 3 ) )
 !
 !--       Add disturbances
@@ -1459,10 +1462,10 @@
                 DO  j = nys, nyn
                    DO  k = nzb, nzt+1
-                      u(k,j,-nbgp+1:0) = ( mean_inflow_profiles(k,1) + dist_yz(k,j,1) )            &
-                                    * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,0), 1 ) )
-                      v(k,j,-nbgp:-1) = ( mean_inflow_profiles(k,2) + dist_yz(k,j,2) )             &
-                                   * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,-1), 2 ) )
-                      w(k,j,-nbgp:-1) =  dist_yz(k,j,3) * MERGE( 1.0_wp, 0.0_wp,                   &
-                                         BTEST( wall_flags_total_0(k,j,-1), 3 ) )
+                      u(k,j,-nbgp+1:0) = ( mean_inflow_profiles(k,1) + dist_yz(k,j,1) ) *          &
+                                     MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,0), 1 ) )
+                      v(k,j,-nbgp:-1)  = ( mean_inflow_profiles(k,2) + dist_yz(k,j,2) ) *          &
+                                     MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,-1), 2 ) )
+                      w(k,j,-nbgp:-1)  = dist_yz(k,j,3) *                                          &
+                                     MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,-1), 3 ) )
                    ENDDO
                 ENDDO
@@ -1471,11 +1474,11 @@
                 DO  j = nys, nyn
                    DO  k = nzb+1, nzt
-                      u(k,j,0)   = ( u(k,j,0) + dist_yz(k,j,1) ) * MERGE( 1.0_wp, 0.0_wp,          &
-                                   BTEST( wall_flags_total_0(k,j,0), 1 ) )
+                      u(k,j,0)   = ( u(k,j,0)  + dist_yz(k,j,1) ) *                                &
+                                   MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,0), 1 ) )
                       u(k,j,-1)  = u(k,j,0)
-                      v(k,j,-1)  = ( v(k,j,-1)  + dist_yz(k,j,2) ) * MERGE( 1.0_wp, 0.0_wp,        &
-                                   BTEST( wall_flags_total_0(k,j,-1), 2 ) )
-                      w(k,j,-1)  = ( w(k,j,-1)  + dist_yz(k,j,3) ) * MERGE( 1.0_wp, 0.0_wp,        &
-                                   BTEST( wall_flags_total_0(k,j,-1), 3 ) )
+                      v(k,j,-1)  = ( v(k,j,-1) + dist_yz(k,j,2) ) *                                &
+                                   MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,-1), 2 ) )
+                      w(k,j,-1)  = ( w(k,j,-1) + dist_yz(k,j,3) ) *                                &
+                                   MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,-1), 3 ) )
                    ENDDO
                 ENDDO
@@ -1485,10 +1488,10 @@
              DO  j = nys, nyn
                 DO  k = nzb+1, nzt
-                   u(k,j,nxr+1) = ( u(k,j,nxr+1) + dist_yz(k,j,1) ) * MERGE( 1.0_wp, 0.0_wp,       &
-                                  BTEST( wall_flags_total_0(k,j,nxr+1), 1 ) )
-                   v(k,j,nxr+1) = ( v(k,j,nxr+1) + dist_yz(k,j,2) ) * MERGE( 1.0_wp, 0.0_wp,       &
-                                    BTEST( wall_flags_total_0(k,j,nxr+1), 2 ) )
-                   w(k,j,nxr+1) = ( w(k,j,nxr+1) + dist_yz(k,j,3) ) * MERGE( 1.0_wp, 0.0_wp,       &
-                                  BTEST( wall_flags_total_0(k,j,nxr+1), 3 ) )
+                   u(k,j,nxr+1) = ( u(k,j,nxr+1) + dist_yz(k,j,1) ) *                              &
+                                  MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,nxr+1), 1 ) )
+                   v(k,j,nxr+1) = ( v(k,j,nxr+1) + dist_yz(k,j,2) ) *                              &
+                                  MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,nxr+1), 2 ) )
+                   w(k,j,nxr+1) = ( w(k,j,nxr+1) + dist_yz(k,j,3) ) *                              &
+                                  MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,nxr+1), 3 ) )
                 ENDDO
              ENDDO
@@ -1556,11 +1559,11 @@
 !--             Lund rotation following Eq. 17 in Xie and Castro (2008).
 !--             Additional factors are added to improve the variance of v and w
-                dist_xz(k,i,1) = MIN( a11(k) * fu_xz(k,i), 3.0_wp ) * MERGE( 1.0_wp, 0.0_wp,       &
-                                 BTEST( wall_flags_total_0(k,j,i), 1 ) )
+                dist_xz(k,i,1) = MIN( a11(k) * fu_xz(k,i), 3.0_wp ) *                              &
+                                 MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 1 ) )
 
                 dist_xz(k,i,3) = MIN( ( SQRT(a33(k) / MAXVAL( a33 ) ) * 1.3_wp )                   &
                                  * ( a31(k) * fu_xz(k,i) + a32(k) * fv_xz(k,i) + a33(k)            &
-                                 * fw_xz(k,i) ), 3.0_wp ) * MERGE( 1.0_wp, 0.0_wp,                 &
-                                 BTEST( wall_flags_total_0(k,j,i), 3 ) )
+                                 * fw_xz(k,i) ), 3.0_wp ) *                                        &
+                                 MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 3 ) )
              ENDDO
           ENDDO
@@ -1579,14 +1582,14 @@
           IF ( myidy == id_stg_north )  j = nyn+1
 
-          mc_factor_l(2) = SUM( dist_xz(nzb:nzt,nxl:nxr,2) * MERGE( 1.0_wp, 0.0_wp,                &
-                           BTEST( wall_flags_total_0(nzb:nzt,j,nxl:nxr), 2 ) ) )
+          mc_factor_l(2) = SUM( dist_xz(nzb:nzt,nxl:nxr,2) *                                       &
+                       MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(nzb:nzt,j,nxl:nxr), 2 ) ) )
 
           IF ( myidy == id_stg_south ) j = nys-1
           IF ( myidy == id_stg_north ) j = nyn+1
 
-          mc_factor_l(1) = SUM( dist_xz(nzb:nzt,nxlu:nxr,1) * MERGE( 1.0_wp, 0.0_wp,               &
-                           BTEST( wall_flags_total_0(nzb:nzt,j,nxlu:nxr), 1 ) ) )
-          mc_factor_l(3) = SUM( dist_xz(nzb:nzt,nxl:nxr,3) * MERGE( 1.0_wp, 0.0_wp,                &
-                           BTEST( wall_flags_total_0(nzb:nzt,j,nxl:nxr), 3 ) ) )
+          mc_factor_l(1) = SUM( dist_xz(nzb:nzt,nxlu:nxr,1) *                                      &
+                       MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(nzb:nzt,j,nxlu:nxr), 1 ) ) )
+          mc_factor_l(3) = SUM( dist_xz(nzb:nzt,nxl:nxr,3) *                                       &
+                       MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(nzb:nzt,j,nxl:nxr), 3 ) ) )
 
 #if defined( __parallel )
@@ -1601,6 +1604,6 @@
           IF ( myidy == id_stg_north ) j = nyn+1
 
-          dist_xz(:,nxl:nxr,2) = ( dist_xz(:,nxl:nxr,2) - mc_factor(2) ) * MERGE( 1.0_wp, 0.0_wp,  &
-                                 BTEST( wall_flags_total_0(:,j,nxl:nxr), 2 ) )
+          dist_xz(:,nxl:nxr,2) = ( dist_xz(:,nxl:nxr,2) - mc_factor(2) ) *                         &
+                                MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(:,j,nxl:nxr), 2 ) )
 
 
@@ -1608,9 +1611,9 @@
           IF ( myidy == id_stg_north ) j = nyn+1
 
-          dist_xz(:,nxl:nxr,1) = ( dist_xz(:,nxl:nxr,1) - mc_factor(1) ) * MERGE( 1.0_wp, 0.0_wp,  &
-                                 BTEST( wall_flags_total_0(:,j,nxl:nxr), 1 ) )
-
-          dist_xz(:,nxl:nxr,3) = ( dist_xz(:,nxl:nxr,3) - mc_factor(3) ) * MERGE( 1.0_wp, 0.0_wp,  &
-                                 BTEST( wall_flags_total_0(:,j,nxl:nxr), 3 ) )
+          dist_xz(:,nxl:nxr,1) = ( dist_xz(:,nxl:nxr,1) - mc_factor(1) ) *                         &
+                                MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(:,j,nxl:nxr), 1 ) )
+
+          dist_xz(:,nxl:nxr,3) = ( dist_xz(:,nxl:nxr,3) - mc_factor(3) ) *                         &
+                                MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(:,j,nxl:nxr), 3 ) )
 !
 !--       Add disturbances
@@ -1632,10 +1635,10 @@
              DO  i = nxl, nxr
                 DO  k = nzb+1, nzt
-                   u(k,nyn+1,i) = ( u(k,nyn+1,i) + dist_xz(k,i,1) ) * MERGE( 1.0_wp, 0.0_wp,       &
-                                  BTEST( wall_flags_total_0(k,nyn+1,i), 1 ) )
-                   v(k,nyn+1,i) = ( v(k,nyn+1,i) + dist_xz(k,i,2) ) * MERGE( 1.0_wp, 0.0_wp,       &
-                                  BTEST( wall_flags_total_0(k,nyn+1,i), 2 ) )
-                   w(k,nyn+1,i) = ( w(k,nyn+1,i) + dist_xz(k,i,3) ) * MERGE( 1.0_wp, 0.0_wp,       &
-                                  BTEST( wall_flags_total_0(k,nyn+1,i), 3 ) )
+                   u(k,nyn+1,i) = ( u(k,nyn+1,i) + dist_xz(k,i,1) ) *                              &
+                                  MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,nyn+1,i), 1 ) )
+                   v(k,nyn+1,i) = ( v(k,nyn+1,i) + dist_xz(k,i,2) ) *                              &
+                                  MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,nyn+1,i), 2 ) )
+                   w(k,nyn+1,i) = ( w(k,nyn+1,i) + dist_xz(k,i,3) ) *                              &
+                                  MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,nyn+1,i), 3 ) )
                 ENDDO
              ENDDO
@@ -2022,7 +2025,8 @@
 !--    u'u' and v'v'. Assume isotropy. Note, add a small negative number to the denominator, else
 !--    the mergpe-function can crash if scale_l is zero.
-       r11(k) = scale_us**2 * ( MERGE( 0.35_wp                                                     &
-                * ABS( - zi_ribulk / ( kappa * scale_l - 10E-4_wp ) )**( 2.0_wp / 3.0_wp ),        &
-                0.0_wp, scale_l < 0.0_wp ) + 5.0_wp - 4.0_wp * zzi ) * blend
+       r11(k) = scale_us**2 * ( MERGE( 0.35_wp *                                                   &
+                         ABS( - zi_ribulk / ( kappa * scale_l - 10E-4_wp ) )**( 2.0_wp / 3.0_wp ), &
+                         0.0_wp, scale_l < 0.0_wp ) + 5.0_wp - 4.0_wp * zzi                                 &
+                              ) * blend
 
        r22(k) = r11(k)
