Index: palm/trunk/SOURCE/transpose.f90
===================================================================
--- palm/trunk/SOURCE/transpose.f90	(revision 4)
+++ palm/trunk/SOURCE/transpose.f90	(revision 164)
@@ -1,8 +1,10 @@
- SUBROUTINE transpose_xy( f_in, work1, f_inv, work2, f_out )
+ SUBROUTINE transpose_xy( f_in, work, f_out )
 
 !------------------------------------------------------------------------------!
 ! Actual revisions:
 ! -----------------
-! 
+! f_inv changed from subroutine argument to automatic array in order to do
+! re-ordering from f_in to f_inv in one step, one array work is needed instead
+! of work1 and work2
 !
 ! Former revisions:
@@ -44,5 +46,5 @@
              f_inv(nys_x:nyn_xa,nzb_x:nzt_xa,0:nxa),                    &
              f_out(0:nya,nxl_y:nxr_ya,nzb_y:nzt_ya),                    &
-             work1(nys_x:nyn_xa,nzb_x:nzt_xa,0:nxa), work2(nnx*nny*nnz)
+             work(nnx*nny*nnz)
 
 #if defined( __parallel )
@@ -51,19 +53,8 @@
 !-- Rearrange indices of input array in order to make data to be send
 !-- by MPI contiguous
-    DO  k = nzb_x, nzt_xa
-       DO  j = nys_x, nyn_xa
-          DO  i = 0, nxa
-             work1(j,k,i) = f_in(i,j,k)
-          ENDDO
-       ENDDO
-    ENDDO
-
-!
-!-- Move data to different array, because memory location of work1 is
-!-- needed further below (work1 = work2)
     DO  i = 0, nxa
        DO  k = nzb_x, nzt_xa
           DO  j = nys_x, nyn_xa
-             f_inv(j,k,i) = work1(j,k,i)
+             f_inv(j,k,i) = f_in(i,j,k)
           ENDDO
        ENDDO
@@ -74,5 +65,5 @@
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'start' )
     CALL MPI_ALLTOALL( f_inv(nys_x,nzb_x,0), sendrecvcount_xy, MPI_REAL, &
-                       work2(1),             sendrecvcount_xy, MPI_REAL, &
+                       work(1),              sendrecvcount_xy, MPI_REAL, &
                        comm1dy, ierr )
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'stop' )
@@ -87,5 +78,5 @@
              DO  j = ys, ys + nyn_xa - nys_x
                 m = m + 1
-                f_out(j,i,k) = work2(m)
+                f_out(j,i,k) = work(m)
              ENDDO
           ENDDO
@@ -98,5 +89,5 @@
 
 
- SUBROUTINE transpose_xz( f_in, work1, f_inv, work2, f_out )
+ SUBROUTINE transpose_xz( f_in, work, f_out )
 
 !------------------------------------------------------------------------------!
@@ -119,7 +110,7 @@
     
     REAL ::  f_in(0:nxa,nys_x:nyn_xa,nzb_x:nzt_xa),             &
-             f_inv(nxl:nxra,nys:nyna,1:nza),                    &
+             f_inv(nys:nyna,nxl:nxra,1:nza),                    &
              f_out(1:nza,nys:nyna,nxl:nxra),                    &
-             work1(1:nza,nys:nyna,nxl:nxra), work2(nnx*nny*nnz)
+             work(nnx*nny*nnz)
 
 #if defined( __parallel )
@@ -135,8 +126,8 @@
           xs = 0 + l * nnx
           DO  k = nzb_x, nzt_xa
-             DO  j = nys_x, nyn_xa
-                DO  i = xs, xs + nnx - 1
+             DO  i = xs, xs + nnx - 1
+                DO  j = nys_x, nyn_xa
                    m = m + 1
-                   work2(m) = f_in(i,j,k)
+                   work(m) = f_in(i,j,k)
                 ENDDO
              ENDDO
@@ -147,6 +138,6 @@
 !--    Transpose array
        CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'start' )
