Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 1932)
+++ palm/trunk/SOURCE/Makefile	(revision 1933)
@@ -312,7 +312,7 @@
 	mod_particle_attributes.f90 netcdf_interface_mod.f90 nudging_mod.f90 \
 	package_parin.f90 palm.f90 parin.f90 plant_canopy_model_mod.f90 pmc_interface_mod.f90 \
-	pmc_client_mod.f90 pmc_general_mod.f90 pmc_handle_communicator_mod.f90 \
-	pmc_mpi_wrapper_mod.f90 pmc_server_mod.f90 poisfft_mod.f90 poismg_mod.f90 \
-	poismg_noopt.f90 pres.f90 print_1d.f90 production_e.f90 \
+	pmc_child_mod.f90 pmc_general_mod.f90 pmc_handle_communicator_mod.f90 \
+	pmc_mpi_wrapper_mod.f90 pmc_parent_mod.f90 poisfft_mod.f90 poismg.f90 \
+	poismg_fast_mod.f90 pres.f90 print_1d.f90 production_e.f90 \
 	prognostic_equations.f90 progress_bar_mod.f90 radiation_model_mod.f90 \
 	random_function_mod.f90 random_gauss.f90 random_generator_parallel_mod.f90 \
@@ -495,12 +495,12 @@
    radiation_model_mod.o microphysics_mod.o wind_turbine_model_mod.o
 plant_canopy_model_mod.o: modules.o mod_kinds.o
-pmc_interface_mod.o: modules.o mod_kinds.o pmc_client_mod.o pmc_general_mod.o\
-	pmc_handle_communicator_mod.o pmc_mpi_wrapper_mod.o pmc_server_mod.o
-pmc_client_mod.o: mod_kinds.o pmc_general_mod.o pmc_handle_communicator_mod.o\
+pmc_interface_mod.o: modules.o mod_kinds.o pmc_child_mod.o pmc_general_mod.o\
+	pmc_handle_communicator_mod.o pmc_mpi_wrapper_mod.o pmc_parent_mod.o
+pmc_child_mod.o: mod_kinds.o pmc_general_mod.o pmc_handle_communicator_mod.o\
    pmc_mpi_wrapper_mod.o
 pmc_general_mod.o: mod_kinds.o
 pmc_handle_communicator_mod.o: modules.o mod_kinds.o pmc_general_mod.o
 pmc_mpi_wrapper_mod.o: pmc_handle_communicator_mod.o
-pmc_server_mod.o: pmc_general_mod.o pmc_handle_communicator_mod.o pmc_mpi_wrapper_mod.o
+pmc_parent_mod.o: pmc_general_mod.o pmc_handle_communicator_mod.o pmc_mpi_wrapper_mod.o
 poisfft_mod.o: modules.o cpulog_mod.o fft_xy_mod.o mod_kinds.o tridia_solver_mod.o
 poismg_mod.o: modules.o cpulog_mod.o mod_kinds.o
Index: palm/trunk/SOURCE/boundary_conds.f90
===================================================================
--- palm/trunk/SOURCE/boundary_conds.f90	(revision 1932)
+++ palm/trunk/SOURCE/boundary_conds.f90	(revision 1933)
@@ -19,9 +19,12 @@
 ! Current revisions:
 ! -----------------
-!
-!
+! 
+! 
 ! Former revisions:
 ! -----------------
 ! $Id$
+!
+! 1823 2016-04-07 08:57:52Z hoffmann
+! Initial version of purely vertical nesting introduced.
 !
 ! 1822 2016-04-07 07:49:42Z hoffmann
@@ -159,4 +162,7 @@
     USE pegrid
 
+    USE pmc_interface,                                                         &
+        ONLY : nesting_mode
+
 
     IMPLICIT NONE
@@ -359,12 +365,13 @@
 !
 !-- The same restoration for u at i=nxl and v at j=nys as above must be made
-!-- in case of nest boundaries. Note however, that the above ELSEIF-structure is
-!-- not appropriate here as there may be more than one nest boundary on a
-!-- PE-domain. Furthermore Neumann conditions for SGS-TKE are not required here.
-    IF ( nest_bound_s )  THEN
-       v_p(:,nys,:) = v_p(:,nys-1,:)
-    ENDIF
-    IF ( nest_bound_l )  THEN
-       u_p(:,:,nxl) = u_p(:,:,nxl-1)
+!-- in case of nest boundaries. This must not be done in case of vertical nesting 
+!-- mode as in that case the lateral boundaries are actually cyclic.
+    IF ( nesting_mode /= 'vertical' )  THEN
+       IF ( nest_bound_s )  THEN
+          v_p(:,nys,:) = v_p(:,nys-1,:)
+       ENDIF
+       IF ( nest_bound_l )  THEN
+          u_p(:,:,nxl) = u_p(:,:,nxl-1)
+       ENDIF
     ENDIF
 
Index: palm/trunk/SOURCE/exchange_horiz.f90
===================================================================
--- palm/trunk/SOURCE/exchange_horiz.f90	(revision 1932)
+++ palm/trunk/SOURCE/exchange_horiz.f90	(revision 1933)
@@ -277,5 +277,5 @@
                 DO  k = nzb, nzt+1
                    ar(k,nys-nbgp_local+j,i) = ar(k,nyn-nbgp_local+1+j,i)
-                     ar(k,nyn+1+j,i)          = ar(k,nys+j,i)
+                   ar(k,nyn+1+j,i)          = ar(k,nys+j,i)
                 ENDDO
              ENDDO
Index: palm/trunk/SOURCE/exchange_horiz_2d.f90
===================================================================
--- palm/trunk/SOURCE/exchange_horiz_2d.f90	(revision 1932)
+++ palm/trunk/SOURCE/exchange_horiz_2d.f90	(revision 1933)
@@ -25,4 +25,7 @@
 ! $Id$
 !
+! 1818 2016-04-06 15:53:27Z maronga
+! Initial version of purely vertical nesting introduced. 
+! 
 ! 1804 2016-04-05 16:30:18Z maronga
 ! Removed code for parameter file check (__check)
@@ -81,4 +84,8 @@
     USE pegrid
 
+    USE pmc_interface,                                                         &
+        ONLY : nesting_mode
+
+
     IMPLICIT NONE
 
@@ -160,23 +167,25 @@
 !
 !-- Neumann-conditions at inflow/outflow/nested boundaries
-    IF ( inflow_l .OR. outflow_l .OR. nest_bound_l )  THEN
-       DO  i = nbgp, 1, -1
-         ar(:,nxl-i) = ar(:,nxl)
-       ENDDO
-    ENDIF
-    IF ( inflow_r .OR. outflow_r .OR. nest_bound_r )  THEN
-       DO  i = 1, nbgp
-          ar(:,nxr+i) = ar(:,nxr)
-       ENDDO
-    ENDIF
-    IF ( inflow_s .OR. outflow_s .OR. nest_bound_s )  THEN
-       DO  i = nbgp, 1, -1
-         ar(nys-i,:) = ar(nys,:)
-       ENDDO
-    ENDIF
-    IF ( inflow_n .OR. outflow_n .OR. nest_bound_n )  THEN
-       DO  i = 1, nbgp
-         ar(nyn+i,:) = ar(nyn,:)
-       ENDDO
+    IF ( nesting_mode /= 'vertical' )  THEN
+       IF ( inflow_l .OR. outflow_l .OR. nest_bound_l )  THEN
+          DO  i = nbgp, 1, -1
+             ar(:,nxl-i) = ar(:,nxl)
+          ENDDO
+       ENDIF
+       IF ( inflow_r .OR. outflow_r .OR. nest_bound_r )  THEN
+          DO  i = 1, nbgp
+             ar(:,nxr+i) = ar(:,nxr)
+          ENDDO
+       ENDIF
+       IF ( inflow_s .OR. outflow_s .OR. nest_bound_s )  THEN
+          DO  i = nbgp, 1, -1
+             ar(nys-i,:) = ar(nys,:)
+          ENDDO
+       ENDIF
+       IF ( inflow_n .OR. outflow_n .OR. nest_bound_n )  THEN
+          DO  i = 1, nbgp
+             ar(nyn+i,:) = ar(nyn,:)
+          ENDDO
+       ENDIF
     ENDIF
 
Index: palm/trunk/SOURCE/init_pegrid.f90
===================================================================
--- palm/trunk/SOURCE/init_pegrid.f90	(revision 1932)
+++ palm/trunk/SOURCE/init_pegrid.f90	(revision 1933)
@@ -25,4 +25,7 @@
 ! $Id$
 !
+! 1923 2016-05-31 16:37:07Z boeske
+! Initial version of purely vertical nesting introduced. 
+! 
 ! 1922 2016-05-31 16:36:08Z boeske
 ! Bugfix: array transposition checks restricted to cases if a fourier 
@@ -153,7 +156,7 @@
                maximum_parallel_io_streams, message_string,                    &
                mg_switch_to_pe0_level, momentum_advec, nest_bound_l,           &
-               nest_bound_n, nest_bound_r, nest_bound_s, neutral, psolver,     &
-               outflow_l, outflow_n, outflow_r, outflow_s, recycling_width,    &
-               scalar_advec, subdomain_size 
+               nest_bound_n, nest_bound_r, nest_bound_s, nest_domain, neutral, &
+               psolver, outflow_l, outflow_n, outflow_r, outflow_s,            &
+               recycling_width, scalar_advec, subdomain_size 
 
     USE grid_variables,                                                        &
@@ -170,5 +173,8 @@
       
     USE pegrid
-
+    
+    USE pmc_interface,                                                         &   
+        ONLY:  nesting_mode
+   
     USE spectra_mod,                                                           &
         ONLY:  calculate_spectra, dt_dosp
@@ -1092,46 +1098,69 @@
 #if defined( __parallel )
 !
-!-- Setting of flags for inflow/outflow/nesting conditions in case of non-cyclic
-!-- horizontal boundary conditions.
-    IF ( pleft == MPI_PROC_NULL )  THEN
-       IF ( bc_lr == 'dirichlet/radiation' )  THEN
-          inflow_l  = .TRUE.
-       ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
-          outflow_l = .TRUE.
-       ELSEIF ( bc_lr == 'nested' )  THEN
+!-- Setting of flags for inflow/outflow/nesting conditions.
+    IF ( nesting_mode == 'vertical' .AND. nest_domain )  THEN
+       IF ( nxl == 0 )  THEN
           nest_bound_l = .TRUE.
        ENDIF
-    ENDIF
-
-    IF ( pright == MPI_PROC_NULL )  THEN
-       IF ( bc_lr == 'dirichlet/radiation' )  THEN
-          outflow_r = .TRUE.
-       ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
-          inflow_r  = .TRUE.
-       ELSEIF ( bc_lr == 'nested' )  THEN
+    ELSE
+       IF ( pleft == MPI_PROC_NULL )  THEN
+          IF ( bc_lr == 'dirichlet/radiation' )  THEN
+             inflow_l  = .TRUE.
+          ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
+             outflow_l = .TRUE.
+          ELSEIF ( bc_lr == 'nested' )  THEN
+             nest_bound_l = .TRUE.
+          ENDIF
+       ENDIF
+    ENDIF
+ 
+    IF ( nesting_mode == 'vertical' .AND. nest_domain )  THEN
+       IF ( nxr == nx )  THEN
           nest_bound_r = .TRUE.
        ENDIF
-    ENDIF
-
-    IF ( psouth == MPI_PROC_NULL )  THEN
-       IF ( bc_ns == 'dirichlet/radiation' )  THEN
-          outflow_s = .TRUE.
-       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
-          inflow_s  = .TRUE.
-       ELSEIF ( bc_ns == 'nested' )  THEN
+    ELSE
+       IF ( pright == MPI_PROC_NULL )  THEN
+          IF ( bc_lr == 'dirichlet/radiation' )  THEN
+             outflow_r = .TRUE.
+          ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
+             inflow_r  = .TRUE.
+          ELSEIF ( bc_lr == 'nested' )  THEN
+             nest_bound_r = .TRUE.
+          ENDIF
+       ENDIF
+    ENDIF
+
+    IF ( nesting_mode == 'vertical' .AND. nest_domain )  THEN
+       IF ( nys == 0 )  THEN
           nest_bound_s = .TRUE.
        ENDIF
-    ENDIF
-
-    IF ( pnorth == MPI_PROC_NULL )  THEN
-       IF ( bc_ns == 'dirichlet/radiation' )  THEN
-          inflow_n  = .TRUE.
-       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
-          outflow_n = .TRUE.
-       ELSEIF ( bc_ns == 'nested' )  THEN
+    ELSE
+       IF ( psouth == MPI_PROC_NULL )  THEN
+          IF ( bc_ns == 'dirichlet/radiation' )  THEN
+             outflow_s = .TRUE.
+          ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
+             inflow_s  = .TRUE.
+          ELSEIF ( bc_ns == 'nested' )  THEN
+             nest_bound_s = .TRUE.
+          ENDIF
+       ENDIF
+    ENDIF
+
+    IF ( nesting_mode == 'vertical' .AND. nest_domain )  THEN
+       IF ( nyn == ny )  THEN
           nest_bound_n = .TRUE.
        ENDIF
-    ENDIF
-
+    ELSE
+       IF ( pnorth == MPI_PROC_NULL )  THEN
+          IF ( bc_ns == 'dirichlet/radiation' )  THEN
+             inflow_n  = .TRUE.
+          ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
+             outflow_n = .TRUE.
+          ELSEIF ( bc_ns == 'nested' )  THEN
+             nest_bound_n = .TRUE.
+          ENDIF
+       ENDIF
+    ENDIF
+       
 !
 !-- Broadcast the id of the inflow PE
Index: palm/trunk/SOURCE/palm.f90
===================================================================
--- palm/trunk/SOURCE/palm.f90	(revision 1932)
+++ palm/trunk/SOURCE/palm.f90	(revision 1933)
@@ -25,4 +25,7 @@
 ! $Id$
 !
+! 1834 2016-04-07 14:34:20Z raasch
+! Initial version of purely vertical nesting introduced. 
+! 
 ! 1833 2016-04-07 14:23:03Z raasch
 ! required user interface version changed
@@ -134,6 +137,6 @@
         ONLY:  constant_diffusion, coupling_char, coupling_mode,               &
                do2d_at_begin, do3d_at_begin, humidity, io_blocks, io_group,    &
-               large_scale_forcing, message_string, nest_domain, nudging,      &
-               passive_scalar, simulated_time, simulated_time_chr,             &
+               large_scale_forcing, message_string, nest_domain, neutral,      &
+               nudging, passive_scalar, simulated_time, simulated_time_chr,    &
                user_interface_current_revision,                                &
                user_interface_required_revision, version, wall_heatflux,       &
@@ -168,6 +171,6 @@
 
     USE pmc_interface,                                                         &
-        ONLY:  cpl_id, nested_run, pmci_client_initialize, pmci_init,          &
-               pmci_modelconfiguration, pmci_server_initialize
+        ONLY:  cpl_id, nested_run, pmci_child_initialize, pmci_init,           &
+               pmci_modelconfiguration, pmci_parent_initialize
 
     USE statistics,                                                            &
@@ -341,11 +344,11 @@
        CALL pmci_modelconfiguration
 !
-!--    Receive and interpolate initial data on client.
-!--    Client initialization must be made first if the model is both client and
-!--    server
-       CALL pmci_client_initialize
-!
-!--    Send initial condition data from server to client
-       CALL pmci_server_initialize
+!--    Receive and interpolate initial data on children.
+!--    Child initialization must be made first if the model is both child and
+!--    parent
+       CALL pmci_child_initialize
+!
+!--    Send initial condition data from parent to children
+       CALL pmci_parent_initialize
 !
 !--    Exchange_horiz is needed after the nest initialization
@@ -354,5 +357,7 @@
           CALL exchange_horiz( v, nbgp )
           CALL exchange_horiz( w, nbgp )
-          CALL exchange_horiz( pt, nbgp )
+          IF ( .NOT. neutral )  THEN
+             CALL exchange_horiz( pt, nbgp )
+          ENDIF
           IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
           IF (humidity  .OR.  passive_scalar)  THEN
Index: palm/trunk/SOURCE/parin.f90
===================================================================
--- palm/trunk/SOURCE/parin.f90	(revision 1932)
+++ palm/trunk/SOURCE/parin.f90	(revision 1933)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! -----------------
-!
+! 
 ! 
 ! Former revisions:
@@ -25,4 +25,7 @@
 ! $Id$
 !
+! 1917 2016-05-27 14:28:12Z witha
+! Initial version of purely vertical nesting introduced.
+! 
 ! 1914 2016-05-26 14:44:07Z witha
 ! Added call to wind turbine model for reading of &wind_turbine_par
@@ -245,5 +248,5 @@
 
     USE pmc_interface,                                                         &
-        ONLY:  nested_run
+        ONLY:  nested_run, nesting_mode
 
     USE profil_parameter,                                                      &
@@ -429,14 +432,36 @@
 
 !
-!--       In case of nested runs, explicitly set nesting boundary conditions
-!--       except for the root domain. This will overwrite the user settings.
-          IF ( nest_domain )  THEN
-             bc_lr   = 'nested'
-             bc_ns   = 'nested'
-             bc_uv_t = 'nested'
-             bc_pt_t = 'nested'
-             bc_q_t  = 'nested'
-             bc_p_t  = 'neumann'
+!--       In case of nested runs, explicitly set nesting boundary conditions. 
+!--       This will overwrite the user settings. bc_lr and bc_ns always need
+!--       to be cyclic for vertical nesting.
+          IF ( nesting_mode == 'vertical' )  THEN
+             IF (bc_lr /= 'cyclic' .OR. bc_ns /= 'cyclic' )  THEN
+                WRITE ( message_string, *)  'bc_lr and bc_ns were set to ,',   &
+                                      'cyclic for vertical nesting'
+                CALL message( 'parin', 'PA0428', 0, 0, 0, 6, 0 )
+                bc_lr   = 'cyclic'
+                bc_ns   = 'cyclic'
+             ENDIF
+             IF ( nest_domain )  THEN
+                bc_uv_t = 'nested'
+                bc_pt_t = 'nested'
+                bc_q_t  = 'nested'
+                bc_p_t  = 'neumann'
+             ENDIF
+          ELSE
+          
+!
+!--       For other nesting modes only set boundary conditions for 
+!--       nested domains.
+             IF ( nest_domain )  THEN
+                bc_lr   = 'nested'
+                bc_ns   = 'nested'
+                bc_uv_t = 'nested'
+                bc_pt_t = 'nested'
+                bc_q_t  = 'nested'
+                bc_p_t  = 'neumann'
+             ENDIF
           ENDIF
+            
 !
 !--       Check validity of lateral boundary conditions. This has to be done
Index: palm/trunk/SOURCE/pmc_child_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_child_mod.f90	(revision 1933)
+++ palm/trunk/SOURCE/pmc_child_mod.f90	(revision 1933)
@@ -0,0 +1,895 @@
+MODULE pmc_child
+
+!-------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! 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-2016 Leibniz Universitaet Hannover
+!-------------------------------------------------------------------------------!
+!
+! Current revisions:
+! ------------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+!
+! 1897 2016-05-03 08:10:23Z raasch
+! Module renamed. Code clean up. The words server/client changed to parent/child.
+!
+! 1896 2016-05-03 08:06:41Z raasch
+! re-formatted to match PALM style
+!
+! 1850 2016-04-08 13:29:27Z maronga
+! Module renamed
+! 
+! 
+! 1833 2016-04-07 14:23:03Z raasch
+! gfortran requires pointer attributes for some array declarations,
+! long line wrapped
+!
+! 1808 2016-04-05 19:44:00Z raasch
+! MPI module used by default on all machines
+!
+! 1797 2016-03-21 16:50:28Z raasch
+! introduction of different datatransfer modes
+!
+! 1791 2016-03-11 10:41:25Z raasch
+! Debug write-statement commented out
+!
+! 1786 2016-03-08 05:49:27Z raasch
+! change in child-parent data transfer: parent now gets data from child
+! instead of that child puts it to the parent
+!
+! 1783 2016-03-06 18:36:17Z raasch
+! Bugfix: wrong data-type in MPI_WIN_CREATE replaced
+!
+! 1779 2016-03-03 08:01:28Z raasch
+! kind=dp replaced by wp, dim_order removed
+! array management changed from linked list to sequential loop
+!
+! 1764 2016-02-28 12:45:19Z raasch
+! cpp-statement added (nesting can only be used in parallel mode),
+! all kinds given in PALM style
+!
+! 1762 2016-02-25 12:31:13Z hellstea
+! Initial revision by K. Ketelsen
+!
+! Description:
+! ------------
+!
+! Child part of Palm Model Coupler
+!-------------------------------------------------------------------------------!
+
+#if defined( __parallel )
+
+    USE, INTRINSIC ::  iso_c_binding
+
+#if defined( __mpifh )
+    INCLUDE "mpif.h"
+#else
+    USE MPI
+#endif
+
+    USE kinds
+    USE pmc_general,                                                            &
+        ONLY:  arraydef, childdef, da_desclen, da_namedef, da_namelen, pedef,   &
+               pmc_da_name_err,  pmc_g_setname, pmc_max_array, pmc_status_ok
+
+    USE pmc_handle_communicator,                                                &
+        ONLY:  m_model_comm, m_model_npes, m_model_rank, m_to_parent_comm
+
+    USE pmc_mpi_wrapper,                                                        &
+        ONLY:  pmc_alloc_mem, pmc_bcast, pmc_inter_bcast, pmc_time
+
+    IMPLICIT NONE
+
+    PRIVATE
+    SAVE
+
+    TYPE(childdef) ::  me   !<
+
+    INTEGER ::  myindex = 0         !< counter and unique number for data arrays
+    INTEGER ::  next_array_in_list = 0   !<
+
+
+    INTERFACE pmc_childinit
+        MODULE PROCEDURE pmc_childinit
+    END INTERFACE pmc_childinit
+
+    INTERFACE pmc_c_clear_next_array_list
+        MODULE PROCEDURE pmc_c_clear_next_array_list
+    END INTERFACE pmc_c_clear_next_array_list
+
+    INTERFACE pmc_c_getbuffer
+        MODULE PROCEDURE pmc_c_getbuffer
+    END INTERFACE pmc_c_getbuffer
+
+    INTERFACE pmc_c_getnextarray
+        MODULE PROCEDURE pmc_c_getnextarray
+    END INTERFACE pmc_c_getnextarray
+
+    INTERFACE pmc_c_get_2d_index_list
+        MODULE PROCEDURE pmc_c_get_2d_index_list
+    END INTERFACE pmc_c_get_2d_index_list
+
+    INTERFACE pmc_c_putbuffer
+        MODULE PROCEDURE pmc_c_putbuffer
+    END INTERFACE pmc_c_putbuffer
+
+    INTERFACE pmc_c_setind_and_allocmem
+        MODULE PROCEDURE pmc_c_setind_and_allocmem
+    END INTERFACE pmc_c_setind_and_allocmem
+
+    INTERFACE pmc_c_set_dataarray
+        MODULE PROCEDURE pmc_c_set_dataarray_2d
+        MODULE PROCEDURE pmc_c_set_dataarray_3d
+    END INTERFACE pmc_c_set_dataarray
+
+    INTERFACE pmc_set_dataarray_name
+        MODULE PROCEDURE pmc_set_dataarray_name
+        MODULE PROCEDURE pmc_set_dataarray_name_lastentry
+    END INTERFACE pmc_set_dataarray_name
+
+
+    PUBLIC pmc_childinit, pmc_c_clear_next_array_list, pmc_c_getbuffer,         &
+           pmc_c_getnextarray, pmc_c_putbuffer, pmc_c_setind_and_allocmem,      &
+           pmc_c_set_dataarray, pmc_set_dataarray_name, pmc_c_get_2d_index_list
+
+ CONTAINS
+
+
+
+ SUBROUTINE pmc_childinit
+
+     IMPLICIT NONE
+
+     INTEGER ::  i        !<
+     INTEGER ::  istat    !<
+
+!
+!--  Get / define the MPI environment
+     me%model_comm = m_model_comm
+     me%inter_comm = m_to_parent_comm
+
+     CALL MPI_COMM_RANK( me%model_comm, me%model_rank, istat )
+     CALL MPI_COMM_SIZE( me%model_comm, me%model_npes, istat )
+     CALL MPI_COMM_REMOTE_SIZE( me%inter_comm, me%inter_npes, istat )
+
+!
+!--  Intra-communicater is used for MPI_GET
+     CALL MPI_INTERCOMM_MERGE( me%inter_comm, .TRUE., me%intra_comm, istat )
+     CALL MPI_COMM_RANK( me%intra_comm, me%intra_rank, istat )
+
+     ALLOCATE( me%pes(me%inter_npes) )
+
+!
+!--  Allocate an array of type arraydef for all parent PEs to store information
+!--  of then transfer array
+     DO  i = 1, me%inter_npes
+        ALLOCATE( me%pes(i)%array_list(pmc_max_array) )
+     ENDDO
+
+ END SUBROUTINE pmc_childinit
+
+
+
+ SUBROUTINE pmc_set_dataarray_name( parentarraydesc, parentarrayname,           &
+                                    childarraydesc, childarrayname, istat )
+
+    IMPLICIT NONE
+
+    CHARACTER(LEN=*), INTENT(IN) ::  parentarrayname  !<
+    CHARACTER(LEN=*), INTENT(IN) ::  parentarraydesc  !<
+    CHARACTER(LEN=*), INTENT(IN) ::  childarrayname   !<
+    CHARACTER(LEN=*), INTENT(IN) ::  childarraydesc   !<
+
+    INTEGER, INTENT(OUT) ::  istat  !<
+
+!
+!-- Local variables
+    TYPE(da_namedef) ::  myname  !<
+
+    INTEGER ::  mype  !<
+    INTEGER ::  my_addiarray = 0  !<
+
+
+    istat = pmc_status_ok
+
+!
+!-- Check length of array names
+    IF ( LEN( TRIM( parentarrayname) ) > da_namelen  .OR.                       &
+         LEN( TRIM( childarrayname) ) > da_namelen )  THEN
+       istat = pmc_da_name_err
+    ENDIF
+
+    IF ( m_model_rank == 0 )  THEN
+       myindex = myindex + 1
+       myname%couple_index = myIndex
+       myname%parentdesc   = TRIM( parentarraydesc )
+       myname%nameonparent = TRIM( parentarrayname )
+       myname%childdesc    = TRIM( childarraydesc )
+       myname%nameonchild  = TRIM( childarrayname )
+    ENDIF
+
+!
+!-- Broadcat to all child PEs
+!-- TODO: describe what is broadcast here and why it is done
+    CALL pmc_bcast( myname%couple_index, 0, comm=m_model_comm )
+    CALL pmc_bcast( myname%parentdesc,   0, comm=m_model_comm )
+    CALL pmc_bcast( myname%nameonparent, 0, comm=m_model_comm )
+    CALL pmc_bcast( myname%childdesc,    0, comm=m_model_comm )
+    CALL pmc_bcast( myname%nameonchild,  0, comm=m_model_comm )
+
+!
+!-- Broadcat to all parent PEs
+!-- TODO: describe what is broadcast here and why it is done
+    IF ( m_model_rank == 0 )  THEN
+        mype = MPI_ROOT
+    ELSE
+        mype = MPI_PROC_NULL
+    ENDIF
+
+    CALL pmc_bcast( myname%couple_index, mype, comm=m_to_parent_comm )
+    CALL pmc_bcast( myname%parentdesc,   mype, comm=m_to_parent_comm )
+    CALL pmc_bcast( myname%nameonparent, mype, comm=m_to_parent_comm )
+    CALL pmc_bcast( myname%childdesc,    mype, comm=m_to_parent_comm )
+    CALL pmc_bcast( myname%nameonchild,  mype, comm=m_to_parent_comm )
+
+    CALL pmc_g_setname( me, myname%couple_index, myname%nameonchild )
+
+ END SUBROUTINE pmc_set_dataarray_name
+
+
+
+ SUBROUTINE pmc_set_dataarray_name_lastentry( lastentry )
+
+    IMPLICIT NONE
+
+    LOGICAL, INTENT(IN), OPTIONAL ::  lastentry  !<
+
+!
+!-- Local variables
+    INTEGER ::  mype  !<
+    TYPE(dA_namedef) ::  myname  !<
+
+    myname%couple_index = -1
+
+    IF ( m_model_rank == 0 )  THEN
+       mype = MPI_ROOT
+    ELSE
+       mype = MPI_PROC_NULL
+    ENDIF
+
+    CALL pmc_bcast( myname%couple_index, mype, comm=m_to_parent_comm )
+
+ END SUBROUTINE pmc_set_dataarray_name_lastentry
+
+
+
+ SUBROUTINE pmc_c_get_2d_index_list
+
+    IMPLICIT NONE
+
+    INTEGER :: dummy               !<
+    INTEGER :: i, ierr, i2, j, nr  !<
+    INTEGER :: indwin              !< MPI window object
+    INTEGER :: indwin2  !          < MPI window object
+
+    INTEGER(KIND=MPI_ADDRESS_KIND) :: win_size !< Size of MPI window 1 (in bytes)
+    INTEGER(KIND=MPI_ADDRESS_KIND) :: disp     !< Displacement unit (Integer = 4, floating poit = 8
+    INTEGER(KIND=MPI_ADDRESS_KIND) :: winsize  !< Size of MPI window 2 (in bytes)
+
+    INTEGER, DIMENSION(me%inter_npes*2) :: nrele  !< Number of Elements of a
+                                                  !< horizontal slice
+    INTEGER, DIMENSION(:), POINTER ::  myind  !<
+
+    TYPE(pedef), POINTER ::  ape  !> Pointer to pedef structure
+
+
+    win_size = C_SIZEOF( dummy )
+    CALL MPI_WIN_CREATE( dummy, win_size, iwp, MPI_INFO_NULL, me%intra_comm,    &
+                         indwin, ierr )
+
+!
+!-- Open window on parent side
+!-- TODO: why is the next MPI routine called twice??
+    CALL MPI_WIN_FENCE( 0, indwin, ierr )
+
+!
+!-- Close window on parent side and open on child side
+    CALL MPI_WIN_FENCE( 0, indwin, ierr )
+
+    DO  i = 1, me%inter_npes
+       disp = me%model_rank * 2
+       CALL MPI_GET( nrele((i-1)*2+1), 2, MPI_INTEGER, i-1, disp, 2,            &
+                     MPI_INTEGER, indwin, ierr )
+    ENDDO
+
+!
+!-- MPI_GET is non-blocking -> data in nrele is not available until MPI_FENCE is
+!-- called
+    CALL MPI_WIN_FENCE( 0, indwin, ierr )
+
+!
+!-- Allocate memory for index array
+    winsize = 0
+    DO  i = 1, me%inter_npes
+       ape => me%pes(i)
+       i2 = ( i-1 ) * 2 + 1
+       nr = nrele(i2+1)
+       IF ( nr > 0 )  THEN
+          ALLOCATE( ape%locind(nr) )
+       ELSE
+          NULLIFY( ape%locind )
+       ENDIF
+       winsize = MAX( nr, winsize )
+    ENDDO
+
+    ALLOCATE( myind(2*winsize) )
+    winsize = 1
+
+!
+!-- Local buffer used in MPI_GET can but must not be inside the MPI Window.
+!-- Here, we use a dummy for the MPI window because the parent PEs do not access
+!-- the RMA window via MPI_GET or MPI_PUT
+    CALL MPI_WIN_CREATE( dummy, winsize, iwp, MPI_INFO_NULL, me%intra_comm,     &
+                         indwin2, ierr )
+
+!
+!-- MPI_GET is non-blocking -> data in nrele is not available until MPI_FENCE is
+!-- called
+!-- TODO: as before: why is this called twice??
+    CALL MPI_WIN_FENCE( 0, indwin2, ierr )
+    CALL MPI_WIN_FENCE( 0, indwin2, ierr )
+
+    DO  i = 1, me%inter_npes
+       ape => me%pes(i)
+       nr = nrele(i*2)
+       IF ( nr > 0 )  THEN
+          disp = nrele(2*(i-1)+1)
+          CALL MPI_WIN_LOCK( MPI_LOCK_SHARED , i-1, 0, indwin2, ierr )
+          CALL MPI_GET( myind, 2*nr, MPI_INTEGER, i-1, disp, 2*nr,              &
+                        MPI_INTEGER, indwin2, ierr )
+          CALL MPI_WIN_UNLOCK( i-1, indwin2, ierr )
+          DO  j = 1, nr
+             ape%locind(j)%i = myind(2*j-1)
+             ape%locind(j)%j = myind(2*j)
+          ENDDO
+          ape%nrele = nr
+       ELSE
+          ape%nrele = -1
+       ENDIF
+    ENDDO
+
+!
+!-- Don't know why, but this barrier is necessary before we can free the windows
+    CALL MPI_BARRIER( me%intra_comm, ierr )
+
+    CALL MPI_WIN_FREE( indWin,  ierr )
+    CALL MPI_WIN_FREE( indwin2, ierr )
+    DEALLOCATE( myind )
+
+ END SUBROUTINE pmc_c_get_2d_index_list
+
+
+
+ SUBROUTINE pmc_c_clear_next_array_list
+
+    IMPLICIT NONE
+
+    next_array_in_list = 0
+
+ END SUBROUTINE pmc_c_clear_next_array_list
+
+
+
+ LOGICAL FUNCTION pmc_c_getnextarray( myname )
+
+!
+!--  List handling is still required to get minimal interaction with
+!--  pmc_interface
+     CHARACTER(LEN=*), INTENT(OUT) ::  myname  !<
+
+!
+!-- Local variables
+    TYPE(pedef), POINTER    :: ape
+    TYPE(arraydef), POINTER :: ar
+
+
+    next_array_in_list = next_array_in_list + 1
+
+!
+!-- Array names are the same on all child PEs, so take first PE to get the name
+    ape => me%pes(1)
+
+!
+!-- Check if all arrays have been processed
+    IF ( next_array_in_list > ape%nr_arrays )  THEN
+       pmc_c_getnextarray = .FALSE.
+       RETURN
+    ENDIF
+
+    ar => ape%array_list( next_array_in_list )
+
+    myname = ar%name
+
+!
+!-- Return true if legal array
+!-- TODO: the case of a non-legal array does not seem to appear, so why is this
+!-- setting required at all?
+    pmc_c_getnextarray = .TRUE.
+
+ END function pmc_c_getnextarray
+
+
+
+ SUBROUTINE pmc_c_set_dataarray_2d( array )
+
+    IMPLICIT NONE
+
+    REAL(wp), INTENT(IN) , DIMENSION(:,:), POINTER ::  array  !<
+
+    INTEGER                 ::  i       !<
+    INTEGER                 ::  nrdims  !<
+    INTEGER, DIMENSION(4)   ::  dims    !<
+
+    TYPE(C_PTR)             ::  array_adr
+    TYPE(arraydef), POINTER ::  ar
+    TYPE(pedef), POINTER    ::  ape
+
+
+    dims    = 1
+    nrdims  = 2
+    dims(1) = SIZE( array, 1 )
+    dims(2) = SIZE( array, 2 )
+
+    array_adr = C_LOC( array )
+
+    DO  i = 1, me%inter_npes
+       ape => me%pes(i)
+       ar  => ape%array_list(next_array_in_list)
+       ar%nrdims = nrdims
+       ar%a_dim  = dims
+       ar%data   = array_adr
+    ENDDO
+
+ END SUBROUTINE pmc_c_set_dataarray_2d
+
+
+
+ SUBROUTINE pmc_c_set_dataarray_3d (array)
+
+    IMPLICIT NONE
+
+    REAL(wp), INTENT(IN), DIMENSION(:,:,:), POINTER ::  array  !<
+
+    INTEGER                 ::  i
+    INTEGER                 ::  nrdims
+    INTEGER, DIMENSION (4)  ::  dims
+    TYPE(C_PTR)             ::  array_adr
+    TYPE(pedef), POINTER    ::  ape
+    TYPE(arraydef), POINTER ::  ar
+
+
+    dims    = 1
+    nrdims  = 3
+    dims(1) = SIZE( array, 1 )
+    dims(2) = SIZE( array, 2 )
+    dims(3) = SIZE( array, 3 )
+
+    array_adr = C_LOC( array )
+
+    DO  i = 1, me%inter_npes
+       ape => me%pes(i)
+       ar  => ape%array_list(next_array_in_list)
+       ar%nrdims = nrdims
+       ar%a_dim  = dims
+       ar%data   = array_adr
+    ENDDO
+
+ END SUBROUTINE pmc_c_set_dataarray_3d
+
+
+
+ SUBROUTINE pmc_c_setind_and_allocmem
+
+    IMPLICIT NONE
+
+!
+!-- Naming convention for appendices:  _pc  -> parent to child transfer
+!--                                    _cp  -> child to parent transfer
+!--                                    recv -> parent to child transfer
+!--                                    send -> child to parent transfer
+    CHARACTER(LEN=da_namelen) ::  myname  !<
+
+    INTEGER ::  arlen    !<
+    INTEGER ::  myindex  !<
+    INTEGER ::  i        !<
+    INTEGER ::  ierr     !<
+    INTEGER ::  istat    !<
+    INTEGER ::  j        !<
+    INTEGER ::  rcount   !<
+    INTEGER ::  tag      !<
+
+    INTEGER, PARAMETER ::  noindex = -1  !<
+
+    INTEGER(idp)                   ::  bufsize  !< size of MPI data window
+    INTEGER(KIND=MPI_ADDRESS_KIND) ::  winsize  !<
+
+    INTEGER,DIMENSION(1024) ::  req  !<
+
+    REAL(wp), DIMENSION(:), POINTER, SAVE ::  base_array_pc  !< base array
+    REAL(wp), DIMENSION(:), POINTER, SAVE ::  base_array_cp  !< base array
+
+    TYPE(pedef), POINTER    ::  ape       !<
+    TYPE(arraydef), POINTER ::  ar        !<
+    Type(C_PTR)             ::  base_ptr  !<
+
+
+    myindex = 0
+    bufsize = 8
+
+!
+!-- Parent to child direction.
+!-- First stride: compute size and set index
+    DO  i = 1, me%inter_npes
+
+       ape => me%pes(i)
+       tag = 200
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => ape%array_list(j)
+
+!
+!--       Receive index from child
+          tag = tag + 1
+          CALL MPI_RECV( myindex, 1, MPI_INTEGER, i-1, tag, me%inter_comm,      &
+                         MPI_STATUS_IGNORE, ierr )
+          ar%recvindex = myindex
+
+!
+!--       Determine max, because child buffer is allocated only once
+!--       TODO: give a more meaningful comment
+          IF( ar%nrdims == 3 )  THEN
+             bufsize = MAX( bufsize, ar%a_dim(1)*ar%a_dim(2)*ar%a_dim(3) )
+          ELSE
+             bufsize = MAX( bufsize, ar%a_dim(1)*ar%a_dim(2) )
+          ENDIF
+
+       ENDDO
+
+    ENDDO
+
+!
+!-- Create RMA (one sided communication) data buffer.
+!-- The buffer for MPI_GET can be PE local, i.e. it can but must not be part of
+!-- the MPI RMA window
+    CALL pmc_alloc_mem( base_array_pc, bufsize, base_ptr )
+    me%totalbuffersize = bufsize*wp  ! total buffer size in byte
+
+!
+!-- Second stride: set buffer pointer
+    DO  i = 1, me%inter_npes
+
+       ape => me%pes(i)
+
+       DO  j = 1, ape%nr_arrays
+          ar => ape%array_list(j)
+          ar%recvbuf = base_ptr
+       ENDDO
+
+    ENDDO
+
+!
+!-- Child to parent direction
+    myindex = 1
+    rcount  = 0
+    bufsize = 8
+
+    DO  i = 1, me%inter_npes
+
+       ape => me%pes(i)
+       tag = 300
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => ape%array_list(j)
+          IF( ar%nrdims == 2 )  THEN
+             arlen = ape%nrele
+          ELSEIF( ar%nrdims == 3 )  THEN
+             arlen = ape%nrele*ar%a_dim(1)
+          ENDIF
+
+          tag    = tag + 1
+          rcount = rcount + 1
+          IF ( ape%nrele > 0 )  THEN
+             CALL MPI_ISEND( myindex, 1, MPI_INTEGER, i-1, tag, me%inter_comm,  &
+                             req(rcount), ierr )
+             ar%sendindex = myindex
+          ELSE
+             CALL MPI_ISEND( noindex, 1, MPI_INTEGER, i-1, tag, me%inter_comm,  &
+                             req(rcount), ierr )
+             ar%sendindex = noindex
+          ENDIF
+
+!
+!--       Maximum of 1024 outstanding requests
+!--       TODO: explain where this maximum comes from (arbitrary?)
+          IF ( rcount == 1024 )  THEN
+             CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
+             rcount = 0
+          ENDIF
+
+          IF ( ape%nrele > 0 )  THEN
+             ar%sendsize = arlen
+             myindex     = myindex + arlen
+             bufsize     = bufsize + arlen
+          ENDIF
+
+       ENDDO
+
+       IF ( rcount > 0 )  THEN
+          CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
+       ENDIF
+
+    ENDDO
+
+!
+!-- Create RMA (one sided communication) window for data buffer child to parent
+!-- transfer.
+!-- The buffer of MPI_GET (counter part of transfer) can be PE-local, i.e. it
+!-- can but must not be part of the MPI RMA window. Only one RMA window is
+!-- required to prepare the data
+!--        for parent -> child transfer on the parent side
+!-- and
+!--        for child -> parent transfer on the child side
+    CALL pmc_alloc_mem( base_array_cp, bufsize )
+    me%totalbuffersize = bufsize * wp  ! total buffer size in byte
+
+    winSize = me%totalbuffersize
+
+    CALL MPI_WIN_CREATE( base_array_cp, winsize, wp, MPI_INFO_NULL,             &
+                         me%intra_comm, me%win_parent_child, ierr )
+    CALL MPI_WIN_FENCE( 0, me%win_parent_child, ierr )
+    CALL MPI_BARRIER( me%intra_comm, ierr )
+
+!
+!-- Second stride: set buffer pointer
+    DO  i = 1, me%inter_npes
+
+       ape => me%pes(i)
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => ape%array_list(j)
+
+          IF ( ape%nrele > 0 )  THEN
+             ar%sendbuf = C_LOC( base_array_cp(ar%sendindex) )
+
+!
+!--          TODO: if this is an error to be really expected, replace the
+!--                following message by a meaningful standard PALM message using
+!--                the message-routine
+             IF ( ar%sendindex+ar%sendsize > bufsize )  THEN
+                WRITE( 0,'(a,i4,4i7,1x,a)') 'Child buffer too small ', i,       &
+                          ar%sendindex, ar%sendsize, ar%sendindex+ar%sendsize,  &
+                          bufsize, TRIM( ar%name )
+                CALL MPI_ABORT( MPI_COMM_WORLD, istat, ierr )
+             ENDIF
+          ENDIF
+
+       ENDDO
+
+    ENDDO
+
+ END SUBROUTINE pmc_c_setind_and_allocmem
+
+
+
+ SUBROUTINE pmc_c_getbuffer( waittime )
+
+    IMPLICIT NONE
+
+    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime  !<
+
+    CHARACTER(LEN=da_namelen) ::  myname  !<
+
+    INTEGER                        ::  ierr     !<
+    INTEGER                        ::  ij       !<
+    INTEGER                        ::  ip       !<
+    INTEGER                        ::  j        !<
+    INTEGER                        ::  myindex  !<
+    INTEGER                        ::  nr       !< number of elements to get
+                                                !< from parent
+    INTEGER(KIND=MPI_ADDRESS_KIND) ::  target_disp
+    INTEGER,DIMENSION(1)           ::  buf_shape
+
+    REAL(wp)                            ::  t1
+    REAL(wp)                            ::  t2
+
+    REAL(wp), POINTER, DIMENSION(:)     ::  buf
+    REAL(wp), POINTER, DIMENSION(:,:)   ::  data_2d
+    REAL(wp), POINTER, DIMENSION(:,:,:) ::  data_3d
+    TYPE(pedef), POINTER                ::  ape
+    TYPE(arraydef), POINTER             ::  ar
+
+!
+!-- Synchronization of the model is done in pmci_synchronize. 
+!-- Therefore the RMA window can be filled without
+!-- sychronization at this point and a barrier is not necessary.
+!-- Please note that waittime has to be set in pmc_s_fillbuffer AND
+!-- pmc_c_getbuffer
+    IF ( PRESENT( waittime ) )  THEN
+       t1 = pmc_time()
+       CALL MPI_BARRIER( me%intra_comm, ierr )
+       t2 = pmc_time()
+       waittime = t2 - t1
+    ENDIF
+
+!
+!-- Wait for buffer is filled.
+!-- TODO: explain in more detail what is happening here. The barrier seems to
+!-- contradict what is said a few lines before (i.e. that no barrier is necessary)
+!-- TODO: In case of PRESENT( waittime ) the barrrier would be calles twice. Why?
+!-- Shouldn't it be done the same way as in pmc_putbuffer?
+    CALL MPI_BARRIER( me%intra_comm, ierr )
+
+    DO  ip = 1, me%inter_npes
+
+       ape => me%pes(ip)
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => ape%array_list(j)
+
+          IF ( ar%nrdims == 2 )  THEN
+             nr = ape%nrele
+          ELSEIF ( ar%nrdims == 3 )  THEN
+             nr = ape%nrele * ar%a_dim(1)
+          ENDIF
+
+          buf_shape(1) = nr
+          CALL C_F_POINTER( ar%recvbuf, buf, buf_shape )
+
+!
+!--       MPI passive target RMA
+!--       TODO: explain the above comment
+          IF ( nr > 0 )  THEN
+             target_disp = ar%recvindex - 1
+             CALL MPI_WIN_LOCK( MPI_LOCK_SHARED , ip-1, 0,                      &
+                                me%win_parent_child, ierr )
+             CALL MPI_GET( buf, nr, MPI_REAL, ip-1, target_disp, nr, MPI_REAL,  &
+                                me%win_parent_child, ierr )
+             CALL MPI_WIN_UNLOCK( ip-1, me%win_parent_child, ierr )
+          ENDIF
+
+          myindex = 1
+          IF ( ar%nrdims == 2 )  THEN
+
+             CALL C_F_POINTER( ar%data, data_2d, ar%a_dim(1:2) )
+
+             DO  ij = 1, ape%nrele
+                data_2d(ape%locind(ij)%j,ape%locind(ij)%i) = buf(myindex)
+                myindex = myindex + 1
+             ENDDO
+
+          ELSEIF ( ar%nrdims == 3 )  THEN
+
+             CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3) )
+
+             DO  ij = 1, ape%nrele
+                data_3d(:,ape%locind(ij)%j,ape%locind(ij)%i) =                  &
+                                              buf(myindex:myindex+ar%a_dim(1)-1)
+                myindex = myindex+ar%a_dim(1)
+             ENDDO
+
+          ENDIF
+
+       ENDDO
+
+    ENDDO
+
+ END SUBROUTINE pmc_c_getbuffer
+
+
+
+ SUBROUTINE pmc_c_putbuffer( waittime )
+
+    IMPLICIT NONE
+
+    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime  !<
+
+    CHARACTER(LEN=da_namelen) ::  myname  !<
+
+    INTEGER                        ::  ierr         !<
+    INTEGER                        ::  ij           !<
+    INTEGER                        ::  ip           !<
+    INTEGER                        ::  j            !<
+    INTEGER                        ::  myindex      !<
+    INTEGER                        ::  nr           !< number of elements to get
+                                                    !< from parent
+    INTEGER(KIND=MPI_ADDRESS_KIND) ::  target_disp  !<
+
+    INTEGER, DIMENSION(1)          ::  buf_shape    !<
+
+    REAL(wp) ::  t1  !<
+    REAL(wp) ::  t2  !<
+
+    REAL(wp), POINTER, DIMENSION(:)     ::  buf      !<
+    REAL(wp), POINTER, DIMENSION(:,:)   ::  data_2d  !<
+    REAL(wp), POINTER, DIMENSION(:,:,:) ::  data_3d  !<
+
+    TYPE(pedef), POINTER               ::  ape  !<
+    TYPE(arraydef), POINTER            ::  ar   !<
+
+!
+!-- Wait for empty buffer
+!-- TODO: explain what is done here
+    t1 = pmc_time()
+    CALL MPI_BARRIER( me%intra_comm, ierr )
+    t2 = pmc_time()
+    IF ( PRESENT( waittime ) )  waittime = t2 - t1
+
+    DO  ip = 1, me%inter_npes
+
+       ape => me%pes(ip)
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => aPE%array_list(j)
+          myindex = 1
+
+          IF ( ar%nrdims == 2 )  THEN
+
+             buf_shape(1) = ape%nrele
+             CALL C_F_POINTER( ar%sendbuf, buf,     buf_shape     )
+             CALL C_F_POINTER( ar%data,    data_2d, ar%a_dim(1:2) )
+
+             DO  ij = 1, ape%nrele
+                buf(myindex) = data_2d(ape%locind(ij)%j,ape%locind(ij)%i)
+                myindex = myindex + 1
+             ENDDO
+
+          ELSEIF ( ar%nrdims == 3 )  THEN
+
+             buf_shape(1) = ape%nrele*ar%a_dim(1)
+             CALL C_F_POINTER( ar%sendbuf, buf,     buf_shape     )
+             CALL C_F_POINTER( ar%data,    data_3d, ar%a_dim(1:3) )
+
+             DO  ij = 1, ape%nrele
+                buf(myindex:myindex+ar%a_dim(1)-1) =                            &
+                                    data_3d(:,ape%locind(ij)%j,ape%locind(ij)%i)
+                myindex = myindex + ar%a_dim(1)
+             ENDDO
+
+          ENDIF
+
+       ENDDO
+
+    ENDDO
+
+!
+!-- TODO: Fence might do it, test later
+!-- Call MPI_WIN_FENCE( 0, me%win_parent_child, ierr)      !
+!
+!-- Buffer is filled
+!-- TODO: explain in more detail what is happening here
+    CALL MPI_Barrier(me%intra_comm, ierr)
+
+ END SUBROUTINE pmc_c_putbuffer
+
+#endif
+ END MODULE pmc_child
Index: palm/trunk/SOURCE/pmc_client_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_client_mod.f90	(revision 1932)
+++ 	(revision )
@@ -1,877 +1,0 @@
-MODULE pmc_client
-
-!--------------------------------------------------------------------------------!
-! This file is part of PALM.
-!
-! 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-2016 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------!
-!
-! Current revisions:
-! ------------------
-! 
-!
-! Former revisions:
-! -----------------
-! $Id$
-!
-! 1896 2016-05-03 08:06:41Z raasch
-! re-formatted to match PALM style
-!
-! 1850 2016-04-08 13:29:27Z maronga
-! Module renamed
-! 
-! 
-! 1833 2016-04-07 14:23:03Z raasch
-! gfortran requires pointer attributes for some array declarations,
-! long line wrapped
-!
-! 1808 2016-04-05 19:44:00Z raasch
-! MPI module used by default on all machines
-!
-! 1797 2016-03-21 16:50:28Z raasch
-! introduction of different datatransfer modes
-!
-! 1791 2016-03-11 10:41:25Z raasch
-! Debug write-statement commented out
-!
-! 1786 2016-03-08 05:49:27Z raasch
-! change in client-server data transfer: server now gets data from client
-! instead that client put's it to the server
-!
-! 1783 2016-03-06 18:36:17Z raasch
-! Bugfix: wrong data-type in MPI_WIN_CREATE replaced
-!
-! 1779 2016-03-03 08:01:28Z raasch
-! kind=dp replaced by wp, dim_order removed
-! array management changed from linked list to sequential loop
-!
-! 1764 2016-02-28 12:45:19Z raasch
-! cpp-statement added (nesting can only be used in parallel mode),
-! all kinds given in PALM style
-!
-! 1762 2016-02-25 12:31:13Z hellstea
-! Initial revision by K. Ketelsen
-!
-! Description:
-! ------------
-!
-! Client part of Palm Model Coupler
-!------------------------------------------------------------------------------!
-
-#if defined( __parallel )
-
-    USE, INTRINSIC ::  iso_c_binding
-
-#if defined( __mpifh )
-    INCLUDE "mpif.h"
-#else
-    USE MPI
-#endif
-
-    USE kinds
-    USE pmc_general,                                                           &
-        ONLY:  arraydef, clientdef, da_desclen, da_namedef, da_namelen, pedef, &
-               pmc_da_name_err,  pmc_g_setname, pmc_max_array, pmc_status_ok
-
-    USE pmc_handle_communicator,                                               &
-        ONLY:  m_model_comm, m_model_npes, m_model_rank, m_to_server_comm
-
-    USE pmc_mpi_wrapper,                                                       &
-        ONLY:  pmc_alloc_mem, pmc_bcast, pmc_inter_bcast,                      &
-               pmc_recv_from_server, pmc_send_to_server, pmc_time
-
-    IMPLICIT NONE
-
-    PRIVATE
-    SAVE
-
-    TYPE(clientdef) ::  me   !<
-
-    INTEGER ::  myindex = 0         !< counter and unique number for data arrays
-    INTEGER ::  next_array_in_list = 0   !<
-
-
-    INTERFACE pmc_clientinit
-        MODULE PROCEDURE pmc_clientinit
-    END INTERFACE PMC_ClientInit
-
-    INTERFACE pmc_c_clear_next_array_list
-        MODULE PROCEDURE pmc_c_clear_next_array_list
-    END INTERFACE pmc_c_clear_next_array_list
-
-    INTERFACE pmc_c_getbuffer
-        MODULE PROCEDURE pmc_c_getbuffer
-    END INTERFACE pmc_c_getbuffer
-
-    INTERFACE pmc_c_getnextarray
-        MODULE PROCEDURE pmc_c_getnextarray
-    END INTERFACE pmc_c_getnextarray
-
-    INTERFACE pmc_c_get_2d_index_list
-        MODULE PROCEDURE pmc_c_get_2d_index_list
-    END INTERFACE pmc_c_get_2d_index_list
-
-    INTERFACE pmc_c_putbuffer
-        MODULE PROCEDURE pmc_c_putbuffer
-    END INTERFACE pmc_c_putbuffer
-
-    INTERFACE pmc_c_setind_and_allocmem
-        MODULE PROCEDURE pmc_c_setind_and_allocmem
-    END INTERFACE pmc_c_setind_and_allocmem
-
-    INTERFACE pmc_c_set_dataarray
-        MODULE PROCEDURE pmc_c_set_dataarray_2d
-        MODULE PROCEDURE pmc_c_set_dataarray_3d
-    END INTERFACE pmc_c_set_dataarray
-
-    INTERFACE pmc_set_dataarray_name
-        MODULE PROCEDURE pmc_set_dataarray_name
-        MODULE PROCEDURE pmc_set_dataarray_name_lastentry
-    END INTERFACE pmc_set_dataarray_name
-
-
-    PUBLIC pmc_clientinit, pmc_c_clear_next_array_list, pmc_c_getbuffer,       &
-           pmc_c_getnextarray, pmc_c_putbuffer, pmc_c_setind_and_allocmem,     &
-           pmc_c_set_dataarray, pmc_set_dataarray_name, pmc_c_get_2d_index_list
-
- CONTAINS
-
-
-
- SUBROUTINE pmc_clientinit
-
-     IMPLICIT NONE
-
-     INTEGER ::  i        !<
-     INTEGER ::  istat    !<
-
-!
-!--  Get / define the MPI environment
-     me%model_comm = m_model_comm
-     me%inter_comm = m_to_server_comm
-
-     CALL MPI_COMM_RANK( me%model_comm, me%model_rank, istat )
-     CALL MPI_COMM_SIZE( me%model_comm, me%model_npes, istat )
-     CALL MPI_COMM_REMOTE_SIZE( me%inter_comm, me%inter_npes, istat )
-!
-!--  Intra-communicater is used for MPI_GET
-     CALL MPI_INTERCOMM_MERGE( me%inter_comm, .TRUE., me%intra_comm, istat )
-     CALL MPI_COMM_RANK( me%intra_comm, me%intra_rank, istat )
-
-     ALLOCATE( me%pes(me%inter_npes) )
-
-!
-!--  Allocate an array of type arraydef for all server PEs to store information
-!--  of then transfer array
-     DO  i = 1, me%inter_npes
-        ALLOCATE( me%pes(i)%array_list(pmc_max_array) )
-     ENDDO
-
- END SUBROUTINE pmc_clientinit
-
-
-
- SUBROUTINE pmc_set_dataarray_name( serverarraydesc, serverarrayname,          &
-                                    clientarraydesc, clientarrayname, istat )
-
-    IMPLICIT NONE
-
-    CHARACTER(LEN=*), INTENT(IN) ::  serverarrayname  !<
-    CHARACTER(LEN=*), INTENT(IN) ::  serverarraydesc  !<
-    CHARACTER(LEN=*), INTENT(IN) ::  clientarrayname  !<
-    CHARACTER(LEN=*), INTENT(IN) ::  clientarraydesc  !<
-
-    INTEGER, INTENT(OUT) ::  istat  !<
-
-!
-!-- Local variables
-    TYPE(da_namedef) ::  myname  !<
-
-    INTEGER ::  mype  !<
-    INTEGER ::  my_addiarray = 0  !<
-
-
-    istat = pmc_status_ok
-!
-!-- Check length of array names
-    IF ( LEN( TRIM( serverarrayname) ) > da_namelen  .OR.                     &
-         LEN( TRIM( clientarrayname) ) > da_namelen )  THEN
-       istat = pmc_da_name_err
-    ENDIF
-
-    IF ( m_model_rank == 0 )  THEN
-       myindex = myindex + 1
-       myname%couple_index = myIndex
-       myname%serverdesc   = TRIM( serverarraydesc )
-       myname%nameonserver = TRIM( serverarrayname )
-       myname%clientdesc   = TRIM( clientarraydesc )
-       myname%nameonclient = TRIM( clientarrayname )
-    ENDIF
-
-!
-!-- Broadcat to all client PEs
-!-- TODO: describe what is broadcast here and why it is done
-    CALL pmc_bcast( myname%couple_index, 0, comm=m_model_comm )
-    CALL pmc_bcast( myname%serverdesc,   0, comm=m_model_comm )
-    CALL pmc_bcast( myname%nameonserver, 0, comm=m_model_comm )
-    CALL pmc_bcast( myname%clientdesc,   0, comm=m_model_comm )
-    CALL pmc_bcast( myname%nameonclient, 0, comm=m_model_comm )
-
-!
-!-- Broadcat to all server PEs
-!-- TODO: describe what is broadcast here and why it is done
-    IF ( m_model_rank == 0 )  THEN
-        mype = MPI_ROOT
-    ELSE
-        mype = MPI_PROC_NULL
-    ENDIF
-
-    CALL pmc_bcast( myname%couple_index, mype, comm=m_to_server_comm )
-    CALL pmc_bcast( myname%serverdesc,   mype, comm=m_to_server_comm )
-    CALL pmc_bcast( myname%nameonserver, mype, comm=m_to_server_comm )
-    CALL pmc_bcast( myname%clientdesc,   mype, comm=m_to_server_comm )
-    CALL pmc_bcast( myname%nameonclient, mype, comm=m_to_server_comm )
-
-    CALL pmc_g_setname( me, myname%couple_index, myname%nameonclient )
-
- END SUBROUTINE pmc_set_dataarray_name
-
-
-
- SUBROUTINE pmc_set_dataarray_name_lastentry( lastentry )
-
-    IMPLICIT NONE
-
-    LOGICAL, INTENT(IN), OPTIONAL ::  lastentry  !<
-
-!
-!-- Local variables
-    INTEGER ::  mype  !<
-    TYPE(dA_namedef) ::  myname  !<
-
-    myname%couple_index = -1
-
-    IF ( m_model_rank == 0 )  THEN
-       mype = MPI_ROOT
-    ELSE
-       mype = MPI_PROC_NULL
-    ENDIF
-
-    CALL pmc_bcast( myname%couple_index, mype, comm=m_to_server_comm )
-
- END SUBROUTINE pmc_set_dataarray_name_lastentry
-
-
-
- SUBROUTINE pmc_c_get_2d_index_list
-
-    IMPLICIT NONE
-
-    INTEGER :: dummy               !<
-    INTEGER :: i, ierr, i2, j, nr  !<
-    INTEGER :: indwin              !< MPI window object
-    INTEGER :: indwin2  !          < MPI window object
-
-    INTEGER(KIND=MPI_ADDRESS_KIND) :: win_size !< Size of MPI window 1 (in bytes)
-    INTEGER(KIND=MPI_ADDRESS_KIND) :: disp     !< Displacement unit (Integer = 4, floating poit = 8
-    INTEGER(KIND=MPI_ADDRESS_KIND) :: winsize  !< Size of MPI window 2 (in bytes)
-
-    INTEGER, DIMENSION(me%inter_npes*2) :: nrele  !< Number of Elements of a
-                                                  !< horizontal slice
-    INTEGER, DIMENSION(:), POINTER ::  myind  !<
-
-    TYPE(pedef), POINTER ::  ape  !> Pointer to pedef structure
-
-
-    win_size = C_SIZEOF( dummy )
-    CALL MPI_WIN_CREATE( dummy, win_size, iwp, MPI_INFO_NULL, me%intra_comm,   &
-                         indwin, ierr )
-!
-!-- Open window on server side
-!-- TODO: why is the next MPI routine called twice??
-    CALL MPI_WIN_FENCE( 0, indwin, ierr )
-!
-!-- Close window on server side and open on client side
-    CALL MPI_WIN_FENCE( 0, indwin, ierr )
-
-    DO  i = 1, me%inter_npes
-       disp = me%model_rank * 2
-       CALL MPI_GET( nrele((i-1)*2+1), 2, MPI_INTEGER, i-1, disp, 2,           &
-                     MPI_INTEGER, indwin, ierr )
-    ENDDO
-!
-!-- MPI_GET is non-blocking -> data in nrele is not available until MPI_FENCE is
-!-- called
-    CALL MPI_WIN_FENCE( 0, indwin, ierr )
-
-!
-!-- Allocate memory for index array
-    winsize = 0
-    DO  i = 1, me%inter_npes
-       ape => me%pes(i)
-       i2 = ( i-1 ) * 2 + 1
-       nr = nrele(i2+1)
-       IF ( nr > 0 )  THEN
-          ALLOCATE( ape%locind(nr) )
-       ELSE
-          NULLIFY( ape%locind )
-       ENDIF
-       winsize = MAX( nr, winsize )
-    ENDDO
-
-    ALLOCATE( myind(2*winsize) )
-    winsize = 1
-
-!
-!-- Local buffer used in MPI_GET can but must not be inside the MPI Window.
-!-- Here, we use a dummy for the MPI window because the server PEs do not access
-!-- the RMA window via MPI_GET or MPI_PUT
-    CALL MPI_WIN_CREATE( dummy, winsize, iwp, MPI_INFO_NULL, me%intra_comm,    &
-                         indwin2, ierr )
-!
-!-- MPI_GET is non-blocking -> data in nrele is not available until MPI_FENCE is
-!-- called
-!-- TODO: as before: why is this called twice??
-    CALL MPI_WIN_FENCE( 0, indwin2, ierr )
-    CALL MPI_WIN_FENCE( 0, indwin2, ierr )
-
-    DO  i = 1, me%inter_npes
-       ape => me%pes(i)
-       nr = nrele(i*2)
-       IF ( nr > 0 )  THEN
-          disp = nrele(2*(i-1)+1)
-          CALL MPI_WIN_LOCK( MPI_LOCK_SHARED , i-1, 0, indwin2, ierr )
-          CALL MPI_GET( myind, 2*nr, MPI_INTEGER, i-1, disp, 2*nr,             &
-                        MPI_INTEGER, indwin2, ierr )
-          CALL MPI_WIN_UNLOCK( i-1, indwin2, ierr )
-          DO  j = 1, nr
-             ape%locind(j)%i = myind(2*j-1)
-             ape%locind(j)%j = myind(2*j)
-          ENDDO
-          ape%nrele = nr
-       ELSE
-          ape%nrele = -1
-       ENDIF
-    ENDDO
-
-!
-!-- Don't know why, but this barrier is necessary before we can free the windows
-    CALL MPI_BARRIER( me%intra_comm, ierr )
-
-    CALL MPI_WIN_FREE( indWin,  ierr )
-    CALL MPI_WIN_FREE( indwin2, ierr )
-    DEALLOCATE( myind )
-
- END SUBROUTINE pmc_c_get_2d_index_list
-
-
-
- SUBROUTINE pmc_c_clear_next_array_list
-
-    IMPLICIT NONE
-
-    next_array_in_list = 0
-
- END SUBROUTINE pmc_c_clear_next_array_list
-
-
-
- LOGICAL FUNCTION pmc_c_getnextarray( myname )
-!
-!--  List handling is still required to get minimal interaction with
-!--  pmc_interface
-     CHARACTER(LEN=*), INTENT(OUT) ::  myname  !<
-
-!
-!-- Local variables
-    TYPE(pedef), POINTER    :: ape
-    TYPE(arraydef), POINTER :: ar
-
-
-    next_array_in_list = next_array_in_list + 1
-
-!
-!-- Array names are the same on all client PEs, so take first PE to get the name
-    ape => me%pes(1)
-!
-!-- Check if all arrays have been processed
-    IF ( next_array_in_list > ape%nr_arrays )  THEN
-       pmc_c_getnextarray = .FALSE.
-       RETURN
-    ENDIF
-
-    ar => ape%array_list( next_array_in_list )
-
-    myname = ar%name
-
-!
-!-- Return true if legal array
-!-- TODO: the case of a non-legal array does not seem to appear, so why is this
-!-- setting required at all?
-    pmc_c_getnextarray = .TRUE.
-
- END function pmc_c_getnextarray
-
-
-
- SUBROUTINE pmc_c_set_dataarray_2d( array )
-
-    IMPLICIT NONE
-
-    REAL(wp), INTENT(IN) , DIMENSION(:,:), POINTER ::  array  !<
-
-    INTEGER                 ::  i       !<
-    INTEGER                 ::  nrdims  !<
-    INTEGER, DIMENSION(4)   ::  dims    !<
-
-    TYPE(C_PTR)             ::  array_adr
-    TYPE(arraydef), POINTER ::  ar
-    TYPE(pedef), POINTER    ::  ape
-
-
-    dims    = 1
-    nrdims  = 2
-    dims(1) = SIZE( array, 1 )
-    dims(2) = SIZE( array, 2 )
-
-    array_adr = C_LOC( array )
-
-    DO  i = 1, me%inter_npes
-       ape => me%pes(i)
-       ar  => ape%array_list(next_array_in_list)
-       ar%nrdims = nrdims
-       ar%a_dim  = dims
-       ar%data   = array_adr
-    ENDDO
-
- END SUBROUTINE pmc_c_set_dataarray_2d
-
-
-
- SUBROUTINE pmc_c_set_dataarray_3d (array)
-
-    IMPLICIT NONE
-
-    REAL(wp), INTENT(IN), DIMENSION(:,:,:), POINTER ::  array  !<
-
-    INTEGER                 ::  i
-    INTEGER                 ::  nrdims
-    INTEGER, DIMENSION (4)  ::  dims
-    TYPE(C_PTR)             ::  array_adr
-    TYPE(pedef), POINTER    ::  ape
-    TYPE(arraydef), POINTER ::  ar
-
-
-    dims    = 1
-    nrdims  = 3
-    dims(1) = SIZE( array, 1 )
-    dims(2) = SIZE( array, 2 )
-    dims(3) = SIZE( array, 3 )
-
-    array_adr = C_LOC( array )
-
-    DO  i = 1, me%inter_npes
-       ape => me%pes(i)
-       ar  => ape%array_list(next_array_in_list)
-       ar%nrdims = nrdims
-       ar%a_dim  = dims
-       ar%data   = array_adr
-    ENDDO
-
- END SUBROUTINE pmc_c_set_dataarray_3d
-
-
-
- SUBROUTINE pmc_c_setind_and_allocmem
-
-    IMPLICIT NONE
-!
-!-- Naming convention for appendices:  _sc  -> server to client transfer
-!--                                    _cs  -> client to server transfer
-!--                                    recv -> server to client transfer
-!--                                    send -> client to server transfer
-    CHARACTER(LEN=da_namelen) ::  myname  !<
-
-    INTEGER ::  arlen    !<
-    INTEGER ::  myindex  !<
-    INTEGER ::  i        !<
-    INTEGER ::  ierr     !<
-    INTEGER ::  istat    !<
-    INTEGER ::  j        !<
-    INTEGER ::  rcount   !<
-    INTEGER ::  tag      !<
-
-    INTEGER, PARAMETER ::  noindex = -1  !<
-
-    INTEGER(idp)                   ::  bufsize  !< size of MPI data window
-    INTEGER(KIND=MPI_ADDRESS_KIND) ::  winsize  !<
-
-    INTEGER,DIMENSION(1024) ::  req  !<
-
-    REAL(wp), DIMENSION(:), POINTER, SAVE ::  base_array_sc  !< base array
-    REAL(wp), DIMENSION(:), POINTER, SAVE ::  base_array_cs  !< base array
-
-    TYPE(pedef), POINTER    ::  ape       !<
-    TYPE(arraydef), POINTER ::  ar        !<
-    Type(C_PTR)             ::  base_ptr  !<
-
-
-    myindex = 0
-    bufsize = 8
-
-!
-!-- Server to client direction.
-!-- First stride: compute size and set index
-    DO  i = 1, me%inter_npes
-
-       ape => me%pes(i)
-       tag = 200
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => ape%array_list(j)
-!
-!--       Receive index from client
-          tag = tag + 1
-          CALL MPI_RECV( myindex, 1, MPI_INTEGER, i-1, tag, me%inter_comm,     &
-                         MPI_STATUS_IGNORE, ierr )
-          ar%recvindex = myindex
-!
-!--       Determine max, because client buffer is allocated only once
-!--       TODO: give a more meaningful comment
-          IF( ar%nrdims == 3 )  THEN
-             bufsize = MAX( bufsize, ar%a_dim(1)*ar%a_dim(2)*ar%a_dim(3) )
-          ELSE
-             bufsize = MAX( bufsize, ar%a_dim(1)*ar%a_dim(2) )
-          ENDIF
-
-       ENDDO
-
-    ENDDO
-
-!
-!-- Create RMA (one sided communication) data buffer.
-!-- The buffer for MPI_GET can be PE local, i.e. it can but must not be part of
-!-- the MPI RMA window
-    CALL pmc_alloc_mem( base_array_sc, bufsize, base_ptr )
-    me%totalbuffersize = bufsize*wp  ! total buffer size in byte
-
-!
-!-- Second stride: set buffer pointer
-    DO  i = 1, me%inter_npes
-
-       ape => me%pes(i)
-
-       DO  j = 1, ape%nr_arrays
-          ar => ape%array_list(j)
-          ar%recvbuf = base_ptr
-       ENDDO
-
-    ENDDO
-
-!
-!-- Client to server direction
-    myindex = 1
-    rcount  = 0
-    bufsize = 8
-
-    DO  i = 1, me%inter_npes
-
-       ape => me%pes(i)
-       tag = 300
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => ape%array_list(j)
-          IF( ar%nrdims == 2 )  THEN
-             arlen = ape%nrele
-          ELSEIF( ar%nrdims == 3 )  THEN
-             arlen = ape%nrele*ar%a_dim(1)
-          ENDIF
-
-          tag    = tag + 1
-          rcount = rcount + 1
-          IF ( ape%nrele > 0 )  THEN
-             CALL MPI_ISEND( myindex, 1, MPI_INTEGER, i-1, tag, me%inter_comm, &
-                             req(rcount), ierr )
-             ar%sendindex = myindex
-          ELSE
-             CALL MPI_ISEND( noindex, 1, MPI_INTEGER, i-1, tag, me%inter_comm, &
-                             req(rcount), ierr )
-             ar%sendindex = noindex
-          ENDIF
-!
-!--       Maximum of 1024 outstanding requests
-!--       TODO: explain where this maximum comes from (arbitrary?)
-          IF ( rcount == 1024 )  THEN
-             CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
-             rcount = 0
-          ENDIF
-
-          IF ( ape%nrele > 0 )  THEN
-             ar%sendsize = arlen
-             myindex     = myindex + arlen
-             bufsize     = bufsize + arlen
-          ENDIF
-
-       ENDDO
-
-       IF ( rcount > 0 )  THEN
-          CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
-       ENDIF
-
-    ENDDO
-
-!
-!-- Create RMA (one sided communication) window for data buffer client to server
-!-- transfer.
-!-- The buffer of MPI_GET (counter part of transfer) can be PE-local, i.e. it
-!-- can but must not be part of the MPI RMA window. Only one RMA window is
-!-- required to prepare the data
-!--        for server -> client transfer on the server side
-!-- and
-!--        for client -> server transfer on the client side
-
-    CALL pmc_alloc_mem( base_array_cs, bufsize )
-    me%totalbuffersize = bufsize * wp  ! total buffer size in byte
-
-    winSize = me%totalbuffersize
-
-    CALL MPI_WIN_CREATE( base_array_cs, winsize, wp, MPI_INFO_NULL,            &
-                         me%intra_comm, me%win_server_client, ierr )
-    CALL MPI_WIN_FENCE( 0, me%win_server_client, ierr )
-    CALL MPI_BARRIER( me%intra_comm, ierr )
-
-!
-!-- Second stride: set buffer pointer
-    DO  i = 1, me%inter_npes
-
-       ape => me%pes(i)
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => ape%array_list(j)
-
-          IF ( ape%nrele > 0 )  THEN
-             ar%sendbuf = C_LOC( base_array_cs(ar%sendindex) )
-!--          TODO: if this is an error to be really expected, replace the
-!--                following message by a meaningful standard PALM message using
-!--                the message-routine
-             IF ( ar%sendindex+ar%sendsize > bufsize )  THEN
-                WRITE( 0,'(a,i4,4i7,1x,a)') 'Client Buffer too small ', i,     &
-                          ar%sendindex, ar%sendsize, ar%sendindex+ar%sendsize, &
-                          bufsize, TRIM( ar%name )
-                CALL MPI_ABORT( MPI_COMM_WORLD, istat, ierr )
-             ENDIF
-          ENDIF
-
-       ENDDO
-
-    ENDDO
-
- END SUBROUTINE pmc_c_setind_and_allocmem
-
-
-
- SUBROUTINE pmc_c_getbuffer( waittime )
-
-    IMPLICIT NONE
-
-    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime  !<
-
-    CHARACTER(LEN=da_namelen) ::  myname  !<
-
-    INTEGER                        ::  ierr     !<
-    INTEGER                        ::  ij       !<
-    INTEGER                        ::  ip       !<
-    INTEGER                        ::  j        !<
-    INTEGER                        ::  myindex  !<
-    INTEGER                        ::  nr       !< number of elements to get
-                                                !< from server
-    INTEGER(KIND=MPI_ADDRESS_KIND) ::  target_disp
-    INTEGER,DIMENSION(1)           ::  buf_shape
-
-    REAL(wp)                            ::  t1
-    REAL(wp)                            ::  t2
-
-    REAL(wp), POINTER, DIMENSION(:)     ::  buf
-    REAL(wp), POINTER, DIMENSION(:,:)   ::  data_2d
-    REAL(wp), POINTER, DIMENSION(:,:,:) ::  data_3d
-    TYPE(pedef), POINTER                ::  ape
-    TYPE(arraydef), POINTER             ::  ar
-
-!
-!-- Synchronization of the model is done in pmci_client_synchronize and
-!-- pmci_server_synchronize. Therefor the RMA window can be filled without
-!-- sychronization at this point and a barrier is not necessary.
-!-- Please note that waittime has to be set in pmc_s_fillbuffer AND
-!-- pmc_c_getbuffer
-    IF ( PRESENT( waittime ) )  THEN
-       t1 = pmc_time()
-       CALL MPI_BARRIER( me%intra_comm, ierr )
-       t2 = pmc_time()
-       waittime = t2 - t1
-    ENDIF
-!
-!-- Wait for buffer is filled
-!-- TODO: explain in more detail what is happening here. The barrier seems to
-!-- contradict what is said a few lines beforer (i.e. that no barrier is necessary)
-!-- TODO: In case of PRESENT( waittime ) the barrrier would be calles twice. Why?
-!-- Shouldn't it be done the same way as in pmc_putbuffer?
-    CALL MPI_BARRIER( me%intra_comm, ierr )
-
-    DO  ip = 1, me%inter_npes
-
-       ape => me%pes(ip)
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => ape%array_list(j)
-
-          IF ( ar%nrdims == 2 )  THEN
-             nr = ape%nrele
-          ELSEIF ( ar%nrdims == 3 )  THEN
-             nr = ape%nrele * ar%a_dim(1)
-          ENDIF
-
-          buf_shape(1) = nr
-          CALL C_F_POINTER( ar%recvbuf, buf, buf_shape )
-!
-!--       MPI passive target RMA
-!--       TODO: explain the above comment
-          IF ( nr > 0 )  THEN
-             target_disp = ar%recvindex - 1
-             CALL MPI_WIN_LOCK( MPI_LOCK_SHARED , ip-1, 0,                     &
-                                me%win_server_client, ierr )
-             CALL MPI_GET( buf, nr, MPI_REAL, ip-1, target_disp, nr, MPI_REAL, &
-                                me%win_server_client, ierr )
-             CALL MPI_WIN_UNLOCK( ip-1, me%win_server_client, ierr )
-          ENDIF
-
-          myindex = 1
-          IF ( ar%nrdims == 2 )  THEN
-
-             CALL C_F_POINTER( ar%data, data_2d, ar%a_dim(1:2) )
-
-             DO  ij = 1, ape%nrele
-                data_2d(ape%locind(ij)%j,ape%locind(ij)%i) = buf(myindex)
-                myindex = myindex + 1
-             ENDDO
-
-          ELSEIF ( ar%nrdims == 3 )  THEN
-
-             CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3) )
-
-             DO  ij = 1, ape%nrele
-                data_3d(:,ape%locind(ij)%j,ape%locind(ij)%i) =                 &
-                                              buf(myindex:myindex+ar%a_dim(1)-1)
-                myindex = myindex+ar%a_dim(1)
-             ENDDO
-
-          ENDIF
-
-       ENDDO
-
-    ENDDO
-
- END SUBROUTINE pmc_c_getbuffer
-
-
-
- SUBROUTINE pmc_c_putbuffer( waittime )
-
-    IMPLICIT NONE
-
-    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime  !<
-
-    CHARACTER(LEN=da_namelen) ::  myname  !<
-
-    INTEGER                        ::  ierr         !<
-    INTEGER                        ::  ij           !<
-    INTEGER                        ::  ip           !<
-    INTEGER                        ::  j            !<
-    INTEGER                        ::  myindex      !<
-    INTEGER                        ::  nr           !< number of elements to get
-                                                    !< from server
-    INTEGER(KIND=MPI_ADDRESS_KIND) ::  target_disp  !<
-
-    INTEGER, DIMENSION(1)          ::  buf_shape    !<
-
-    REAL(wp) ::  t1  !<
-    REAL(wp) ::  t2  !<
-
-    REAL(wp), POINTER, DIMENSION(:)     ::  buf      !<
-    REAL(wp), POINTER, DIMENSION(:,:)   ::  data_2d  !<
-    REAL(wp), POINTER, DIMENSION(:,:,:) ::  data_3d  !<
-
-    TYPE(pedef), POINTER               ::  ape  !<
-    TYPE(arraydef), POINTER            ::  ar   !<
-
-!
-!-- Wait for empty buffer
-!-- TODO: explain what is done here
-    t1 = pmc_time()
-    CALL MPI_BARRIER( me%intra_comm, ierr )
-    t2 = pmc_time()
-    IF ( PRESENT( waittime ) )  waittime = t2 - t1
-
-    DO  ip = 1, me%inter_npes
-
-       ape => me%pes(ip)
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => aPE%array_list(j)
-          myindex = 1
-
-          IF ( ar%nrdims == 2 )  THEN
-
-             buf_shape(1) = ape%nrele
-             CALL C_F_POINTER( ar%sendbuf, buf,     buf_shape     )
-             CALL C_F_POINTER( ar%data,    data_2d, ar%a_dim(1:2) )
-
-             DO  ij = 1, ape%nrele
-                buf(myindex) = data_2d(ape%locind(ij)%j,ape%locind(ij)%i)
-                myindex = myindex + 1
-             ENDDO
-
-          ELSEIF ( ar%nrdims == 3 )  THEN
-
-             buf_shape(1) = ape%nrele*ar%a_dim(1)
-             CALL C_F_POINTER( ar%sendbuf, buf,     buf_shape     )
-             CALL C_F_POINTER( ar%data,    data_3d, ar%a_dim(1:3) )
-
-             DO  ij = 1, ape%nrele
-                buf(myindex:myindex+ar%a_dim(1)-1) =                           &
-                                    data_3d(:,ape%locind(ij)%j,ape%locind(ij)%i)
-                myindex = myindex + ar%a_dim(1)
-             ENDDO
-
-          ENDIF
-
-       ENDDO
-
-    ENDDO
-!
-!-- TODO: Fence might do it, test later
-!-- Call MPI_WIN_FENCE( 0, me%win_server_client, ierr)      !
-!
-!-- Buffer is filled
-!-- TODO: explain in more detail what is happening here
-    CALL MPI_Barrier(me%intra_comm, ierr)
-
- END SUBROUTINE pmc_c_putbuffer
-
-#endif
- END MODULE pmc_client
Index: palm/trunk/SOURCE/pmc_general_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_general_mod.f90	(revision 1932)
+++ palm/trunk/SOURCE/pmc_general_mod.f90	(revision 1933)
@@ -1,5 +1,5 @@
  MODULE pmc_general
 
-!--------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 ! This file is part of PALM.
 !
@@ -16,14 +16,17 @@
 !
 ! Copyright 1997-2016 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! ------------------
-!
-!
+! 
+! 
 ! Former revisions:
 ! -----------------
 ! $Id$
 !
+! 1901 2016-05-04 15:39:38Z raasch
+! Code clean up. The words server/client changed to parent/child.
+!
 ! 1900 2016-05-04 15:27:53Z raasch
 ! re-formatted to match PALM style, file renamed again
@@ -33,6 +36,6 @@
 !
 ! 1786 2016-03-08 05:49:27Z raasch
-! change in client-server data transfer: server now gets data from client
-! instead that client put's it to the server
+! change in child-parent data transfer: parent now gets data from child
+! instead of that child puts it to the parent
 !
 ! 1779 2016-03-03 08:01:28Z raasch
@@ -90,5 +93,5 @@
        INTEGER                   :: nrdims       !< number of dimensions
        INTEGER, DIMENSION(4)     :: a_dim        !< size of dimensions
-       TYPE(C_PTR)               :: data         !< pointer of data in server space
+       TYPE(C_PTR)               :: data         !< pointer of data in parent space
        TYPE(C_PTR), DIMENSION(2) :: po_data      !< base pointers,
                                                  !< pmc_s_set_active_data_array
@@ -113,23 +116,23 @@
     END TYPE pedef
 
-    TYPE, PUBLIC ::  clientdef
+    TYPE, PUBLIC ::  childdef
        INTEGER(idp) ::  totalbuffersize    !<
        INTEGER      ::  model_comm         !< communicator of this model
-       INTEGER      ::  inter_comm         !< inter communicator model and client
-       INTEGER      ::  intra_comm         !< intra communicator model and client
+       INTEGER      ::  inter_comm         !< inter communicator model and child
+       INTEGER      ::  intra_comm         !< intra communicator model and child
        INTEGER      ::  model_rank         !< rank of this model
        INTEGER      ::  model_npes         !< number of PEs this model
-       INTEGER      ::  inter_npes         !< number of PEs client model
+       INTEGER      ::  inter_npes         !< number of PEs child model
        INTEGER      ::  intra_rank         !< rank within intra_comm
-       INTEGER      ::  win_server_client  !< MPI RMA for preparing data on server AND client side
-       TYPE(pedef), DIMENSION(:), POINTER ::  pes  !< list of all client PEs
-    END TYPE clientdef
+       INTEGER      ::  win_parent_child   !< MPI RMA for preparing data on parent AND child side
+       TYPE(pedef), DIMENSION(:), POINTER ::  pes  !< list of all child PEs
+    END TYPE childdef
 
     TYPE, PUBLIC ::  da_namedef  !< data array name definition
        INTEGER                   ::  couple_index  !< unique number of array
-       CHARACTER(LEN=da_desclen) ::  serverdesc    !< server array description
-       CHARACTER(LEN=da_namelen) ::  nameonserver  !< name of array within server
-       CHARACTER(LEN=da_desclen) ::  clientdesc    !< client array description
-       CHARACTER(LEN=da_namelen) ::  nameonclient  !< name of array within client
+       CHARACTER(LEN=da_desclen) ::  parentdesc    !< parent array description
+       CHARACTER(LEN=da_namelen) ::  nameonparent  !< name of array within parent
+       CHARACTER(LEN=da_desclen) ::  childdesc     !< child array description
+       CHARACTER(LEN=da_namelen) ::  nameonchild   !< name of array within child
     END TYPE da_namedef
 
@@ -146,5 +149,5 @@
  CONTAINS
 
- SUBROUTINE pmc_g_setname( myclient, couple_index, aname )
+ SUBROUTINE pmc_g_setname( mychild, couple_index, aname )
 
     IMPLICIT NONE
@@ -152,5 +155,5 @@
     CHARACTER(LEN=*)               ::  aname         !<
     INTEGER, INTENT(IN)            ::  couple_index  !<
-    TYPE(clientdef), INTENT(INOUT) ::  myclient      !<
+    TYPE(childdef), INTENT(INOUT)  ::  mychild       !<
 
     INTEGER ::  i  !<
@@ -162,7 +165,7 @@
 !-- Assign array to next free index in array list.
 !-- Set name of array in arraydef structure
-    DO  i = 1, myclient%inter_npes
-
-       ape => myclient%pes(i)
+    DO  i = 1, mychild%inter_npes
+
+       ape => mychild%pes(i)
        ape%nr_arrays = ape%nr_arrays + 1
        ape%array_list(ape%nr_arrays)%name        = aname
Index: palm/trunk/SOURCE/pmc_handle_communicator_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_handle_communicator_mod.f90	(revision 1932)
+++ palm/trunk/SOURCE/pmc_handle_communicator_mod.f90	(revision 1933)
@@ -1,5 +1,5 @@
  MODULE PMC_handle_communicator
 
-!--------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 ! This file is part of PALM.
 !
@@ -16,13 +16,17 @@
 !
 ! Copyright 1997-2016 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! ------------------
 ! 
-!
+! 
 ! Former revisions:
 ! -----------------
 ! $Id$
+!
+! 1901 2016-05-04 15:39:38Z raasch
+! Initial version of purely vertical nesting introduced.
+! Code clean up. The words server/client changed to parent/child.
 !
 ! 1900 2016-05-04 15:27:53Z raasch
@@ -70,5 +74,5 @@
 ! ------------
 ! Handle MPI communicator in PALM model coupler
-!------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 
 #if defined( __parallel )
@@ -81,6 +85,8 @@
 #endif
 
-    USE pmc_general,                                                           &
+    USE pmc_general,                                                            &
         ONLY: pmc_status_ok, pmc_status_error, pmc_max_models
+    USE control_parameters,                                                     &
+        ONLY: message_string
 
     IMPLICIT NONE
@@ -113,13 +119,13 @@
 
     INTEGER, PUBLIC ::  m_model_comm          !< communicator of this model
-    INTEGER, PUBLIC ::  m_to_server_comm      !< communicator to the server
+    INTEGER, PUBLIC ::  m_to_parent_comm      !< communicator to the parent
     INTEGER, PUBLIC ::  m_world_rank          !<
     INTEGER         ::  m_world_npes          !<
     INTEGER, PUBLIC ::  m_model_rank          !<
     INTEGER, PUBLIC ::  m_model_npes          !<
-    INTEGER         ::  m_server_remote_size  !< number of server PEs
-
-    INTEGER, DIMENSION(pmc_max_models), PUBLIC ::  m_to_client_comm   !< communicator to the client(s)
-    INTEGER, DIMENSION(:), POINTER, PUBLIC ::  pmc_server_for_client  !<
+    INTEGER         ::  m_parent_remote_size  !< number of parent PEs
+
+    INTEGER, DIMENSION(pmc_max_models), PUBLIC ::  m_to_child_comm    !< communicator to the child(ren)
+    INTEGER, DIMENSION(:), POINTER, PUBLIC ::  pmc_parent_for_child   !<
 
 
@@ -136,16 +142,16 @@
  CONTAINS
 
- SUBROUTINE pmc_init_model( comm, nesting_datatransfer_mode, nesting_mode,     &
+ SUBROUTINE pmc_init_model( comm, nesting_datatransfer_mode, nesting_mode,      &
                               pmc_status )
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                     &
         ONLY:  message_string
 
-    USE pegrid,                                                                &
+    USE pegrid,                                                                 &
         ONLY:  myid
 
       IMPLICIT NONE
 
-    CHARACTER(LEN=7), INTENT(OUT) ::  nesting_mode               !<
+    CHARACTER(LEN=8), INTENT(OUT) ::  nesting_mode               !<
     CHARACTER(LEN=7), INTENT(OUT) ::  nesting_datatransfer_mode  !<
 
@@ -153,5 +159,5 @@
     INTEGER, INTENT(OUT) ::  pmc_status  !<
 
-    INTEGER ::  clientcount    !<
+    INTEGER ::  childcount     !<
     INTEGER ::  i              !<
     INTEGER ::  ierr           !<
@@ -160,5 +166,5 @@
     INTEGER ::  tag            !<
 
-    INTEGER, DIMENSION(pmc_max_models)   ::  activeserver  ! I am active server for this client ID
+    INTEGER, DIMENSION(pmc_max_models)   ::  activeparent  ! I am active parent for this child ID
     INTEGER, DIMENSION(pmc_max_models+1) ::  start_pe
 
@@ -167,6 +173,6 @@
     m_world_comm = MPI_COMM_WORLD
     m_my_cpl_id  = -1
-    clientcount  =  0
-    activeserver = -1
+    childcount   =  0
+    activeparent = -1
     start_pe(:)  =  0
 
@@ -177,9 +183,9 @@
     IF ( m_world_rank == 0 )  THEN
 
-       CALL read_coupling_layout( nesting_datatransfer_mode, nesting_mode,     &
+       CALL read_coupling_layout( nesting_datatransfer_mode, nesting_mode,      &
                                   pmc_status )
 
-       IF ( pmc_status /= pmc_no_namelist_found  .AND.                         &
-            pmc_status /= pmc_namelist_error )                                 &
+       IF ( pmc_status /= pmc_no_namelist_found  .AND.                          &
+            pmc_status /= pmc_namelist_error )                                  &
        THEN
 !
@@ -194,8 +200,8 @@
 !--       total sum of cores required by all nest domains
           IF ( start_pe(m_ncpl+1) /= m_world_npes )  THEN
-             WRITE ( message_string, '(A,I6,A,I6,A)' )                         &
-                             'nesting-setup requires more MPI procs (',        &
-                             start_pe(m_ncpl+1), ') than provided (',          &
-                             m_world_npes,')'
+             WRITE ( message_string, '(A,I6,A,I6,A)' )                          &
+                             'nesting-setup requires different number of ',     &
+                             'MPI procs (', start_pe(m_ncpl+1), ') than ',      &
+                             'provided (', m_world_npes,')'
              CALL message( 'pmc_init_model', 'PA0229', 3, 2, 0, 6, 0 )
           ENDIF
@@ -234,20 +240,20 @@
 !-- Broadcast coupling layout
     DO  i = 1, m_ncpl
-       CALL MPI_BCAST( m_couplers(i)%name, LEN( m_couplers(i)%name ),          &
+       CALL MPI_BCAST( m_couplers(i)%name, LEN( m_couplers(i)%name ),           &
                        MPI_CHARACTER, 0, MPI_COMM_WORLD, istat )
-       CALL MPI_BCAST( m_couplers(i)%id,           1, MPI_INTEGER, 0,          &
-                       MPI_COMM_WORLD, istat )
-       CALL MPI_BCAST( m_couplers(i)%Parent_id,    1, MPI_INTEGER, 0,          &
-                       MPI_COMM_WORLD, istat )
-       CALL MPI_BCAST( m_couplers(i)%npe_total,    1, MPI_INTEGER, 0,          &
-                       MPI_COMM_WORLD, istat )
-       CALL MPI_BCAST( m_couplers(i)%lower_left_x, 1, MPI_REAL,    0,          &
-                       MPI_COMM_WORLD, istat )
-       CALL MPI_BCAST( m_couplers(i)%lower_left_y, 1, MPI_REAL,    0,          &
+       CALL MPI_BCAST( m_couplers(i)%id,           1, MPI_INTEGER, 0,           &
+                       MPI_COMM_WORLD, istat )
+       CALL MPI_BCAST( m_couplers(i)%Parent_id,    1, MPI_INTEGER, 0,           &
+                       MPI_COMM_WORLD, istat )
+       CALL MPI_BCAST( m_couplers(i)%npe_total,    1, MPI_INTEGER, 0,           &
+                       MPI_COMM_WORLD, istat )
+       CALL MPI_BCAST( m_couplers(i)%lower_left_x, 1, MPI_REAL,    0,           &
+                       MPI_COMM_WORLD, istat )
+       CALL MPI_BCAST( m_couplers(i)%lower_left_y, 1, MPI_REAL,    0,           &
                        MPI_COMM_WORLD, istat )
     ENDDO
-    CALL MPI_BCAST( nesting_mode, LEN( nesting_mode ), MPI_CHARACTER, 0,       &
+    CALL MPI_BCAST( nesting_mode, LEN( nesting_mode ), MPI_CHARACTER, 0,        &
                     MPI_COMM_WORLD, istat )
-    CALL MPI_BCAST( nesting_datatransfer_mode, LEN(nesting_datatransfer_mode), &
+    CALL MPI_BCAST( nesting_datatransfer_mode, LEN(nesting_datatransfer_mode),  &
                     MPI_CHARACTER, 0, MPI_COMM_WORLD, istat )
 
@@ -255,5 +261,5 @@
 !-- Assign global MPI processes to individual models by setting the couple id
     DO  i = 1, m_ncpl
-       IF ( m_world_rank >= start_pe(i)  .AND.  m_world_rank < start_pe(i+1) ) &
+       IF ( m_world_rank >= start_pe(i)  .AND.  m_world_rank < start_pe(i+1) )  &
        THEN
           m_my_cpl_id = i
@@ -267,5 +273,5 @@
 !-- The communictors for the individual models as created by MPI_COMM_SPLIT.
 !-- The color of the model is represented by the coupler id
-    CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, m_my_cpl_id, m_my_cpl_rank, comm,     &
+    CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, m_my_cpl_id, m_my_cpl_rank, comm,      &
                          istat )
 !
@@ -277,7 +283,7 @@
 !-- Broadcast (from PE 0) the parent id and id of every model
     DO  i = 1, m_ncpl
-       CALL MPI_BCAST( m_couplers(i)%parent_id, 1, MPI_INTEGER, 0,             &
-                       MPI_COMM_WORLD, istat )
-       CALL MPI_BCAST( m_couplers(i)%id,        1, MPI_INTEGER, 0,             &
+       CALL MPI_BCAST( m_couplers(i)%parent_id, 1, MPI_INTEGER, 0,              &
+                       MPI_COMM_WORLD, istat )
+       CALL MPI_BCAST( m_couplers(i)%id,        1, MPI_INTEGER, 0,              &
                        MPI_COMM_WORLD, istat )
     ENDDO
@@ -288,5 +294,5 @@
 
 !
-!-- Create intercommunicator between server and clients.
+!-- Create intercommunicator between parent and children.
 !-- MPI_INTERCOMM_CREATE creates an intercommunicator between 2 groups of
 !-- different colors.
@@ -296,24 +302,23 @@
        IF ( m_couplers(i)%parent_id == m_my_cpl_id )  THEN
 !
-!--       Collect server PEs.
+!--       Collect parent PEs.
 !--       Every model exept the root model has a parent model which acts as
-!--       server model. Create an intercommunicator to connect current PE to
-!--       all client PEs
+!--       parent model. Create an intercommunicator to connect current PE to
+!--       all children PEs
           tag = 500 + i
-          CALL MPI_INTERCOMM_CREATE( comm, 0, MPI_COMM_WORLD, start_pe(i),     &
-                                     tag, m_to_client_comm(i), istat)
-          clientcount = clientcount + 1
-          activeserver(i) = 1
+          CALL MPI_INTERCOMM_CREATE( comm, 0, MPI_COMM_WORLD, start_pe(i),      &
+                                     tag, m_to_child_comm(i), istat)
+          childcount = childcount + 1
+          activeparent(i) = 1
 
        ELSEIF ( i == m_my_cpl_id)  THEN
 !
-!--       Collect client PEs.
-!--       Every model exept the root model has a paremt model which acts as
-!--       server model. Create an intercommunicator to connect current PE to
-!--       all server PEs
+!--       Collect children PEs.
+!--       Every model except the root model has a parent model. 
+!--       Create an intercommunicator to connect current PE to all parent PEs
           tag = 500 + i
-          CALL MPI_INTERCOMM_CREATE( comm, 0, MPI_COMM_WORLD,                  &
-                                     start_pe(m_couplers(i)%parent_id),        &
-                                     tag, m_to_server_comm, istat )
+          CALL MPI_INTERCOMM_CREATE( comm, 0, MPI_COMM_WORLD,                   &
+                                     start_pe(m_couplers(i)%parent_id),         &
+                                     tag, m_to_parent_comm, istat )
        ENDIF
 
@@ -321,25 +326,25 @@
 
 !
-!-- If I am server, count the number of clients that I have
-!-- Although this loop is symmetric on all processes, the "activeserver" flag
+!-- If I am parent, count the number of children that I have
+!-- Although this loop is symmetric on all processes, the "activeparent" flag
 !-- is true (==1) on the respective individual PE only.
-    ALLOCATE( pmc_server_for_client(clientcount+1) )
-
-    clientcount = 0
+    ALLOCATE( pmc_parent_for_child(childcount+1) )
+
+    childcount = 0
     DO  i = 2, m_ncpl
-       IF ( activeserver(i) == 1 )  THEN
-          clientcount = clientcount + 1
-          pmc_server_for_client(clientcount) = i
+       IF ( activeparent(i) == 1 )  THEN
+          childcount = childcount + 1
+          pmc_parent_for_child(childcount) = i
        ENDIF
     ENDDO
 !
-!-- Get the size of the server model
+!-- Get the size of the parent model
     IF ( m_my_cpl_id > 1 )  THEN
-       CALL MPI_COMM_REMOTE_SIZE( m_to_server_comm, m_server_remote_size,      &
+       CALL MPI_COMM_REMOTE_SIZE( m_to_parent_comm, m_parent_remote_size,       &
                                   istat)
     ELSE
 !
-!--    The root model does not have a server
-       m_server_remote_size = -1
+!--    The root model does not have a parent
+       m_parent_remote_size = -1
     ENDIF
 !
@@ -356,6 +361,6 @@
 
 
- SUBROUTINE pmc_get_model_info( comm_world_nesting, cpl_id, cpl_name,          &
-                                cpl_parent_id, lower_left_x, lower_left_y,     &
+ SUBROUTINE pmc_get_model_info( comm_world_nesting, cpl_id, cpl_name,           &
+                                cpl_parent_id, lower_left_x, lower_left_y,      &
                                 ncpl, npe_total, request_for_cpl_id )
 !
@@ -366,7 +371,7 @@
     IMPLICIT NONE
 
-    CHARACTER(LEN=*), INTENT(OUT), OPTIONAL ::  cpl_name  !<
-
-    INTEGER, INTENT(IN), OPTIONAL ::  request_for_cpl_id  !<
+    CHARACTER(LEN=*), INTENT(OUT), OPTIONAL ::  cpl_name   !<
+
+    INTEGER, INTENT(IN), OPTIONAL ::  request_for_cpl_id   !<
 
     INTEGER, INTENT(OUT), OPTIONAL ::  comm_world_nesting  !<
@@ -433,14 +438,16 @@
 
 
- SUBROUTINE read_coupling_layout( nesting_datatransfer_mode, nesting_mode,     &
+ SUBROUTINE read_coupling_layout( nesting_datatransfer_mode, nesting_mode,      &
                                   pmc_status )
 
     IMPLICIT NONE
 
-    CHARACTER(LEN=7), INTENT(INOUT) ::  nesting_mode
+    CHARACTER(LEN=8), INTENT(INOUT) ::  nesting_mode
     CHARACTER(LEN=7), INTENT(INOUT) ::  nesting_datatransfer_mode
 
-    INTEGER, INTENT(INOUT) ::  pmc_status
-    INTEGER                ::  i, istat
+    INTEGER(iwp), INTENT(INOUT) ::  pmc_status
+    INTEGER(iwp)                ::  bad_llcorner
+    INTEGER(iwp)                ::  i
+    INTEGER(iwp)                ::  istat
 
     TYPE(pmc_layout), DIMENSION(pmc_max_models) ::  domain_layouts
@@ -461,7 +468,9 @@
 
     IF ( istat < 0 )  THEN
+
 !
 !--    No nestpar-NAMELIST found
        pmc_status = pmc_no_namelist_found
+
 !
 !--    Set filepointer to the beginning of the file. Otherwise PE0 will later
@@ -471,4 +480,5 @@
 
     ELSEIF ( istat > 0 )  THEN
+
 !
 !--    Errors in reading nestpar-NAMELIST
@@ -481,4 +491,5 @@
 !-- Output location message
     CALL location_message( 'initialize communicators for nesting', .FALSE. )
+
 !
 !-- Assign the layout to the internally used variable
@@ -490,5 +501,5 @@
 !
 !--    When id=-1 is found for the first time, the list of domains is finished
-       IF ( m_couplers(i)%id == -1  .OR.  i == pmc_max_models )  THEN
+        IF ( m_couplers(i)%id == -1  .OR.  i == pmc_max_models )  THEN
           IF ( m_couplers(i)%id == -1 )  THEN
              m_ncpl = i - 1
@@ -501,4 +512,24 @@
     ENDDO
 
+!
+!-- Make sure that all domains have equal lower left corner in case of vertical
+!-- nesting
+    IF ( nesting_mode == 'vertical' )  THEN
+       bad_llcorner = 0
+       DO  i = 1, m_ncpl
+          IF ( domain_layouts(i)%lower_left_x /= 0.0_wp .OR.                    &
+               domain_layouts(i)%lower_left_y /= 0.0_wp )  THEN
+             bad_llcorner = bad_llcorner + 1
+             domain_layouts(i)%lower_left_x = 0.0_wp
+             domain_layouts(i)%lower_left_y = 0.0_wp
+          ENDIF
+       ENDDO
+       IF ( bad_llcorner /= 0)  THEN
+          WRITE ( message_string, *)  'Lower left corners do not match,',       &
+                                      'they were set to (0, 0)'
+          CALL message( 'read_coupling_layout', 'PA0427', 0, 0, 0, 6, 0 )
+       ENDIF
+    ENDIF
+
  END SUBROUTINE read_coupling_layout
 
Index: palm/trunk/SOURCE/pmc_interface_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 1932)
+++ palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 1933)
@@ -1,5 +1,5 @@
 MODULE pmc_interface
 
-!------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 ! This file is part of PALM.
 !
@@ -16,5 +16,5 @@
 !
 ! Copyright 1997-2016 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 !
 ! Current revisions:
@@ -26,6 +26,7 @@
 ! $Id$
 !
-! 1927 2016-06-07 11:56:53Z hellstea
-! Error check for overlapping parallel nests added 
+! 1901 2016-05-04 15:39:38Z raasch
+! Initial version of purely vertical nesting introduced.
+! Code clean up. The words server/client changed to parent/child.
 !
 ! 1900 2016-05-04 15:27:53Z raasch
@@ -62,5 +63,5 @@
 ! introduction of different datatransfer modes,
 ! further formatting cleanup, parameter checks added (including mismatches
-! between root and client model settings),
+! between root and nest model settings),
 ! +routine pmci_check_setting_mismatches
 ! comm_world_nesting introduced
@@ -106,32 +107,32 @@
 ! Domain nesting interface routines. The low-level inter-domain communication   
 ! is conducted by the PMC-library routines.
-!------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 
 #if defined( __nopointer )
-    USE arrays_3d,                                                             &
-        ONLY:  dzu, dzw, e, e_p, pt, pt_p, q, q_p, u, u_p, v, v_p, w, w_p, zu, &
+    USE arrays_3d,                                                              &
+        ONLY:  dzu, dzw, e, e_p, pt, pt_p, q, q_p, u, u_p, v, v_p, w, w_p, zu,  &
                zw, z0
 #else
-   USE arrays_3d,                                                              &
-        ONLY:  dzu, dzw, e, e_p, e_1, e_2, pt, pt_p, pt_1, pt_2, q, q_p, q_1,  &
-               q_2, u, u_p, u_1, u_2, v, v_p, v_1, v_2, w, w_p, w_1, w_2, zu,  &
+   USE arrays_3d,                                                               &
+        ONLY:  dzu, dzw, e, e_p, e_1, e_2, pt, pt_p, pt_1, pt_2, q, q_p, q_1,   &
+               q_2, u, u_p, u_1, u_2, v, v_p, v_1, v_2, w, w_p, w_1, w_2, zu,   &
                zw, z0
 #endif
 
-    USE control_parameters,                                                    &
-        ONLY:  coupling_char, dt_3d, dz, humidity, message_string,             &
-               nest_bound_l, nest_bound_r, nest_bound_s, nest_bound_n,         &
-               nest_domain, neutral, passive_scalar, simulated_time,           &
+    USE control_parameters,                                                     &
+        ONLY:  coupling_char, dt_3d, dz, humidity, message_string,              &
+               nest_bound_l, nest_bound_r, nest_bound_s, nest_bound_n,          &
+               nest_domain, neutral, passive_scalar, simulated_time,            &
                topography, volume_flow
 
-    USE cpulog,                                                                &
+    USE cpulog,                                                                 &
         ONLY:  cpu_log, log_point_s
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                         &
         ONLY:  dx, dy
 
-    USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxlg, nxlu, nxr, nxrg, ny, nyn, nyng, nys, nysg, &
-               nysv, nz, nzb, nzb_s_inner, nzb_u_inner, nzb_u_outer,           &
+    USE indices,                                                                &
+        ONLY:  nbgp, nx, nxl, nxlg, nxlu, nxr, nxrg, ny, nyn, nyng, nys, nysg,  &
+               nysv, nz, nzb, nzb_s_inner, nzb_u_inner, nzb_u_outer,            &
                nzb_v_inner, nzb_v_outer, nzb_w_inner, nzb_w_outer, nzt
 
@@ -145,29 +146,29 @@
 #endif
 
-    USE pegrid,                                                                &
-        ONLY:  collective_wait, comm1dx, comm1dy, comm2d, myid, myidx, myidy,  &
+    USE pegrid,                                                                 &
+        ONLY:  collective_wait, comm1dx, comm1dy, comm2d, myid, myidx, myidy,   &
                numprocs
 
-    USE pmc_client,                                                            &
-        ONLY:  pmc_clientinit, pmc_c_clear_next_array_list,                    &
-               pmc_c_getnextarray, pmc_c_get_2d_index_list, pmc_c_getbuffer,   &
-               pmc_c_putbuffer, pmc_c_setind_and_allocmem,                     &
+    USE pmc_child,                                                              &
+        ONLY:  pmc_childinit, pmc_c_clear_next_array_list,                      &
+               pmc_c_getnextarray, pmc_c_get_2d_index_list, pmc_c_getbuffer,    &
+               pmc_c_putbuffer, pmc_c_setind_and_allocmem,                      &
                pmc_c_set_dataarray, pmc_set_dataarray_name
 
-    USE pmc_general,                                                           &
+    USE pmc_general,                                                            &
         ONLY:  da_namelen
 
-    USE pmc_handle_communicator,                                               &
-        ONLY:  pmc_get_model_info, pmc_init_model, pmc_is_rootmodel,           &
-               pmc_no_namelist_found, pmc_server_for_client
-
-    USE pmc_mpi_wrapper,                                                       &
-        ONLY:  pmc_bcast, pmc_recv_from_client, pmc_recv_from_server,          &
-               pmc_send_to_client, pmc_send_to_server
-
-    USE pmc_server,                                                            &
-        ONLY:  pmc_serverinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer,  &
-               pmc_s_getdata_from_buffer, pmc_s_getnextarray,                  &
-               pmc_s_setind_and_allocmem, pmc_s_set_active_data_array,         &
+    USE pmc_handle_communicator,                                                &
+        ONLY:  pmc_get_model_info, pmc_init_model, pmc_is_rootmodel,            &
+               pmc_no_namelist_found, pmc_parent_for_child
+
+    USE pmc_mpi_wrapper,                                                        &
+        ONLY:  pmc_bcast, pmc_recv_from_child, pmc_recv_from_parent,            &
+               pmc_send_to_child, pmc_send_to_parent
+
+    USE pmc_parent,                                                             &
+        ONLY:  pmc_parentinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer,   &
+               pmc_s_getdata_from_buffer, pmc_s_getnextarray,                   &
+               pmc_s_setind_and_allocmem, pmc_s_set_active_data_array,          &
                pmc_s_set_dataarray, pmc_s_set_2d_index_list
 
@@ -180,6 +181,6 @@
 !
 !-- Constants
-    INTEGER(iwp), PARAMETER ::  client_to_server = 2   !:
-    INTEGER(iwp), PARAMETER ::  server_to_client = 1   !:
+    INTEGER(iwp), PARAMETER ::  child_to_parent = 2   !:
+    INTEGER(iwp), PARAMETER ::  parent_to_child = 1   !:
 
 !
@@ -196,5 +197,5 @@
                                                          !: parameter for data-
                                                          !: transfer mode
-    CHARACTER(LEN=7), SAVE ::  nesting_mode = 'two-way'  !: steering parameter
+    CHARACTER(LEN=8), SAVE ::  nesting_mode = 'two-way'  !: steering parameter
                                                          !: for 1- or 2-way nesting
 
@@ -216,5 +217,5 @@
 
 !
-!-- Client coarse data arrays
+!-- Child coarse data arrays
     INTEGER(iwp), DIMENSION(5)                  ::  coarse_bound   !:
 
@@ -237,6 +238,6 @@
 
 !
-!-- Client interpolation coefficients and client-array indices to be precomputed
-!-- and stored.
+!-- Child interpolation coefficients and child-array indices to be 
+!-- precomputed and stored.
     INTEGER(iwp), SAVE, ALLOCATABLE, DIMENSION(:) ::  ico    !:
     INTEGER(iwp), SAVE, ALLOCATABLE, DIMENSION(:) ::  icu    !:
@@ -259,5 +260,5 @@
 
 !
-!-- Client index arrays and log-ratio arrays for the log-law near-wall
+!-- Child index arrays and log-ratio arrays for the log-law near-wall
 !-- corrections. These are not truly 3-D arrays but multiple 2-D arrays.
     INTEGER(iwp), SAVE :: ncorr  !: 4th dimension of the log_ratio-arrays
@@ -313,5 +314,5 @@
 
 !
-!-- Client-array indices to be precomputed and stored for anterpolation.
+!-- Child-array indices to be precomputed and stored for anterpolation.
     INTEGER(iwp), SAVE, ALLOCATABLE, DIMENSION(:) ::  iflu   !:
     INTEGER(iwp), SAVE, ALLOCATABLE, DIMENSION(:) ::  ifuu   !:
@@ -363,6 +364,6 @@
     END INTERFACE
 
-    INTERFACE pmci_client_initialize
-       MODULE PROCEDURE pmci_client_initialize
+    INTERFACE pmci_child_initialize
+       MODULE PROCEDURE pmci_child_initialize
     END INTERFACE
 
@@ -387,6 +388,6 @@
     END INTERFACE
 
-    INTERFACE pmci_server_initialize
-       MODULE PROCEDURE pmci_server_initialize
+    INTERFACE pmci_parent_initialize
+       MODULE PROCEDURE pmci_parent_initialize
     END INTERFACE
 
@@ -395,15 +396,15 @@
     END INTERFACE pmci_set_swaplevel
 
-    PUBLIC anterp_relax_length_l, anterp_relax_length_r,                       &
-           anterp_relax_length_s, anterp_relax_length_n,                       &
-           anterp_relax_length_t, client_to_server, comm_world_nesting,        &
-           cpl_id, nested_run, nesting_datatransfer_mode, nesting_mode,        &
-           server_to_client
-    PUBLIC pmci_client_initialize
+    PUBLIC anterp_relax_length_l, anterp_relax_length_r,                        &
+           anterp_relax_length_s, anterp_relax_length_n,                        &
+           anterp_relax_length_t, child_to_parent, comm_world_nesting,          &
+           cpl_id, nested_run, nesting_datatransfer_mode, nesting_mode,         &
+           parent_to_child
+    PUBLIC pmci_child_initialize
     PUBLIC pmci_datatrans
     PUBLIC pmci_ensure_nest_mass_conservation
     PUBLIC pmci_init
     PUBLIC pmci_modelconfiguration
-    PUBLIC pmci_server_initialize
+    PUBLIC pmci_parent_initialize
     PUBLIC pmci_synchronize
     PUBLIC pmci_set_swaplevel
@@ -415,5 +416,5 @@
  SUBROUTINE pmci_init( world_comm )
 
-    USE control_parameters,                                                  &
+    USE control_parameters,                                                     &
         ONLY:  message_string
 
@@ -429,5 +430,5 @@
 
 
-    CALL pmc_init_model( world_comm, nesting_datatransfer_mode, nesting_mode,  &
+    CALL pmc_init_model( world_comm, nesting_datatransfer_mode, nesting_mode,   &
                          pmc_status )
 
@@ -445,6 +446,7 @@
 !
 !-- Check steering parameter values
-    IF ( TRIM( nesting_mode ) /= 'one-way'  .AND.                              &
-         TRIM( nesting_mode ) /= 'two-way' )                                   &
+    IF ( TRIM( nesting_mode ) /= 'one-way'  .AND.                               &
+         TRIM( nesting_mode ) /= 'two-way'  .AND.                               &
+         TRIM( nesting_mode ) /= 'vertical' )                                   &                 
     THEN
        message_string = 'illegal nesting mode: ' // TRIM( nesting_mode )
@@ -452,9 +454,9 @@
     ENDIF
 
-    IF ( TRIM( nesting_datatransfer_mode ) /= 'cascade'  .AND.                 &
-         TRIM( nesting_datatransfer_mode ) /= 'mixed'    .AND.                 &
-         TRIM( nesting_datatransfer_mode ) /= 'overlap' )                      &
+    IF ( TRIM( nesting_datatransfer_mode ) /= 'cascade'  .AND.                  &
+         TRIM( nesting_datatransfer_mode ) /= 'mixed'    .AND.                  &
+         TRIM( nesting_datatransfer_mode ) /= 'overlap' )                       &
     THEN
-       message_string = 'illegal nesting datatransfer mode: '                  &
+       message_string = 'illegal nesting datatransfer mode: '                   &
                         // TRIM( nesting_datatransfer_mode )
        CALL message( 'pmci_init', 'PA0418', 3, 2, 0, 6, 0 )
@@ -468,8 +470,8 @@
 !-- Get some variables required by the pmc-interface (and in some cases in the
 !-- PALM code out of the pmci) out of the pmc-core
-    CALL pmc_get_model_info( comm_world_nesting = comm_world_nesting,          &
-                             cpl_id = cpl_id, cpl_parent_id = cpl_parent_id,   &
-                             cpl_name = cpl_name, npe_total = cpl_npe_total,   &
-                             lower_left_x = lower_left_coord_x,                &
+    CALL pmc_get_model_info( comm_world_nesting = comm_world_nesting,           &
+                             cpl_id = cpl_id, cpl_parent_id = cpl_parent_id,    &
+                             cpl_name = cpl_name, npe_total = cpl_npe_total,    &
+                             lower_left_x = lower_left_coord_x,                 &
                              lower_left_y = lower_left_coord_y )
 !
@@ -513,12 +515,12 @@
     CALL pmci_setup_coordinates
 !
-!-- Initialize the client (must be called before pmc_setup_server)
-    CALL pmci_setup_client
-!
-!-- Initialize PMC Server
-    CALL pmci_setup_server
-!
-!-- Check for mismatches between settings of master and client variables
-!-- (e.g., all clients have to follow the end_time settings of the root master)
+!-- Initialize the child (must be called before pmc_setup_parent)
+    CALL pmci_setup_child
+!
+!-- Initialize PMC parent
+    CALL pmci_setup_parent
+!
+!-- Check for mismatches between settings of master and child variables
+!-- (e.g., all children have to follow the end_time settings of the root master)
     CALL pmci_check_setting_mismatches
 
@@ -529,5 +531,5 @@
 
 
- SUBROUTINE pmci_setup_server
+ SUBROUTINE pmci_setup_parent
 
 #if defined( __parallel )
@@ -536,5 +538,5 @@
     CHARACTER(LEN=32) ::  myname
 
-    INTEGER(iwp) ::  client_id        !:
+    INTEGER(iwp) ::  child_id         !:
     INTEGER(iwp) ::  ierr             !:
     INTEGER(iwp) ::  i                !:
@@ -558,4 +560,8 @@
     REAL(wp) ::  dx_cl            !:
     REAL(wp) ::  dy_cl            !:
+    REAL(wp) ::  left_limit       !:
+    REAL(wp) ::  north_limit      !:
+    REAL(wp) ::  right_limit      !:
+    REAL(wp) ::  south_limit      !:
     REAL(wp) ::  xez              !:
     REAL(wp) ::  yez              !:
@@ -568,25 +574,25 @@
 
 !
-!   Initialize the pmc server
-    CALL pmc_serverinit
+!   Initialize the pmc parent
+    CALL pmc_parentinit
 
 !
 !-- Corners of all children of the present parent
-    IF ( ( SIZE( pmc_server_for_client ) - 1 > 0 ) .AND. myid == 0 )  THEN 
-       ALLOCATE( ch_xl(1:SIZE( pmc_server_for_client ) - 1) )
-       ALLOCATE( ch_xr(1:SIZE( pmc_server_for_client ) - 1) )
-       ALLOCATE( ch_ys(1:SIZE( pmc_server_for_client ) - 1) )
-       ALLOCATE( ch_yn(1:SIZE( pmc_server_for_client ) - 1) )
+    IF ( ( SIZE( pmc_parent_for_child ) - 1 > 0 ) .AND. myid == 0 )  THEN 
+       ALLOCATE( ch_xl(1:SIZE( pmc_parent_for_child ) - 1) )
+       ALLOCATE( ch_xr(1:SIZE( pmc_parent_for_child ) - 1) )
+       ALLOCATE( ch_ys(1:SIZE( pmc_parent_for_child ) - 1) )
+       ALLOCATE( ch_yn(1:SIZE( pmc_parent_for_child ) - 1) )
     ENDIF
 
 !
 !-- Get coordinates from all children
-    DO  m = 1, SIZE( pmc_server_for_client ) - 1
-
-       client_id = pmc_server_for_client(m)
+    DO  m = 1, SIZE( pmc_parent_for_child ) - 1
+
+       child_id = pmc_parent_for_child(m)
        IF ( myid == 0 )  THEN        
 
-          CALL pmc_recv_from_client( client_id, val,  size(val),  0, 123, ierr )
-          CALL pmc_recv_from_client( client_id, fval, size(fval), 0, 124, ierr )
+          CALL pmc_recv_from_child( child_id, val,  size(val),  0, 123, ierr )
+          CALL pmc_recv_from_child( child_id, fval, size(fval), 0, 124, ierr )
          
           nx_cl = val(1)
@@ -598,5 +604,5 @@
 
 !
-!--       Find the highest client level in the coarse grid for the reduced z
+!--       Find the highest nest level in the coarse grid for the reduced z
 !--       transfer
           DO  k = 1, nz                 
@@ -612,9 +618,9 @@
           ALLOCATE( cl_coord_y(-nbgp:ny_cl+nbgp) )
          
-          CALL pmc_recv_from_client( client_id, cl_coord_x, SIZE( cl_coord_x ),&
+          CALL pmc_recv_from_child( child_id, cl_coord_x, SIZE( cl_coord_x ),   &
                                      0, 11, ierr )
-          CALL pmc_recv_from_client( client_id, cl_coord_y, SIZE( cl_coord_y ),&
+          CALL pmc_recv_from_child( child_id, cl_coord_y, SIZE( cl_coord_y ),   &
                                      0, 12, ierr )
-!          WRITE ( 0, * )  'receive from pmc Client ', client_id, nx_cl, ny_cl
+!          WRITE ( 0, * )  'receive from pmc child ', child_id, nx_cl, ny_cl
          
           define_coarse_grid_real(1) = lower_left_coord_x
@@ -631,14 +637,29 @@
 
 !
-!--       Check that the client domain is completely inside the server domain. 
+!--       Check that the child domain matches parent domain. 
           nomatch = 0
-          xez = ( nbgp + 1 ) * dx 
-          yez = ( nbgp + 1 ) * dy 
-          IF ( ( cl_coord_x(0) < define_coarse_grid_real(1) + xez )       .OR. &
-               ( cl_coord_x(nx_cl+1) > define_coarse_grid_real(5) - xez ) .OR. &
-               ( cl_coord_y(0) < define_coarse_grid_real(2) + yez )       .OR. &
-               ( cl_coord_y(ny_cl+1) > define_coarse_grid_real(6) - yez ) )    &
-          THEN
-             nomatch = 1
+          IF ( nesting_mode == 'vertical' )  THEN
+             right_limit = define_coarse_grid_real(5)
+             north_limit = define_coarse_grid_real(6)
+             IF ( ( cl_coord_x(nx_cl+1) /= right_limit ) .OR.                   &
+                  ( cl_coord_y(ny_cl+1) /= north_limit ) )  THEN
+                nomatch = 1
+             ENDIF
+          ELSE
+          
+!
+!--       Check that the children domain is completely inside the parent domain. 
+             xez = ( nbgp + 1 ) * dx 
+             yez = ( nbgp + 1 ) * dy 
+             left_limit  = lower_left_coord_x + xez
+             right_limit = define_coarse_grid_real(5) - xez
+             south_limit = lower_left_coord_y + yez
+             north_limit = define_coarse_grid_real(6) - yez
+             IF ( ( cl_coord_x(0) < left_limit )        .OR.                    &
+                  ( cl_coord_x(nx_cl+1) > right_limit ) .OR.                    &
+                  ( cl_coord_y(0) < south_limit )       .OR.                    &
+                  ( cl_coord_y(ny_cl+1) > north_limit ) )  THEN
+                nomatch = 1
+             ENDIF
           ENDIF
 
@@ -646,5 +667,5 @@
 !--       Check that parallel nest domains, if any, do not overlap.
           nest_overlap = 0
-          IF ( SIZE( pmc_server_for_client ) - 1 > 0 )  THEN
+          IF ( SIZE( pmc_parent_for_child ) - 1 > 0 )  THEN
              ch_xl(m) = cl_coord_x(-nbgp)
              ch_xr(m) = cl_coord_x(nx_cl+nbgp)
@@ -654,6 +675,8 @@
              IF ( m > 1 )  THEN
                 DO mm = 1, m-1
-                   IF ( ( ch_xl(m) < ch_xr(mm) .OR. ch_xr(m) > ch_xl(mm) ) .AND.  &
-                        ( ch_ys(m) < ch_yn(mm) .OR. ch_yn(m) > ch_ys(mm) ) )  THEN                        
+                   IF ( ( ch_xl(m) < ch_xr(mm) .OR.                             &
+                          ch_xr(m) > ch_xl(mm) )  .AND.                         &
+                        ( ch_ys(m) < ch_yn(mm) .OR.                             &
+                          ch_yn(m) > ch_ys(mm) ) )  THEN                        
                       nest_overlap = 1
                    ENDIF
@@ -667,23 +690,23 @@
 !
 !--       Send coarse grid information to child
-          CALL pmc_send_to_client( client_id, define_coarse_grid_real,         &
-                                   SIZE( define_coarse_grid_real ), 0, 21,     &
+          CALL pmc_send_to_child( child_id, define_coarse_grid_real,            &
+                                   SIZE( define_coarse_grid_real ), 0, 21,      &
                                    ierr )
-          CALL pmc_send_to_client( client_id, define_coarse_grid_int,  3, 0,   &
+          CALL pmc_send_to_child( child_id, define_coarse_grid_int,  3, 0,      &
                                    22, ierr )
 
 !
 !--       Send local grid to child
-          CALL pmc_send_to_client( client_id, coord_x, nx+1+2*nbgp, 0, 24,     &
+          CALL pmc_send_to_child( child_id, coord_x, nx+1+2*nbgp, 0, 24,        &
                                    ierr )
-          CALL pmc_send_to_client( client_id, coord_y, ny+1+2*nbgp, 0, 25,     &
+          CALL pmc_send_to_child( child_id, coord_y, ny+1+2*nbgp, 0, 25,        &
                                    ierr )
 
 !
 !--       Also send the dzu-, dzw-, zu- and zw-arrays here
-          CALL pmc_send_to_client( client_id, dzu, nz_cl+1, 0, 26, ierr )
-          CALL pmc_send_to_client( client_id, dzw, nz_cl+1, 0, 27, ierr )
-          CALL pmc_send_to_client( client_id, zu,  nz_cl+2, 0, 28, ierr )
-          CALL pmc_send_to_client( client_id, zw,  nz_cl+2, 0, 29, ierr )
+          CALL pmc_send_to_child( child_id, dzu, nz_cl+1, 0, 26, ierr )
+          CALL pmc_send_to_child( child_id, dzw, nz_cl+1, 0, 27, ierr )
+          CALL pmc_send_to_child( child_id, zu,  nz_cl+2, 0, 28, ierr )
+          CALL pmc_send_to_child( child_id, zw,  nz_cl+2, 0, 29, ierr )
 
        ENDIF
@@ -691,7 +714,7 @@
        CALL MPI_BCAST( nomatch, 1, MPI_INTEGER, 0, comm2d, ierr )
        IF ( nomatch /= 0 ) THEN
-          WRITE ( message_string, * )  'Error: nested child domain does ',    &
+          WRITE ( message_string, * )  'Error: nested child domain does ',      &
                                        'not fit into its parent domain'
-          CALL message( 'pmc_palm_setup_server', 'PA0425', 3, 2, 0, 6, 0 )
+          CALL message( 'pmci_setup_parent', 'PA0425', 3, 2, 0, 6, 0 )
        ENDIF
   
@@ -700,5 +723,5 @@
           WRITE ( message_string, * )  'Nested parallel child ',    &
                                        'domains overlap'
-          CALL message( 'pmc_palm_setup_server', 'PA0426', 3, 2, 0, 6, 0 )
+          CALL message( 'pmci_setup_parent', 'PA0426', 3, 2, 0, 6, 0 )
        ENDIF
       
@@ -710,15 +733,15 @@
 
 !
-!--    Include couple arrays into server content
+!--    Include couple arrays into parent content
 !--    TO_DO: Klaus: please give a more meaningful comment
        CALL pmc_s_clear_next_array_list
-       DO  WHILE ( pmc_s_getnextarray( client_id, myname ) )
-          CALL pmci_set_array_pointer( myname, client_id = client_id,          &
+       DO  WHILE ( pmc_s_getnextarray( child_id, myname ) )
+          CALL pmci_set_array_pointer( myname, child_id = child_id,             &
                                        nz_cl = nz_cl )
        ENDDO
-       CALL pmc_s_setind_and_allocmem( client_id )
+       CALL pmc_s_setind_and_allocmem( child_id )
     ENDDO
 
-    IF ( ( SIZE( pmc_server_for_client ) - 1 > 0 ) .AND. myid == 0 )  THEN 
+    IF ( ( SIZE( pmc_parent_for_child ) - 1 > 0 ) .AND. myid == 0 )  THEN 
        DEALLOCATE( ch_xl )
        DEALLOCATE( ch_xr )
@@ -747,5 +770,5 @@
        INTEGER(iwp) ::  px                 !:
        INTEGER(iwp) ::  py                 !:
-       INTEGER(iwp) ::  server_pe          !:
+       INTEGER(iwp) ::  parent_pe          !:
 
        INTEGER(iwp), DIMENSION(2) ::  scoord             !:
@@ -757,8 +780,8 @@
        IF ( myid == 0 )  THEN
 !--       TO_DO: Klaus: give more specific comment what size_of_array stands for
-          CALL pmc_recv_from_client( client_id, size_of_array, 2, 0, 40, ierr )
+          CALL pmc_recv_from_child( child_id, size_of_array, 2, 0, 40, ierr )
           ALLOCATE( coarse_bound_all(size_of_array(1),size_of_array(2)) )
-          CALL pmc_recv_from_client( client_id, coarse_bound_all,              &
-                                     SIZE( coarse_bound_all ), 0, 41, ierr )
+          CALL pmc_recv_from_child( child_id, coarse_bound_all,                 &
+                                    SIZE( coarse_bound_all ), 0, 41, ierr )
 
 !
@@ -783,11 +806,11 @@
           ic  = 0
 !
-!--       Loop over all client PEs
+!--       Loop over all children PEs
           DO  k = 1, size_of_array(2)
 !
-!--          Area along y required by actual client PE
+!--          Area along y required by actual child PE
              DO  j = coarse_bound_all(3,k), coarse_bound_all(4,k)
 !
-!--             Area along x required by actual client PE
+!--             Area along x required by actual child PE
                 DO  i = coarse_bound_all(1,k), coarse_bound_all(2,k)
 
@@ -796,25 +819,25 @@
                    scoord(1) = px
                    scoord(2) = py
-                   CALL MPI_CART_RANK( comm2d, scoord, server_pe, ierr )
+                   CALL MPI_CART_RANK( comm2d, scoord, parent_pe, ierr )
                   
                    ic = ic + 1
 !
-!--                First index in server array
+!--                First index in parent array
                    index_list(1,ic) = i - ( px * nrx ) + 1 + nbgp
 !
-!--                Second index in server array
+!--                Second index in parent array
                    index_list(2,ic) = j - ( py * nry ) + 1 + nbgp
 !
-!--                x index of client coarse grid
+!--                x index of child coarse grid
                    index_list(3,ic) = i - coarse_bound_all(1,k) + 1
 !
-!--                y index of client coarse grid
+!--                y index of child coarse grid
                    index_list(4,ic) = j - coarse_bound_all(3,k) + 1
 !
-!--                PE number of client
+!--                PE number of child
                    index_list(5,ic) = k - 1
 !
-!--                PE number of server
-                   index_list(6,ic) = server_pe
+!--                PE number of parent
+                   index_list(6,ic) = parent_pe
 
                 ENDDO
@@ -823,5 +846,5 @@
 !
 !--       TO_DO: Klaus: comment what is done here
-          CALL pmc_s_set_2d_index_list( client_id, index_list(:,1:ic) )
+          CALL pmc_s_set_2d_index_list( child_id, index_list(:,1:ic) )
 
        ELSE
@@ -829,5 +852,5 @@
 !--       TO_DO: Klaus: comment why this dummy allocation is required
           ALLOCATE( index_list(6,1) )
-          CALL pmc_s_set_2d_index_list( client_id, index_list )
+          CALL pmc_s_set_2d_index_list( child_id, index_list )
        ENDIF
 
@@ -837,9 +860,9 @@
 
 #endif
- END SUBROUTINE pmci_setup_server
-
-
-
- SUBROUTINE pmci_setup_client
+ END SUBROUTINE pmci_setup_parent
+
+
+
+ SUBROUTINE pmci_setup_child
 
 #if defined( __parallel )
@@ -867,16 +890,16 @@
 !
 !-- TO_DO: describe what is happening in this if-clause
-!-- Root Model does not have Server and is not a client
+!-- Root model does not have a parent and is not a child
     IF ( .NOT. pmc_is_rootmodel() )  THEN
 
-       CALL pmc_clientinit
+       CALL pmc_childinit
 !
 !--    Here AND ONLY HERE the arrays are defined, which actualy will be
-!--    exchanged between client and server.
+!--    exchanged between child and parent.
 !--    If a variable is removed, it only has to be removed from here.
 !--    Please check, if the arrays are in the list of POSSIBLE exchange arrays
 !--    in subroutines:
-!--    pmci_set_array_pointer (for server arrays)
-!--    pmci_create_client_arrays (for client arrays)
+!--    pmci_set_array_pointer (for parent arrays)
+!--    pmci_create_child_arrays (for child arrays)
        CALL pmc_set_dataarray_name( 'coarse', 'u'  ,'fine', 'u',  ierr )
        CALL pmc_set_dataarray_name( 'coarse', 'v'  ,'fine', 'v',  ierr )
@@ -893,5 +916,5 @@
 
 !
-!--    Send grid to server
+!--    Send grid to parent
        val(1)  = nx
        val(2)  = ny
@@ -903,18 +926,18 @@
        IF ( myid == 0 )  THEN
 
-          CALL pmc_send_to_server( val, SIZE( val ), 0, 123, ierr )
-          CALL pmc_send_to_server( fval, SIZE( fval ), 0, 124, ierr )
-          CALL pmc_send_to_server( coord_x, nx + 1 + 2 * nbgp, 0, 11, ierr )
-          CALL pmc_send_to_server( coord_y, ny + 1 + 2 * nbgp, 0, 12, ierr )
+          CALL pmc_send_to_parent( val, SIZE( val ), 0, 123, ierr )
+          CALL pmc_send_to_parent( fval, SIZE( fval ), 0, 124, ierr )
+          CALL pmc_send_to_parent( coord_x, nx + 1 + 2 * nbgp, 0, 11, ierr )
+          CALL pmc_send_to_parent( coord_y, ny + 1 + 2 * nbgp, 0, 12, ierr )
 
 !
 !--       Receive Coarse grid information.
 !--       TO_DO: find shorter and more meaningful name for  define_coarse_grid_real
-          CALL pmc_recv_from_server( define_coarse_grid_real,                  &
+          CALL pmc_recv_from_parent( define_coarse_grid_real,                  &
                                      SIZE(define_coarse_grid_real), 0, 21, ierr )
-          CALL pmc_recv_from_server( define_coarse_grid_int,  3, 0, 22, ierr )
+          CALL pmc_recv_from_parent( define_coarse_grid_int,  3, 0, 22, ierr )
 !
 !--        Debug-printouts - keep them
-!          WRITE(0,*) 'Coarse grid from Server '
+!          WRITE(0,*) 'Coarse grid from parent '
 !          WRITE(0,*) 'startx_tot    = ',define_coarse_grid_real(1)
 !          WRITE(0,*) 'starty_tot    = ',define_coarse_grid_real(2)
@@ -929,5 +952,5 @@
        ENDIF
 
-       CALL MPI_BCAST( define_coarse_grid_real, SIZE(define_coarse_grid_real), &
+       CALL MPI_BCAST( define_coarse_grid_real, SIZE(define_coarse_grid_real),  &
                        MPI_REAL, 0, comm2d, ierr )
        CALL MPI_BCAST( define_coarse_grid_int, 3, MPI_INTEGER, 0, comm2d, ierr )
@@ -941,5 +964,5 @@
 
 !
-!--    Get server coordinates on coarse grid
+!--    Get parent coordinates on coarse grid
        ALLOCATE( cg%coord_x(-nbgp:cg%nx+nbgp) )
        ALLOCATE( cg%coord_y(-nbgp:cg%ny+nbgp) )
@@ -951,13 +974,13 @@
 
 !
-!--    Get coarse grid coordinates and vales of the z-direction from server
+!--    Get coarse grid coordinates and values of the z-direction from the parent
        IF ( myid == 0)  THEN
 
-          CALL pmc_recv_from_server( cg%coord_x, cg%nx+1+2*nbgp, 0, 24, ierr )
-          CALL pmc_recv_from_server( cg%coord_y, cg%ny+1+2*nbgp, 0, 25, ierr )
-          CALL pmc_recv_from_server( cg%dzu, cg%nz + 1, 0, 26, ierr )
-          CALL pmc_recv_from_server( cg%dzw, cg%nz + 1, 0, 27, ierr )
-          CALL pmc_recv_from_server( cg%zu, cg%nz + 2, 0, 28, ierr )
-          CALL pmc_recv_from_server( cg%zw, cg%nz + 2, 0, 29, ierr )
+          CALL pmc_recv_from_parent( cg%coord_x, cg%nx+1+2*nbgp, 0, 24, ierr )
+          CALL pmc_recv_from_parent( cg%coord_y, cg%ny+1+2*nbgp, 0, 25, ierr )
+          CALL pmc_recv_from_parent( cg%dzu, cg%nz + 1, 0, 26, ierr )
+          CALL pmc_recv_from_parent( cg%dzw, cg%nz + 1, 0, 27, ierr )
+          CALL pmc_recv_from_parent( cg%zu, cg%nz + 2, 0, 28, ierr )
+          CALL pmc_recv_from_parent( cg%zw, cg%nz + 2, 0, 29, ierr )
 
        ENDIF
@@ -980,15 +1003,15 @@
 
 !
-!--    Include couple arrays into client content
-!--    TO_DO: Klaus: better explain the above comment (what is client content?)
+!--    Include couple arrays into child content
+!--    TO_DO: Klaus: better explain the above comment (what is child content?)
        CALL  pmc_c_clear_next_array_list
        DO  WHILE ( pmc_c_getnextarray( myname ) )
-!--       TO_DO: Klaus, why the c-arrays are still up to cg%nz??
-          CALL pmci_create_client_arrays ( myname, icl, icr, jcs, jcn, cg%nz )
+!--       TO_DO: Klaus, why the child-arrays are still up to cg%nz??
+          CALL pmci_create_child_arrays ( myname, icl, icr, jcs, jcn, cg%nz )
        ENDDO
        CALL pmc_c_setind_and_allocmem
 
 !
-!--    Precompute interpolation coefficients and client-array indices
+!--    Precompute interpolation coefficients and child-array indices
        CALL pmci_init_interp_tril
 
@@ -1002,8 +1025,9 @@
 
 !
-!--    Two-way coupling.
+!--    Two-way coupling for general and vertical nesting.
 !--    Precompute the index arrays and relaxation functions for the
 !--    anterpolation
-       IF ( nesting_mode == 'two-way' )  THEN
+       IF ( TRIM( nesting_mode ) == 'two-way' .OR.                              &
+                  nesting_mode == 'vertical' )  THEN
           CALL pmci_init_anterp_tophat
        ENDIF
@@ -1097,5 +1121,5 @@
 !--    Note that MPI_Gather receives data from all processes in the rank order
 !--    TO_DO: refer to the line where this fact becomes important
-       CALL MPI_GATHER( coarse_bound, 5, MPI_INTEGER, coarse_bound_all, 5, &
+       CALL MPI_GATHER( coarse_bound, 5, MPI_INTEGER, coarse_bound_all, 5,      &
                         MPI_INTEGER, 0, comm2d, ierr )
 
@@ -1103,6 +1127,6 @@
           size_of_array(1) = SIZE( coarse_bound_all, 1 )
           size_of_array(2) = SIZE( coarse_bound_all, 2 )
-          CALL pmc_send_to_server( size_of_array, 2, 0, 40, ierr )
-          CALL pmc_send_to_server( coarse_bound_all, SIZE( coarse_bound_all ), &
+          CALL pmc_send_to_parent( size_of_array, 2, 0, 40, ierr )
+          CALL pmc_send_to_parent( coarse_bound_all, SIZE( coarse_bound_all ),  &
                                    0, 41, ierr )
        ENDIF
@@ -1114,5 +1138,5 @@
     SUBROUTINE pmci_init_interp_tril
 !
-!--    Precomputation of the interpolation coefficients and client-array indices
+!--    Precomputation of the interpolation coefficients and child-array indices
 !--    to be used by the interpolation routines interp_tril_lr, interp_tril_ns
 !--    and interp_tril_t.
@@ -1167,5 +1191,5 @@
 !
 !--    Note that the node coordinates xfs... and xcs... are relative to the
-!--    lower-left-bottom corner of the fc-array, not the actual client domain
+!--    lower-left-bottom corner of the fc-array, not the actual child domain
 !--    corner
        DO  i = nxlg, nxrg
@@ -1262,5 +1286,5 @@
           DO  i = nxl-1, nxl
              DO  j = nys, nyn
-                nzt_topo_nestbc_l = MAX( nzt_topo_nestbc_l, nzb_u_inner(j,i),  &
+                nzt_topo_nestbc_l = MAX( nzt_topo_nestbc_l, nzb_u_inner(j,i),   &
                                          nzb_v_inner(j,i), nzb_w_inner(j,i) )
              ENDDO
@@ -1273,5 +1297,5 @@
           i = nxr + 1
           DO  j = nys, nyn
-             nzt_topo_nestbc_r = MAX( nzt_topo_nestbc_r, nzb_u_inner(j,i),     &
+             nzt_topo_nestbc_r = MAX( nzt_topo_nestbc_r, nzb_u_inner(j,i),      &
                                       nzb_v_inner(j,i), nzb_w_inner(j,i) )
           ENDDO
@@ -1283,5 +1307,5 @@
           DO  j = nys-1, nys
              DO  i = nxl, nxr
-                nzt_topo_nestbc_s = MAX( nzt_topo_nestbc_s, nzb_u_inner(j,i),  &
+                nzt_topo_nestbc_s = MAX( nzt_topo_nestbc_s, nzb_u_inner(j,i),   &
                                          nzb_v_inner(j,i), nzb_w_inner(j,i) )
              ENDDO
@@ -1294,5 +1318,5 @@
           j = nyn + 1
           DO  i = nxl, nxr
-             nzt_topo_nestbc_n = MAX( nzt_topo_nestbc_n, nzb_u_inner(j,i),     &
+             nzt_topo_nestbc_n = MAX( nzt_topo_nestbc_n, nzb_u_inner(j,i),      &
                                       nzb_v_inner(j,i), nzb_w_inner(j,i) )
           ENDDO
@@ -1303,5 +1327,5 @@
 !--    Then determine the maximum number of near-wall nodes per wall point based
 !--    on the grid-spacing ratios.
-       nzt_topo_max = MAX( nzt_topo_nestbc_l, nzt_topo_nestbc_r,               &
+       nzt_topo_max = MAX( nzt_topo_nestbc_l, nzt_topo_nestbc_r,                &
                            nzt_topo_nestbc_s, nzt_topo_nestbc_n )
 
@@ -1343,5 +1367,5 @@
              k   = kb + 1
              wall_index = kb
-             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,     &
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,      &
                                 inc, wall_index, z0(j,i), kb, direction, ncorr )
              logc_u_l(1,k,j) = lc
@@ -1354,5 +1378,5 @@
              k   =  kb + 1
              wall_index = kb
-             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,     &
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,      &
                                 inc, wall_index, z0(j,i), kb, direction, ncorr )
              logc_v_l(1,k,j) = lc
@@ -1385,5 +1409,5 @@
              k   = kb + 1
              wall_index = kb
-             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,     &
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,      &
                                 inc, wall_index, z0(j,i), kb, direction, ncorr )
              logc_u_r(1,k,j) = lc
@@ -1396,5 +1420,5 @@
              k   = kb + 1
              wall_index = kb
-             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,     &
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,      &
                                 inc, wall_index, z0(j,i), kb, direction, ncorr )
              logc_v_r(1,k,j) = lc
@@ -1428,5 +1452,5 @@
              k   =  kb + 1
              wall_index = kb
-             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,     &
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,      &
                                 inc, wall_index, z0(j,i), kb, direction, ncorr )
              logc_u_s(1,k,i) = lc
@@ -1439,5 +1463,5 @@
              k   = kb + 1
              wall_index = kb
-             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,     &
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,      &
                                 inc, wall_index, z0(j,i), kb, direction, ncorr )
              logc_v_s(1,k,i) = lc
@@ -1471,5 +1495,5 @@
              k   = kb + 1
              wall_index = kb
-             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,     &
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,      &
                                 inc, wall_index, z0(j,i), kb, direction, ncorr )
              logc_u_n(1,k,i) = lc
@@ -1482,5 +1506,5 @@
              k   = kb + 1
              wall_index = kb
-             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,     &
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k, j,      &
                                 inc, wall_index, z0(j,i), kb, direction, ncorr )
              logc_v_n(1,k,i) = lc
@@ -1502,5 +1526,5 @@
 
              ALLOCATE( logc_w_l(1:2,nzb:nzt_topo_nestbc_l,nys:nyn) )
-             ALLOCATE( logc_ratio_w_l(1:2,0:ncorr-1,nzb:nzt_topo_nestbc_l,     &
+             ALLOCATE( logc_ratio_w_l(1:2,0:ncorr-1,nzb:nzt_topo_nestbc_l,      &
                                       nys:nyn) )
 
@@ -1513,10 +1537,10 @@
 !--                Wall for u on the south side, but not on the north side
                    i  = 0
-                   IF ( ( nzb_u_outer(j,i) > nzb_u_outer(j+1,i) ) .AND.        &
-                        ( nzb_u_outer(j,i) == nzb_u_outer(j-1,i) ) )           &
+                   IF ( ( nzb_u_outer(j,i) > nzb_u_outer(j+1,i) ) .AND.         &
+                        ( nzb_u_outer(j,i) == nzb_u_outer(j-1,i) ) )            &
                    THEN
                       inc        =  1
                       wall_index =  j
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, j, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1531,9 +1555,9 @@
 !--                Wall for u on the north side, but not on the south side
                    i  = 0
-                   IF ( ( nzb_u_outer(j,i) > nzb_u_outer(j-1,i) ) .AND.        &
+                   IF ( ( nzb_u_outer(j,i) > nzb_u_outer(j-1,i) ) .AND.         &
                         ( nzb_u_outer(j,i) == nzb_u_outer(j+1,i) ) )  THEN
                       inc        = -1
                       wall_index =  j + 1
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, j, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1548,9 +1572,9 @@
 !--                Wall for w on the south side, but not on the north side.
                    i  = -1
-                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j+1,i) )  .AND.       &
+                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j+1,i) )  .AND.        &
                         ( nzb_w_outer(j,i) == nzb_w_outer(j-1,i) ) )  THEN
                       inc        =  1
                       wall_index =  j
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, j, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1565,9 +1589,9 @@
 !--                Wall for w on the north side, but not on the south side.
                    i  = -1
-                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j-1,i) )  .AND.       &
+                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j-1,i) )  .AND.        &
                         ( nzb_w_outer(j,i) == nzb_w_outer(j+1,i) ) )  THEN
                       inc        = -1
                       wall_index =  j+1
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, j, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1589,5 +1613,5 @@
 
              ALLOCATE( logc_w_r(1:2,nzb:nzt_topo_nestbc_r,nys:nyn) )
-             ALLOCATE( logc_ratio_w_r(1:2,0:ncorr-1,nzb:nzt_topo_nestbc_r,     &
+             ALLOCATE( logc_ratio_w_r(1:2,0:ncorr-1,nzb:nzt_topo_nestbc_r,      &
                                       nys:nyn) )
              logc_w_r       = 0
@@ -1600,9 +1624,9 @@
 !
 !--                Wall for u on the south side, but not on the north side
-                   IF ( ( nzb_u_outer(j,i) > nzb_u_outer(j+1,i) )  .AND.       &
+                   IF ( ( nzb_u_outer(j,i) > nzb_u_outer(j+1,i) )  .AND.        &
                         ( nzb_u_outer(j,i) == nzb_u_outer(j-1,i) ) )  THEN
                       inc        = 1
                       wall_index = j
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, j, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1616,9 +1640,9 @@
 !
 !--                Wall for u on the north side, but not on the south side
-                   IF ( ( nzb_u_outer(j,i) > nzb_u_outer(j-1,i) )  .AND.       &
+                   IF ( ( nzb_u_outer(j,i) > nzb_u_outer(j-1,i) )  .AND.        &
                         ( nzb_u_outer(j,i) == nzb_u_outer(j+1,i) ) )  THEN
                       inc        = -1
                       wall_index =  j+1
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, j, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1632,9 +1656,9 @@
 !
 !--                Wall for w on the south side, but not on the north side
-                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j+1,i) )  .AND.       &
+                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j+1,i) )  .AND.        &
                         ( nzb_w_outer(j,i) == nzb_w_outer(j-1,i) ) )  THEN
                       inc        =  1
                       wall_index =  j
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, j, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1648,9 +1672,9 @@
 !
 !--                Wall for w on the north side, but not on the south side
-                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j-1,i) )  .AND.       &
+                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j-1,i) )  .AND.        &
                         ( nzb_w_outer(j,i) == nzb_w_outer(j+1,i) ) )  THEN
                       inc        = -1
                       wall_index =  j+1
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, j, inc, wall_index, z0(j,i), kb, direction, ncorr )
 
@@ -1673,5 +1697,5 @@
 
              ALLOCATE( logc_w_s(1:2,nzb:nzt_topo_nestbc_s,nxl:nxr) )
-             ALLOCATE( logc_ratio_w_s(1:2,0:ncorr-1,nzb:nzt_topo_nestbc_s,     &
+             ALLOCATE( logc_ratio_w_s(1:2,0:ncorr-1,nzb:nzt_topo_nestbc_s,      &
                                       nxl:nxr) )
              logc_w_s       = 0
@@ -1684,9 +1708,9 @@
 !--                Wall for v on the left side, but not on the right side
                    j  = 0
-                   IF ( ( nzb_v_outer(j,i) > nzb_v_outer(j,i+1) )  .AND.       &
+                   IF ( ( nzb_v_outer(j,i) > nzb_v_outer(j,i+1) )  .AND.        &
                         ( nzb_v_outer(j,i) == nzb_v_outer(j,i-1) ) )  THEN
                       inc        =  1
                       wall_index =  i
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, i, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1701,9 +1725,9 @@
 !--                Wall for v on the right side, but not on the left side
                    j  = 0
-                   IF ( ( nzb_v_outer(j,i) > nzb_v_outer(j,i-1) )  .AND.       &
+                   IF ( ( nzb_v_outer(j,i) > nzb_v_outer(j,i-1) )  .AND.        &
                         ( nzb_v_outer(j,i) == nzb_v_outer(j,i+1) ) )  THEN
                       inc        = -1
                       wall_index =  i+1
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, i, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1718,9 +1742,9 @@
 !--                Wall for w on the left side, but not on the right side
                    j  = -1
-                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j,i+1) )  .AND.       &
+                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j,i+1) )  .AND.        &
                         ( nzb_w_outer(j,i) == nzb_w_outer(j,i-1) ) )  THEN
                       inc        =  1
                       wall_index =  i
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, i, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1735,9 +1759,9 @@
 !--                Wall for w on the right side, but not on the left side
                    j  = -1
-                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j,i-1) )  .AND.       &
+                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j,i-1) )  .AND.        &
                         ( nzb_w_outer(j,i) == nzb_w_outer(j,i+1) ) )  THEN
                       inc        = -1
                       wall_index =  i+1
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, i, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1759,5 +1783,5 @@
 
              ALLOCATE( logc_w_n(1:2,nzb:nzt_topo_nestbc_n, nxl:nxr) )
-             ALLOCATE( logc_ratio_w_n(1:2,0:ncorr-1,nzb:nzt_topo_nestbc_n,     &
+             ALLOCATE( logc_ratio_w_n(1:2,0:ncorr-1,nzb:nzt_topo_nestbc_n,      &
                                       nxl:nxr) )
              logc_w_n       = 0
@@ -1770,9 +1794,9 @@
 !
 !--                Wall for v on the left side, but not on the right side
-                   IF ( ( nzb_v_outer(j,i) > nzb_v_outer(j,i+1) )  .AND.       &
+                   IF ( ( nzb_v_outer(j,i) > nzb_v_outer(j,i+1) )  .AND.        &
                         ( nzb_v_outer(j,i) == nzb_v_outer(j,i-1) ) )  THEN
                       inc        = 1
                       wall_index = i
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, i, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1786,9 +1810,9 @@
 !
 !--                Wall for v on the right side, but not on the left side
-                   IF ( ( nzb_v_outer(j,i) > nzb_v_outer(j,i-1) )  .AND.       &
+                   IF ( ( nzb_v_outer(j,i) > nzb_v_outer(j,i-1) )  .AND.        &
                         ( nzb_v_outer(j,i) == nzb_v_outer(j,i+1) ) )  THEN
                       inc        = -1
                       wall_index =  i + 1
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, i, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1802,9 +1826,9 @@
 !
 !--                Wall for w on the left side, but not on the right side
-                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j,i+1) )  .AND.       &
+                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j,i+1) )  .AND.        &
                         ( nzb_w_outer(j,i) == nzb_w_outer(j,i-1) ) )  THEN
                       inc        = 1
                       wall_index = i
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, i, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1818,9 +1842,9 @@
 !
 !--                Wall for w on the right side, but not on the left side
-                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j,i-1) )  .AND.       &
+                   IF ( ( nzb_w_outer(j,i) > nzb_w_outer(j,i-1) )  .AND.        &
                         ( nzb_w_outer(j,i) == nzb_w_outer(j,i+1) ) )  THEN
                       inc        = -1
                       wall_index =  i+1
-                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,  &
+                      CALL pmci_define_loglaw_correction_parameters( lc, lcr,   &
                           k, i, inc, wall_index, z0(j,i), kb, direction, ncorr )
 !
@@ -1843,5 +1867,5 @@
 
 
-    SUBROUTINE pmci_define_loglaw_correction_parameters( lc, lcr, k, ij, inc,  &
+    SUBROUTINE pmci_define_loglaw_correction_parameters( lc, lcr, k, ij, inc,   &
                                         wall_index, z0_l, kb, direction, ncorr )
 
@@ -1897,5 +1921,5 @@
                 corr_index = ij + lcorr   ! In this case (direction = 2) ij is j
                 IF ( lcorr == 0 )  THEN
-                   CALL pmci_find_logc_pivot_j( lc, logvelc1, ij, wall_index,  &
+                   CALL pmci_find_logc_pivot_j( lc, logvelc1, ij, wall_index,   &
                                                 z0_l, inc )
                 ENDIF
@@ -1905,6 +1929,6 @@
 !--             valid in both directions
                 IF ( inc * corr_index < inc * lc )  THEN
-                   lcr(alcorr) = LOG( ABS( coord_y(corr_index) + 0.5_wp * dy   &
-                                         - coord_y(wall_index) ) / z0_l )      &
+                   lcr(alcorr) = LOG( ABS( coord_y(corr_index) + 0.5_wp * dy    &
+                                         - coord_y(wall_index) ) / z0_l )       &
                                  / logvelc1
                    more = .TRUE.
@@ -1924,5 +1948,5 @@
                 corr_index = ij + lcorr   ! In this case (direction = 3) ij is i
                 IF ( lcorr == 0 )  THEN
-                   CALL pmci_find_logc_pivot_i( lc, logvelc1, ij, wall_index,  &
+                   CALL pmci_find_logc_pivot_i( lc, logvelc1, ij, wall_index,   &
                                                 z0_l, inc )
                 ENDIF
@@ -1931,6 +1955,6 @@
 !--             valid in both directions
                 IF ( inc * corr_index < inc * lc )  THEN
-                   lcr(alcorr) = LOG( ABS( coord_x(corr_index) + 0.5_wp * dx   &
-                                         - coord_x(wall_index) ) / z0_l )      &
+                   lcr(alcorr) = LOG( ABS( coord_x(corr_index) + 0.5_wp * dx    &
+                                         - coord_x(wall_index) ) / z0_l )       &
                                  / logvelc1
                    more = .TRUE.
@@ -1963,5 +1987,5 @@
        INTEGER(iwp) ::  k1     !:
 
-       REAL(wp),INTENT(OUT) ::  logzc1     !:
+       REAL(wp), INTENT(OUT) ::  logzc1     !:
        REAL(wp), INTENT(IN) ::  z0_l       !:
 
@@ -2072,5 +2096,5 @@
     SUBROUTINE pmci_init_anterp_tophat
 !
-!--    Precomputation of the client-array indices for
+!--    Precomputation of the child-array indices for
 !--    corresponding coarse-grid array index and the
 !--    Under-relaxation coefficients to be used by anterp_tophat.
@@ -2148,10 +2172,10 @@
        DO  ii = icl, icr
           i = istart
-          DO  WHILE ( ( coord_x(i) < cg%coord_x(ii) - 0.5_wp * cg%dx )  .AND.  &
+          DO  WHILE ( ( coord_x(i) < cg%coord_x(ii) - 0.5_wp * cg%dx )  .AND.   &
                       ( i < nxrg ) )
              i = i + 1
           ENDDO
           iflu(ii) = MIN( MAX( i, nxlg ), nxrg )
-          DO  WHILE ( ( coord_x(i) < cg%coord_x(ii) + 0.5_wp * cg%dx )  .AND.  &
+          DO  WHILE ( ( coord_x(i) < cg%coord_x(ii) + 0.5_wp * cg%dx )  .AND.   &
                       ( i < nxrg ) )
              i = i + 1
@@ -2166,10 +2190,10 @@
        DO  ii = icl, icr
           i = istart
-          DO  WHILE ( ( coord_x(i) + 0.5_wp * dx < cg%coord_x(ii) )  .AND.     &
+          DO  WHILE ( ( coord_x(i) + 0.5_wp * dx < cg%coord_x(ii) )  .AND.      &
                       ( i < nxrg ) )
              i = i + 1
           ENDDO
           iflo(ii) = MIN( MAX( i, nxlg ), nxrg )
-          DO  WHILE ( ( coord_x(i) + 0.5_wp * dx < cg%coord_x(ii) + cg%dx )    &
+          DO  WHILE ( ( coord_x(i) + 0.5_wp * dx < cg%coord_x(ii) + cg%dx )     &
                       .AND.  ( i < nxrg ) )
              i = i + 1
@@ -2184,10 +2208,10 @@
        DO  jj = jcs, jcn
           j = jstart
-          DO  WHILE ( ( coord_y(j) < cg%coord_y(jj) - 0.5_wp * cg%dy )  .AND.  &
+          DO  WHILE ( ( coord_y(j) < cg%coord_y(jj) - 0.5_wp * cg%dy )  .AND.   &
                       ( j < nyng ) )
              j = j + 1
           ENDDO
           jflv(jj) = MIN( MAX( j, nysg ), nyng )
-          DO  WHILE ( ( coord_y(j) < cg%coord_y(jj) + 0.5_wp * cg%dy )  .AND.  &
+          DO  WHILE ( ( coord_y(j) < cg%coord_y(jj) + 0.5_wp * cg%dy )  .AND.   &
                       ( j < nyng ) )
              j = j + 1
@@ -2202,10 +2226,10 @@
        DO  jj = jcs, jcn
           j = jstart
-          DO  WHILE ( ( coord_y(j) + 0.5_wp * dy < cg%coord_y(jj) )  .AND.     &
+          DO  WHILE ( ( coord_y(j) + 0.5_wp * dy < cg%coord_y(jj) )  .AND.      &
                       ( j < nyng ) )
              j = j + 1
           ENDDO
           jflo(jj) = MIN( MAX( j, nysg ), nyng )
-          DO  WHILE ( ( coord_y(j) + 0.5_wp * dy < cg%coord_y(jj) + cg%dy )    &
+          DO  WHILE ( ( coord_y(j) + 0.5_wp * dy < cg%coord_y(jj) + cg%dy )     &
                       .AND.  ( j < nyng ) )
              j = j + 1
@@ -2222,10 +2246,10 @@
        DO  kk = 1, kctw
           k = kstart
-          DO  WHILE ( ( zw(k) < cg%zw(kk) - 0.5_wp * cg%dzw(kk) )  .AND.       &
+          DO  WHILE ( ( zw(k) < cg%zw(kk) - 0.5_wp * cg%dzw(kk) )  .AND.        &
                       ( k < nzt ) )
              k = k + 1
           ENDDO
           kflw(kk) = MIN( MAX( k, 1 ), nzt + 1 )
-          DO  WHILE ( ( zw(k) < cg%zw(kk) + 0.5_wp * cg%dzw(kk+1) )  .AND.     &
+          DO  WHILE ( ( zw(k) < cg%zw(kk) + 0.5_wp * cg%dzw(kk+1) )  .AND.      &
                       ( k < nzt ) )
              k = k + 1
@@ -2242,10 +2266,10 @@
        DO  kk = 1, kctu
           k = kstart
-          DO  WHILE ( ( zu(k) < cg%zu(kk) - 0.5_wp * cg%dzu(kk) )  .AND.       &
+          DO  WHILE ( ( zu(k) < cg%zu(kk) - 0.5_wp * cg%dzu(kk) )  .AND.        &
                       ( k < nzt ) )
              k = k + 1
           ENDDO
           kflo(kk) = MIN( MAX( k, 1 ), nzt + 1 )
-          DO  WHILE ( ( zu(k) < cg%zu(kk) + 0.5_wp * cg%dzu(kk+1) )  .AND.     &
+          DO  WHILE ( ( zu(k) < cg%zu(kk) + 0.5_wp * cg%dzu(kk+1) )  .AND.      &
                       ( k < nzt ) )
              k = k + 1
@@ -2272,34 +2296,39 @@
 !--    Spatial under-relaxation coefficients
        ALLOCATE( frax(icl:icr) )
-
-       DO  ii = icl, icr
-          IF ( nest_bound_l )  THEN
-             xi = ( MAX( 0.0_wp, ( cg%coord_x(ii) - lower_left_coord_x ) ) /   &
-                    anterp_relax_length_l )**4
-          ELSEIF ( nest_bound_r )  THEN
-             xi = ( MAX( 0.0_wp, ( lower_left_coord_x + ( nx + 1 ) * dx -      &
-                                   cg%coord_x(ii) ) ) /                        &
-                    anterp_relax_length_r )**4
-          ELSE
-             xi = 999999.9_wp
-          ENDIF
-          frax(ii) = xi / ( 1.0_wp + xi )
-       ENDDO
-
        ALLOCATE( fray(jcs:jcn) )
-
-       DO  jj = jcs, jcn
-          IF ( nest_bound_s )  THEN
-             eta = ( MAX( 0.0_wp, ( cg%coord_y(jj) - lower_left_coord_y ) ) /  &
-                     anterp_relax_length_s )**4
-          ELSEIF ( nest_bound_n )  THEN
-             eta = ( MAX( 0.0_wp, ( lower_left_coord_y + ( ny + 1 ) * dy -     &
-                                    cg%coord_y(jj)) ) /                        &
-                     anterp_relax_length_n )**4
-          ELSE
-             eta = 999999.9_wp
-          ENDIF
-          fray(jj) = eta / ( 1.0_wp + eta )
-       ENDDO
+       
+       frax(icl:icr) = 1.0_wp
+       fray(jcs:jcn) = 1.0_wp
+
+       IF ( nesting_mode /= 'vertical' )  THEN
+          DO  ii = icl, icr
+             IF ( nest_bound_l )  THEN
+                xi = ( MAX( 0.0_wp, ( cg%coord_x(ii) -                          &
+                       lower_left_coord_x ) ) / anterp_relax_length_l )**4
+             ELSEIF ( nest_bound_r )  THEN
+                xi = ( MAX( 0.0_wp, ( lower_left_coord_x + ( nx + 1 ) * dx -    &
+                                      cg%coord_x(ii) ) ) /                      &
+                       anterp_relax_length_r )**4
+             ELSE
+                xi = 999999.9_wp
+             ENDIF
+             frax(ii) = xi / ( 1.0_wp + xi )
+          ENDDO
+
+
+          DO  jj = jcs, jcn
+             IF ( nest_bound_s )  THEN
+                eta = ( MAX( 0.0_wp, ( cg%coord_y(jj) -                         &
+                        lower_left_coord_y ) ) / anterp_relax_length_s )**4
+             ELSEIF ( nest_bound_n )  THEN
+                eta = ( MAX( 0.0_wp, ( lower_left_coord_y + ( ny + 1 ) * dy -   &
+                                       cg%coord_y(jj)) ) /                      &
+                        anterp_relax_length_n )**4
+             ELSE
+                eta = 999999.9_wp
+             ENDIF
+             fray(jj) = eta / ( 1.0_wp + eta )
+          ENDDO
+       ENDIF
       
        ALLOCATE( fraz(0:kctu) )
@@ -2347,5 +2376,5 @@
                 height = zu(k) - zu(nzb_s_inner(j,i))
                 fw     = EXP( -cfw * height / glsf )
-                tkefactor_l(k,j) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *     &
+                tkefactor_l(k,j) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *      &
                                               ( glsf / glsc )**p23 )
              ENDDO
@@ -2365,5 +2394,5 @@
                 height = zu(k) - zu(nzb_s_inner(j,i))
                 fw     = EXP( -cfw * height / glsf )
-                tkefactor_r(k,j) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *     &
+                tkefactor_r(k,j) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *      &
                                               ( glsf / glsc )**p23 )
              ENDDO
@@ -2383,5 +2412,5 @@
                 height = zu(k) - zu(nzb_s_inner(j,i))
                 fw     = EXP( -cfw*height / glsf )
-                tkefactor_s(k,i) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *     &
+                tkefactor_s(k,i) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *      &
                                               ( glsf / glsc )**p23 )
              ENDDO
@@ -2401,5 +2430,5 @@
                 height = zu(k) - zu(nzb_s_inner(j,i))
                 fw     = EXP( -cfw * height / glsf )
-                tkefactor_n(k,i) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *     &
+                tkefactor_n(k,i) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *      &
                                               ( glsf / glsc )**p23 )
              ENDDO
@@ -2417,5 +2446,5 @@
              height = zu(k) - zu(nzb_s_inner(j,i))
              fw     = EXP( -cfw * height / glsf )
-             tkefactor_t(j,i) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *        &
+             tkefactor_t(j,i) = c_tkef * ( fw0 * fw + ( 1.0_wp - fw ) *         &
                                            ( glsf / glsc )**p23 )
           ENDDO
@@ -2425,5 +2454,5 @@
 
 #endif
- END SUBROUTINE pmci_setup_client
+ END SUBROUTINE pmci_setup_child
 
 
@@ -2456,9 +2485,9 @@
 
 
- SUBROUTINE pmci_set_array_pointer( name, client_id, nz_cl )
+ SUBROUTINE pmci_set_array_pointer( name, child_id, nz_cl )
 
     IMPLICIT NONE
 
-    INTEGER, INTENT(IN)          ::  client_id   !:
+    INTEGER, INTENT(IN)          ::  child_id    !:
     INTEGER, INTENT(IN)          ::  nz_cl       !:
     CHARACTER(LEN=*), INTENT(IN) ::  name        !:
@@ -2493,7 +2522,7 @@
 #if defined( __nopointer )
     IF ( ASSOCIATED( p_3d ) )  THEN
-       CALL pmc_s_set_dataarray( client_id, p_3d, nz_cl, nz )
+       CALL pmc_s_set_dataarray( child_id, p_3d, nz_cl, nz )
     ELSEIF ( ASSOCIATED( p_2d ) )  THEN
-       CALL pmc_s_set_dataarray( client_id, p_2d )
+       CALL pmc_s_set_dataarray( child_id, p_2d )
     ELSE
 !
@@ -2501,5 +2530,5 @@
        IF ( myid == 0  .AND.  cpl_id == 1 )  THEN
 
-          message_string = 'pointer for array "' // TRIM( name ) //            &
+          message_string = 'pointer for array "' // TRIM( name ) //             &
                            '" can''t be associated'
           CALL message( 'pmci_set_array_pointer', 'PA0117', 3, 2, 0, 6, 0 )
@@ -2519,8 +2548,8 @@
 
     IF ( ASSOCIATED( p_3d ) )  THEN
-       CALL pmc_s_set_dataarray( client_id, p_3d, nz_cl, nz, &
+       CALL pmc_s_set_dataarray( child_id, p_3d, nz_cl, nz,                     &
                                  array_2 = p_3d_sec )
     ELSEIF ( ASSOCIATED( p_2d ) )  THEN
-       CALL pmc_s_set_dataarray( client_id, p_2d )
+       CALL pmc_s_set_dataarray( child_id, p_2d )
     ELSE
 !
@@ -2528,5 +2557,5 @@
        IF ( myid == 0  .AND.  cpl_id == 1 )  THEN
 
-          message_string = 'pointer for array "' // TRIM( name ) //            &
+          message_string = 'pointer for array "' // TRIM( name ) //             &
                            '" can''t be associated'
           CALL message( 'pmci_set_array_pointer', 'PA0117', 3, 2, 0, 6, 0 )
@@ -2545,5 +2574,5 @@
 
 
- SUBROUTINE pmci_create_client_arrays( name, is, ie, js, je, nzc  )
+ SUBROUTINE pmci_create_child_arrays( name, is, ie, js, je, nzc  )
 
     IMPLICIT NONE
@@ -2599,10 +2628,10 @@
     ELSE
 !
-!--    Give only one message for the first client domain
+!--    Give only one message for the first child domain
        IF ( myid == 0  .AND.  cpl_id == 2 )  THEN
 
-          message_string = 'pointer for array "' // TRIM( name ) //            &
+          message_string = 'pointer for array "' // TRIM( name ) //             &
                            '" can''t be associated'
-          CALL message( 'pmci_create_client_arrays', 'PA0170', 3, 2, 0, 6, 0 )
+          CALL message( 'pmci_create_child_arrays', 'PA0170', 3, 2, 0, 6, 0 )
        ELSE
 !
@@ -2613,31 +2642,37 @@
 
 #endif
- END SUBROUTINE pmci_create_client_arrays
-
-
-
- SUBROUTINE pmci_server_initialize
-!-- TO_DO: add general explanations about what this subroutine does
+ END SUBROUTINE pmci_create_child_arrays
+
+
+
+ SUBROUTINE pmci_parent_initialize
+
+!
+!-- Send data for the children in order to let them create initial 
+!-- conditions by interpolating the parent-domain fields.
 #if defined( __parallel )
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  client_id   !:
+    INTEGER(iwp) ::  child_id    !:
     INTEGER(iwp) ::  m           !:
 
-    REAL(wp) ::  waittime    !:
-
-
-    DO  m = 1, SIZE( pmc_server_for_client ) - 1
-       client_id = pmc_server_for_client(m)
-       CALL pmc_s_fillbuffer( client_id, waittime=waittime )
+    REAL(wp) ::  waittime        !:
+
+
+    DO  m = 1, SIZE( pmc_parent_for_child ) - 1
+       child_id = pmc_parent_for_child(m)
+       CALL pmc_s_fillbuffer( child_id, waittime=waittime )
     ENDDO
 
 #endif
- END SUBROUTINE pmci_server_initialize
-
-
-
- SUBROUTINE pmci_client_initialize
-!-- TO_DO: add general explanations about what this subroutine does
+ END SUBROUTINE pmci_parent_initialize
+
+
+
+ SUBROUTINE pmci_child_initialize
+
+!
+!-- Create initial conditions for the current child domain by interpolating 
+!-- the parent-domain fields.
 #if defined( __parallel )
     IMPLICIT NONE
@@ -2650,12 +2685,12 @@
     INTEGER(iwp) ::  jcs        !:
 
-    REAL(wp) ::  waittime   !:
-
-!
-!-- Root id is never a client
+    REAL(wp) ::  waittime       !:
+
+!
+!-- Root id is never a child
     IF ( cpl_id > 1 )  THEN
 
 !
-!--    Client domain boundaries in the server index space
+!--    Child domain boundaries in the parent index space
        icl = coarse_bound(1)
        icr = coarse_bound(2)
@@ -2664,23 +2699,23 @@
 
 !
-!--    Get data from server
+!--    Get data from the parent
        CALL pmc_c_getbuffer( waittime = waittime )
 
 !
 !--    The interpolation.
-       CALL pmci_interp_tril_all ( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo,   &
+       CALL pmci_interp_tril_all ( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo,    &
                                    r2yo, r1zo, r2zo, nzb_u_inner, 'u' )
-       CALL pmci_interp_tril_all ( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv,   &
+       CALL pmci_interp_tril_all ( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv,    &
                                    r2yv, r1zo, r2zo, nzb_v_inner, 'v' )
-       CALL pmci_interp_tril_all ( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo,   &
+       CALL pmci_interp_tril_all ( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo,    &
                                    r2yo, r1zw, r2zw, nzb_w_inner, 'w' )
-       CALL pmci_interp_tril_all ( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo,   &
+       CALL pmci_interp_tril_all ( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo,    &
                                    r2yo, r1zo, r2zo, nzb_s_inner, 'e' )
        IF ( .NOT. neutral )  THEN
-          CALL pmci_interp_tril_all ( pt, ptc, ico, jco, kco, r1xo, r2xo,      &
+          CALL pmci_interp_tril_all ( pt, ptc, ico, jco, kco, r1xo, r2xo,       &
                                       r1yo, r2yo, r1zo, r2zo, nzb_s_inner, 's' )
        ENDIF
        IF ( humidity  .OR.  passive_scalar )  THEN
-          CALL pmci_interp_tril_all ( q, qc, ico, jco, kco, r1xo, r2xo, r1yo,  &
+          CALL pmci_interp_tril_all ( q, qc, ico, jco, kco, r1xo, r2xo, r1yo,   &
                                       r2yo, r1zo, r2zo, nzb_s_inner, 's' )
        ENDIF
@@ -2710,8 +2745,8 @@
 
 
-    SUBROUTINE pmci_interp_tril_all( f, fc, ic, jc, kc, r1x, r2x, r1y, r2y,    &
+    SUBROUTINE pmci_interp_tril_all( f, fc, ic, jc, kc, r1x, r2x, r1y, r2y,     &
                                      r1z, r2z, kb, var )
 !
-!--    Interpolation of the internal values for the client-domain initialization
+!--    Interpolation of the internal values for the child-domain initialization
 !--    This subroutine is based on trilinear interpolation.
 !--    Coding based on interp_tril_lr/sn/t
@@ -2739,5 +2774,5 @@
 
        REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg), INTENT(INOUT) :: f !:
-       REAL(wp), DIMENSION(0:cg%nz+1,jcs:jcn,icl:icr), INTENT(IN) :: fc    !:
+       REAL(wp), DIMENSION(0:cg%nz+1,jcs:jcn,icl:icr), INTENT(IN) :: fc       !:
        REAL(wp), DIMENSION(nxlg:nxrg), INTENT(IN) :: r1x   !:
        REAL(wp), DIMENSION(nxlg:nxrg), INTENT(IN) :: r2x   !:
@@ -2762,27 +2797,28 @@
        jb = nys
        je = nyn
-       IF ( nest_bound_l )  THEN
-          ib = nxl - 1
-!
-!--       For u, nxl is a ghost node, but not for the other variables
-          IF ( var == 'u' )  THEN
-             ib = nxl
+       IF ( nesting_mode /= 'vertical' )  THEN
+          IF ( nest_bound_l )  THEN
+             ib = nxl - 1
+!
+!--          For u, nxl is a ghost node, but not for the other variables
+             IF ( var == 'u' )  THEN
+                ib = nxl
+             ENDIF
           ENDIF
-       ENDIF
-       IF ( nest_bound_s )  THEN
-          jb = nys - 1
-!
-!--       For v, nys is a ghost node, but not for the other variables
-          IF ( var == 'v' )  THEN
-             jb = nys
+          IF ( nest_bound_s )  THEN
+             jb = nys - 1
+!
+!--          For v, nys is a ghost node, but not for the other variables
+             IF ( var == 'v' )  THEN
+                jb = nys
+             ENDIF
           ENDIF
-       ENDIF
-       IF ( nest_bound_r )  THEN
-          ie = nxr + 1
-       ENDIF
-       IF ( nest_bound_n )  THEN
-          je = nyn + 1
-       ENDIF
-
+          IF ( nest_bound_r )  THEN
+             ie = nxr + 1
+          ENDIF
+          IF ( nest_bound_n )  THEN
+             je = nyn + 1
+          ENDIF
+       ENDIF
 !
 !--    Trilinear interpolation.
@@ -2828,5 +2864,6 @@
                 k = kb(j,i) + 1
                 DO  WHILE ( zu(k) < zuc1 )
-                   logratio = ( LOG( ( zu(k) - zu(kb(j,i)) ) / z0(j,i)) ) / logzuc1
+                   logratio = ( LOG( ( zu(k) - zu(kb(j,i)) ) / z0(j,i)) ) /     &
+                                logzuc1
                    f(k,j,i) = logratio * f(k1,j,i)
                    k  = k + 1
@@ -2849,5 +2886,5 @@
 
 #endif
- END SUBROUTINE pmci_client_initialize
+ END SUBROUTINE pmci_child_initialize
 
 
@@ -2855,6 +2892,6 @@
  SUBROUTINE pmci_check_setting_mismatches
 !
-!-- Check for mismatches between settings of master and client variables
-!-- (e.g., all clients have to follow the end_time settings of the root model).
+!-- Check for mismatches between settings of master and child variables
+!-- (e.g., all children have to follow the end_time settings of the root model).
 !-- The root model overwrites variables in the other models, so these variables
 !-- only need to be set once in file PARIN.
@@ -2862,5 +2899,5 @@
 #if defined( __parallel )
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                     &
         ONLY:  dt_restart, end_time, message_string, restart_time, time_restart
 
@@ -2884,9 +2921,9 @@
     IF ( .NOT. pmc_is_rootmodel() )  THEN
        IF ( end_time /= end_time_root )  THEN
-          WRITE( message_string, * )  'mismatch between root model and ',      &
-               'client settings &   end_time(root) = ', end_time_root,         &
-               ' &   end_time(client) = ', end_time, ' & client value is set', &
+          WRITE( message_string, * )  'mismatch between root model and ',       &
+               'child settings &   end_time(root) = ', end_time_root,           &
+               ' &   end_time(child) = ', end_time, ' & child value is set',    &
                ' to root value'
-          CALL message( 'pmci_check_setting_mismatches', 'PA0419', 0, 1, 0, 6, &
+          CALL message( 'pmci_check_setting_mismatches', 'PA0419', 0, 1, 0, 6,  &
                         0 )
           end_time = end_time_root
@@ -2901,9 +2938,9 @@
     IF ( .NOT. pmc_is_rootmodel() )  THEN
        IF ( restart_time /= restart_time_root )  THEN
-          WRITE( message_string, * )  'mismatch between root model and ',      &
-               'client settings &   restart_time(root) = ', restart_time_root, &
-               ' &   restart_time(client) = ', restart_time, ' & client ',     &
+          WRITE( message_string, * )  'mismatch between root model and ',       &
+               'child settings &   restart_time(root) = ', restart_time_root,   &
+               ' &   restart_time(child) = ', restart_time, ' & child ',        &
                'value is set to root value'
-          CALL message( 'pmci_check_setting_mismatches', 'PA0419', 0, 1, 0, 6, &
+          CALL message( 'pmci_check_setting_mismatches', 'PA0419', 0, 1, 0, 6,  &
                         0 )
           restart_time = restart_time_root
@@ -2918,9 +2955,9 @@
     IF ( .NOT. pmc_is_rootmodel() )  THEN
        IF ( dt_restart /= dt_restart_root )  THEN
-          WRITE( message_string, * )  'mismatch between root model and ',      &
-               'client settings &   dt_restart(root) = ', dt_restart_root,     &
-               ' &   dt_restart(client) = ', dt_restart, ' & client ',         &
+          WRITE( message_string, * )  'mismatch between root model and ',       &
+               'child settings &   dt_restart(root) = ', dt_restart_root,       &
+               ' &   dt_restart(child) = ', dt_restart, ' & child ',            &
                'value is set to root value'
-          CALL message( 'pmci_check_setting_mismatches', 'PA0419', 0, 1, 0, 6, &
+          CALL message( 'pmci_check_setting_mismatches', 'PA0419', 0, 1, 0, 6,  &
                         0 )
           dt_restart = dt_restart_root
@@ -2935,9 +2972,9 @@
     IF ( .NOT. pmc_is_rootmodel() )  THEN
        IF ( time_restart /= time_restart_root )  THEN
-          WRITE( message_string, * )  'mismatch between root model and ',      &
-               'client settings &   time_restart(root) = ', time_restart_root, &
-               ' &   time_restart(client) = ', time_restart, ' & client ',     &
+          WRITE( message_string, * )  'mismatch between root model and ',       &
+               'child settings &   time_restart(root) = ', time_restart_root,   &
+               ' &   time_restart(child) = ', time_restart, ' & child ',        &
                'value is set to root value'
-          CALL message( 'pmci_check_setting_mismatches', 'PA0419', 0, 1, 0, 6, &
+          CALL message( 'pmci_check_setting_mismatches', 'PA0419', 0, 1, 0, 6,  &
                         0 )
           time_restart = time_restart_root
@@ -2953,5 +2990,4 @@
  SUBROUTINE pmci_ensure_nest_mass_conservation
 
-#if defined( __parallel )
 !
 !-- Adjust the volume-flow rate through the top boundary so that the net volume
@@ -2959,8 +2995,8 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i                          !:
-    INTEGER(iwp) ::  ierr                       !:
-    INTEGER(iwp) ::  j                          !:
-    INTEGER(iwp) ::  k                          !:
+    INTEGER(iwp) ::  i                           !:
+    INTEGER(iwp) ::  ierr                        !:
+    INTEGER(iwp) ::  j                           !:
+    INTEGER(iwp) ::  k                           !:
 
     REAL(wp) ::  dxdy                            !:
@@ -2996,5 +3032,5 @@
 #if defined( __parallel )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( volume_flow_l(1), volume_flow(1), 1, MPI_REAL, &
+    CALL MPI_ALLREDUCE( volume_flow_l(1), volume_flow(1), 1, MPI_REAL,          &
                         MPI_SUM, comm2d, ierr )
 #else
@@ -3029,5 +3065,5 @@
 #if defined( __parallel )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( volume_flow_l(2), volume_flow(2), 1, MPI_REAL,         &
+    CALL MPI_ALLREDUCE( volume_flow_l(2), volume_flow(2), 1, MPI_REAL,          &
                         MPI_SUM, comm2d, ierr )
 #else
@@ -3049,5 +3085,5 @@
 #if defined( __parallel )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( volume_flow_l(3), volume_flow(3), 1, MPI_REAL,         &
+    CALL MPI_ALLREDUCE( volume_flow_l(3), volume_flow(3), 1, MPI_REAL,          &
                         MPI_SUM, comm2d, ierr )
 #else
@@ -3066,5 +3102,4 @@
     ENDDO
 
-#endif
  END SUBROUTINE pmci_ensure_nest_mass_conservation
 
@@ -3101,13 +3136,13 @@
     IMPLICIT NONE
 
-    INTEGER(iwp),INTENT(IN) ::  swaplevel  !: swaplevel (1 or 2) of PALM's
-                                           !: timestep
-
-    INTEGER(iwp)            ::  client_id  !:
-    INTEGER(iwp)            ::  m          !:
-
-    DO  m = 1, SIZE( pmc_server_for_client )-1
-       client_id = pmc_server_for_client(m)
-       CALL pmc_s_set_active_data_array( client_id, swaplevel )
+    INTEGER(iwp), INTENT(IN) ::  swaplevel  !: swaplevel (1 or 2) of PALM's
+                                            !: timestep
+
+    INTEGER(iwp)            ::  child_id    !:
+    INTEGER(iwp)            ::  m           !:
+
+    DO  m = 1, SIZE( pmc_parent_for_child )-1
+       child_id = pmc_parent_for_child(m)
+       CALL pmc_s_set_active_data_array( child_id, swaplevel )
     ENDDO
 
@@ -3131,36 +3166,36 @@
     INTEGER(iwp)           ::  istat  !:
 
-    CHARACTER(LEN=*),INTENT(IN) ::  local_nesting_mode
-
-    IF ( local_nesting_mode == 'one-way' )  THEN
-
-       CALL pmci_client_datatrans( server_to_client )
-       CALL pmci_server_datatrans( server_to_client )
+    CHARACTER(LEN=*), INTENT(IN) ::  local_nesting_mode
+
+    IF ( TRIM( local_nesting_mode ) == 'one-way' )  THEN
+
+       CALL pmci_child_datatrans( parent_to_child )
+       CALL pmci_parent_datatrans( parent_to_child )
 
     ELSE
 
-       IF ( nesting_datatransfer_mode == 'cascade' )  THEN
-
-          CALL pmci_client_datatrans( server_to_client )
-          CALL pmci_server_datatrans( server_to_client )
-
-          CALL pmci_server_datatrans( client_to_server )
-          CALL pmci_client_datatrans( client_to_server )
-
-       ELSEIF ( nesting_datatransfer_mode == 'overlap' )  THEN
-
-          CALL pmci_server_datatrans( server_to_client )
-          CALL pmci_client_datatrans( server_to_client )
-
-          CALL pmci_client_datatrans( client_to_server )
-          CALL pmci_server_datatrans( client_to_server )
-
-       ELSEIF ( TRIM( nesting_datatransfer_mode ) == 'mixed' )  THEN
-
-          CALL pmci_server_datatrans( server_to_client )
-          CALL pmci_client_datatrans( server_to_client )
-
-          CALL pmci_server_datatrans( client_to_server )
-          CALL pmci_client_datatrans( client_to_server )
+       IF( nesting_datatransfer_mode == 'cascade' )  THEN
+
+          CALL pmci_child_datatrans( parent_to_child )
+          CALL pmci_parent_datatrans( parent_to_child )
+
+          CALL pmci_parent_datatrans( child_to_parent )
+          CALL pmci_child_datatrans( child_to_parent )
+
+       ELSEIF( nesting_datatransfer_mode == 'overlap')  THEN
+
+          CALL pmci_parent_datatrans( parent_to_child )
+          CALL pmci_child_datatrans( parent_to_child )
+
+          CALL pmci_child_datatrans( child_to_parent )
+          CALL pmci_parent_datatrans( child_to_parent )
+
+       ELSEIF( TRIM( nesting_datatransfer_mode ) == 'mixed' )  THEN
+
+          CALL pmci_parent_datatrans( parent_to_child )
+          CALL pmci_child_datatrans( parent_to_child )
+
+          CALL pmci_parent_datatrans( child_to_parent )
+          CALL pmci_child_datatrans( child_to_parent )
 
        ENDIF
@@ -3173,12 +3208,12 @@
 
 
- SUBROUTINE pmci_server_datatrans( direction )
+ SUBROUTINE pmci_parent_datatrans( direction )
 
     IMPLICIT NONE
 
-    INTEGER(iwp),INTENT(IN) ::  direction   !:
+    INTEGER(iwp), INTENT(IN) ::  direction   !:
 
 #if defined( __parallel )
-    INTEGER(iwp) ::  client_id   !:
+    INTEGER(iwp) ::  child_id    !:
     INTEGER(iwp) ::  i           !:
     INTEGER(iwp) ::  j           !:
@@ -3191,18 +3226,18 @@
 
 
-    DO  m = 1, SIZE( PMC_Server_for_Client )-1
-       client_id = PMC_Server_for_Client(m)
+    DO  m = 1, SIZE( pmc_parent_for_child ) - 1
+       child_id = pmc_parent_for_child(m)
        
-       IF ( direction == server_to_client )  THEN
-          CALL cpu_log( log_point_s(71), 'pmc server send', 'start' )
-          CALL pmc_s_fillbuffer( client_id )
-          CALL cpu_log( log_point_s(71), 'pmc server send', 'stop' )
+       IF ( direction == parent_to_child )  THEN
+          CALL cpu_log( log_point_s(71), 'pmc parent send', 'start' )
+          CALL pmc_s_fillbuffer( child_id )
+          CALL cpu_log( log_point_s(71), 'pmc parent send', 'stop' )
        ELSE
 !
-!--       Communication from client to server
-          CALL cpu_log( log_point_s(72), 'pmc server recv', 'start' )
-          client_id = pmc_server_for_client(m)
-          CALL pmc_s_getdata_from_buffer( client_id )
-          CALL cpu_log( log_point_s(72), 'pmc server recv', 'stop' )
+!--       Communication from child to parent
+          CALL cpu_log( log_point_s(72), 'pmc parent recv', 'start' )
+          child_id = pmc_parent_for_child(m)
+          CALL pmc_s_getdata_from_buffer( child_id )
+          CALL cpu_log( log_point_s(72), 'pmc parent recv', 'stop' )
 
 !
@@ -3234,9 +3269,9 @@
 
 #endif
- END SUBROUTINE pmci_server_datatrans
-
-
-
- SUBROUTINE pmci_client_datatrans( direction )
+ END SUBROUTINE pmci_parent_datatrans
+
+
+
+ SUBROUTINE pmci_child_datatrans( direction )
 
     IMPLICIT NONE
@@ -3258,5 +3293,5 @@
     IF ( cpl_id > 1 )  THEN
 !
-!--    Client domain boundaries in the server indice space.
+!--    Child domain boundaries in the parent indice space.
        icl = coarse_bound(1)
        icr = coarse_bound(2)
@@ -3264,9 +3299,9 @@
        jcn = coarse_bound(4)
 
-       IF ( direction == server_to_client )  THEN
-
-          CALL cpu_log( log_point_s(73), 'pmc client recv', 'start' )
+       IF ( direction == parent_to_child )  THEN
+
+          CALL cpu_log( log_point_s(73), 'pmc child recv', 'start' )
           CALL pmc_c_getbuffer( )
-          CALL cpu_log( log_point_s(73), 'pmc client recv', 'stop' )
+          CALL cpu_log( log_point_s(73), 'pmc child recv', 'stop' )
 
           CALL cpu_log( log_point_s(75), 'pmc interpolation', 'start' )
@@ -3276,12 +3311,12 @@
        ELSE
 !
-!--       direction == client_to_server
+!--       direction == child_to_parent
           CALL cpu_log( log_point_s(76), 'pmc anterpolation', 'start' )
           CALL pmci_anterpolation
           CALL cpu_log( log_point_s(76), 'pmc anterpolation', 'stop' )
 
-          CALL cpu_log( log_point_s(74), 'pmc client send', 'start' )
+          CALL cpu_log( log_point_s(74), 'pmc child send', 'start' )
           CALL pmc_c_putbuffer( )
-          CALL cpu_log( log_point_s(74), 'pmc client send', 'stop' )
+          CALL cpu_log( log_point_s(74), 'pmc child send', 'stop' )
 
        ENDIF
@@ -3297,210 +3332,219 @@
 
 !
-!--    Add IF-condition here: IF not vertical nesting
+!--    In case of vertical nesting no interpolation is needed for the
+!--    horizontal boundaries
+       IF ( nesting_mode /= 'vertical' )  THEN
+       
+!
 !--    Left border pe:
-       IF ( nest_bound_l )  THEN
-          CALL pmci_interp_tril_lr( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo,  &
-                                    r2yo, r1zo, r2zo, nzb_u_inner, logc_u_l,   &
-                                    logc_ratio_u_l, nzt_topo_nestbc_l, 'l',    &
-                                    'u' )
-          CALL pmci_interp_tril_lr( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv,  &
-                                    r2yv, r1zo, r2zo, nzb_v_inner, logc_v_l,   &
-                                    logc_ratio_v_l, nzt_topo_nestbc_l, 'l',    &
-                                    'v' )
-          CALL pmci_interp_tril_lr( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo,  &
-                                    r2yo, r1zw, r2zw, nzb_w_inner, logc_w_l,   &
-                                    logc_ratio_w_l, nzt_topo_nestbc_l, 'l',    &
-                                    'w' )
-          CALL pmci_interp_tril_lr( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo,  &
-                                    r2yo, r1zo, r2zo, nzb_s_inner, logc_u_l,   &
-                                    logc_ratio_u_l, nzt_topo_nestbc_l, 'l',    &
-                                    'e' )
-          IF ( .NOT. neutral )  THEN
-             CALL pmci_interp_tril_lr( pt, ptc, ico, jco, kco, r1xo, r2xo,     &
-                                       r1yo, r2yo, r1zo, r2zo, nzb_s_inner,    &
-                                       logc_u_l, logc_ratio_u_l,               &
-                                       nzt_topo_nestbc_l, 'l', 's' )
-          ENDIF
-          IF ( humidity  .OR.  passive_scalar )  THEN
-             CALL pmci_interp_tril_lr( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, &
-                                       r2yo, r1zo, r2zo, nzb_s_inner,          &
-                                       logc_u_l, logc_ratio_u_l,               &
-                                       nzt_topo_nestbc_l, 'l', 's' )
-          ENDIF
-
-          IF ( nesting_mode == 'one-way' )  THEN
-             CALL pmci_extrap_ifoutflow_lr( u, nzb_u_inner, 'l', 'u' )
-             CALL pmci_extrap_ifoutflow_lr( v, nzb_v_inner, 'l', 'v' )
-             CALL pmci_extrap_ifoutflow_lr( w, nzb_w_inner, 'l', 'w' )
-             CALL pmci_extrap_ifoutflow_lr( e, nzb_s_inner, 'l', 'e' )
+          IF ( nest_bound_l )  THEN
+             CALL pmci_interp_tril_lr( u,  uc,  icu, jco, kco, r1xu, r2xu,      &
+                                       r1yo, r2yo, r1zo, r2zo, nzb_u_inner,     &
+                                       logc_u_l, logc_ratio_u_l,                &
+                                       nzt_topo_nestbc_l, 'l', 'u' )
+             CALL pmci_interp_tril_lr( v,  vc,  ico, jcv, kco, r1xo, r2xo,      &
+                                       r1yv, r2yv, r1zo, r2zo, nzb_v_inner,     &
+                                       logc_v_l, logc_ratio_v_l,                &
+                                       nzt_topo_nestbc_l, 'l', 'v' )
+             CALL pmci_interp_tril_lr( w,  wc,  ico, jco, kcw, r1xo, r2xo,      &
+                                       r1yo, r2yo, r1zw, r2zw, nzb_w_inner,     &
+                                       logc_w_l, logc_ratio_w_l,                &
+                                       nzt_topo_nestbc_l, 'l', 'w' )
+             CALL pmci_interp_tril_lr( e,  ec,  ico, jco, kco, r1xo, r2xo,      &
+                                       r1yo, r2yo, r1zo, r2zo, nzb_s_inner,     &
+                                       logc_u_l, logc_ratio_u_l,                &
+                                       nzt_topo_nestbc_l, 'l', 'e' )
              IF ( .NOT. neutral )  THEN
-                CALL pmci_extrap_ifoutflow_lr( pt,nzb_s_inner, 'l', 's' )
+                CALL pmci_interp_tril_lr( pt, ptc, ico, jco, kco, r1xo, r2xo,   &
+                                          r1yo, r2yo, r1zo, r2zo, nzb_s_inner,  &
+                                          logc_u_l, logc_ratio_u_l,             &
+                                          nzt_topo_nestbc_l, 'l', 's' )
              ENDIF
              IF ( humidity  .OR.  passive_scalar )  THEN
-                CALL pmci_extrap_ifoutflow_lr( q, nzb_s_inner, 'l', 's' )
+                CALL pmci_interp_tril_lr( q, qc, ico, jco, kco, r1xo, r2xo,     &
+                                          r1yo, r2yo, r1zo, r2zo, nzb_s_inner,  &
+                                          logc_u_l, logc_ratio_u_l,             &
+                                          nzt_topo_nestbc_l, 'l', 's' )
              ENDIF
+
+             IF ( TRIM( nesting_mode ) == 'one-way' )  THEN
+                CALL pmci_extrap_ifoutflow_lr( u, nzb_u_inner, 'l', 'u' )
+                CALL pmci_extrap_ifoutflow_lr( v, nzb_v_inner, 'l', 'v' )
+                CALL pmci_extrap_ifoutflow_lr( w, nzb_w_inner, 'l', 'w' )
+                CALL pmci_extrap_ifoutflow_lr( e, nzb_s_inner, 'l', 'e' )
+                IF ( .NOT. neutral )  THEN
+                   CALL pmci_extrap_ifoutflow_lr( pt,nzb_s_inner, 'l', 's' )
+                ENDIF
+                IF ( humidity  .OR.  passive_scalar )  THEN
+                   CALL pmci_extrap_ifoutflow_lr( q, nzb_s_inner, 'l', 's' )
+                ENDIF
+             ENDIF
+
           ENDIF
 
-       ENDIF
-!
-!--    Right border pe
-       IF ( nest_bound_r )  THEN
-          CALL pmci_interp_tril_lr( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo,  &
-                                    r2yo, r1zo, r2zo, nzb_u_inner, logc_u_r,   &
-                                    logc_ratio_u_r, nzt_topo_nestbc_r, 'r',    &
-                                    'u' )
-          CALL pmci_interp_tril_lr( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv,  &
-                                    r2yv, r1zo, r2zo, nzb_v_inner, logc_v_r,   &
-                                    logc_ratio_v_r, nzt_topo_nestbc_r, 'r',    &
-                                    'v' )
-          CALL pmci_interp_tril_lr( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo,  &
-                                    r2yo, r1zw, r2zw, nzb_w_inner, logc_w_r,   &
-                                    logc_ratio_w_r, nzt_topo_nestbc_r, 'r',    &
-                                    'w' )
-          CALL pmci_interp_tril_lr( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo,  &
-                                    r2yo, r1zo, r2zo, nzb_s_inner, logc_u_r,   &
-                                    logc_ratio_u_r, nzt_topo_nestbc_r, 'r',    &
-                                    'e' )
-          IF ( .NOT. neutral )  THEN
-             CALL pmci_interp_tril_lr( pt, ptc, ico, jco, kco, r1xo, r2xo,     &
-                                       r1yo, r2yo, r1zo, r2zo, nzb_s_inner,    &
-                                       logc_u_r, logc_ratio_u_r,               &
-                                       nzt_topo_nestbc_r, 'r', 's' )
-          ENDIF
-          IF ( humidity  .OR.  passive_scalar )  THEN
-             CALL pmci_interp_tril_lr( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, &
-                                       r2yo, r1zo, r2zo, nzb_s_inner,          &
-                                       logc_u_r, logc_ratio_u_r,               &
-                                       nzt_topo_nestbc_r, 'r', 's' )
-          ENDIF
-
-          IF ( nesting_mode == 'one-way' )  THEN
-             CALL pmci_extrap_ifoutflow_lr( u, nzb_u_inner, 'r', 'u' )
-             CALL pmci_extrap_ifoutflow_lr( v, nzb_v_inner, 'r', 'v' )
-             CALL pmci_extrap_ifoutflow_lr( w, nzb_w_inner, 'r', 'w' )
-             CALL pmci_extrap_ifoutflow_lr( e, nzb_s_inner, 'r', 'e' )
+   !
+   !--    Right border pe
+          IF ( nest_bound_r )  THEN
+             CALL pmci_interp_tril_lr( u,  uc,  icu, jco, kco, r1xu, r2xu,      &
+                                       r1yo, r2yo, r1zo, r2zo, nzb_u_inner,     &
+                                       logc_u_r, logc_ratio_u_r,                &
+                                       nzt_topo_nestbc_r, 'r', 'u' )
+             CALL pmci_interp_tril_lr( v,  vc,  ico, jcv, kco, r1xo, r2xo,      &
+                                       r1yv, r2yv, r1zo, r2zo, nzb_v_inner,     &
+                                       logc_v_r, logc_ratio_v_r,                &
+                                       nzt_topo_nestbc_r, 'r', 'v' )
+             CALL pmci_interp_tril_lr( w,  wc,  ico, jco, kcw, r1xo, r2xo,      &
+                                       r1yo, r2yo, r1zw, r2zw, nzb_w_inner,     &
+                                       logc_w_r, logc_ratio_w_r,                &
+                                       nzt_topo_nestbc_r, 'r', 'w' )
+             CALL pmci_interp_tril_lr( e,  ec,  ico, jco, kco, r1xo, r2xo,      &
+                                       r1yo,r2yo, r1zo, r2zo, nzb_s_inner,      &
+                                       logc_u_r, logc_ratio_u_r,                &
+                                       nzt_topo_nestbc_r, 'r', 'e' )
              IF ( .NOT. neutral )  THEN
-                CALL pmci_extrap_ifoutflow_lr( pt,nzb_s_inner, 'r', 's' )
+                CALL pmci_interp_tril_lr( pt, ptc, ico, jco, kco, r1xo, r2xo,   &
+                                          r1yo, r2yo, r1zo, r2zo, nzb_s_inner,  &
+                                          logc_u_r, logc_ratio_u_r,             &
+                                          nzt_topo_nestbc_r, 'r', 's' )
              ENDIF
              IF ( humidity  .OR.  passive_scalar )  THEN
-                CALL pmci_extrap_ifoutflow_lr( q, nzb_s_inner, 'r', 's' )
+                CALL pmci_interp_tril_lr( q, qc, ico, jco, kco, r1xo, r2xo,     &
+                                          r1yo, r2yo, r1zo, r2zo, nzb_s_inner,  &
+                                          logc_u_r, logc_ratio_u_r,             &
+                                          nzt_topo_nestbc_r, 'r', 's' )
              ENDIF
+
+             IF ( TRIM( nesting_mode ) == 'one-way' )  THEN
+                CALL pmci_extrap_ifoutflow_lr( u, nzb_u_inner, 'r', 'u' )
+                CALL pmci_extrap_ifoutflow_lr( v, nzb_v_inner, 'r', 'v' )
+                CALL pmci_extrap_ifoutflow_lr( w, nzb_w_inner, 'r', 'w' )
+                CALL pmci_extrap_ifoutflow_lr( e, nzb_s_inner, 'r', 'e' )
+                IF ( .NOT. neutral )  THEN
+                   CALL pmci_extrap_ifoutflow_lr( pt,nzb_s_inner, 'r', 's' )
+                ENDIF
+                IF ( humidity  .OR.  passive_scalar )  THEN
+                   CALL pmci_extrap_ifoutflow_lr( q, nzb_s_inner, 'r', 's' )
+                ENDIF
+             ENDIF
+
           ENDIF
 
-       ENDIF
-!
-!--    South border pe
-       IF ( nest_bound_s )  THEN
-          CALL pmci_interp_tril_sn( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo,  &
-                                    r2yo, r1zo, r2zo, nzb_u_inner, logc_u_s,   &
-                                    logc_ratio_u_s, nzt_topo_nestbc_s, 's',    &
-                                    'u' )
-          CALL pmci_interp_tril_sn( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv,  &
-                                    r2yv, r1zo, r2zo, nzb_v_inner, logc_v_s,   &
-                                    logc_ratio_v_s, nzt_topo_nestbc_s, 's',    &
-                                    'v' )
-          CALL pmci_interp_tril_sn( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo,  &
-                                    r2yo, r1zw, r2zw, nzb_w_inner, logc_w_s,   &
-                                    logc_ratio_w_s, nzt_topo_nestbc_s, 's',    &
-                                    'w' )
-          CALL pmci_interp_tril_sn( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo,  &
-                                    r2yo, r1zo, r2zo, nzb_s_inner, logc_u_s,   &
-                                    logc_ratio_u_s, nzt_topo_nestbc_s, 's',    &
-                                    'e' )
-          IF ( .NOT. neutral )  THEN
-             CALL pmci_interp_tril_sn( pt, ptc, ico, jco, kco, r1xo, r2xo,     &
-                                       r1yo, r2yo, r1zo, r2zo, nzb_s_inner,    &
-                                       logc_u_s, logc_ratio_u_s,               &
-                                       nzt_topo_nestbc_s, 's', 's' )
-          ENDIF
-          IF ( humidity  .OR.  passive_scalar )  THEN
-             CALL pmci_interp_tril_sn( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, &
-                                       r2yo, r1zo, r2zo, nzb_s_inner,          &
-                                       logc_u_s, logc_ratio_u_s,               &
-                                       nzt_topo_nestbc_s, 's', 's' )
-          ENDIF
-
-          IF ( nesting_mode == 'one-way' )  THEN
-             CALL pmci_extrap_ifoutflow_sn( u, nzb_u_inner, 's', 'u' )
-             CALL pmci_extrap_ifoutflow_sn( v, nzb_v_inner, 's', 'v' )
-             CALL pmci_extrap_ifoutflow_sn( w, nzb_w_inner, 's', 'w' )
-             CALL pmci_extrap_ifoutflow_sn( e, nzb_s_inner, 's', 'e' )
+   !
+   !--    South border pe
+          IF ( nest_bound_s )  THEN
+             CALL pmci_interp_tril_sn( u,  uc,  icu, jco, kco, r1xu, r2xu,      &
+                                       r1yo, r2yo, r1zo, r2zo, nzb_u_inner,     &
+                                       logc_u_s, logc_ratio_u_s,                &
+                                       nzt_topo_nestbc_s, 's', 'u' )
+             CALL pmci_interp_tril_sn( v,  vc,  ico, jcv, kco, r1xo, r2xo,      &
+                                       r1yv, r2yv, r1zo, r2zo, nzb_v_inner,     &
+                                       logc_v_s, logc_ratio_v_s,                &
+                                       nzt_topo_nestbc_s, 's', 'v' )
+             CALL pmci_interp_tril_sn( w,  wc,  ico, jco, kcw, r1xo, r2xo,      &
+                                       r1yo, r2yo, r1zw, r2zw, nzb_w_inner,     &
+                                       logc_w_s, logc_ratio_w_s,                &
+                                       nzt_topo_nestbc_s, 's','w' )
+             CALL pmci_interp_tril_sn( e,  ec,  ico, jco, kco, r1xo, r2xo,      &
+                                       r1yo, r2yo, r1zo, r2zo, nzb_s_inner,     &
+                                       logc_u_s, logc_ratio_u_s,                &
+                                       nzt_topo_nestbc_s, 's', 'e' )
              IF ( .NOT. neutral )  THEN
-                CALL pmci_extrap_ifoutflow_sn( pt,nzb_s_inner, 's', 's' )
+                CALL pmci_interp_tril_sn( pt, ptc, ico, jco, kco, r1xo, r2xo,   &
+                                          r1yo, r2yo, r1zo, r2zo, nzb_s_inner,  &
+                                          logc_u_s, logc_ratio_u_s,             &
+                                          nzt_topo_nestbc_s, 's', 's' )
              ENDIF
              IF ( humidity  .OR.  passive_scalar )  THEN
-                CALL pmci_extrap_ifoutflow_sn( q, nzb_s_inner, 's', 's' )
+                CALL pmci_interp_tril_sn( q, qc, ico, jco, kco, r1xo, r2xo,     &
+                                          r1yo,r2yo, r1zo, r2zo, nzb_s_inner,   &
+                                          logc_u_s, logc_ratio_u_s,             &
+                                          nzt_topo_nestbc_s, 's', 's' )
              ENDIF
+
+             IF ( TRIM( nesting_mode ) == 'one-way' )  THEN
+                CALL pmci_extrap_ifoutflow_sn( u, nzb_u_inner, 's', 'u' )
+                CALL pmci_extrap_ifoutflow_sn( v, nzb_v_inner, 's', 'v' )
+                CALL pmci_extrap_ifoutflow_sn( w, nzb_w_inner, 's', 'w' )
+                CALL pmci_extrap_ifoutflow_sn( e, nzb_s_inner, 's', 'e' )
+                IF ( .NOT. neutral )  THEN
+                   CALL pmci_extrap_ifoutflow_sn( pt,nzb_s_inner, 's', 's' )
+                ENDIF
+                IF ( humidity  .OR.  passive_scalar )  THEN
+                   CALL pmci_extrap_ifoutflow_sn( q, nzb_s_inner, 's', 's' )
+                ENDIF
+             ENDIF
+
           ENDIF
 
-       ENDIF
-!
-!--    North border pe
-       IF ( nest_bound_n )  THEN
-          CALL pmci_interp_tril_sn( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo,  &
-                                    r2yo, r1zo, r2zo, nzb_u_inner, logc_u_n,   &
-                                    logc_ratio_u_n, nzt_topo_nestbc_n, 'n',    &
-                                    'u' )
-          CALL pmci_interp_tril_sn( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv,  &
-                                    r2yv, r1zo, r2zo, nzb_v_inner, logc_v_n,   &
-                                    logc_ratio_v_n, nzt_topo_nestbc_n, 'n',    &
-                                    'v' )
-          CALL pmci_interp_tril_sn( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo,  &
-                                    r2yo, r1zw, r2zw, nzb_w_inner, logc_w_n,   &
-                                    logc_ratio_w_n, nzt_topo_nestbc_n, 'n',    &
-                                    'w' )
-          CALL pmci_interp_tril_sn( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo,  &
-                                    r2yo, r1zo, r2zo, nzb_s_inner, logc_u_n,   &
-                                    logc_ratio_u_n, nzt_topo_nestbc_n, 'n',    &
-                                    'e' )
-          IF ( .NOT. neutral )  THEN
-             CALL pmci_interp_tril_sn( pt, ptc, ico, jco, kco, r1xo, r2xo,     &
-                                       r1yo, r2yo, r1zo, r2zo, nzb_s_inner,    &
-                                       logc_u_n, logc_ratio_u_n,               &
-                                       nzt_topo_nestbc_n, 'n', 's' )
-          ENDIF
-          IF ( humidity  .OR.  passive_scalar )  THEN
-             CALL pmci_interp_tril_sn( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, &
-                                       r2yo, r1zo, r2zo, nzb_s_inner,          &
-                                       logc_u_n, logc_ratio_u_n,               &
-                                       nzt_topo_nestbc_n, 'n', 's' )
-          ENDIF
-
-          IF ( nesting_mode == 'one-way' )  THEN
-             CALL pmci_extrap_ifoutflow_sn( u, nzb_u_inner, 'n', 'u' )
-             CALL pmci_extrap_ifoutflow_sn( v, nzb_v_inner, 'n', 'v' )
-             CALL pmci_extrap_ifoutflow_sn( w, nzb_w_inner, 'n', 'w' )
-             CALL pmci_extrap_ifoutflow_sn( e, nzb_s_inner, 'n', 'e' )
+   !
+   !--    North border pe
+          IF ( nest_bound_n )  THEN
+             CALL pmci_interp_tril_sn( u,  uc,  icu, jco, kco, r1xu, r2xu,      &
+                                       r1yo, r2yo, r1zo, r2zo, nzb_u_inner,     &
+                                       logc_u_n, logc_ratio_u_n,                &
+                                       nzt_topo_nestbc_n, 'n', 'u' )
+             CALL pmci_interp_tril_sn( v,  vc,  ico, jcv, kco, r1xo, r2xo,      &
+                                       r1yv, r2yv, r1zo, r2zo, nzb_v_inner,     &
+                                       logc_v_n, logc_ratio_v_n,                & 
+                                       nzt_topo_nestbc_n, 'n', 'v' )
+             CALL pmci_interp_tril_sn( w,  wc,  ico, jco, kcw, r1xo, r2xo,      &
+                                       r1yo, r2yo, r1zw, r2zw, nzb_w_inner,     &
+                                       logc_w_n, logc_ratio_w_n,                &
+                                       nzt_topo_nestbc_n, 'n', 'w' )
+             CALL pmci_interp_tril_sn( e,  ec,  ico, jco, kco, r1xo, r2xo,      &
+                                       r1yo, r2yo, r1zo, r2zo, nzb_s_inner,     &
+                                       logc_u_n, logc_ratio_u_n,                &
+                                       nzt_topo_nestbc_n, 'n', 'e' )
              IF ( .NOT. neutral )  THEN
-                CALL pmci_extrap_ifoutflow_sn( pt,nzb_s_inner, 'n', 's' )
+                CALL pmci_interp_tril_sn( pt, ptc, ico, jco, kco, r1xo, r2xo,   &
+                                          r1yo, r2yo, r1zo, r2zo, nzb_s_inner,  &
+                                          logc_u_n, logc_ratio_u_n,             &
+                                          nzt_topo_nestbc_n, 'n', 's' )
              ENDIF
              IF ( humidity  .OR.  passive_scalar )  THEN
-                CALL pmci_extrap_ifoutflow_sn( q, nzb_s_inner, 'n', 's' )
+                CALL pmci_interp_tril_sn( q, qc, ico, jco, kco, r1xo, r2xo,     &
+                                          r1yo, r2yo, r1zo, r2zo, nzb_s_inner,  &
+                                          logc_u_n, logc_ratio_u_n,             &
+                                          nzt_topo_nestbc_n, 'n', 's' )
              ENDIF
 
+             IF ( TRIM( nesting_mode ) == 'one-way' )  THEN
+                CALL pmci_extrap_ifoutflow_sn( u, nzb_u_inner, 'n', 'u' )
+                CALL pmci_extrap_ifoutflow_sn( v, nzb_v_inner, 'n', 'v' )
+                CALL pmci_extrap_ifoutflow_sn( w, nzb_w_inner, 'n', 'w' )
+                CALL pmci_extrap_ifoutflow_sn( e, nzb_s_inner, 'n', 'e' )
+                IF ( .NOT. neutral )  THEN
+                   CALL pmci_extrap_ifoutflow_sn( pt,nzb_s_inner, 'n', 's' )
+                ENDIF
+                IF ( humidity  .OR.  passive_scalar )  THEN
+                   CALL pmci_extrap_ifoutflow_sn( q, nzb_s_inner, 'n', 's' )
+                ENDIF
+
+             ENDIF
+
           ENDIF
 
-       ENDIF
+       ENDIF       !: IF ( nesting_mode /= 'vertical' )
 
 !
 !--    All PEs are top-border PEs
-       CALL pmci_interp_tril_t( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo,      &
+       CALL pmci_interp_tril_t( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo,       &
                                 r2yo, r1zo, r2zo, 'u' )
-       CALL pmci_interp_tril_t( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv,      &
+       CALL pmci_interp_tril_t( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv,       &
                                 r2yv, r1zo, r2zo, 'v' )
-       CALL pmci_interp_tril_t( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo,      &
+       CALL pmci_interp_tril_t( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo,       &
                                 r2yo, r1zw, r2zw, 'w' )
-       CALL pmci_interp_tril_t( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo,      &
+       CALL pmci_interp_tril_t( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo,       &
                                 r2yo, r1zo, r2zo, 'e' )
        IF ( .NOT. neutral )  THEN
-          CALL pmci_interp_tril_t( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo,   &
+          CALL pmci_interp_tril_t( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo,    &
                                    r2yo, r1zo, r2zo, 's' )
        ENDIF
        IF ( humidity .OR. passive_scalar )  THEN
-          CALL pmci_interp_tril_t( q, qc, ico, jco, kco, r1xo, r2xo, r1yo,     &
+          CALL pmci_interp_tril_t( q, qc, ico, jco, kco, r1xo, r2xo, r1yo,      &
                                    r2yo, r1zo, r2zo, 's' )
        ENDIF
 
-       IF ( nesting_mode == 'one-way' )  THEN
+       IF ( TRIM( nesting_mode ) == 'one-way' )  THEN
           CALL pmci_extrap_ifoutflow_t( u,  'u' )
           CALL pmci_extrap_ifoutflow_t( v,  'v' )
@@ -3513,5 +3557,5 @@
              CALL pmci_extrap_ifoutflow_t( q, 's' )
           ENDIF
-      ENDIF
+       ENDIF
 
    END SUBROUTINE pmci_interpolation
@@ -3526,16 +3570,16 @@
       IMPLICIT NONE
 
-      CALL pmci_anterp_tophat( u,  uc,  kctu, iflu, ifuu, jflo, jfuo, kflo,    &
+      CALL pmci_anterp_tophat( u,  uc,  kctu, iflu, ifuu, jflo, jfuo, kflo,     &
                                kfuo, ijfc_u, 'u' )
-      CALL pmci_anterp_tophat( v,  vc,  kctu, iflo, ifuo, jflv, jfuv, kflo,    &
+      CALL pmci_anterp_tophat( v,  vc,  kctu, iflo, ifuo, jflv, jfuv, kflo,     &
                                kfuo, ijfc_v, 'v' )
-      CALL pmci_anterp_tophat( w,  wc,  kctw, iflo, ifuo, jflo, jfuo, kflw,    &
+      CALL pmci_anterp_tophat( w,  wc,  kctw, iflo, ifuo, jflo, jfuo, kflw,     &
                                kfuw, ijfc_s, 'w' )
       IF ( .NOT. neutral )  THEN
-         CALL pmci_anterp_tophat( pt, ptc, kctu, iflo, ifuo, jflo, jfuo, kflo, &
+         CALL pmci_anterp_tophat( pt, ptc, kctu, iflo, ifuo, jflo, jfuo, kflo,  &
                                   kfuo, ijfc_s, 's' )
       ENDIF
       IF ( humidity  .OR.  passive_scalar )  THEN
-         CALL pmci_anterp_tophat( q, qc, kctu, iflo, ifuo, jflo, jfuo, kflo,   &
+         CALL pmci_anterp_tophat( q, qc, kctu, iflo, ifuo, jflo, jfuo, kflo,    &
                                   kfuo, ijfc_s, 's' )
       ENDIF
@@ -3545,9 +3589,9 @@
 
 
-   SUBROUTINE pmci_interp_tril_lr( f, fc, ic, jc, kc, r1x, r2x, r1y, r2y, r1z, &
-                                   r2z, kb, logc, logc_ratio, nzt_topo_nestbc, &
+   SUBROUTINE pmci_interp_tril_lr( f, fc, ic, jc, kc, r1x, r2x, r1y, r2y, r1z,  &
+                                   r2z, kb, logc, logc_ratio, nzt_topo_nestbc,  &
                                    edge, var )
 !
-!--   Interpolation of ghost-node values used as the client-domain boundary
+!--   Interpolation of ghost-node values used as the child-domain boundary
 !--   conditions. This subroutine handles the left and right boundaries. It is
 !--   based on trilinear interpolation.
@@ -3555,9 +3599,9 @@
       IMPLICIT NONE
 
-      REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
+      REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                       &
                                       INTENT(INOUT) ::  f       !:
-      REAL(wp), DIMENSION(0:cg%nz+1,jcs:jcn,icl:icr),                          &
+      REAL(wp), DIMENSION(0:cg%nz+1,jcs:jcn,icl:icr),                           &
                                       INTENT(IN)    ::  fc      !:
-      REAL(wp), DIMENSION(1:2,0:ncorr-1,nzb:nzt_topo_nestbc,nys:nyn),          &
+      REAL(wp), DIMENSION(1:2,0:ncorr-1,nzb:nzt_topo_nestbc,nys:nyn),           &
                                       INTENT(IN)    ::  logc_ratio   !:
       REAL(wp), DIMENSION(nxlg:nxrg), INTENT(IN)    ::  r1x     !:
@@ -3572,10 +3616,10 @@
       INTEGER(iwp), DIMENSION(nysg:nyng,nxlg:nxrg), INTENT(IN) ::  kb     !:
       INTEGER(iwp), DIMENSION(nzb:nzt+1), INTENT(IN)           ::  kc     !:
-      INTEGER(iwp), DIMENSION(1:2,nzb:nzt_topo_nestbc,nys:nyn),                &
+      INTEGER(iwp), DIMENSION(1:2,nzb:nzt_topo_nestbc,nys:nyn),                 &
                                           INTENT(IN)           ::  logc   !:
       INTEGER(iwp) ::  nzt_topo_nestbc   !:
 
-      CHARACTER(LEN=1),INTENT(IN) ::  edge   !:
-      CHARACTER(LEN=1),INTENT(IN) ::  var    !:
+      CHARACTER(LEN=1), INTENT(IN) ::  edge   !:
+      CHARACTER(LEN=1), INTENT(IN) ::  var    !:
 
       INTEGER(iwp) ::  i       !:
@@ -3701,7 +3745,7 @@
                      DO  kcorr = 0, ncorr-1
                         kco = k + kcorr
-                        f(kco,jco,i) = 0.5_wp * ( logc_ratio(1,kcorr,k,j) *    &
-                                                  f(k1,j,i)                    &
-                                                + logc_ratio(2,jcorr,k,j) *    &
+                        f(kco,jco,i) = 0.5_wp * ( logc_ratio(1,kcorr,k,j) *     &
+                                                  f(k1,j,i)                     &
+                                                + logc_ratio(2,jcorr,k,j) *     &
                                                   f(k,j1,i) )
                      ENDDO
@@ -3747,10 +3791,10 @@
 
 
-   SUBROUTINE pmci_interp_tril_sn( f, fc, ic, jc, kc, r1x, r2x, r1y, r2y, r1z, &
-                                   r2z, kb, logc, logc_ratio,                  &
+   SUBROUTINE pmci_interp_tril_sn( f, fc, ic, jc, kc, r1x, r2x, r1y, r2y, r1z,  &
+                                   r2z, kb, logc, logc_ratio,                   &
                                    nzt_topo_nestbc, edge, var )
 
 !
-!--   Interpolation of ghost-node values used as the client-domain boundary
+!--   Interpolation of ghost-node values used as the child-domain boundary
 !--   conditions. This subroutine handles the south and north boundaries. 
 !--   This subroutine is based on trilinear interpolation.
@@ -3758,9 +3802,9 @@
       IMPLICIT NONE
 
-      REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
+      REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                       &
                                       INTENT(INOUT) ::  f             !:
-      REAL(wp), DIMENSION(0:cg%nz+1,jcs:jcn,icl:icr),                          &
+      REAL(wp), DIMENSION(0:cg%nz+1,jcs:jcn,icl:icr),                           &
                                       INTENT(IN)    ::  fc            !:
-      REAL(wp), DIMENSION(1:2,0:ncorr-1,nzb:nzt_topo_nestbc,nxl:nxr),          &
+      REAL(wp), DIMENSION(1:2,0:ncorr-1,nzb:nzt_topo_nestbc,nxl:nxr),           &
                                       INTENT(IN)    ::  logc_ratio    !:
       REAL(wp), DIMENSION(nxlg:nxrg), INTENT(IN)    ::  r1x           !:
@@ -3775,5 +3819,5 @@
       INTEGER(iwp), DIMENSION(nysg:nyng,nxlg:nxrg), INTENT(IN) ::  kb    !:
       INTEGER(iwp), DIMENSION(nzb:nzt+1), INTENT(IN)           ::  kc    !:
-      INTEGER(iwp), DIMENSION(1:2,nzb:nzt_topo_nestbc,nxl:nxr),                &
+      INTEGER(iwp), DIMENSION(1:2,nzb:nzt_topo_nestbc,nxl:nxr),                 &
                                           INTENT(IN)           ::  logc  !:
       INTEGER(iwp) ::  nzt_topo_nestbc   !:
@@ -3902,7 +3946,7 @@
                      DO  kcorr = 0, ncorr-1
                         kco = k + kcorr
-                        f(kco,i,ico) = 0.5_wp * ( logc_ratio(1,kcorr,k,i) *    &
+                        f(kco,i,ico) = 0.5_wp * ( logc_ratio(1,kcorr,k,i) *     &
                                                   f(k1,j,i)  &
-                                                + logc_ratio(2,icorr,k,i) *    &
+                                                + logc_ratio(2,icorr,k,i) *     &
                                                   f(k,j,i1) )
                      ENDDO
@@ -3948,9 +3992,9 @@
  
 
-   SUBROUTINE pmci_interp_tril_t( f, fc, ic, jc, kc, r1x, r2x, r1y, r2y, r1z,  &
+   SUBROUTINE pmci_interp_tril_t( f, fc, ic, jc, kc, r1x, r2x, r1y, r2y, r1z,   &
                                   r2z, var )
 
 !
-!--   Interpolation of ghost-node values used as the client-domain boundary
+!--   Interpolation of ghost-node values used as the child-domain boundary
 !--   conditions. This subroutine handles the top boundary. 
 !--   This subroutine is based on trilinear interpolation.
@@ -3958,7 +4002,7 @@
       IMPLICIT NONE
 
-      REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
+      REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                       &
                                       INTENT(INOUT) ::  f     !:
-      REAL(wp), DIMENSION(0:cg%nz+1,jcs:jcn,icl:icr),                          &
+      REAL(wp), DIMENSION(0:cg%nz+1,jcs:jcn,icl:icr),                           &
                                       INTENT(IN)    ::  fc    !:
       REAL(wp), DIMENSION(nxlg:nxrg), INTENT(IN)    ::  r1x   !:
@@ -3969,7 +4013,7 @@
       REAL(wp), DIMENSION(nzb:nzt+1), INTENT(IN)    ::  r2z   !:
       
-      INTEGER(iwp), DIMENSION(nxlg:nxrg), INTENT(IN) ::  ic   !:
-      INTEGER(iwp), DIMENSION(nysg:nyng), INTENT(IN) ::  jc   !:
-      INTEGER(iwp), DIMENSION(nzb:nzt+1), INTENT(IN) ::  kc   !:
+      INTEGER(iwp), DIMENSION(nxlg:nxrg), INTENT(IN) ::  ic    !:
+      INTEGER(iwp), DIMENSION(nysg:nyng), INTENT(IN) ::  jc    !:
+      INTEGER(iwp), DIMENSION(nzb:nzt+1), INTENT(IN) ::  kc    !:
       
       CHARACTER(LEN=1), INTENT(IN) :: var   !:
@@ -4038,5 +4082,5 @@
     SUBROUTINE pmci_extrap_ifoutflow_lr( f, kb, edge, var )
 !
-!--    After the interpolation of ghost-node values for the client-domain
+!--    After the interpolation of ghost-node values for the child-domain
 !--    boundary conditions, this subroutine checks if there is a local outflow
 !--    through the boundary. In that case this subroutine overwrites the
@@ -4047,6 +4091,6 @@
        IMPLICIT NONE
 
-       CHARACTER(LEN=1),INTENT(IN) ::  edge   !:
-       CHARACTER(LEN=1),INTENT(IN) ::  var    !:
+       CHARACTER(LEN=1), INTENT(IN) ::  edge   !:
+       CHARACTER(LEN=1), INTENT(IN) ::  var    !:
 
        INTEGER(iwp) ::  i     !:
@@ -4116,5 +4160,5 @@
     SUBROUTINE pmci_extrap_ifoutflow_sn( f, kb, edge, var )
 !
-!--    After  the interpolation of ghost-node values for the client-domain
+!--    After  the interpolation of ghost-node values for the child-domain
 !--    boundary conditions, this subroutine checks if there is a local outflow
 !--    through the boundary. In that case this subroutine overwrites the
@@ -4193,5 +4237,5 @@
     SUBROUTINE pmci_extrap_ifoutflow_t( f, var )
 !
-!--    Interpolation of ghost-node values used as the client-domain boundary
+!--    Interpolation of ghost-node values used as the child-domain boundary
 !--    conditions. This subroutine handles the top boundary. It is based on
 !--    trilinear interpolation.
@@ -4208,5 +4252,5 @@
        REAL(wp) ::  vdotnor   !:
 
-       REAL(wp), DIMENSION(nzb:nzt+1,nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp),     &
+       REAL(wp), DIMENSION(nzb:nzt+1,nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp),      &
                  INTENT(INOUT) ::  f   !:
      
@@ -4241,8 +4285,8 @@
 
 
-    SUBROUTINE pmci_anterp_tophat( f, fc, kct, ifl, ifu, jfl, jfu, kfl, kfu,   &
+    SUBROUTINE pmci_anterp_tophat( f, fc, kct, ifl, ifu, jfl, jfu, kfl, kfu,    &
                                    ijfc, var )
 !
-!--    Anterpolation of internal-node values to be used as the server-domain
+!--    Anterpolation of internal-node values to be used as the parent-domain
 !--    values. This subroutine is based on the first-order numerical
 !--    integration of the fine-grid values contained within the coarse-grid
@@ -4296,27 +4340,43 @@
 !--    Note that kcb is simply zero and kct enters here as a parameter and it is
 !--    determined in pmci_init_anterp_tophat
-       IF ( nest_bound_l )  THEN
-          IF ( var == 'u' )  THEN
-             iclp = icl + nhll + 1
-          ELSE
+
+       IF ( nesting_mode == 'vertical' )  THEN
+          IF ( nest_bound_l )  THEN
              iclp = icl + nhll
           ENDIF
-       ENDIF
-       IF ( nest_bound_r )  THEN
-          icrm = icr - nhlr
-       ENDIF
-
-       IF ( nest_bound_s )  THEN
-          IF ( var == 'v' )  THEN
-             jcsp = jcs + nhls + 1
-          ELSE
+          IF ( nest_bound_r ) THEN
+             icrm = icr - nhlr
+          ENDIF
+          IF ( nest_bound_s )  THEN
              jcsp = jcs + nhls
           ENDIF
-       ENDIF
-       IF ( nest_bound_n )  THEN
-          jcnm = jcn - nhln
-       ENDIF
-       kcb = 0
-
+          IF ( nest_bound_n )  THEN
+             jcnm = jcn - nhln
+          ENDIF
+       ELSE
+          IF ( nest_bound_l )  THEN
+             IF ( var == 'u' )  THEN
+                iclp = icl + nhll + 1
+             ELSE
+                iclp = icl + nhll
+             ENDIF
+          ENDIF
+          IF ( nest_bound_r )  THEN
+             icrm = icr - nhlr
+          ENDIF
+
+          IF ( nest_bound_s )  THEN
+             IF ( var == 'v' )  THEN
+                jcsp = jcs + nhls + 1
+             ELSE
+                jcsp = jcs + nhls
+             ENDIF
+          ENDIF
+          IF ( nest_bound_n )  THEN
+             jcnm = jcn - nhln
+          ENDIF
+          kcb = 0
+       ENDIF
+       
 !
 !--    Note that ii, jj, and kk are coarse-grid indices and i,j, and k 
@@ -4349,5 +4409,5 @@
                 ENDIF
 
-                fc(kk,jj,ii) = ( 1.0_wp - fra ) * fc(kk,jj,ii) +               &
+                fc(kk,jj,ii) = ( 1.0_wp - fra ) * fc(kk,jj,ii) +                &
                                fra * cellsum / REAL( nfc, KIND = wp )
 
@@ -4359,5 +4419,5 @@
 
 #endif
- END SUBROUTINE pmci_client_datatrans
+ END SUBROUTINE pmci_child_datatrans
 
 END MODULE pmc_interface
Index: palm/trunk/SOURCE/pmc_mpi_wrapper_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_mpi_wrapper_mod.f90	(revision 1932)
+++ palm/trunk/SOURCE/pmc_mpi_wrapper_mod.f90	(revision 1933)
@@ -1,5 +1,5 @@
  MODULE pmc_mpi_wrapper
 
-!--------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 ! This file is part of PALM.
 !
@@ -16,14 +16,17 @@
 !
 ! Copyright 1997-2016 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! ------------------
 ! 
-!
+! 
 ! Former revisions:
 ! -----------------
 ! $Id$
 !
+! 1901 2016-05-04 15:39:38Z raasch
+! Code clean up. The words server/client changed to parent/child. 
+!
 ! 1900 2016-05-04 15:27:53Z raasch
 ! re-formatted to match PALM style
@@ -50,5 +53,5 @@
 !
 ! MPI Wrapper of Palm Model Coupler
-!------------------------------------------------------------------------------!
+!-------------------------------------------------------------------------------!
 
 #if defined( __parallel )
@@ -62,6 +65,6 @@
 
     USE kinds
-    USE pmc_handle_communicator,                                               &
-        ONLY: m_model_comm, m_model_rank, m_to_server_comm, m_to_client_comm
+    USE pmc_handle_communicator,                                                &
+        ONLY: m_model_comm, m_model_rank, m_to_parent_comm, m_to_child_comm
 
     IMPLICIT NONE
@@ -70,33 +73,33 @@
     SAVE
 
-    INTERFACE pmc_send_to_server
-       MODULE PROCEDURE pmc_send_to_server_integer
-       MODULE PROCEDURE pmc_send_to_server_integer_2
-       MODULE PROCEDURE pmc_send_to_server_real_r1
-       MODULE PROCEDURE pmc_send_to_server_real_r2
-       MODULE PROCEDURE pmc_send_to_server_real_r3
-    END INTERFACE pmc_send_to_server
-
-    INTERFACE pmc_recv_from_server
-       MODULE PROCEDURE pmc_recv_from_server_integer
-       MODULE PROCEDURE pmc_recv_from_server_real_r1
-       MODULE PROCEDURE pmc_recv_from_server_real_r2
-       MODULE PROCEDURE pmc_recv_from_server_real_r3
-    END INTERFACE pmc_recv_from_server
-
-    INTERFACE pmc_send_to_client
-       MODULE PROCEDURE pmc_send_to_client_integer
-       MODULE PROCEDURE pmc_send_to_client_real_r1
-       MODULE PROCEDURE pmc_send_to_client_real_r2
-       MODULE PROCEDURE pmc_send_to_client_real_r3
-    END INTERFACE pmc_send_to_client
-
-    INTERFACE pmc_recv_from_client
-       MODULE PROCEDURE pmc_recv_from_client_integer
-       MODULE PROCEDURE pmc_recv_from_client_integer_2
-       MODULE PROCEDURE pmc_recv_from_client_real_r1
-       MODULE PROCEDURE pmc_recv_from_client_real_r2
-       MODULE PROCEDURE pmc_recv_from_client_real_r3
-    END INTERFACE pmc_recv_from_client
+    INTERFACE pmc_send_to_parent
+       MODULE PROCEDURE pmc_send_to_parent_integer
+       MODULE PROCEDURE pmc_send_to_parent_integer_2
+       MODULE PROCEDURE pmc_send_to_parent_real_r1
+       MODULE PROCEDURE pmc_send_to_parent_real_r2
+       MODULE PROCEDURE pmc_send_to_parent_real_r3
+    END INTERFACE pmc_send_to_parent
+
+    INTERFACE pmc_recv_from_parent
+       MODULE PROCEDURE pmc_recv_from_parent_integer
+       MODULE PROCEDURE pmc_recv_from_parent_real_r1
+       MODULE PROCEDURE pmc_recv_from_parent_real_r2
+       MODULE PROCEDURE pmc_recv_from_parent_real_r3
+    END INTERFACE pmc_recv_from_parent
+
+    INTERFACE pmc_send_to_child
+       MODULE PROCEDURE pmc_send_to_child_integer
+       MODULE PROCEDURE pmc_send_to_child_real_r1
+       MODULE PROCEDURE pmc_send_to_child_real_r2
+       MODULE PROCEDURE pmc_send_to_child_real_r3
+    END INTERFACE pmc_send_to_child
+
+    INTERFACE pmc_recv_from_child
+       MODULE PROCEDURE pmc_recv_from_child_integer
+       MODULE PROCEDURE pmc_recv_from_child_integer_2
+       MODULE PROCEDURE pmc_recv_from_child_real_r1
+       MODULE PROCEDURE pmc_recv_from_child_real_r2
+       MODULE PROCEDURE pmc_recv_from_child_real_r3
+    END INTERFACE pmc_recv_from_child
 
     INTERFACE pmc_bcast
@@ -118,6 +121,6 @@
     END INTERFACE pmc_time
 
-    PUBLIC pmc_alloc_mem, pmc_bcast, pmc_inter_bcast, pmc_recv_from_client,    &
-           pmc_recv_from_server, pmc_send_to_client, pmc_send_to_server,       &
+    PUBLIC pmc_alloc_mem, pmc_bcast, pmc_inter_bcast, pmc_recv_from_child,      &
+           pmc_recv_from_parent, pmc_send_to_child, pmc_send_to_parent,         &
            pmc_time
 
@@ -125,5 +128,5 @@
 
 
- SUBROUTINE pmc_send_to_server_integer( buf, n, server_rank, tag, ierr )
+ SUBROUTINE pmc_send_to_parent_integer( buf, n, parent_rank, tag, ierr )
 
     IMPLICIT NONE
@@ -131,17 +134,17 @@
     INTEGER, DIMENSION(:), INTENT(IN) ::  buf          !<
     INTEGER, INTENT(IN)               ::  n            !<
-    INTEGER, INTENT(IN)               ::  server_rank  !<
+    INTEGER, INTENT(IN)               ::  parent_rank  !<
     INTEGER, INTENT(IN)               ::  tag          !<
     INTEGER, INTENT(OUT)              ::  ierr         !<
 
     ierr = 0
-    CALL MPI_SEND( buf, n, MPI_INTEGER, server_rank, tag, m_to_server_comm,    &
+    CALL MPI_SEND( buf, n, MPI_INTEGER, parent_rank, tag, m_to_parent_comm,     &
                    ierr)
 
- END SUBROUTINE pmc_send_to_server_integer
-
-
-
- SUBROUTINE pmc_recv_from_server_integer( buf, n, server_rank, tag, ierr )
+ END SUBROUTINE pmc_send_to_parent_integer
+
+
+
+ SUBROUTINE pmc_recv_from_parent_integer( buf, n, parent_rank, tag, ierr )
 
     IMPLICIT NONE
@@ -149,17 +152,17 @@
     INTEGER, DIMENSION(:), INTENT(OUT) ::  buf          !<
     INTEGER, INTENT(IN)                ::  n            !<
-    INTEGER, INTENT(IN)                ::  server_rank  !<
+    INTEGER, INTENT(IN)                ::  parent_rank  !<
     INTEGER, INTENT(IN)                ::  tag          !<
     INTEGER, INTENT(OUT)               ::  ierr         !<
 
     ierr = 0
-    CALL MPI_RECV( buf, n, MPI_INTEGER, server_rank, tag, m_to_server_comm,    &
+    CALL MPI_RECV( buf, n, MPI_INTEGER, parent_rank, tag, m_to_parent_comm,     &
                    MPI_STATUS_IGNORE, ierr )
 
- END SUBROUTINE pmc_recv_from_server_integer
-
-
-
- SUBROUTINE pmc_send_to_server_integer_2( buf, n, server_rank, tag, ierr )
+ END SUBROUTINE pmc_recv_from_parent_integer
+
+
+
+ SUBROUTINE pmc_send_to_parent_integer_2( buf, n, parent_rank, tag, ierr )
 
     IMPLICIT NONE
@@ -167,17 +170,17 @@
     INTEGER, DIMENSION(:,:), INTENT(IN) :: buf          !<
     INTEGER, INTENT(IN)                 :: n            !<
-    INTEGER, INTENT(IN)                 :: server_rank  !<
+    INTEGER, INTENT(IN)                 :: parent_rank  !<
     INTEGER, INTENT(IN)                 :: tag          !<
     INTEGER, INTENT(OUT)                :: ierr         !<
 
     ierr = 0
-    CALL MPI_SEND( buf, n, MPI_INTEGER, server_rank, tag, m_to_server_comm,    &
+    CALL MPI_SEND( buf, n, MPI_INTEGER, parent_rank, tag, m_to_parent_comm,     &
                    ierr )
 
- END SUBROUTINE pmc_send_to_server_integer_2
-
-
-
- SUBROUTINE pmc_send_to_server_real_r1( buf, n, server_rank, tag, ierr )
+ END SUBROUTINE pmc_send_to_parent_integer_2
+
+
+
+ SUBROUTINE pmc_send_to_parent_real_r1( buf, n, parent_rank, tag, ierr )
 
     IMPLICIT NONE
@@ -185,16 +188,16 @@
     REAL(wp), DIMENSION(:), INTENT(IN) ::  buf          !<
     INTEGER, INTENT(IN)                ::  n            !<
-    INTEGER, INTENT(IN)                ::  server_rank  !<
+    INTEGER, INTENT(IN)                ::  parent_rank  !<
     INTEGER, INTENT(IN)                ::  tag          !<
     INTEGER, INTENT(OUT)               ::  ierr         !<
 
     ierr = 0
-    CALL MPI_SEND( buf, n, MPI_REAL, server_rank, tag, m_to_server_comm, ierr )
-
- END SUBROUTINE pmc_send_to_server_real_r1
-
-
-
- SUBROUTINE pmc_recv_from_server_real_r1( buf, n, server_rank, tag, ierr )
+    CALL MPI_SEND( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm, ierr )
+
+ END SUBROUTINE pmc_send_to_parent_real_r1
+
+
+
+ SUBROUTINE pmc_recv_from_parent_real_r1( buf, n, parent_rank, tag, ierr )
 
     IMPLICIT NONE
@@ -202,17 +205,17 @@
     REAL(wp), DIMENSION(:), INTENT(OUT) ::  buf          !<
     INTEGER, INTENT(IN)                 ::  n            !<
-    INTEGER, INTENT(IN)                 ::  server_rank  !<
+    INTEGER, INTENT(IN)                 ::  parent_rank  !<
     INTEGER, INTENT(IN)                 ::  tag          !<
     INTEGER, INTENT(OUT)                ::  ierr         !<
 
     ierr = 0
-    CALL MPI_RECV( buf, n, MPI_REAL, server_rank, tag, m_to_server_comm,       &
+    CALL MPI_RECV( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm,        &
                    MPI_STATUS_IGNORE, ierr )
 
- END SUBROUTINE pmc_recv_from_server_real_r1
-
-
-
- SUBROUTINE pmc_send_to_server_real_r2( buf, n, server_rank, tag, ierr )
+ END SUBROUTINE pmc_recv_from_parent_real_r1
+
+
+
+ SUBROUTINE pmc_send_to_parent_real_r2( buf, n, parent_rank, tag, ierr )
 
     IMPLICIT NONE
@@ -220,15 +223,15 @@
     REAL(wp), DIMENSION(:,:), INTENT(IN) ::  buf          !<
     INTEGER, INTENT(IN)                  ::  n            !<
-    INTEGER, INTENT(IN)                  ::  server_rank  !<
+    INTEGER, INTENT(IN)                  ::  parent_rank  !<
     INTEGER, INTENT(IN)                  ::  tag          !<
     INTEGER, INTENT(OUT)                 ::  ierr         !<
 
     ierr = 0
-    CALL MPI_SEND( buf, n, MPI_REAL, server_rank, tag, m_to_server_comm, ierr )
-
- END SUBROUTINE pmc_send_to_server_real_r2
-
-
- SUBROUTINE pmc_recv_from_server_real_r2( buf, n, server_rank, tag, ierr )
+    CALL MPI_SEND( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm, ierr )
+
+ END SUBROUTINE pmc_send_to_parent_real_r2
+
+
+ SUBROUTINE pmc_recv_from_parent_real_r2( buf, n, parent_rank, tag, ierr )
 
     IMPLICIT NONE
@@ -236,17 +239,17 @@
     REAL(wp), DIMENSION(:,:), INTENT(OUT) ::  buf          !<
     INTEGER, INTENT(IN)                   ::  n            !<
-    INTEGER, INTENT(IN)                   ::  server_rank  !<
+    INTEGER, INTENT(IN)                   ::  parent_rank  !<
     INTEGER, INTENT(IN)                   ::  tag          !<
     INTEGER, INTENT(OUT)                  ::  ierr         !<
 
     ierr = 0
-    CALL MPI_RECV( buf, n, MPI_REAL, server_rank, tag, m_to_server_comm,       &
+    CALL MPI_RECV( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm,        &
                    MPI_STATUS_IGNORE, ierr )
 
- END SUBROUTINE pmc_recv_from_server_real_r2
-
-
-
- SUBROUTINE pmc_send_to_server_real_r3( buf, n, server_rank, tag, ierr )
+ END SUBROUTINE pmc_recv_from_parent_real_r2
+
+
+
+ SUBROUTINE pmc_send_to_parent_real_r3( buf, n, parent_rank, tag, ierr )
 
     IMPLICIT NONE
@@ -254,16 +257,16 @@
     REAL(wp), DIMENSION(:,:,:), INTENT(IN) ::  buf          !<
     INTEGER, INTENT(IN)                    ::  n            !<
-    INTEGER, INTENT(IN)                    ::  server_rank  !<
+    INTEGER, INTENT(IN)                    ::  parent_rank  !<
     INTEGER, INTENT(IN)                    ::  tag          !<
     INTEGER, INTENT(OUT)                   ::  ierr         !<
 
     ierr = 0
-    CALL MPI_SEND( buf, n, MPI_REAL, server_rank, tag, m_to_server_comm, ierr )
-
- END SUBROUTINE pmc_send_to_server_real_r3
-
-
-
- SUBROUTINE pmc_recv_from_server_real_r3( buf, n, server_rank, tag, ierr )
+    CALL MPI_SEND( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm, ierr )
+
+ END SUBROUTINE pmc_send_to_parent_real_r3
+
+
+
+ SUBROUTINE pmc_recv_from_parent_real_r3( buf, n, parent_rank, tag, ierr )
 
     IMPLICIT NONE
@@ -271,193 +274,193 @@
     REAL(wp), DIMENSION(:,:,:), INTENT(OUT) ::  buf          !<
     INTEGER, INTENT(IN)                     ::  n            !<
-    INTEGER, INTENT(IN)                     ::  server_rank  !<
+    INTEGER, INTENT(IN)                     ::  parent_rank  !<
     INTEGER, INTENT(IN)                     ::  tag          !<
     INTEGER, INTENT(OUT)                    ::  ierr         !<
 
     ierr = 0
-    CALL MPI_RECV( buf, n, MPI_REAL, server_rank, tag, m_to_server_comm,       &
+    CALL MPI_RECV( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm,        &
                    MPI_STATUS_IGNORE, ierr )
 
- END SUBROUTINE pmc_recv_from_server_real_r3
-
-
-
- SUBROUTINE pmc_send_to_client_integer( client_id, buf, n, client_rank, tag,   &
-                                        ierr )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)               ::  client_id    !<
+ END SUBROUTINE pmc_recv_from_parent_real_r3
+
+
+
+ SUBROUTINE pmc_send_to_child_integer( child_id, buf, n, child_rank, tag,       &
+                                       ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)               ::  child_id     !<
     INTEGER, DIMENSION(:), INTENT(IN) ::  buf          !<
     INTEGER, INTENT(IN)               ::  n            !<
-    INTEGER, INTENT(IN)               ::  client_rank  !<
+    INTEGER, INTENT(IN)               ::  child_rank   !<
     INTEGER, INTENT(IN)               ::  tag          !<
     INTEGER, INTENT(OUT)              ::  ierr         !<
 
     ierr = 0
-    CALL MPI_SEND( buf, n, MPI_INTEGER, client_rank, tag,                      &
-                   m_to_client_comm(client_id), ierr )
-
- END SUBROUTINE pmc_send_to_client_integer
-
-
-
- SUBROUTINE pmc_recv_from_client_integer( client_id, buf, n, client_rank, tag, &
-                                          ierr )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)                  ::  client_id    !<
+    CALL MPI_SEND( buf, n, MPI_INTEGER, child_rank, tag,                        &
+                   m_to_child_comm(child_id), ierr )
+
+ END SUBROUTINE pmc_send_to_child_integer
+
+
+
+ SUBROUTINE pmc_recv_from_child_integer( child_id, buf, n, child_rank, tag,     &
+                                         ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)                  ::  child_id     !<
     INTEGER, DIMENSION(:), INTENT(INOUT) ::  buf          !<
     INTEGER, INTENT(IN)                  ::  n            !<
-    INTEGER, INTENT(IN)                  ::  client_rank  !<
+    INTEGER, INTENT(IN)                  ::  child_rank   !<
     INTEGER, INTENT(IN)                  ::  tag          !<
     INTEGER, INTENT(OUT)                 ::  ierr         !<
 
     ierr = 0
-    CALL MPI_RECV( buf, n, MPI_INTEGER, client_rank, tag,                      &
-                   m_to_client_comm(client_id), MPI_STATUS_IGNORE, ierr )
-
- END SUBROUTINE pmc_recv_from_client_integer
-
-
-
- SUBROUTINE pmc_recv_from_client_integer_2( client_id, buf, n, client_rank,    &
-                                            tag, ierr )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)                  ::  client_id    !<
+    CALL MPI_RECV( buf, n, MPI_INTEGER, child_rank, tag,                        &
+                   m_to_child_comm(child_id), MPI_STATUS_IGNORE, ierr )
+
+ END SUBROUTINE pmc_recv_from_child_integer
+
+
+
+ SUBROUTINE pmc_recv_from_child_integer_2( child_id, buf, n, child_rank,        &
+                                           tag, ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)                  ::  child_id     !<
     INTEGER, DIMENSION(:,:), INTENT(OUT) ::  buf          !<
     INTEGER, INTENT(IN)                  ::  n            !<
-    INTEGER, INTENT(IN)                  ::  client_rank  !<
+    INTEGER, INTENT(IN)                  ::  child_rank   !<
     INTEGER, INTENT(IN)                  ::  tag          !<
     INTEGER, INTENT(OUT)                 ::  ierr         !<
 
     ierr = 0
-    CALL MPI_RECV( buf, n, MPI_INTEGER, client_rank, tag,                      &
-                   m_to_client_comm(client_id), MPI_STATUS_IGNORE, ierr )
-
- END SUBROUTINE pmc_recv_from_client_integer_2
-
-
-
- SUBROUTINE pmc_send_to_client_real_r1( client_id, buf, n, client_rank, tag,   &
-                                        ierr )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)                ::  client_id    !<
+    CALL MPI_RECV( buf, n, MPI_INTEGER, child_rank, tag,                        &
+                   m_to_child_comm(child_id), MPI_STATUS_IGNORE, ierr )
+
+ END SUBROUTINE pmc_recv_from_child_integer_2
+
+
+
+ SUBROUTINE pmc_send_to_child_real_r1( child_id, buf, n, child_rank, tag,       &
+                                       ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)                ::  child_id     !<
     REAL(wp), DIMENSION(:), INTENT(IN) ::  buf          !<
     INTEGER, INTENT(IN)                ::  n            !<
-    INTEGER, INTENT(IN)                ::  client_rank  !<
+    INTEGER, INTENT(IN)                ::  child_rank   !<
     INTEGER, INTENT(IN)                ::  tag          !<
     INTEGER, INTENT(OUT)               ::  ierr         !<
 
     ierr = 0
-    CALL MPI_SEND( buf, n, MPI_REAL, client_rank, tag,                         &
-                   m_to_client_comm(client_id), ierr )
-
- END SUBROUTINE pmc_send_to_client_real_r1
-
-
-
- SUBROUTINE pmc_recv_from_client_real_r1( client_id, buf, n, client_rank, tag, &
-                                          ierr )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)                   ::  client_id    !<
+    CALL MPI_SEND( buf, n, MPI_REAL, child_rank, tag,                           &
+                   m_to_child_comm(child_id), ierr )
+
+ END SUBROUTINE pmc_send_to_child_real_r1
+
+
+
+ SUBROUTINE pmc_recv_from_child_real_r1( child_id, buf, n, child_rank, tag,     &
+                                         ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)                   ::  child_id     !<
     REAL(wp), DIMENSION(:), INTENT(INOUT) ::  buf          !<
     INTEGER, INTENT(IN)                   ::  n            !<
-    INTEGER, INTENT(IN)                   ::  client_rank  !<
+    INTEGER, INTENT(IN)                   ::  child_rank   !<
     INTEGER, INTENT(IN)                   ::  tag          !<
     INTEGER, INTENT(OUT)                  ::  ierr         !<
 
     ierr = 0
-    CALL MPI_RECV( buf, n, MPI_REAL, client_rank, tag,                         &
-                   m_to_client_comm(client_id), MPI_STATUS_IGNORE, ierr )
-
- END SUBROUTINE pmc_recv_from_client_real_r1
-
-
-
- SUBROUTINE pmc_send_to_client_real_r2( client_id, buf, n, client_rank, tag,   &
-                                        ierr )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)                  ::  client_id    !<
+    CALL MPI_RECV( buf, n, MPI_REAL, child_rank, tag,                           &
+                   m_to_child_comm(child_id), MPI_STATUS_IGNORE, ierr )
+
+ END SUBROUTINE pmc_recv_from_child_real_r1
+
+
+
+ SUBROUTINE pmc_send_to_child_real_r2( child_id, buf, n, child_rank, tag,       &
+                                       ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)                  ::  child_id     !<
     REAL(wp), DIMENSION(:,:), INTENT(IN) ::  buf          !<
     INTEGER, INTENT(IN)                  ::  n            !<
-    INTEGER, INTENT(IN)                  ::  client_rank  !<
+    INTEGER, INTENT(IN)                  ::  child_rank   !<
     INTEGER, INTENT(IN)                  ::  tag          !<
     INTEGER, INTENT(OUT)                 ::  ierr         !<
 
     ierr = 0
-    CALL MPI_SEND( buf, n, MPI_REAL, client_rank, tag,                         &
-                   m_to_client_comm(client_id), ierr )
-
- END SUBROUTINE pmc_send_to_client_real_r2
-
-
-
- SUBROUTINE pmc_recv_from_client_real_r2( client_id, buf, n, client_rank, tag, &
-                                          ierr )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)                   ::  client_id    !<
+    CALL MPI_SEND( buf, n, MPI_REAL, child_rank, tag,                           &
+                   m_to_child_comm(child_id), ierr )
+
+ END SUBROUTINE pmc_send_to_child_real_r2
+
+
+
+ SUBROUTINE pmc_recv_from_child_real_r2( child_id, buf, n, child_rank, tag,     &
+                                         ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)                   ::  child_id     !<
     REAL(wp), DIMENSION(:,:), INTENT(OUT) ::  buf          !<
     INTEGER, INTENT(IN)                   ::  n            !<
-    INTEGER, INTENT(IN)                   ::  client_rank  !<
+    INTEGER, INTENT(IN)                   ::  child_rank   !<
     INTEGER, INTENT(IN)                   ::  tag          !<
     INTEGER, INTENT(OUT)                  ::  ierr         !<
 
     ierr = 0
-    CALL MPI_RECV( buf, n, MPI_REAL, client_rank, tag,                         &
-                   m_to_client_comm(client_id), MPI_STATUS_IGNORE, ierr )
-
- END SUBROUTINE pmc_recv_from_client_real_r2
-
-
-
- SUBROUTINE pmc_send_to_client_real_r3( client_id, buf, n, client_rank, tag,   &
-                                        ierr)
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)                    ::  client_id    !<
+    CALL MPI_RECV( buf, n, MPI_REAL, child_rank, tag,                           &
+                   m_to_child_comm(child_id), MPI_STATUS_IGNORE, ierr )
+
+ END SUBROUTINE pmc_recv_from_child_real_r2
+
+
+
+ SUBROUTINE pmc_send_to_child_real_r3( child_id, buf, n, child_rank, tag,       &
+                                       ierr)
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)                    ::  child_id     !<
     REAL(wp), DIMENSION(:,:,:), INTENT(IN) ::  buf          !<
     INTEGER, INTENT(IN)                    ::  n            !<
-    INTEGER, INTENT(IN)                    ::  client_rank  !<
+    INTEGER, INTENT(IN)                    ::  child_rank   !<
     INTEGER, INTENT(IN)                    ::  tag          !<
     INTEGER, INTENT(OUT)                   ::  ierr         !<
 
     ierr = 0
-    CALL MPI_SEND( buf, n, MPI_REAL, client_rank, tag,                         &
-                   m_to_client_comm(client_id), ierr )
-
- END SUBROUTINE pmc_send_to_client_real_r3
-
-
-
- SUBROUTINE pmc_recv_from_client_real_r3( client_id, buf, n, client_rank, tag, &
-                                          ierr )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)                     ::  client_id    !<
+    CALL MPI_SEND( buf, n, MPI_REAL, child_rank, tag,                           &
+                   m_to_child_comm(child_id), ierr )
+
+ END SUBROUTINE pmc_send_to_child_real_r3
+
+
+
+ SUBROUTINE pmc_recv_from_child_real_r3( child_id, buf, n, child_rank, tag,     &
+                                         ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)                     ::  child_id     !<
     REAL(wp), DIMENSION(:,:,:), INTENT(OUT) ::  buf          !<
     INTEGER, INTENT(IN)                     ::  n            !<
-    INTEGER, INTENT(IN)                     ::  client_rank  !<
+    INTEGER, INTENT(IN)                     ::  child_rank   !<
     INTEGER, INTENT(IN)                     ::  tag          !<
     INTEGER, INTENT(OUT)                    ::  ierr         !<
 
     ierr = 0
-    CALL MPI_RECV( buf, n, MPI_REAL, client_rank, tag,                         &
-                   m_to_client_comm(client_id), MPI_STATUS_IGNORE, ierr )
-
- END SUBROUTINE pmc_recv_from_client_real_r3
+    CALL MPI_RECV( buf, n, MPI_REAL, child_rank, tag,                           & 
+                   m_to_child_comm(child_id), MPI_STATUS_IGNORE, ierr )
+
+ END SUBROUTINE pmc_recv_from_child_real_r3
 
 
@@ -520,10 +523,10 @@
 
 
- SUBROUTINE pmc_inter_bcast_integer_1( buf, client_id, ierr )
+ SUBROUTINE pmc_inter_bcast_integer_1( buf, child_id, ierr )
 
     IMPLICIT NONE
 
     INTEGER, INTENT(INOUT),DIMENSION(:) ::  buf        !<
-    INTEGER, INTENT(IN),optional        ::  client_id  !<
+    INTEGER, INTENT(IN),optional        ::  child_id   !<
     INTEGER, INTENT(OUT),optional       ::  ierr       !<
 
@@ -533,8 +536,8 @@
 
 !
-!-- PE 0 server broadcast to all client PEs
-    IF ( PRESENT( client_id ) )  THEN
-
-       mycomm = m_to_client_comm(client_id)
+!-- PE 0 on parent broadcast to all child PEs
+    IF ( PRESENT( child_id ) )  THEN
+
+       mycomm = m_to_child_comm(child_id)
 
        IF ( m_model_rank == 0 )  THEN
@@ -545,5 +548,5 @@
 
     ELSE
-       mycomm  = m_to_server_comm
+       mycomm  = m_to_parent_comm
        root_pe = 0
     ENDIF
Index: palm/trunk/SOURCE/pmc_parent_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_parent_mod.f90	(revision 1933)
+++ palm/trunk/SOURCE/pmc_parent_mod.f90	(revision 1933)
@@ -0,0 +1,1042 @@
+ MODULE pmc_parent
+
+!-------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! 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-2016 Leibniz Universitaet Hannover
+!-------------------------------------------------------------------------------!
+!
+! Current revisions:
+! ------------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+!
+! 1901 2016-05-04 15:39:38Z raasch
+! Module renamed. Code clean up. The words server/client changed to parent/child. 
+!
+! 1900 2016-05-04 15:27:53Z raasch
+! re-formatted to match PALM style
+!
+! 1850 2016-04-08 13:29:27Z maronga
+! Module renamed
+! 
+! 
+! 1833 2016-04-07 14:23:03Z raasch
+! gfortran requires pointer attributes for some array declarations,
+! long line wrapped
+!
+! 1808 2016-04-05 19:44:00Z raasch
+! MPI module used by default on all machines
+!
+! 1797 2016-03-21 16:50:28Z raasch
+! introduction of different datatransfer modes
+!
+! 1791 2016-03-11 10:41:25Z raasch
+! Debug write-statements commented out
+!
+! 1786 2016-03-08 05:49:27Z raasch
+! change in child-parent data transfer: parent now gets data from child
+! instead that child put's it to the parent
+!
+! 1779 2016-03-03 08:01:28Z raasch
+! kind=dp replaced by wp,
+! error messages removed or changed to PALM style, dim_order removed
+! array management changed from linked list to sequential loop
+!
+! 1766 2016-02-29 08:37:15Z raasch
+! modifications to allow for using PALM's pointer version
+! +new routine pmc_s_set_active_data_array
+!
+! 1764 2016-02-28 12:45:19Z raasch
+! cpp-statement added (nesting can only be used in parallel mode)
+!
+! 1762 2016-02-25 12:31:13Z hellstea
+! Initial revision by K. Ketelsen
+!
+! Description:
+! ------------
+!
+! Parent part of Palm Model Coupler
+!-------------------------------------------------------------------------------!
+
+#if defined( __parallel )
+    USE, INTRINSIC ::  ISO_C_BINDING
+
+#if defined( __mpifh )
+    INCLUDE "mpif.h"
+#else
+    USE MPI
+#endif
+    USE kinds
+    USE pmc_general,                                                            &
+        ONLY: arraydef, childdef, da_namedef, da_namelen, pedef,                &
+              pmc_g_setname, pmc_max_array, pmc_max_models, pmc_sort
+
+    USE pmc_handle_communicator,                                                &
+        ONLY: m_model_comm,m_model_rank,m_model_npes, m_to_child_comm,          &
+              m_world_rank, pmc_parent_for_child
+
+    USE pmc_mpi_wrapper,                                                        &
+        ONLY: pmc_alloc_mem, pmc_bcast, pmc_time
+
+   IMPLICIT NONE
+
+   PRIVATE
+   SAVE
+
+   TYPE childindexdef
+      INTEGER                              ::  nrpoints       !<
+      INTEGER, DIMENSION(:,:), ALLOCATABLE ::  index_list_2d  !<
+   END TYPE childindexdef
+
+   TYPE(childdef), DIMENSION(pmc_max_models)       ::  children     !<
+   TYPE(childindexdef), DIMENSION(pmc_max_models)  ::  indchildren  !<
+
+   INTEGER ::  next_array_in_list = 0  !<
+
+
+   PUBLIC pmc_parent_for_child
+
+
+   INTERFACE pmc_parentinit
+      MODULE PROCEDURE  pmc_parentinit
+   END INTERFACE pmc_parentinit
+
+    INTERFACE pmc_s_set_2d_index_list
+        MODULE PROCEDURE pmc_s_set_2d_index_list
+    END INTERFACE pmc_s_set_2d_index_list
+
+    INTERFACE pmc_s_clear_next_array_list
+        MODULE PROCEDURE pmc_s_clear_next_array_list
+    END INTERFACE pmc_s_clear_next_array_list
+
+    INTERFACE pmc_s_getnextarray
+        MODULE PROCEDURE pmc_s_getnextarray
+    END INTERFACE pmc_s_getnextarray
+
+    INTERFACE pmc_s_set_dataarray
+        MODULE PROCEDURE pmc_s_set_dataarray_2d
+        MODULE PROCEDURE pmc_s_set_dataarray_3d
+    END INTERFACE pmc_s_set_dataarray
+
+    INTERFACE pmc_s_setind_and_allocmem
+        MODULE PROCEDURE pmc_s_setind_and_allocmem
+    END INTERFACE pmc_s_setind_and_allocmem
+
+    INTERFACE pmc_s_fillbuffer
+        MODULE PROCEDURE pmc_s_fillbuffer
+    END INTERFACE pmc_s_fillbuffer
+
+    INTERFACE pmc_s_getdata_from_buffer
+        MODULE PROCEDURE pmc_s_getdata_from_buffer
+    END INTERFACE pmc_s_getdata_from_buffer
+
+    INTERFACE pmc_s_set_active_data_array
+        MODULE PROCEDURE pmc_s_set_active_data_array
+    END INTERFACE pmc_s_set_active_data_array
+
+    PUBLIC pmc_parentinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer,       &
+           pmc_s_getdata_from_buffer, pmc_s_getnextarray,                       &
+           pmc_s_setind_and_allocmem, pmc_s_set_active_data_array,              &
+           pmc_s_set_dataarray, pmc_s_set_2d_index_list
+
+ CONTAINS
+
+
+ SUBROUTINE pmc_parentinit
+
+    IMPLICIT NONE
+
+    INTEGER ::  childid   !<
+    INTEGER ::  i         !<
+    INTEGER ::  j         !<
+    INTEGER ::  istat     !<
+
+
+    DO  i = 1, SIZE( pmc_parent_for_child )-1
+
+       childid = pmc_parent_for_child( i )
+
+       children(childid)%model_comm = m_model_comm
+       children(childid)%inter_comm = m_to_child_comm(childid)
+
+!
+!--    Get rank and size
+       CALL MPI_COMM_RANK( children(childid)%model_comm,                        &
+                           children(childid)%model_rank, istat )
+       CALL MPI_COMM_SIZE( children(childid)%model_comm,                        &
+                           children(childid)%model_npes, istat )
+       CALL MPI_COMM_REMOTE_SIZE( children(childid)%inter_comm,                 &
+                                  children(childid)%inter_npes, istat )
+
+!
+!--    Intra communicater is used for MPI_GET
+       CALL MPI_INTERCOMM_MERGE( children(childid)%inter_comm, .FALSE.,         &
+                                 children(childid)%intra_comm, istat )
+       CALL MPI_COMM_RANK( children(childid)%intra_comm,                        &
+                           children(childid)%intra_rank, istat )
+
+       ALLOCATE( children(childid)%pes(children(childid)%inter_npes))
+
+!
+!--    Allocate array of TYPE arraydef for all child PEs to store information
+!--    of the transfer array
+       DO  j = 1, children(childid)%inter_npes
+         ALLOCATE( children(childid)%pes(j)%array_list(pmc_max_array) )
+       ENDDO
+
+       CALL get_da_names_from_child (childid)
+
+    ENDDO
+
+ END SUBROUTINE pmc_parentinit
+
+
+
+ SUBROUTINE pmc_s_set_2d_index_list( childid, index_list )
+
+     IMPLICIT NONE
+
+     INTEGER, INTENT(IN)                    :: childid     !<
+     INTEGER, DIMENSION(:,:), INTENT(INOUT) :: index_list  !<
+
+     INTEGER ::  ian    !<
+     INTEGER ::  ic     !<
+     INTEGER ::  ie     !<
+     INTEGER ::  ip     !<
+     INTEGER ::  is     !<
+     INTEGER ::  istat  !<
+     INTEGER ::  n      !<
+
+
+     IF ( m_model_rank == 0 )  THEN
+
+!
+!--     Sort to ascending parent PE order
+        CALL pmc_sort( index_list, 6 )
+
+        is = 1
+        DO  ip = 0, m_model_npes-1
+
+!
+!--        Split into parent PEs
+           ie = is - 1
+
+!
+!--        There may be no entry for this PE
+           IF ( is <= SIZE( index_list,2 )  .AND.  ie >= 0 )  THEN
+
+              DO WHILE ( index_list(6,ie+1 ) == ip )
+                 ie = ie + 1
+                 IF ( ie == SIZE( index_list,2 ) )  EXIT
+              ENDDO
+
+              ian = ie - is + 1
+
+           ELSE
+              is  = -1
+              ie  = -2
+              ian =  0
+           ENDIF
+
+!
+!--        Send data to other parent PEs
+           IF ( ip == 0 )  THEN
+              indchildren(childid)%nrpoints = ian
+              IF ( ian > 0)  THEN
+                  ALLOCATE( indchildren(childid)%index_list_2d(6,ian) )
+                  indchildren(childid)%index_list_2d(:,1:ian) =                 &
+                                                             index_list(:,is:ie)
+              ENDIF
+           ELSE
+              CALL MPI_SEND( ian, 1, MPI_INTEGER, ip, 1000, m_model_comm,       &
+                             istat )
+              IF ( ian > 0)  THEN
+                  CALL MPI_SEND( index_list(1,is), 6*ian, MPI_INTEGER, ip,      &
+                                 1001, m_model_comm, istat )
+              ENDIF
+           ENDIF
+           is = ie + 1
+
+        ENDDO
+
+     ELSE
+
+        CALL MPI_RECV( indchildren(childid)%nrpoints, 1, MPI_INTEGER, 0, 1000,  &
+                       m_model_comm, MPI_STATUS_IGNORE, istat )
+        ian = indchildren(childid)%nrpoints
+
+        IF ( ian > 0 )  THEN
+           ALLOCATE( indchildren(childid)%index_list_2d(6,ian) )
+           CALL MPI_RECV( indchildren(childid)%index_list_2d, 6*ian,            &
+                          MPI_INTEGER, 0, 1001, m_model_comm,                   &
+                          MPI_STATUS_IGNORE, istat)
+        ENDIF
+
+     ENDIF
+
+     CALL set_pe_index_list( childid, children(childid),                        &
+                             indchildren(childid)%index_list_2d,                &
+                             indchildren(childid)%nrpoints )
+
+ END SUBROUTINE pmc_s_set_2d_index_list
+
+
+
+ SUBROUTINE pmc_s_clear_next_array_list
+
+    IMPLICIT NONE
+
+    next_array_in_list = 0
+
+ END SUBROUTINE pmc_s_clear_next_array_list
+
+
+
+ LOGICAL FUNCTION pmc_s_getnextarray( childid, myname )
+
+!
+!-- List handling is still required to get minimal interaction with
+!-- pmc_interface
+!-- TODO: what does "still" mean? Is there a chance to change this!
+    CHARACTER(LEN=*), INTENT(OUT) ::  myname    !<
+    INTEGER(iwp), INTENT(IN)      ::  childid   !<
+
+    TYPE(arraydef), POINTER :: ar
+    TYPE(pedef), POINTER    :: ape
+
+    next_array_in_list = next_array_in_list + 1
+
+!
+!-- Array names are the same on all children PEs, so take first PE to get the name
+    ape => children(childid)%pes(1)
+
+    IF ( next_array_in_list > ape%nr_arrays )  THEN
+
+!
+!--    All arrays are done
+       pmc_s_getnextarray = .FALSE.
+       RETURN
+    ENDIF
+
+    ar => ape%array_list(next_array_in_list)
+    myname = ar%name
+
+!
+!-- Return true if legal array
+!-- TODO: what does this comment mean? Can there be non-legal arrays??
+    pmc_s_getnextarray = .TRUE.
+
+ END FUNCTION pmc_s_getnextarray
+
+
+
+ SUBROUTINE pmc_s_set_dataarray_2d( childid, array, array_2 )
+
+    IMPLICIT NONE
+
+    INTEGER,INTENT(IN) ::  childid   !<
+
+    REAL(wp), INTENT(IN), DIMENSION(:,:), POINTER           ::  array    !<
+    REAL(wp), INTENT(IN), DIMENSION(:,:), POINTER, OPTIONAL ::  array_2  !<
+
+    INTEGER               ::  nrdims      !<
+    INTEGER, DIMENSION(4) ::  dims        !<
+    TYPE(C_PTR)           ::  array_adr   !<
+    TYPE(C_PTR)           ::  second_adr  !<
+
+
+    dims      = 1
+    nrdims    = 2
+    dims(1)   = SIZE( array,1 )
+    dims(2)   = SIZE( array,2 )
+    array_adr = C_LOC( array )
+
+    IF ( PRESENT( array_2 ) )  THEN
+       second_adr = C_LOC(array_2)
+       CALL pmc_s_setarray( childid, nrdims, dims, array_adr,                   &
+                            second_adr = second_adr)
+    ELSE
+       CALL pmc_s_setarray( childid, nrdims, dims, array_adr )
+    ENDIF
+
+ END SUBROUTINE pmc_s_set_dataarray_2d
+
+
+
+ SUBROUTINE pmc_s_set_dataarray_3d( childid, array, nz_cl, nz, array_2 )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN) ::  childid   !<
+    INTEGER, INTENT(IN) ::  nz        !<
+    INTEGER, INTENT(IN) ::  nz_cl     !<
+
+    REAL(wp), INTENT(IN), DIMENSION(:,:,:), POINTER           ::  array    !<
+    REAL(wp), INTENT(IN), DIMENSION(:,:,:), POINTER, OPTIONAL ::  array_2  !<
+
+    INTEGER               ::  nrdims      !<
+    INTEGER, DIMENSION(4) ::  dims        !<
+    TYPE(C_PTR)           ::  array_adr   !<
+    TYPE(C_PTR)           ::  second_adr  !<
+
+!
+!-- TODO: the next assignment seems to be obsolete. Please check!
+    dims      = 1
+    dims      = 0
+    nrdims    = 3
+    dims(1)   = SIZE( array,1 )
+    dims(2)   = SIZE( array,2 )
+    dims(3)   = SIZE( array,3 )
+    dims(4)   = nz_cl+dims(1)-nz  ! works for first dimension 1:nz and 0:nz+1
+
+    array_adr = C_LOC(array)
+
+!
+!-- In PALM's pointer version, two indices have to be stored internally.
+!-- The active address of the data array is set in swap_timelevel.
+    IF ( PRESENT( array_2 ) )  THEN
+      second_adr = C_LOC( array_2 )
+      CALL pmc_s_setarray( childid, nrdims, dims, array_adr,                    &
+                           second_adr = second_adr)
+    ELSE
+       CALL pmc_s_setarray( childid, nrdims, dims, array_adr )
+    ENDIF
+
+ END SUBROUTINE pmc_s_set_dataarray_3d
+
+
+
+ SUBROUTINE pmc_s_setind_and_allocmem( childid )
+
+    USE control_parameters,                                                     &
+        ONLY:  message_string
+
+    IMPLICIT NONE
+
+!
+!-- Naming convention for appendices:   _pc  -> parent to child transfer
+!--                                     _cp  -> child to parent transfer
+!--                                     send -> parent to child transfer
+!--                                     recv -> child to parent transfer
+    INTEGER, INTENT(IN) ::  childid   !<
+
+    INTEGER                        ::  arlen    !<
+    INTEGER                        ::  i        !<
+    INTEGER                        ::  ierr     !<
+    INTEGER                        ::  istat    !<
+    INTEGER                        ::  j        !<
+    INTEGER                        ::  myindex  !<
+    INTEGER                        ::  rcount   !< count MPI requests
+    INTEGER                        ::  tag      !<
+
+    INTEGER(idp)                   ::  bufsize  !< size of MPI data window
+    INTEGER(KIND=MPI_ADDRESS_KIND) ::  winsize  !<
+
+    INTEGER, DIMENSION(1024)       ::  req      !<
+
+    TYPE(C_PTR)             ::  base_ptr  !<
+    TYPE(pedef), POINTER    ::  ape       !<
+    TYPE(arraydef), POINTER ::  ar        !<
+
+    REAL(wp),DIMENSION(:), POINTER, SAVE ::  base_array_pc  !< base array for parent to child transfer
+    REAL(wp),DIMENSION(:), POINTER, SAVE ::  base_array_cp  !< base array for child to parent transfer
+
+!
+!-- Parent to child direction
+    myindex = 1
+    rcount  = 0
+    bufsize = 8
+
+!
+!-- First stride: compute size and set index
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
+       tag = 200
+
+       DO  j = 1, ape%nr_arrays
+
+          ar  => ape%array_list(j)
+          IF ( ar%nrdims == 2 )  THEN
+             arlen = ape%nrele
+          ELSEIF ( ar%nrdims == 3 )  THEN
+             arlen = ape%nrele * ar%a_dim(4)
+          ELSE
+             arlen = -1
+          ENDIF
+          ar%sendindex = myindex
+
+          tag    = tag + 1
+          rcount = rcount + 1
+          CALL MPI_ISEND( myindex, 1, MPI_INTEGER, i-1, tag,                    &
+                          children(childid)%inter_comm, req(rcount), ierr )
+
+!
+!--       Maximum of 1024 outstanding requests
+!--       TODO: what does this limit mean?
+          IF ( rcount == 1024 )  THEN
+             CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
+             rcount = 0
+          ENDIF
+
+          myindex = myindex + arlen
+          bufsize = bufsize + arlen
+          ar%sendsize = arlen
+
+       ENDDO
+
+       IF ( rcount > 0 )  THEN
+          CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
+       ENDIF
+
+    ENDDO
+
+!
+!-- Create RMA (One Sided Communication) window for data buffer parent to
+!-- child transfer.
+!-- The buffer of MPI_GET (counterpart of transfer) can be PE-local, i.e.
+!-- it can but must not be part of the MPI RMA window. Only one RMA window is
+!-- required to prepare the data for
+!--                       parent -> child transfer on the parent side
+!-- and for
+!--                       child -> parent transfer on the child side
+    CALL pmc_alloc_mem( base_array_pc, bufsize )
+    children(childid)%totalbuffersize = bufsize * wp
+
+    winsize = bufsize * wp
+    CALL MPI_WIN_CREATE( base_array_pc, winsize, wp, MPI_INFO_NULL,             &
+                         children(childid)%intra_comm,                          &
+                         children(childid)%win_parent_child, ierr )
+
+!
+!-- Open window to set data
+    CALL MPI_WIN_FENCE( 0, children(childid)%win_parent_child, ierr )
+
+!
+!-- Second stride: set buffer pointer
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => ape%array_list(j)
+          ar%sendbuf = C_LOC( base_array_pc(ar%sendindex) )
+
+          IF ( ar%sendindex + ar%sendsize > bufsize )  THEN             
+             WRITE( message_string, '(a,i4,4i7,1x,a)' )                         &
+                    'Parent buffer too small ',i,                               &
+                    ar%sendindex,ar%sendsize,ar%sendindex+ar%sendsize,          &
+                    bufsize,trim(ar%name)
+             CALL message( 'pmc_s_setind_and_allocmem', 'PA0429', 3, 2, 0, 6, 0 )
+          ENDIF
+       ENDDO
+    ENDDO
+
+!
+!-- Child to parent direction
+    bufsize = 8
+
+!
+!-- First stride: compute size and set index
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
+       tag = 300
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => ape%array_list(j)
+
+!
+!--       Receive index from child
+          tag = tag + 1
+          CALL MPI_RECV( myindex, 1, MPI_INTEGER, i-1, tag,                     &
+                         children(childid)%inter_comm, MPI_STATUS_IGNORE, ierr )
+
+          IF ( ar%nrdims == 3 )  THEN
+             bufsize = MAX( bufsize, ape%nrele * ar%a_dim(4) )
+          ELSE
+             bufsize = MAX( bufsize, ape%nrele )
+          ENDIF
+          ar%recvindex = myindex
+
+        ENDDO
+
+    ENDDO
+
+!
+!-- Create RMA (one sided communication) data buffer.
+!-- The buffer for MPI_GET can be PE local, i.e. it can but must not be part of
+!-- the MPI RMA window
+    CALL pmc_alloc_mem( base_array_cp, bufsize, base_ptr )
+    children(childid)%totalbuffersize = bufsize * wp
+
+    CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
+
+!
+!-- Second stride: set buffer pointer
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
+
+       DO  j = 1, ape%nr_arrays
+          ar => ape%array_list(j)
+          ar%recvbuf = base_ptr
+       ENDDO
+
+    ENDDO
+
+ END SUBROUTINE pmc_s_setind_and_allocmem
+
+
+
+ SUBROUTINE pmc_s_fillbuffer( childid, waittime )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)             ::  childid   !<
+
+    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime  !<
+
+    INTEGER               ::  ierr     !<
+    INTEGER               ::  ij       !<
+    INTEGER               ::  ip       !<
+    INTEGER               ::  istat    !<
+    INTEGER               ::  j        !<
+    INTEGER               ::  myindex  !<
+
+    INTEGER, DIMENSION(1) ::  buf_shape
+
+    REAL(wp)                            ::  t1       !<
+    REAL(wp)                            ::  t2       !<
+    REAL(wp), POINTER, DIMENSION(:)     ::  buf      !<
+    REAL(wp), POINTER, DIMENSION(:,:)   ::  data_2d  !<
+    REAL(wp), POINTER, DIMENSION(:,:,:) ::  data_3d  !<
+
+    TYPE(pedef), POINTER    ::  ape  !<
+    TYPE(arraydef), POINTER ::  ar   !<
+
+!
+!-- Synchronization of the model is done in pmci_synchronize.
+!-- Therefor the RMA window can be filled without
+!-- sychronization at this point and a barrier is not necessary.
+!-- Please note that waittime has to be set in pmc_s_fillbuffer AND
+!-- pmc_c_getbuffer
+    IF ( PRESENT( waittime) )  THEN
+      t1 = pmc_time()
+      CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
+      t2 = pmc_time()
+      waittime = t2- t1
+    ENDIF
+
+    DO  ip = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(ip)
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => ape%array_list(j)
+          myindex = 1
+
+          IF ( ar%nrdims == 2 )  THEN
+
+             buf_shape(1) = ape%nrele
+             CALL C_F_POINTER( ar%sendbuf, buf, buf_shape )
+             CALL C_F_POINTER( ar%data, data_2d, ar%a_dim(1:2) )
+             DO  ij = 1, ape%nrele
+                buf(myindex) = data_2d(ape%locind(ij)%j,ape%locind(ij)%i)
+                myindex = myindex + 1
+             ENDDO
+
+          ELSEIF ( ar%nrdims == 3 )  THEN
+
+             buf_shape(1) = ape%nrele*ar%a_dim(4)
+             CALL C_F_POINTER( ar%sendbuf, buf, buf_shape )
+             CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3) )
+             DO  ij = 1, ape%nrele
+                buf(myindex:myindex+ar%a_dim(4)-1) =                            &
+                        data_3d(1:ar%a_dim(4),ape%locind(ij)%j,ape%locind(ij)%i)
+                myindex = myindex + ar%a_dim(4)
+             ENDDO
+
+          ENDIF
+
+        ENDDO
+
+    ENDDO
+
+!
+!-- Buffer is filled
+    CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
+
+ END SUBROUTINE pmc_s_fillbuffer
+
+
+
+ SUBROUTINE pmc_s_getdata_from_buffer( childid, waittime )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)             ::  childid      !<
+    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime     !<
+
+    INTEGER                        ::  ierr          !<
+    INTEGER                        ::  ij            !<
+    INTEGER                        ::  ip            !<
+    INTEGER                        ::  istat         !<
+    INTEGER                        ::  j             !<
+    INTEGER                        ::  myindex       !<
+    INTEGER                        ::  nr            !<
+    INTEGER                        ::  target_pe     !<
+    INTEGER(kind=MPI_ADDRESS_KIND) ::  target_disp   !<
+
+    INTEGER, DIMENSION(1)          ::  buf_shape     !<
+
+    REAL(wp)                            ::  t1       !<
+    REAL(wp)                            ::  t2       !<
+    REAL(wp), POINTER, DIMENSION(:)     ::  buf      !<
+    REAL(wp), POINTER, DIMENSION(:,:)   ::  data_2d  !<
+    REAL(wp), POINTER, DIMENSION(:,:,:) ::  data_3d  !<
+
+    TYPE(pedef), POINTER    ::  ape  !<
+    TYPE(arraydef), POINTER ::  ar   !<
+
+
+    t1 = pmc_time()
+
+!
+!-- Wait for child to fill buffer
+    CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
+    t2 = pmc_time() - t1
+    IF ( PRESENT( waittime ) )  waittime = t2
+
+!
+!-- TODO: check next statement
+!-- Fence might do it, test later
+!-- CALL MPI_WIN_FENCE( 0, children(childid)%win_parent_child, ierr)
+    CALL MPI_BARRIER( children(childid)%intra_comm, ierr )
+
+    DO  ip = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(ip)
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => ape%array_list(j)
+
+          IF ( ar%recvindex < 0 )  CYCLE
+
+          IF ( ar%nrdims == 2 )  THEN
+             nr = ape%nrele
+          ELSEIF ( ar%nrdims == 3 )  THEN
+             nr = ape%nrele * ar%a_dim(4)
+          ENDIF
+
+          buf_shape(1) = nr
+          CALL C_F_POINTER( ar%recvbuf, buf, buf_shape )
+
+!
+!--       MPI passive target RMA
+          IF ( nr > 0 )  THEN
+             target_disp = ar%recvindex - 1
+
+!
+!--          Child PEs are located behind parent PEs
+             target_pe = ip - 1 + m_model_npes
+             CALL MPI_WIN_LOCK( MPI_LOCK_SHARED, target_pe, 0,                  &
+                                children(childid)%win_parent_child, ierr )
+             CALL MPI_GET( buf, nr, MPI_REAL, target_pe, target_disp, nr,       &
+                           MPI_REAL, children(childid)%win_parent_child, ierr )
+             CALL MPI_WIN_UNLOCK( target_pe,                                    &
+                                  children(childid)%win_parent_child, ierr )
+          ENDIF
+
+          myindex = 1
+          IF ( ar%nrdims == 2 )  THEN
+
+             CALL C_F_POINTER( ar%data, data_2d, ar%a_dim(1:2) )
+             DO  ij = 1, ape%nrele
+                data_2d(ape%locind(ij)%j,ape%locind(ij)%i) = buf(myindex)
+                myindex = myindex + 1
+             ENDDO
+
+          ELSEIF ( ar%nrdims == 3 )  THEN
+
+             CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3))
+             DO  ij = 1, ape%nrele
+                data_3d(1:ar%a_dim(4),ape%locind(ij)%j,ape%locind(ij)%i) =      &
+                                              buf(myindex:myindex+ar%a_dim(4)-1)
+                myindex = myindex + ar%a_dim(4)
+             ENDDO
+
+          ENDIF
+
+       ENDDO
+
+    ENDDO
+
+ END SUBROUTINE pmc_s_getdata_from_buffer
+
+
+
+ SUBROUTINE get_da_names_from_child( childid )
+
+!
+!-- Get data array description and name from child
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN) ::  childid  !<
+
+    TYPE(da_namedef) ::  myname  !<
+
+    DO
+       CALL pmc_bcast( myname%couple_index, 0, comm=m_to_child_comm(childid) )
+       IF ( myname%couple_index == -1 )  EXIT
+       CALL pmc_bcast( myname%parentdesc,   0, comm=m_to_child_comm(childid) )
+       CALL pmc_bcast( myname%nameonparent, 0, comm=m_to_child_comm(childid) )
+       CALL pmc_bcast( myname%childdesc,    0, comm=m_to_child_comm(childid) )
+       CALL pmc_bcast( myname%nameonchild,  0, comm=m_to_child_comm(childid) )
+
+       CALL pmc_g_setname( children(childid), myname%couple_index,              &
+                           myname%nameonparent )
+   ENDDO
+
+ END SUBROUTINE get_da_names_from_child
+
+
+
+ SUBROUTINE pmc_s_setarray(childid, nrdims, dims, array_adr, second_adr )
+
+!
+!-- Set array for child inter PE 0
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)               ::  childid    !<
+    INTEGER, INTENT(IN)               ::  nrdims     !<
+    INTEGER, INTENT(IN), DIMENSION(:) ::  dims       !<
+
+    TYPE(C_PTR), INTENT(IN)           :: array_adr   !<
+    TYPE(C_PTR), INTENT(IN), OPTIONAL :: second_adr  !<
+
+    INTEGER ::  i  !< local counter
+
+    TYPE(pedef), POINTER    ::  ape  !<
+    TYPE(arraydef), POINTER ::  ar   !<
+
+
+    DO  i = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(i)
+       ar  => ape%array_list(next_array_in_list)
+       ar%nrdims = nrdims
+       ar%a_dim  = dims
+       ar%data   = array_adr
+
+       IF ( PRESENT( second_adr ) )  THEN
+          ar%po_data(1) = array_adr
+          ar%po_data(2) = second_adr
+       ELSE
+          ar%po_data(1) = C_NULL_PTR
+          ar%po_data(2) = C_NULL_PTR
+       ENDIF
+
+    ENDDO
+
+ END SUBROUTINE pmc_s_setarray
+
+
+
+ SUBROUTINE pmc_s_set_active_data_array( childid, iactive )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN) ::  childid   !<
+    INTEGER, INTENT(IN) ::  iactive   !<
+
+    INTEGER :: i   !<
+    INTEGER :: ip  !<
+    INTEGER :: j   !<
+
+    TYPE(pedef), POINTER    ::  ape  !<
+    TYPE(arraydef), POINTER ::  ar   !<
+
+    DO  ip = 1, children(childid)%inter_npes
+
+       ape => children(childid)%pes(ip)
+
+       DO  j = 1, ape%nr_arrays
+
+          ar => ape%array_list(j)
+          IF ( iactive == 1  .OR.  iactive == 2 )  THEN
+             ar%data = ar%po_data(iactive)
+          ENDIF
+
+       ENDDO
+
+    ENDDO
+
+ END SUBROUTINE pmc_s_set_active_data_array
+
+
+
+ SUBROUTINE set_pe_index_list( childid, mychild, index_list, nrp )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(IN)                 ::  childid     !<
+    INTEGER, INTENT(IN), DIMENSION(:,:) ::  index_list  !<
+    INTEGER, INTENT(IN)                 ::  nrp         !<
+
+    TYPE(childdef), INTENT(INOUT)       ::  mychild     !<
+
+    INTEGER                                 :: i        !<
+    INTEGER                                 :: ierr     !<
+    INTEGER                                 :: ind      !<
+    INTEGER                                 :: indwin   !<
+    INTEGER                                 :: indwin2  !<
+    INTEGER                                 :: i2       !<
+    INTEGER                                 :: j        !<
+    INTEGER                                 :: rempe    !<
+    INTEGER(KIND=MPI_ADDRESS_KIND)          :: winsize  !<
+
+    INTEGER, DIMENSION(mychild%inter_npes)  :: remind   !<
+
+    INTEGER, DIMENSION(:), POINTER          :: remindw  !<
+    INTEGER, DIMENSION(:), POINTER          :: rldef    !<
+
+    TYPE(pedef), POINTER                    :: ape      !<
+
+!
+!-- First, count entries for every remote child PE
+    DO  i = 1, mychild%inter_npes
+       ape => mychild%pes(i)
+       ape%nrele = 0
+    ENDDO
+
+!
+!-- Loop over number of coarse grid cells
+    DO  j = 1, nrp
+       rempe = index_list(5,j) + 1   ! PE number on remote PE
+       ape => mychild%pes(rempe)
+       ape%nrele = ape%nrele + 1     ! Increment number of elements for this child PE
+    ENDDO
+
+    DO  i = 1, mychild%inter_npes
+       ape => mychild%pes(i)
+       ALLOCATE( ape%locind(ape%nrele) )
+    ENDDO
+
+    remind = 0
+
+!
+!-- Second, create lists
+!-- Loop over number of coarse grid cells
+    DO  j = 1, nrp
+       rempe = index_list(5,j) + 1
+       ape => mychild%pes(rempe)
+       remind(rempe)     = remind(rempe)+1
+       ind               = remind(rempe)
+       ape%locind(ind)%i = index_list(1,j)
+       ape%locind(ind)%j = index_list(2,j)
+    ENDDO
+
+!
+!-- Prepare number of elements for children PEs
+    CALL pmc_alloc_mem( rldef, mychild%inter_npes*2 )
+
+!
+!-- Number of child PEs * size of INTEGER (i just arbitrary INTEGER)
+    winsize = mychild%inter_npes*c_sizeof(i)*2
+
+    CALL MPI_WIN_CREATE( rldef, winsize, iwp, MPI_INFO_NULL,                    &
+                         mychild%intra_comm, indwin, ierr )
+
+!
+!-- Open window to set data
+    CALL MPI_WIN_FENCE( 0, indwin, ierr )
+
+    rldef(1) = 0            ! index on remote PE 0
+    rldef(2) = remind(1)    ! number of elements on remote PE 0
+
+!
+!-- Reserve buffer for index array
+    DO  i = 2, mychild%inter_npes
+       i2          = (i-1) * 2 + 1
+       rldef(i2)   = rldef(i2-2) + rldef(i2-1) * 2  ! index on remote PE
+       rldef(i2+1) = remind(i)                      ! number of elements on remote PE
+    ENDDO
+
+!
+!-- Close window to allow child to access data
+    CALL MPI_WIN_FENCE( 0, indwin, ierr )
+
+!
+!-- Child has retrieved data
+    CALL MPI_WIN_FENCE( 0, indwin, ierr )
+
+    i2 = 2 * mychild%inter_npes - 1
+    winsize = ( rldef(i2) + rldef(i2+1) ) * 2
+
+!
+!-- Make sure, MPI_ALLOC_MEM works
+    winsize = MAX( winsize, 1 )
+
+    CALL pmc_alloc_mem( remindw, INT( winsize ) )
+
+    CALL MPI_BARRIER( m_model_comm, ierr )
+    CALL MPI_WIN_CREATE( remindw, winsize*c_sizeof(i), iwp, MPI_INFO_NULL,      &
+                         mychild%intra_comm, indwin2, ierr )
+!
+!-- Open window to set data
+    CALL MPI_WIN_FENCE( 0, indwin2, ierr )
+
+!
+!-- Create the 2D index list
+    DO  j = 1, nrp
+       rempe = index_list(5,j) + 1    ! PE number on remote PE
+       ape => mychild%pes(rempe)
+       i2    = rempe * 2 - 1
+       ind   = rldef(i2) + 1
+       remindw(ind)   = index_list(3,j)
+       remindw(ind+1) = index_list(4,j)
+       rldef(i2)      = rldef(i2)+2
+    ENDDO
+
+!
+!-- All data are set
+    CALL MPI_WIN_FENCE( 0, indwin2, ierr )
+
+!
+!-- Don't know why, but this barrier is necessary before windows can be freed
+!-- TODO: find out why this is required
+    CALL MPI_BARRIER( mychild%intra_comm, ierr )
+
+    CALL MPI_WIN_FREE( indwin, ierr )
+    CALL MPI_WIN_FREE( indwin2, ierr )
+
+!
+!-- TODO: check if the following idea needs to be done
+!-- Sollte funktionieren, Problem mit MPI implementation
+!-- https://www.lrz.de/services/software/parallel/mpi/onesided
+!-- CALL MPI_Free_mem (remindw, ierr)
+
+ END SUBROUTINE set_pe_index_list
+
+#endif
+ END MODULE pmc_parent
Index: palm/trunk/SOURCE/pmc_server_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_server_mod.f90	(revision 1932)
+++ 	(revision )
@@ -1,1002 +1,0 @@
- MODULE pmc_server
-
-!--------------------------------------------------------------------------------!
-! This file is part of PALM.
-!
-! 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-2016 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------!
-!
-! Current revisions:
-! ------------------
-! 
-!
-! Former revisions:
-! -----------------
-! $Id$
-!
-! 1900 2016-05-04 15:27:53Z raasch
-! re-formatted to match PALM style
-!
-! 1850 2016-04-08 13:29:27Z maronga
-! Module renamed
-! 
-! 
-! 1833 2016-04-07 14:23:03Z raasch
-! gfortran requires pointer attributes for some array declarations,
-! long line wrapped
-!
-! 1808 2016-04-05 19:44:00Z raasch
-! MPI module used by default on all machines
-!
-! 1797 2016-03-21 16:50:28Z raasch
-! introduction of different datatransfer modes
-!
-! 1791 2016-03-11 10:41:25Z raasch
-! Debug write-statements commented out
-!
-! 1786 2016-03-08 05:49:27Z raasch
-! change in client-server data transfer: server now gets data from client
-! instead that client put's it to the server
-!
-! 1779 2016-03-03 08:01:28Z raasch
-! kind=dp replaced by wp,
-! error messages removed or changed to PALM style, dim_order removed
-! array management changed from linked list to sequential loop
-!
-! 1766 2016-02-29 08:37:15Z raasch
-! modifications to allow for using PALM's pointer version
-! +new routine pmc_s_set_active_data_array
-!
-! 1764 2016-02-28 12:45:19Z raasch
-! cpp-statement added (nesting can only be used in parallel mode)
-!
-! 1762 2016-02-25 12:31:13Z hellstea
-! Initial revision by K. Ketelsen
-!
-! Description:
-! ------------
-!
-! Server part of Palm Model Coupler
-!------------------------------------------------------------------------------!
-
-#if defined( __parallel )
-    USE, INTRINSIC ::  ISO_C_BINDING
-
-#if defined( __mpifh )
-    INCLUDE "mpif.h"
-#else
-    USE MPI
-#endif
-    USE kinds
-    USE pmc_general,                                                           &
-        ONLY: arraydef, clientdef, da_namedef, da_namelen, pedef,              &
-              pmc_g_setname, pmc_max_array, pmc_max_models, pmc_sort
-
-    USE pmc_handle_communicator,                                               &
-        ONLY: m_model_comm,m_model_rank,m_model_npes, m_to_client_comm,        &
-              m_world_rank, pmc_server_for_client
-
-    USE pmc_mpi_wrapper,                                                       &
-        ONLY: pmc_alloc_mem, pmc_bcast, pmc_time
-
-   IMPLICIT NONE
-
-   PRIVATE
-   SAVE
-
-   TYPE clientindexdef
-      INTEGER                              ::  nrpoints       !<
-      INTEGER, DIMENSION(:,:), ALLOCATABLE ::  index_list_2d  !<
-   END TYPE clientindexdef
-
-   TYPE(clientdef), DIMENSION(pmc_max_models)      ::  clients     !<
-   TYPE(clientindexdef), DIMENSION(pmc_max_models) ::  indclients  !<
-
-   INTEGER ::  next_array_in_list = 0  !<
-
-
-   PUBLIC pmc_server_for_client
-
-
-   INTERFACE pmc_serverinit
-      MODULE PROCEDURE  pmc_serverinit
-   END INTERFACE pmc_serverinit
-
-    INTERFACE pmc_s_set_2d_index_list
-        MODULE PROCEDURE pmc_s_set_2d_index_list
-    END INTERFACE pmc_s_set_2d_index_list
-
-    INTERFACE pmc_s_clear_next_array_list
-        MODULE PROCEDURE pmc_s_clear_next_array_list
-    END INTERFACE pmc_s_clear_next_array_list
-
-    INTERFACE pmc_s_getnextarray
-        MODULE PROCEDURE pmc_s_getnextarray
-    END INTERFACE pmc_s_getnextarray
-
-    INTERFACE pmc_s_set_dataarray
-        MODULE PROCEDURE pmc_s_set_dataarray_2d
-        MODULE PROCEDURE pmc_s_set_dataarray_3d
-    END INTERFACE pmc_s_set_dataarray
-
-    INTERFACE pmc_s_setind_and_allocmem
-        MODULE PROCEDURE pmc_s_setind_and_allocmem
-    END INTERFACE pmc_s_setind_and_allocmem
-
-    INTERFACE pmc_s_fillbuffer
-        MODULE PROCEDURE pmc_s_fillbuffer
-    END INTERFACE pmc_s_fillbuffer
-
-    INTERFACE pmc_s_getdata_from_buffer
-        MODULE PROCEDURE pmc_s_getdata_from_buffer
-    END INTERFACE pmc_s_getdata_from_buffer
-
-    INTERFACE pmc_s_set_active_data_array
-        MODULE PROCEDURE pmc_s_set_active_data_array
-    END INTERFACE pmc_s_set_active_data_array
-
-    PUBLIC pmc_serverinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer,      &
-           pmc_s_getdata_from_buffer, pmc_s_getnextarray,                      &
-           pmc_s_setind_and_allocmem, pmc_s_set_active_data_array,             &
-           pmc_s_set_dataarray, pmc_s_set_2d_index_list
-
- CONTAINS
-
-
- SUBROUTINE pmc_serverinit
-
-    IMPLICIT NONE
-
-    INTEGER ::  clientid  !<
-    INTEGER ::  i         !<
-    INTEGER ::  j         !<
-    INTEGER ::  istat     !<
-
-
-    DO  i = 1, SIZE( pmc_server_for_client )-1
-
-       clientid = pmc_server_for_client( i )
-
-       clients(clientid)%model_comm = m_model_comm
-       clients(clientid)%inter_comm = m_to_client_comm(clientid)
-!
-!--    Get rank and size
-       CALL MPI_COMM_RANK( clients(clientid)%model_comm,                       &
-                           clients(clientid)%model_rank, istat )
-       CALL MPI_COMM_SIZE( clients(clientid)%model_comm,                       &
-                           clients(clientid)%model_npes, istat )
-       CALL MPI_COMM_REMOTE_SIZE( clients(clientid)%inter_comm,                &
-                                  clients(clientid)%inter_npes, istat )
-!
-!--    Intra communicater is used for MPI_GET
-       CALL MPI_INTERCOMM_MERGE( clients(clientid)%inter_comm, .FALSE.,        &
-                                 clients(clientid)%intra_comm, istat )
-       CALL MPI_COMM_RANK( clients(clientid)%intra_comm,                       &
-                           clients(clientid)%intra_rank, istat )
-
-       ALLOCATE( clients(clientid)%pes(clients(clientid)%inter_npes))
-!
-!--    Allocate array of TYPE arraydef for all client PEs to store information
-!--    of the transfer array
-       DO  j = 1, clients(clientid)%inter_npes
-         ALLOCATE( clients(clientid)%pes(j)%array_list(pmc_max_array) )
-       ENDDO
-
-       CALL get_da_names_from_client (clientid)
-
-    ENDDO
-
- END SUBROUTINE pmc_serverinit
-
-
-
- SUBROUTINE pmc_s_set_2d_index_list( clientid, index_list )
-
-     IMPLICIT NONE
-
-     INTEGER, INTENT(IN)                    :: clientid    !<
-     INTEGER, DIMENSION(:,:), INTENT(INOUT) :: index_list  !<
-
-     INTEGER ::  ian    !<
-     INTEGER ::  ic     !<
-     INTEGER ::  ie     !<
-     INTEGER ::  ip     !<
-     INTEGER ::  is     !<
-     INTEGER ::  istat  !<
-     INTEGER ::  n      !<
-
-
-     IF ( m_model_rank == 0 )  THEN
-!
-!--     Sort to ascending server PE
-        CALL pmc_sort( index_list, 6 )
-
-        is = 1
-        DO  ip = 0, m_model_npes-1
-!
-!--        Split into server PEs
-           ie = is - 1
-!
-!--        There may be no entry for this PE
-           IF ( is <= SIZE( index_list,2 )  .AND.  ie >= 0 )  THEN
-
-              DO WHILE ( index_list(6,ie+1 ) == ip )
-                 ie = ie + 1
-                 IF ( ie == SIZE( index_list,2 ) )  EXIT
-              ENDDO
-
-              ian = ie - is + 1
-
-           ELSE
-              is  = -1
-              ie  = -2
-              ian =  0
-           ENDIF
-!
-!--        Send data to other server PEs
-           IF ( ip == 0 )  THEN
-              indclients(clientid)%nrpoints = ian
-              IF ( ian > 0)  THEN
-                  ALLOCATE( indclients(clientid)%index_list_2d(6,ian) )
-                  indclients(clientid)%index_list_2d(:,1:ian) =                &
-                                                             index_list(:,is:ie)
-              ENDIF
-           ELSE
-              CALL MPI_SEND( ian, 1, MPI_INTEGER, ip, 1000, m_model_comm,      &
-                             istat )
-              IF ( ian > 0)  THEN
-                  CALL MPI_SEND( index_list(1,is), 6*ian, MPI_INTEGER, ip,  &
-                                 1001, m_model_comm, istat )
-              ENDIF
-           ENDIF
-           is = ie + 1
-
-        ENDDO
-
-     ELSE
-
-        CALL MPI_RECV( indclients(clientid)%nrpoints, 1, MPI_INTEGER, 0, 1000, &
-                       m_model_comm, MPI_STATUS_IGNORE, istat )
-        ian = indclients(clientid)%nrpoints
-
-        IF ( ian > 0 )  THEN
-           ALLOCATE( indclients(clientid)%index_list_2d(6,ian) )
-           CALL MPI_RECV( indclients(clientid)%index_list_2d, 6*ian,           &
-                          MPI_INTEGER, 0, 1001, m_model_comm,                  &
-                          MPI_STATUS_IGNORE, istat)
-        ENDIF
-
-     ENDIF
-
-     CALL set_pe_index_list( clientid, clients(clientid),                      &
-                             indclients(clientid)%index_list_2d,               &
-                             indclients(clientid)%nrpoints )
-
- END SUBROUTINE pmc_s_set_2d_index_list
-
-
-
- SUBROUTINE pmc_s_clear_next_array_list
-
-    IMPLICIT NONE
-
-    next_array_in_list = 0
-
- END SUBROUTINE pmc_s_clear_next_array_list
-
-
-
- LOGICAL FUNCTION pmc_s_getnextarray( clientid, myname )
-!
-!-- List handling is still required to get minimal interaction with
-!-- pmc_interface
-!-- TODO: what does "still" mean? Is there a chance to change this!
-    CHARACTER(LEN=*), INTENT(OUT) ::  myname    !<
-    INTEGER(iwp), INTENT(IN)      ::  clientid  !<
-
-    TYPE(arraydef), POINTER :: ar
-    TYPE(pedef), POINTER    :: ape
-
-    next_array_in_list = next_array_in_list + 1
-!
-!-- Array names are the same on all client PEs, so take first PE to get the name
-    ape => clients(clientid)%pes(1)
-
-    IF ( next_array_in_list > ape%nr_arrays )  THEN
-!
-!--    All arrays are done
-       pmc_s_getnextarray = .FALSE.
-       RETURN
-    ENDIF
-
-    ar => ape%array_list(next_array_in_list)
-    myname = ar%name
-!
-!-- Return true if legal array
-!-- TODO: what does this comment mean? Can there be non-legal arrays??
-    pmc_s_getnextarray = .TRUE.
-
- END FUNCTION pmc_s_getnextarray
-
-
-
- SUBROUTINE pmc_s_set_dataarray_2d( clientid, array, array_2 )
-
-    IMPLICIT NONE
-
-    INTEGER,INTENT(IN) ::  clientid  !<
-
-    REAL(wp), INTENT(IN), DIMENSION(:,:), POINTER           ::  array    !<
-    REAL(wp), INTENT(IN), DIMENSION(:,:), POINTER, OPTIONAL ::  array_2  !<
-
-    INTEGER               ::  nrdims      !<
-    INTEGER, DIMENSION(4) ::  dims        !<
-    TYPE(C_PTR)           ::  array_adr   !<
-    TYPE(C_PTR)           ::  second_adr  !<
-
-
-    dims      = 1
-    nrdims    = 2
-    dims(1)   = SIZE( array,1 )
-    dims(2)   = SIZE( array,2 )
-    array_adr = C_LOC( array )
-
-    IF ( PRESENT( array_2 ) )  THEN
-       second_adr = C_LOC(array_2)
-       CALL pmc_s_setarray( clientid, nrdims, dims, array_adr,                 &
-                            second_adr = second_adr)
-    ELSE
-       CALL pmc_s_setarray( clientid, nrdims, dims, array_adr )
-    ENDIF
-
- END SUBROUTINE pmc_s_set_dataarray_2d
-
-
-
- SUBROUTINE pmc_s_set_dataarray_3d( clientid, array, nz_cl, nz, array_2 )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN) ::  clientid  !<
-    INTEGER, INTENT(IN) ::  nz        !<
-    INTEGER, INTENT(IN) ::  nz_cl     !<
-
-    REAL(wp), INTENT(IN), DIMENSION(:,:,:), POINTER           ::  array    !<
-    REAL(wp), INTENT(IN), DIMENSION(:,:,:), POINTER, OPTIONAL ::  array_2  !<
-
-    INTEGER               ::  nrdims      !<
-    INTEGER, DIMENSION(4) ::  dims        !<
-    TYPE(C_PTR)           ::  array_adr   !<
-    TYPE(C_PTR)           ::  second_adr  !<
-
-!-- TODO: the next assignment seems to be obsolete. Please check!
-    dims      = 1
-    dims      = 0
-    nrdims    = 3
-    dims(1)   = SIZE( array,1 )
-    dims(2)   = SIZE( array,2 )
-    dims(3)   = SIZE( array,3 )
-    dims(4)   = nz_cl+dims(1)-nz  ! works for first dimension 1:nz and 0:nz+1
-
-    array_adr = C_LOC(array)
-
-!
-!-- In PALM's pointer version, two indices have to be stored internally.
-!-- The active address of the data array is set in swap_timelevel.
-    IF ( PRESENT( array_2 ) )  THEN
-      second_adr = C_LOC( array_2 )
-      CALL pmc_s_setarray( clientid, nrdims, dims, array_adr,                  &
-                           second_adr = second_adr)
-    ELSE
-       CALL pmc_s_setarray( clientid, nrdims, dims, array_adr )
-    ENDIF
-
- END SUBROUTINE pmc_s_set_dataarray_3d
-
-
-
- SUBROUTINE pmc_s_setind_and_allocmem( clientid )
-
-    USE control_parameters,                                                    &
-        ONLY:  message_string
-
-    IMPLICIT NONE
-
-!
-!-- Naming convention for appendices:   _sc  -> server to client transfer
-!--                                     _cs  -> client to server transfer
-!--                                     send -> server to client transfer
-!--                                     recv -> client to server transfer
-    INTEGER, INTENT(IN) ::  clientid  !<
-
-    INTEGER                        ::  arlen    !<
-    INTEGER                        ::  i        !<
-    INTEGER                        ::  ierr     !<
-    INTEGER                        ::  istat    !<
-    INTEGER                        ::  j        !<
-    INTEGER                        ::  myindex  !<
-    INTEGER                        ::  rcount   !< count MPI requests
-    INTEGER                        ::  tag      !<
-
-    INTEGER(idp)                   ::  bufsize  !< size of MPI data window
-    INTEGER(KIND=MPI_ADDRESS_KIND) ::  winsize  !<
-
-    INTEGER, DIMENSION(1024)       ::  req      !<
-
-    TYPE(C_PTR)             ::  base_ptr  !<
-    TYPE(pedef), POINTER    ::  ape       !<
-    TYPE(arraydef), POINTER ::  ar        !<
-
-    REAL(wp),DIMENSION(:), POINTER, SAVE ::  base_array_sc  !< base array for server to client transfer
-    REAL(wp),DIMENSION(:), POINTER, SAVE ::  base_array_cs  !< base array for client to server transfer
-
-!
-!-- Server to client direction
-    myindex = 1
-    rcount  = 0
-    bufsize = 8
-
-!
-!-- First stride: compute size and set index
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
-       tag = 200
-
-       DO  j = 1, ape%nr_arrays
-
-          ar  => ape%array_list(j)
-          IF ( ar%nrdims == 2 )  THEN
-             arlen = ape%nrele
-          ELSEIF ( ar%nrdims == 3 )  THEN
-             arlen = ape%nrele * ar%a_dim(4)
-          ELSE
-             arlen = -1
-          ENDIF
-          ar%sendindex = myindex
-
-          tag    = tag + 1
-          rcount = rcount + 1
-          CALL MPI_ISEND( myindex, 1, MPI_INTEGER, i-1, tag,                   &
-                          clients(clientid)%inter_comm, req(rcount), ierr )
-!
-!--       Maximum of 1024 outstanding requests
-!--       TODO: what does this limit means?
-          IF ( rcount == 1024 )  THEN
-             CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
-             rcount = 0
-          ENDIF
-
-          myindex = myindex + arlen
-          bufsize = bufsize + arlen
-          ar%sendsize = arlen
-
-       ENDDO
-
-       IF ( rcount > 0 )  THEN
-          CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
-       ENDIF
-
-    ENDDO
-
-!
-!-- Create RMA (One Sided Communication) window for data buffer server to
-!-- client transfer.
-!-- The buffer of MPI_GET (counterpart of transfer) can be PE-local, i.e.
-!-- it can but must not be part of the MPI RMA window. Only one RMA window is
-!-- required to prepare the data for
-!--                       server -> client transfer on the server side
-!-- and for
-!--                       client -> server transfer on the client side
-    CALL pmc_alloc_mem( base_array_sc, bufsize )
-    clients(clientid)%totalbuffersize = bufsize * wp
-
-    winsize = bufsize * wp
-    CALL MPI_WIN_CREATE( base_array_sc, winsize, wp, MPI_INFO_NULL,            &
-                         clients(clientid)%intra_comm,                         &
-                         clients(clientid)%win_server_client, ierr )
-!
-!-- Open window to set data
-    CALL MPI_WIN_FENCE( 0, clients(clientid)%win_server_client, ierr )
-!
-!-- Second stride: set buffer pointer
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => ape%array_list(j)
-          ar%sendbuf = C_LOC( base_array_sc(ar%sendindex) )
-
-!--       TODO: replace this by standard PALM error message using the message routine
-          IF ( ar%sendindex + ar%sendsize > bufsize )  THEN
-             write(0,'(a,i4,4i7,1x,a)') 'Server Buffer too small ',i,        &
-                ar%sendindex,ar%sendsize,ar%sendindex+ar%sendsize,bufsize,trim(ar%name)
-             CALL MPI_Abort (MPI_COMM_WORLD, istat, ierr)
-          ENDIF
-       ENDDO
-    ENDDO
-
-!
-!-- Client to server direction
-    bufsize = 8
-!
-!-- First stride: compute size and set index
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
-       tag = 300
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => ape%array_list(j)
-!
-!--       Receive index from client
-          tag = tag + 1
-          CALL MPI_RECV( myindex, 1, MPI_INTEGER, i-1, tag,                    &
-                         clients(clientid)%inter_comm, MPI_STATUS_IGNORE, ierr )
-
-          IF ( ar%nrdims == 3 )  THEN
-             bufsize = MAX( bufsize, ape%nrele * ar%a_dim(4) )
-          ELSE
-             bufsize = MAX( bufsize, ape%nrele )
-          ENDIF
-          ar%recvindex = myindex
-
-        ENDDO
-
-    ENDDO
-
-!
-!-- Create RMA (one sided communication) data buffer.
-!-- The buffer for MPI_GET can be PE local, i.e. it can but must not be part of
-!-- the MPI RMA window
-    CALL pmc_alloc_mem( base_array_cs, bufsize, base_ptr )
-    clients(clientid)%totalbuffersize = bufsize * wp
-
-    CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
-!
-!-- Second stride: set buffer pointer
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
-
-       DO  j = 1, ape%nr_arrays
-          ar => ape%array_list(j)
-          ar%recvbuf = base_ptr
-       ENDDO
-
-    ENDDO
-
- END SUBROUTINE pmc_s_setind_and_allocmem
-
-
-
- SUBROUTINE pmc_s_fillbuffer( clientid, waittime )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)             ::  clientid  !<
-
-    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime  !<
-
-    INTEGER               ::  ierr     !<
-    INTEGER               ::  ij       !<
-    INTEGER               ::  ip       !<
-    INTEGER               ::  istat    !<
-    INTEGER               ::  j        !<
-    INTEGER               ::  myindex  !<
-
-    INTEGER, DIMENSION(1) ::  buf_shape
-
-    REAL(wp)                            ::  t1       !<
-    REAL(wp)                            ::  t2       !<
-    REAL(wp), POINTER, DIMENSION(:)     ::  buf      !<
-    REAL(wp), POINTER, DIMENSION(:,:)   ::  data_2d  !<
-    REAL(wp), POINTER, DIMENSION(:,:,:) ::  data_3d  !<
-
-    TYPE(pedef), POINTER    ::  ape  !<
-    TYPE(arraydef), POINTER ::  ar   !<
-
-!
-!-- Synchronization of the model is done in pmci_client_synchronize and
-!-- pmci_server_synchronize. Therefor the RMA window can be filled without
-!-- sychronization at this point and a barrier is not necessary.
-!-- Please note that waittime has to be set in pmc_s_fillbuffer AND
-!-- pmc_c_getbuffer
-    IF ( PRESENT( waittime) )  THEN
-      t1 = pmc_time()
-      CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
-      t2 = pmc_time()
-      waittime = t2- t1
-    ENDIF
-
-    DO  ip = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(ip)
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => ape%array_list(j)
-          myindex = 1
-
-          IF ( ar%nrdims == 2 )  THEN
-
-             buf_shape(1) = ape%nrele
-             CALL C_F_POINTER( ar%sendbuf, buf, buf_shape )
-             CALL C_F_POINTER( ar%data, data_2d, ar%a_dim(1:2) )
-             DO  ij = 1, ape%nrele
-                buf(myindex) = data_2d(ape%locind(ij)%j,ape%locind(ij)%i)
-                myindex = myindex + 1
-             ENDDO
-
-          ELSEIF ( ar%nrdims == 3 )  THEN
-
-             buf_shape(1) = ape%nrele*ar%a_dim(4)
-             CALL C_F_POINTER( ar%sendbuf, buf, buf_shape )
-             CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3) )
-             DO  ij = 1, ape%nrele
-                buf(myindex:myindex+ar%a_dim(4)-1) =                           &
-                        data_3d(1:ar%a_dim(4),ape%locind(ij)%j,ape%locind(ij)%i)
-                myindex = myindex + ar%a_dim(4)
-             ENDDO
-
-          ENDIF
-
-        ENDDO
-
-    ENDDO
-!
-!-- Buffer is filled
-    CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
-
- END SUBROUTINE pmc_s_fillbuffer
-
-
-
- SUBROUTINE pmc_s_getdata_from_buffer( clientid, waittime )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)             ::  clientid  !<
-    REAL(wp), INTENT(OUT), OPTIONAL ::  waittime  !<
-
-    INTEGER                        ::  ierr         !<
-    INTEGER                        ::  ij           !<
-    INTEGER                        ::  ip           !<
-    INTEGER                        ::  istat        !<
-    INTEGER                        ::  j            !<
-    INTEGER                        ::  myindex      !<
-    INTEGER                        ::  nr           !<
-    INTEGER                        ::  target_pe    !<
-    INTEGER(kind=MPI_ADDRESS_KIND) ::  target_disp  !<
-
-    INTEGER, DIMENSION(1)          ::  buf_shape    !<
-
-    REAL(wp)                            ::  t1       !<
-    REAL(wp)                            ::  t2       !<
-    REAL(wp), POINTER, DIMENSION(:)     ::  buf      !<
-    REAL(wp), POINTER, DIMENSION(:,:)   ::  data_2d  !<
-    REAL(wp), POINTER, DIMENSION(:,:,:) ::  data_3d  !<
-
-    TYPE(pedef), POINTER    ::  ape  !<
-    TYPE(arraydef), POINTER ::  ar   !<
-
-
-    t1 = pmc_time()
-!
-!-- Wait for client to fill buffer
-    CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
-    t2 = pmc_time() - t1
-    IF ( PRESENT( waittime ) )  waittime = t2
-!
-!-- TODO: check next statement
-!-- Fence might do it, test later
-!-- CALL MPI_WIN_FENCE( 0, clients(clientid)%win_server_client, ierr)
-    CALL MPI_BARRIER( clients(clientid)%intra_comm, ierr )
-
-    DO  ip = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(ip)
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => ape%array_list(j)
-
-          IF ( ar%recvindex < 0 )  CYCLE
-
-          IF ( ar%nrdims == 2 )  THEN
-             nr = ape%nrele
-          ELSEIF ( ar%nrdims == 3 )  THEN
-             nr = ape%nrele * ar%a_dim(4)
-          ENDIF
-
-          buf_shape(1) = nr
-          CALL C_F_POINTER( ar%recvbuf, buf, buf_shape )
-
-!
-!--       MPI passive target RMA
-          IF ( nr > 0 )  THEN
-             target_disp = ar%recvindex - 1
-!
-!--          Client PEs are located behind server PEs
-             target_pe = ip - 1 + m_model_npes
-             CALL MPI_WIN_LOCK( MPI_LOCK_SHARED, target_pe, 0,                 &
-                                clients(clientid)%win_server_client, ierr )
-             CALL MPI_GET( buf, nr, MPI_REAL, target_pe, target_disp, nr,      &
-                           MPI_REAL, clients(clientid)%win_server_client, ierr )
-             CALL MPI_WIN_UNLOCK( target_pe,                                   &
-                                  clients(clientid)%win_server_client, ierr )
-          ENDIF
-
-          myindex = 1
-          IF ( ar%nrdims == 2 )  THEN
-
-             CALL C_F_POINTER( ar%data, data_2d, ar%a_dim(1:2) )
-             DO  ij = 1, ape%nrele
-                data_2d(ape%locind(ij)%j,ape%locind(ij)%i) = buf(myindex)
-                myindex = myindex + 1
-             ENDDO
-
-          ELSEIF ( ar%nrdims == 3 )  THEN
-
-             CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3))
-             DO  ij = 1, ape%nrele
-                data_3d(1:ar%a_dim(4),ape%locind(ij)%j,ape%locind(ij)%i) =     &
-                                              buf(myindex:myindex+ar%a_dim(4)-1)
-                myindex = myindex + ar%a_dim(4)
-             ENDDO
-
-          ENDIF
-
-       ENDDO
-
-    ENDDO
-
- END SUBROUTINE pmc_s_getdata_from_buffer
-
-
-
- SUBROUTINE get_da_names_from_client( clientid )
-!
-!-- Get data array description and name from client
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN) ::  clientid  !<
-
-    TYPE(da_namedef) ::  myname  !<
-
-    DO
-       CALL pmc_bcast( myname%couple_index, 0, comm=m_to_client_comm(clientid) )
-       IF ( myname%couple_index == -1 )  EXIT
-       CALL pmc_bcast( myname%serverdesc,   0, comm=m_to_client_comm(clientid) )
-       CALL pmc_bcast( myname%nameonserver, 0, comm=m_to_client_comm(clientid) )
-       CALL pmc_bcast( myname%clientdesc,   0, comm=m_to_client_comm(clientid) )
-       CALL pmc_bcast( myname%nameonclient, 0, comm=m_to_client_comm(clientid) )
-
-       CALL pmc_g_setname( clients(clientid), myname%couple_index,             &
-                           myname%nameonserver )
-   ENDDO
-
- END SUBROUTINE get_da_names_from_client
-
-
-
- SUBROUTINE pmc_s_setarray(clientid, nrdims, dims, array_adr, second_adr )
-!
-!-- Set array for client interPE 0
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)               ::  clientid  !<
-    INTEGER, INTENT(IN)               ::  nrdims    !<
-    INTEGER, INTENT(IN), DIMENSION(:) ::  dims      !<
-
-    TYPE(C_PTR), INTENT(IN)           :: array_adr   !<
-    TYPE(C_PTR), INTENT(IN), OPTIONAL :: second_adr  !<
-
-    INTEGER ::  i  !< local counter
-
-    TYPE(pedef), POINTER    ::  ape  !<
-    TYPE(arraydef), POINTER ::  ar   !<
-
-
-    DO  i = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(i)
-       ar  => ape%array_list(next_array_in_list)
-       ar%nrdims = nrdims
-       ar%a_dim  = dims
-       ar%data   = array_adr
-
-       IF ( PRESENT( second_adr ) )  THEN
-          ar%po_data(1) = array_adr
-          ar%po_data(2) = second_adr
-       ELSE
-          ar%po_data(1) = C_NULL_PTR
-          ar%po_data(2) = C_NULL_PTR
-       ENDIF
-
-    ENDDO
-
- END SUBROUTINE pmc_s_setarray
-
-
-
- SUBROUTINE pmc_s_set_active_data_array( clientid, iactive )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN) ::  clientid  !<
-    INTEGER, INTENT(IN) ::  iactive   !<
-
-    INTEGER :: i   !<
-    INTEGER :: ip  !<
-    INTEGER :: j   !<
-
-    TYPE(pedef), POINTER    ::  ape  !<
-    TYPE(arraydef), POINTER ::  ar   !<
-
-    DO  ip = 1, clients(clientid)%inter_npes
-
-       ape => clients(clientid)%pes(ip)
-
-       DO  j = 1, ape%nr_arrays
-
-          ar => ape%array_list(j)
-          IF ( iactive == 1  .OR.  iactive == 2 )  THEN
-             ar%data = ar%po_data(iactive)
-          ENDIF
-
-       ENDDO
-
-    ENDDO
-
- END SUBROUTINE pmc_s_set_active_data_array
-
-
-
- SUBROUTINE set_pe_index_list( clientid, myclient, index_list, nrp )
-
-    IMPLICIT NONE
-
-    INTEGER, INTENT(IN)                 ::  clientid    !<
-    INTEGER, INTENT(IN), DIMENSION(:,:) ::  index_list  !<
-    INTEGER, INTENT(IN)                 ::  nrp         !<
-
-    TYPE(clientdef), INTENT(INOUT) ::  myclient  !<
-
-    INTEGER                                 :: i        !<
-    INTEGER                                 :: ierr     !<
-    INTEGER                                 :: ind      !<
-    INTEGER                                 :: indwin   !<
-    INTEGER                                 :: indwin2  !<
-    INTEGER                                 :: i2       !<
-    INTEGER                                 :: j        !<
-    INTEGER                                 :: rempe    !<
-    INTEGER(KIND=MPI_ADDRESS_KIND)          :: winsize  !<
-
-    INTEGER, DIMENSION(myclient%inter_npes) :: remind   !<
-
-    INTEGER, DIMENSION(:), POINTER          :: remindw  !<
-    INTEGER, DIMENSION(:), POINTER          :: rldef    !<
-
-    TYPE(pedef), POINTER                    :: ape      !<
-
-!
-!-- First, count entries for every remote client PE
-    DO  i = 1, myclient%inter_npes
-       ape => myclient%pes(i)
-       ape%nrele = 0
-    ENDDO
-!
-!-- Loop over number of coarse grid cells
-    DO  j = 1, nrp
-       rempe = index_list(5,j) + 1   ! PE number on remote PE
-       ape => myclient%pes(rempe)
-       ape%nrele = ape%nrele + 1 ! Increment number of elements for this client PE
-    ENDDO
-
-    DO  i = 1, myclient%inter_npes
-       ape => myclient%pes(i)
-       ALLOCATE( ape%locind(ape%nrele) )
-    ENDDO
-
-    remind = 0
-
-!
-!-- Second, create lists
-!-- Loop over number of coarse grid cells
-    DO  j = 1, nrp
-       rempe = index_list(5,j) + 1
-       ape => myclient%pes(rempe)
-       remind(rempe)     = remind(rempe)+1
-       ind               = remind(rempe)
-       ape%locind(ind)%i = index_list(1,j)
-       ape%locind(ind)%j = index_list(2,j)
-    ENDDO
-!
-!-- Prepare number of elements for client PEs
-    CALL pmc_alloc_mem( rldef, myclient%inter_npes*2 )
-!
-!-- Number of client PEs * size of INTEGER (i just arbitrary INTEGER)
-    winsize = myclient%inter_npes*c_sizeof(i)*2
-
-    CALL MPI_WIN_CREATE( rldef, winsize, iwp, MPI_INFO_NULL,                   &
-                         myclient%intra_comm, indwin, ierr )
-!
-!-- Open window to set data
-    CALL MPI_WIN_FENCE( 0, indwin, ierr )
-
-    rldef(1) = 0            ! index on remote PE 0
-    rldef(2) = remind(1)    ! number of elements on remote PE 0
-!
-!-- Reserve buffer for index array
-    DO  i = 2, myclient%inter_npes
-       i2          = (i-1) * 2 + 1
-       rldef(i2)   = rldef(i2-2) + rldef(i2-1) * 2  ! index on remote PE
-       rldef(i2+1) = remind(i)                ! number of elements on remote PE
-    ENDDO
-!
-!-- Close window to allow client to access data
-    CALL MPI_WIN_FENCE( 0, indwin, ierr )
-!
-!-- Client has retrieved data
-    CALL MPI_WIN_FENCE( 0, indwin, ierr )
-
-    i2 = 2 * myclient%inter_npes - 1
-    winsize = ( rldef(i2) + rldef(i2+1) ) * 2
-!
-!-- Make sure, MPI_ALLOC_MEM works
-    winsize = MAX( winsize, 1 )
-
-    CALL pmc_alloc_mem( remindw, INT( winsize ) )
-
-    CALL MPI_BARRIER( m_model_comm, ierr )
-    CALL MPI_WIN_CREATE( remindw, winsize*c_sizeof(i), iwp, MPI_INFO_NULL,     &
-                         myclient%intra_comm, indwin2, ierr )
-!
-!-- Open window to set data
-    CALL MPI_WIN_FENCE( 0, indwin2, ierr )
-!
-!-- Create the 2D index list
-    DO  j = 1, nrp
-       rempe = index_list(5,j) + 1    ! PE number on remote PE
-       ape => myclient%pes(rempe)
-       i2    = rempe * 2 - 1
-       ind   = rldef(i2) + 1
-       remindw(ind)   = index_list(3,j)
-       remindw(ind+1) = index_list(4,j)
-       rldef(i2)      = rldef(i2)+2
-    ENDDO
-!
-!-- All data areset
-    CALL MPI_WIN_FENCE( 0, indwin2, ierr )
-!
-!-- Don't know why, but this barrier is necessary before windows can be freed
-!-- TODO: find out why this is required
-    CALL MPI_BARRIER( myclient%intra_comm, ierr )
-
-    CALL MPI_WIN_FREE( indwin, ierr )
-    CALL MPI_WIN_FREE( indwin2, ierr )
-
-!-- TODO: check if the following idea needs to be done
-!-- Sollte funktionieren, Problem mit MPI implementation
-!-- https://www.lrz.de/services/software/parallel/mpi/onesided
-!-- CALL MPI_Free_mem (remindw, ierr)
-
- END SUBROUTINE set_pe_index_list
-
-#endif
- END MODULE pmc_server
Index: palm/trunk/SOURCE/pres.f90
===================================================================
--- palm/trunk/SOURCE/pres.f90	(revision 1932)
+++ palm/trunk/SOURCE/pres.f90	(revision 1933)
@@ -24,4 +24,7 @@
 ! -----------------
 ! $Id$
+!
+! 1932 2016-06-10 12:09:21Z suehring
+! Initial version of purely vertical nesting introduced.
 !
 ! 1931 2016-06-10 12:06:59Z suehring
@@ -127,6 +130,5 @@
                gathered_size, ibc_p_b, ibc_p_t, intermediate_timestep_count,   &
                intermediate_timestep_count_max, mg_switch_to_pe0_level,        &
-               nest_domain, nest_bound_l, nest_bound_n, nest_bound_r,          &
-               nest_bound_s, on_device, outflow_l, outflow_n, outflow_r,       &
+               nest_domain, on_device, outflow_l, outflow_n, outflow_r,        &
                outflow_s, psolver, subdomain_size, topography, volume_flow,    &
                volume_flow_area, volume_flow_initial
@@ -147,4 +149,7 @@
 
     USE pegrid
+    
+    USE pmc_interface,                                                         &
+        ONLY:  nesting_mode 
 
     USE poisfft_mod,                                                           &
@@ -174,4 +179,6 @@
     REAL(wp), DIMENSION(1:nzt) ::  w_l                 !<
     REAL(wp), DIMENSION(1:nzt) ::  w_l_l               !<
+
+    LOGICAL :: nest_domain_nvn      !<
 
 
@@ -312,9 +319,17 @@
 !
 !-- Remove mean vertical velocity in case that Neumann conditions are
-!-- used both at bottom and top boundary, and if not a nested domain.
+!-- used both at bottom and top boundary, and if not a nested domain in a 
+!-- normal nesting run. In case of vertical nesting, this must be done.
+!-- Therefore an auxiliary logical variable nest_domain_nvn is used here, and 
+!-- nvn stands for non-vertical nesting. 
 !-- This cannot be done before the first initial time step because ngp_2dh_outer
 !-- is not yet known then.
-    IF ( ibc_p_b == 1  .AND.  ibc_p_t == 1  .AND.  .NOT. nest_domain  .AND.    &
-         intermediate_timestep_count /= 0 )                                    &
+    nest_domain_nvn = nest_domain
+    IF ( nest_domain .AND. nesting_mode == 'vertical' )  THEN
+       nest_domain_nvn = .FALSE.
+    ENDIF
+
+    IF ( ibc_p_b == 1  .AND.  ibc_p_t == 1  .AND.                               &
+         .NOT. nest_domain_nvn  .AND. intermediate_timestep_count /= 0 )        &
     THEN
        w_l = 0.0_wp;  w_l_l = 0.0_wp
Index: palm/trunk/SOURCE/time_integration.f90
===================================================================
--- palm/trunk/SOURCE/time_integration.f90	(revision 1932)
+++ palm/trunk/SOURCE/time_integration.f90	(revision 1933)
@@ -25,7 +25,6 @@
 ! $Id$
 !
-! 1927 2016-06-07 11:56:53Z hellstea
-! Synchronization moved before CALL run_control. Exchange_horiz for pt after 
-! CALL pmci_datatrans is now only called if ( .NOT. neutral ).  
+! 1919 2016-05-27 14:51:23Z raasch
+! Initial version of purely vertical nesting introduced. 
 !
 ! 1918 2016-05-27 14:35:57Z raasch
@@ -298,7 +297,6 @@
 
     USE pmc_interface,                                                         &
-        ONLY:  client_to_server, nested_run, nesting_mode,                     &
-               pmci_datatrans, pmci_ensure_nest_mass_conservation,             &
-               pmci_synchronize, server_to_client
+        ONLY:  nested_run, nesting_mode, pmci_datatrans,                       &
+               pmci_ensure_nest_mass_conservation, pmci_synchronize
 
     USE production_e_mod,                                                      &
@@ -726,6 +724,6 @@
              CALL cpu_log( log_point(60), 'nesting', 'start' )
 !
-!--          Domain nesting. The data transfer subroutines pmci_server_datatrans
-!--          and pmci_client_datatatrans are called inside the wrapper
+!--          Domain nesting. The data transfer subroutines pmci_parent_datatrans
+!--          and pmci_child_datatrans are called inside the wrapper
 !--          subroutine pmci_datatrans according to the control parameters
 !--          nesting_mode and nesting_datatransfer_mode.
@@ -733,7 +731,8 @@
              CALL pmci_datatrans( nesting_mode )
 
-             IF ( nesting_mode == 'two-way' )  THEN
-!
-!--             Exchange_horiz is needed for all server-domains after the
+             IF ( TRIM( nesting_mode ) == 'two-way' .OR.                               &
+                  nesting_mode == 'vertical' )  THEN
+!
+!--             Exchange_horiz is needed for all parent-domains after the
 !--             anterpolation
                 CALL exchange_horiz( u, nbgp )
@@ -750,5 +749,6 @@
 !
 !--          Correct the w top-BC in nest domains to ensure mass conservation.
-!--          This action must never be done for the root domain.
+!--          This action must never be done for the root domain. Vertical 
+!--          nesting implies mass conservation.
              IF ( nest_domain )  THEN
                 CALL pmci_ensure_nest_mass_conservation
