Index: palm/trunk/SOURCE/global_min_max.f90
===================================================================
--- palm/trunk/SOURCE/global_min_max.f90	(revision 4429)
+++ palm/trunk/SOURCE/global_min_max.f90	(revision 4646)
@@ -1,36 +1,37 @@
-!> @file global_min_max.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
+!
+! 4429 2020-02-27 15:24:30Z raasch
 ! bugfix: cpp-directives added for serial mode
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! OpenACC support added
-! 
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Corrected "Former revisions" section
@@ -43,14 +44,14 @@
 ! ------------
 !> Determine the array minimum/maximum and the corresponding indices.
-!------------------------------------------------------------------------------!
- SUBROUTINE global_min_max( i1, i2, j1, j2, k1, k2, ar, mode, offset, value, &
-                            value_ijk, value1, value1_ijk )
- 
-
-    USE indices,                                                               &
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE global_min_max( i1, i2, j1, j2, k1, k2, ar, mode, offset, value, value_ijk, value1,    &
+                            value1_ijk )
+
+
+    USE indices,                                                                                   &
         ONLY:  nbgp, ny, nx
-        
+
     USE kinds
-    
+
     USE pegrid
 
@@ -72,16 +73,19 @@
     INTEGER(iwp) ::  k1             !<
     INTEGER(iwp) ::  k2             !<
-    INTEGER(iwp) ::  fmax_ijk(3)    !<
-    INTEGER(iwp) ::  fmax_ijk_l(3)  !<
-    INTEGER(iwp) ::  fmin_ijk(3)    !<
-    INTEGER(iwp) ::  fmin_ijk_l(3)  !<
     INTEGER(iwp) ::  value_ijk(3)   !<
-    
-    INTEGER(iwp), OPTIONAL ::  value1_ijk(3)  !<
-    
-    REAL(wp) ::  offset                 !<
-    REAL(wp) ::  value                  !<
+
+    INTEGER(iwp), DIMENSION(3) ::  fmax_ijk    !<
+    INTEGER(iwp), DIMENSION(3) ::  fmax_ijk_l  !<
+    INTEGER(iwp), DIMENSION(3) ::  fmin_ijk    !<
+    INTEGER(iwp), DIMENSION(3) ::  fmin_ijk_l  !<
+
+    INTEGER(iwp), DIMENSION(3), OPTIONAL ::  value1_ijk  !<
+
+    REAL(wp) ::  offset            !<
+    REAL(wp) ::  value             !<
+    REAL(wp), OPTIONAL ::  value1  !<
+
     REAL(wp) ::  ar(i1:i2,j1:j2,k1:k2)  !<
-    
+
 #if defined( __ibm )
     REAL(sp) ::  fmax(2)    !<
@@ -89,17 +93,17 @@
     REAL(sp) ::  fmin(2)    !<
     REAL(sp) ::  fmin_l(2)  !<
-             ! on 32bit-machines MPI_2REAL must not be replaced 
+             ! on 32bit-machines MPI_2REAL must not be replaced
              ! by MPI_2DOUBLE_PRECISION
 #else
-    REAL(wp) ::  fmax(2)    !<
-    REAL(wp) ::  fmax_l(2)  !<
-    REAL(wp) ::  fmin(2)    !<
-    REAL(wp) ::  fmin_l(2)  !<
-#endif
+    REAL(wp), DIMENSION(2) ::  fmax    !<
+    REAL(wp), DIMENSION(2) ::  fmax_l  !<
+    REAL(wp), DIMENSION(2) ::  fmin    !<
+    REAL(wp), DIMENSION(2) ::  fmin_l  !<
+#endif
+
 #if defined( _OPENACC )
+    INTEGER(iwp) ::  count_eq   !< counter for locations of maximum
     REAL(wp)     ::  red        !< scalar for reduction with OpenACC
-    INTEGER(iwp) ::  count_eq   !< counter for locations of maximum
-#endif
-    REAL(wp), OPTIONAL ::  value1  !<
+#endif
 
 
@@ -119,6 +123,5 @@
        fmin_l(2)  = myid
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( fmin_l, fmin, 1, MPI_2REAL, MPI_MINLOC, comm2d, &
-                           ierr )
+       CALL MPI_ALLREDUCE( fmin_l, fmin, 1, MPI_2REAL, MPI_MINLOC, comm2d, ierr )
 
 !
@@ -127,6 +130,5 @@
        IF ( id_fmin /= 0 )  THEN
           IF ( myid == 0 )  THEN