-       CALL MPI_ALLTOALL( work2(1),         sendrecvcount_zx, MPI_REAL, &
-                          f_inv(nxl,nys,1), sendrecvcount_zx, MPI_REAL, &
+       CALL MPI_ALLTOALL( work(1),          sendrecvcount_zx, MPI_REAL, &
+                          f_inv(nys,nxl,1), sendrecvcount_zx, MPI_REAL, &
                           comm1dx, ierr )
        CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'stop' )
@@ -154,8 +145,8 @@
 !
 !--    Reorder transposed array in a way that the z index is in first position
-       DO  i = nxl, nxra
-          DO  j = nys, nyna
-             DO  k = 1, nza
-                work1(k,j,i) = f_inv(i,j,k)
+       DO  k = 1, nza
+          DO  i = nxl, nxra
+             DO  j = nys, nyna
+                f_out(k,j,i) = f_inv(j,i,k)
              ENDDO
           ENDDO
@@ -167,19 +158,19 @@
           DO  j = nys, nyna
              DO  k = 1, nza
-                work1(k,j,i) = f_in(i,j,k)
-             ENDDO
-          ENDDO
-       ENDDO
+                f_inv(j,i,k) = f_in(i,j,k)
+             ENDDO
+          ENDDO
+       ENDDO
+
+       DO  k = 1, nza
+          DO  i = nxl, nxra
+             DO  j = nys, nyna
+                f_out(k,j,i) = f_inv(j,i,k)
+             ENDDO
+          ENDDO
+       ENDDO
+
     ENDIF
 
-!
-!-- Move data to output array
-    DO  i = nxl, nxra
-       DO  j = nys, nyna
-          DO  k = 1, nza
-             f_out(k,j,i) = work1(k,j,i)
-          ENDDO
-       ENDDO
-    ENDDO
 
 #endif
@@ -188,5 +179,5 @@
 
 
- SUBROUTINE transpose_yx( f_in, work1, f_inv, work2, f_out )
+ SUBROUTINE transpose_yx( f_in, work, f_out )
 
 !------------------------------------------------------------------------------!
@@ -211,5 +202,5 @@
              f_inv(nys_x:nyn_xa,nzb_x:nzt_xa,0:nxa),                    &
              f_out(0:nxa,nys_x:nyn_xa,nzb_x:nzt_xa),                    &
-             work1(0:nxa,nys_x:nyn_xa,nzb_x:nzt_xa), work2(nnx*nny*nnz)
+             work(nnx*nny*nnz)
 
 #if defined( __parallel )
@@ -224,5 +215,5 @@
              DO  j = ys, ys + nyn_xa - nys_x
                 m = m + 1
-                work2(m) = f_in(j,i,k)
+                work(m) = f_in(j,i,k)
              ENDDO
           ENDDO
@@ -233,5 +224,5 @@
 !-- Transpose array
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'start' )
-    CALL MPI_ALLTOALL( work2(1),             sendrecvcount_xy, MPI_REAL, &
+    CALL MPI_ALLTOALL( work(1),              sendrecvcount_xy, MPI_REAL, &
                        f_inv(nys_x,nzb_x,0), sendrecvcount_xy, MPI_REAL, &
                        comm1dy, ierr )
@@ -243,15 +234,5 @@
        DO  k = nzb_x, nzt_xa
           DO  j = nys_x, nyn_xa
-             work1(i,j,k) = f_inv(j,k,i)
-          ENDDO
-       ENDDO
-    ENDDO
-
-!
-!-- Move data to output array
-    DO  k = nzb_x, nzt_xa
-       DO  j = nys_x, nyn_xa
-          DO  i = 0, nxa
-             f_out(i,j,k) = work1(i,j,k)
+             f_out(i,j,k) = f_inv(j,k,i)
           ENDDO
        ENDDO
@@ -263,5 +244,5 @@
 
 
- SUBROUTINE transpose_yxd( f_in, work1, f_inv, work2, f_out )
+ SUBROUTINE transpose_yxd( f_in, work, f_out )
 
 !------------------------------------------------------------------------------!
@@ -287,5 +268,5 @@
     REAL ::  f_in(1:nza,nys:nyna,nxl:nxra), f_inv(nxl:nxra,1:nza,nys:nyna), &
              f_out(0:nxa,nys_x:nyn_xa,nzb_x:nzt_xa),                        &
-             work1(nxl:nxra,1:nza,nys:nyna), work2(nnx*nny*nnz)
+             work(nnx*nny*nnz)
 
 #if defined( __parallel )
@@ -297,16 +278,5 @@
        DO  j = nys, nyna
           DO  i = nxl, nxra
-             work1(i,k,j) = f_in(k,j,i)
-          ENDDO
-       ENDDO
-    ENDDO
-
-!
-!-- Move data to different array, because memory location of work1 is
-!-- needed further below (work1 = work2)
-    DO  j = nys, nyna
-       DO  k = 1, nza
-          DO  i = nxl, nxra
-             f_inv(i,k,j) = work1(i,k,j)
+             f_inv(i,k,j) = f_in(k,j,i)
           ENDDO
        ENDDO
@@ -317,5 +287,5 @@
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'start' )
     CALL MPI_ALLTOALL( f_inv(nxl,1,nys), sendrecvcount_xy, MPI_REAL, &
-                       work2(1),         sendrecvcount_xy, MPI_REAL, &
+                       work(1),          sendrecvcount_xy, MPI_REAL, &
                        comm1dx, ierr )
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'stop' )
@@ -330,5 +300,5 @@
              DO  i = xs, xs + nnx - 1
                 m = m + 1