-             CALL MPI_RECV( fmin_ijk, 3, MPI_INTEGER, id_fmin, 0, comm2d, &
-                            status, ierr )
+             CALL MPI_RECV( fmin_ijk, 3, MPI_INTEGER, id_fmin, 0, comm2d, status, ierr )
           ELSEIF ( myid == id_fmin )  THEN
              CALL MPI_SEND( fmin_ijk_l, 3, MPI_INTEGER, 0, 0, comm2d, ierr )
@@ -160,6 +162,5 @@
        fmax_l(2)  = myid
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, &
-                           ierr )
+       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, ierr )
 
 !
@@ -168,6 +169,5 @@
        IF ( id_fmax /= 0 )  THEN
           IF ( myid == 0 )  THEN
-             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, &
-                            status, ierr )
+             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, status, ierr )
           ELSEIF ( myid == id_fmax )  THEN
              CALL MPI_SEND( fmax_ijk_l, 3, MPI_INTEGER, 0, 0, comm2d, ierr )
@@ -177,5 +177,5 @@
        ENDIF
 !
-!--    send the indices of the just determined array maximum to other PEs
+!--    Send the indices of the just determined array maximum to other PEs
        CALL MPI_BCAST( fmax_ijk, 3, MPI_INTEGER, 0, comm2d, ierr )
 #else
@@ -226,6 +226,6 @@
        IF ( count_eq == 1 ) THEN
 !
-!--       We found a single maximum element and correctly got its position. Transfer its
-!--       value to handle the negative case correctly.
+!--       We found a single maximum element and correctly got its position. Transfer its value to
+!--       handle the negative case correctly.
           !$ACC UPDATE HOST(ar(fmax_ijk_l(1):fmax_ijk_l(1),fmax_ijk_l(2),fmax_ijk_l(3)))
        ELSE
@@ -257,5 +257,5 @@
 #if defined( _OPENACC )
 !
-!--       Close ELSE case from above
+!--    Close ELSE case from above
        ENDIF
 #endif
@@ -263,6 +263,5 @@
 !
 !--    Set a flag in case that the determined value is negative.
-!--    A constant offset has to be subtracted in order to handle the special
-!--    case i=0 correctly
+!--    A constant offset has to be subtracted in order to handle the special case i=0 correctly.
        IF ( ar(fmax_ijk_l(1),fmax_ijk_l(2),fmax_ijk_l(3)) < 0.0_wp )  THEN
           fmax_ijk_l(1) = -fmax_ijk_l(1) - 10
@@ -272,6 +271,5 @@
        fmax_l(2)  = myid
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, &
-                           ierr )
+       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, ierr )
 
 !
@@ -280,6 +278,5 @@
        IF ( id_fmax /= 0 )  THEN
           IF ( myid == 0 )  THEN
-             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, &
-                            status, ierr )
+             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, status, ierr )
           ELSEIF ( myid == id_fmax )  THEN
              CALL MPI_SEND( fmax_ijk_l, 3, MPI_INTEGER, 0, 0, comm2d, ierr )
@@ -311,7 +308,7 @@
           DO  j = j1, j2
 !
-!--          Attention: the lowest gridpoint is excluded here, because there
-!--          ---------  is no advection at nzb=0 and mode 'absoff' is only
-!--                     used for calculating u,v extrema for CFL-criteria
+!--          Attention: the lowest gridpoint is excluded here, because there is no advection at
+!--          ---------- nzb=0 and mode 'absoff' is only used for calculating u,v extrema for
+!--                     CFL-criteria.
              DO  i = i1+1, i2
                 IF ( ABS( ar(i,j,k) - offset ) > fmax_l(1) )  THEN
@@ -327,6 +324,5 @@
 !
 !--    Set a flag in case that the determined value is negative.
-!--    A constant offset has to be subtracted in order to handle the special
-!--    case i=0 correctly
+!--    A constant offset has to be subtracted in order to handle the special case i=0 correctly.
        IF ( ar(fmax_ijk_l(1),fmax_ijk_l(2),fmax_ijk_l(3)) < 0.0_wp )  THEN
           fmax_ijk_l(1) = -fmax_ijk_l(1) - 10
@@ -336,6 +332,5 @@
        fmax_l(2)  = myid
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, &
-                           ierr )
+       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, ierr )
 
 !
@@ -344,6 +339,5 @@
        IF ( id_fmax /= 0 )  THEN
           IF ( myid == 0 )  THEN
-             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, &
-                            status, ierr )
+             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, status, ierr )
           ELSEIF ( myid == id_fmax )  THEN
              CALL MPI_SEND( fmax_ijk_l, 3, MPI_INTEGER, 0, 0, comm2d, ierr )