-                f_out(i,j,k) = work2(m)
+                f_out(i,j,k) = work(m)
              ENDDO
           ENDDO
@@ -341,5 +311,5 @@
 
 
- SUBROUTINE transpose_yz( f_in, work1, f_inv, work2, f_out )
+ SUBROUTINE transpose_yz( f_in, work, f_out )
 
 !------------------------------------------------------------------------------!
@@ -364,5 +334,5 @@
              f_inv(nxl_y:nxr_ya,nzb_y:nzt_ya,0:nya),                    &
              f_out(nxl_z:nxr_za,nys_z:nyn_za,1:nza),                    &
-             work1(nxl_y:nxr_ya,nzb_y:nzt_ya,0:nya), work2(nnx*nny*nnz)
+             work(nnx*nny*nnz)
 
 #if defined( __parallel )
@@ -371,8 +341,8 @@
 !-- Rearrange indices of input array in order to make data to be send
 !-- by MPI contiguous
-    DO  k = nzb_y, nzt_ya
-       DO  i = nxl_y, nxr_ya
-          DO  j = 0, nya
-             work1(i,k,j) = f_in(j,i,k)
+    DO  j = 0, nya
+       DO  k = nzb_y, nzt_ya
+          DO  i = nxl_y, nxr_ya
+             f_inv(i,k,j) = f_in(j,i,k)
           ENDDO
        ENDDO
@@ -388,17 +358,9 @@
           DO  k = nzb_y, nzt_ya
              DO  i = nxl_y, nxr_ya
-                f_out(i,j,k) = work1(i,k,j)
+                f_out(i,j,k) = f_inv(i,k,j)
              ENDDO
           ENDDO
        ENDDO
        RETURN
-    ELSE
-       DO  j = 0, nya
-          DO  k = nzb_y, nzt_ya
-             DO  i = nxl_y, nxr_ya
-                f_inv(i,k,j) = work1(i,k,j)
-             ENDDO
-          ENDDO
-       ENDDO
     ENDIF
 
@@ -407,5 +369,5 @@
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'start' )
     CALL MPI_ALLTOALL( f_inv(nxl_y,nzb_y,0), sendrecvcount_yz, MPI_REAL, &
-                       work2(1),             sendrecvcount_yz, MPI_REAL, &
+                       work(1),              sendrecvcount_yz, MPI_REAL, &
                        comm1dx, ierr )
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'stop' )
@@ -420,5 +382,5 @@
              DO  i = nxl_z, nxr_za
                 m = m + 1
-                f_out(i,j,k) = work2(m)
+                f_out(i,j,k) = work(m)
              ENDDO
           ENDDO
@@ -431,5 +393,5 @@
 
 
- SUBROUTINE transpose_zx( f_in, work1, f_inv, work2, f_out )
+ SUBROUTINE transpose_zx( f_in, work, f_out )
 
 !------------------------------------------------------------------------------!
@@ -451,7 +413,7 @@
     INTEGER ::  i, j, k, l, m, xs
     
-    REAL ::  f_in(1:nza,nys:nyna,nxl:nxra), f_inv(nxl:nxra,nys:nyna,1:nza), &
+    REAL ::  f_in(1:nza,nys:nyna,nxl:nxra), f_inv(nys:nyna,nxl:nxra,1:nza), &
              f_out(0:nxa,nys_x:nyn_xa,nzb_x:nzt_xa),                        &
-             work1(nxl:nxra,nys:nyna,1:nza), work2(nnx*nny*nnz)
+             work(nnx*nny*nnz)
 
 #if defined( __parallel )
@@ -460,8 +422,8 @@
 !-- Rearrange indices of input array in order to make data to be send
 !-- by MPI contiguous
-    DO  i = nxl, nxra
-       DO  j = nys, nyna
-          DO  k = 1,nza
-             work1(i,j,k) = f_in(k,j,i)
+    DO  k = 1,nza
+       DO  i = nxl, nxra
+          DO  j = nys, nyna
+             f_inv(j,i,k) = f_in(k,j,i)
           ENDDO
        ENDDO
@@ -475,19 +437,11 @@
     IF ( pdims(1) == 1 )  THEN
        DO  k = 1, nza
-          DO  j = nys, nyna
-             DO  i = nxl, nxra
-                f_out(i,j,k) = work1(i,j,k)
+          DO  i = nxl, nxra
+             DO  j = nys, nyna
+                f_out(i,j,k) = f_inv(j,i,k)
              ENDDO
           ENDDO
        ENDDO
        RETURN
-    ELSE
-       DO  k = 1, nza
-          DO  j = nys, nyna
-             DO  i = nxl, nxra
-                f_inv(i,j,k) = work1(i,j,k)
-             ENDDO
-          ENDDO
-       ENDDO
     ENDIF
 
@@ -495,6 +449,6 @@
 !-- Transpose array
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'start' )
-    CALL MPI_ALLTOALL( f_inv(nxl,nys,1), sendrecvcount_zx, MPI_REAL, &
-                       work2(1),         sendrecvcount_zx, MPI_REAL, &
+    CALL MPI_ALLTOALL( f_inv(nys,nxl,1), sendrecvcount_zx, MPI_REAL, &
+                       work(1),          sendrecvcount_zx, MPI_REAL, &
                        comm1dx, ierr )
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'stop' )
@@ -506,8 +460,8 @@
        xs = 0 + l * nnx
        DO  k = nzb_x, nzt_xa
-          DO  j = nys_x, nyn_xa
-             DO  i = xs, xs + nnx - 1
+          DO  i = xs, xs + nnx - 1
+             DO  j = nys_x, nyn_xa
                 m = m + 1
-                f_out(i,j,k) = work2(m)
+                f_out(i,j,k) = work(m)
              ENDDO
           ENDDO
@@ -520,5 +474,5 @@
 
 
- SUBROUTINE transpose_zy( f_in, work1, f_inv, work2, f_out )
+ SUBROUTINE transpose_zy( f_in, work, f_out )
 
 !------------------------------------------------------------------------------!
@@ -543,5 +497,5 @@
              f_inv(nxl_y:nxr_ya,nzb_y:nzt_ya,0:nya),                    &
              f_out(0:nya,nxl_y:nxr_ya,nzb_y:nzt_ya),                    &
-             work1(0:nya,nxl_y:nxr_ya,nzb_y:nzt_ya), work2(nnx*nny*nnz)
+             work(nnx*nny*nnz)
 
 #if defined( __parallel )
@@ -560,5 +514,5 @@
                 DO  i = nxl_z, nxr_za
                    m = m + 1
-                   work2(m) = f_in(i,j,k)
+                   work(m) = f_in(i,j,k)
                 ENDDO
              ENDDO
@@ -569,5 +523,5 @@
 !--    Transpose array
        CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'start' )
-       CALL MPI_ALLTOALL( work2(1),             sendrecvcount_yz, MPI_REAL, &
+       CALL MPI_ALLTOALL( work(1),              sendrecvcount_yz, MPI_REAL, &
                           f_inv(nxl_y,nzb_y,0), sendrecvcount_yz, MPI_REAL, &
                           comm1dx, ierr )
@@ -576,33 +530,33 @@
 !
 !--    Reorder transposed array in a way that the y index is in first position
+       DO  j = 0, nya
+          DO  k = nzb_y, nzt_ya
+             DO  i = nxl_y, nxr_ya
+                f_out(j,i,k) = f_inv(i,k,j)
+             ENDDO
+          ENDDO
+       ENDDO
+    ELSE
+!
+!--    Reorder the array in a way that the y index is in first position
+       DO  k = nzb_y, nzt_ya
+          DO  j = 0, nya
+             DO  i = nxl_y, nxr_ya
+                f_inv(i,k,j) = f_in(i,j,k)
+             ENDDO
+          ENDDO
+       ENDDO
+!
+!--    Move data to output array
        DO  k = nzb_y, nzt_ya
           DO  i = nxl_y, nxr_ya
              DO  j = 0, nya
-                work1(j,i,k) = f_inv(i,k,j)
-             ENDDO
-          ENDDO
-       ENDDO
-    ELSE
-!
-!--    Reorder the array in a way that the y index is in first position
-       DO  k = nzb_y, nzt_ya
-          DO  i = nxl_y, nxr_ya
-             DO  j = 0, nya
-                work1(j,i,k) = f_in(i,j,k)
-             ENDDO
-          ENDDO
-       ENDDO
+                f_out(j,i,k) = f_inv(i,k,j)
+             ENDDO
+          ENDDO
+       ENDDO
+
     ENDIF
 
-!
-!-- Move data to output array
-    DO  k = nzb_y, nzt_ya
-       DO  i = nxl_y, nxr_ya
-          DO  j = 0, nya
-             f_out(j,i,k) = work1(j,i,k)
-          ENDDO
-       ENDDO
-    ENDDO
-
 #endif
 
@@ -610,5 +564,5 @@
 
 
- SUBROUTINE transpose_zyd( f_in, work1, f_inv, work2, f_out )
+ SUBROUTINE transpose_zyd( f_in, work, f_out )
 
 !------------------------------------------------------------------------------!
@@ -634,5 +588,5 @@
     REAL ::  f_in(1:nza,nys:nyna,nxl:nxra), f_inv(nys:nyna,nxl:nxra,1:nza), &
              f_out(0:nya,nxl_yd:nxr_yda,nzb_yd:nzt_yda),                    &
-             work1(nys:nyna,nxl:nxra,1:nza), work2(nnx*nny*nnz)
+             work(nnx*nny*nnz)
 
 #if defined( __parallel )
@@ -644,5 +598,5 @@
        DO  j = nys, nyna
           DO  k = 1, nza
-             work1(j,i,k) = f_in(k,j,i)
+             f_inv(j,i,k) = f_in(k,j,i)
           ENDDO
        ENDDO
@@ -658,17 +612,9 @@
           DO  i = nxl, nxra
              DO  j = nys, nyna
-                f_out(j,i,k) = work1(j,i,k)
+                f_out(j,i,k) = f_inv(j,i,k)
              ENDDO
           ENDDO
        ENDDO
        RETURN
-    ELSE
-       DO  k = 1, nza
-          DO  i = nxl, nxra
-             DO  j = nys, nyna
-                f_inv(j,i,k) = work1(j,i,k)
-             ENDDO
-          ENDDO
-       ENDDO
     ENDIF
 
@@ -677,5 +623,5 @@
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'start' )
     CALL MPI_ALLTOALL( f_inv(nys,nxl,1), sendrecvcount_zyd, MPI_REAL, &
-                       work2(1),         sendrecvcount_zyd, MPI_REAL, &
+                       work(1),          sendrecvcount_zyd, MPI_REAL, &
                        comm1dy, ierr )
     CALL cpu_log( log_point_s(32), 'mpi_alltoall', 'stop' )
@@ -690,5 +636,5 @@
              DO  j = ys, ys + nny - 1
                 m = m + 1
-                f_out(j,i,k) = work2(m)
+                f_out(j,i,k) = work(m)
              ENDDO
           ENDDO
