Index: /palm/trunk/SOURCE/Makefile
===================================================================
--- /palm/trunk/SOURCE/Makefile	(revision 2598)
+++ /palm/trunk/SOURCE/Makefile	(revision 2599)
@@ -446,4 +446,6 @@
 # The following line is needed for palm_simple_install, don't remove it!
 #to_be_replaced_by_include
+
+#BOUNDS="-Rbc"  # Array bounds checking. Compromises performance seriously.
 
 .SUFFIXES:
Index: /palm/trunk/SOURCE/parin.f90
===================================================================
--- /palm/trunk/SOURCE/parin.f90	(revision 2598)
+++ /palm/trunk/SOURCE/parin.f90	(revision 2599)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! The i/o grouping is updated to work correctly also in nested runs.
+! 
+! 2575 2017-10-24 09:57:58Z maronga
 ! Renamed phi -> latitude, added longitude
 ! 
@@ -390,5 +393,6 @@
     INTEGER(iwp) ::  i      !<
     INTEGER(iwp) ::  ioerr  !< error flag for open/read/write
-
+    INTEGER(iwp) ::  myworldid       !<
+    INTEGER(iwp) ::  numworldprocs   !<
 
     NAMELIST /inipar/  aerosol_bulk, alpha_surface, approximation, bc_e_b,     &
@@ -513,5 +517,4 @@
 
     CALL location_message( 'finished', .TRUE. )
-
 !
 !-- Calculate the number of groups into which parallel I/O is split.
@@ -522,7 +525,9 @@
 !-- system.
 !-- First, set the default:
+    CALL MPI_COMM_RANK( MPI_COMM_WORLD, myworldid, ierr ) 
+    CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numworldprocs, ierr )
     IF ( maximum_parallel_io_streams == -1  .OR.                               &
-         maximum_parallel_io_streams > numprocs )  THEN
-       maximum_parallel_io_streams = numprocs
+         maximum_parallel_io_streams > numworldprocs )  THEN
+       maximum_parallel_io_streams = numworldprocs
     ENDIF
 !
@@ -532,7 +537,9 @@
 !-- These settings are repeated in init_pegrid for the communicator comm2d,
 !-- which is not available here
-    io_blocks = numprocs / maximum_parallel_io_streams
-    io_group  = MOD( myid+1, io_blocks )
-
+    !io_blocks = numprocs / maximum_parallel_io_streams
+    io_blocks = numworldprocs / maximum_parallel_io_streams
+    !io_group  = MOD( myid+1, io_blocks )
+    io_group  = MOD( myworldid+1, io_blocks )
+    
     CALL location_message( 'reading NAMELIST parameters from PARIN', .FALSE. )
 !
Index: /palm/trunk/SOURCE/pmc_child_mod.f90
===================================================================
--- /palm/trunk/SOURCE/pmc_child_mod.f90	(revision 2598)
+++ /palm/trunk/SOURCE/pmc_child_mod.f90	(revision 2599)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Some cleanup and commenting improvements only.
+! 
+! 2101 2017-01-05 16:42:31Z suehring
 !
 ! 2000 2016-08-20 18:09:15Z knoop
@@ -171,15 +174,13 @@
      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
+!
+!--  Intra-communicator 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
+!
+!--  Allocate an array of type arraydef for all parent processes to store 
+!--  information of then transfer array
      DO  i = 1, me%inter_npes
         ALLOCATE( me%pes(i)%array_list(pmc_max_array) )
@@ -201,5 +202,4 @@
 
     INTEGER, INTENT(OUT) ::  istat  !<
-
 !
 !-- Local variables
@@ -211,5 +211,4 @@
 
     istat = pmc_status_ok
-
 !
 !-- Check length of array names
@@ -229,5 +228,5 @@
 
 !
-!-- Broadcat to all child PEs
+!-- Broadcast to all child processes
 !-- TODO: describe what is broadcast here and why it is done
     CALL pmc_bcast( myname%couple_index, 0, comm=m_model_comm )
@@ -236,7 +235,6 @@
     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
+!
+!-- Broadcast to all parent processes
 !-- TODO: describe what is broadcast here and why it is done
     IF ( m_model_rank == 0 )  THEN
@@ -263,5 +261,4 @@
 
     LOGICAL, INTENT(IN), OPTIONAL ::  lastentry  !<
-
 !
 !-- Local variables
@@ -290,5 +287,5 @@
     INTEGER :: i, ierr, i2, j, nr  !<
     INTEGER :: indwin              !< MPI window object
-    INTEGER :: indwin2  !          < MPI window object
+    INTEGER :: indwin2             !< MPI window object
 
     INTEGER(KIND=MPI_ADDRESS_KIND) :: win_size !< Size of MPI window 1 (in bytes)
@@ -306,10 +303,8 @@
     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
@@ -321,10 +316,8 @@
                      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
@@ -344,12 +337,10 @@
     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
+!-- Here, we use a dummy for the MPI window because the parent processes 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
@@ -377,5 +368,4 @@
        ENDIF
     ENDDO
-
 !
 !-- Don't know why, but this barrier is necessary before we can free the windows
@@ -406,5 +396,4 @@
 !--  pmc_interface
      CHARACTER(LEN=*), INTENT(OUT) ::  myname  !<
-
 !
 !-- Local variables
@@ -414,9 +403,8 @@
 
     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
+!
+!-- Array names are the same on all child PEs, so take first process to
+!-- get the name    
     ape => me%pes(1)
-
 !
 !-- Check if all arrays have been processed
@@ -429,5 +417,4 @@
 
     myname = ar%name
-
 !
 !-- Return true if legal array
@@ -545,17 +532,12 @@
     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
@@ -564,5 +546,4 @@
                          MPI_STATUS_IGNORE, ierr )
           ar%recvindex = myindex
-
 !
 !--       Determine max, because child buffer is allocated only once
@@ -573,9 +554,6 @@
              bufsize = MAX( bufsize, ar%a_dim(1)*ar%a_dim(2) )
           ENDIF
-
        ENDDO
-
-    ENDDO
-
+    ENDDO
 !
 !-- Create RMA (one sided communication) data buffer.
@@ -584,18 +562,13 @@
     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
-
+    ENDDO
 !
 !-- Child to parent direction
@@ -605,10 +578,7 @@
 
     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
@@ -617,5 +587,4 @@
              arlen = ape%nrele*ar%a_dim(1)
           ENDIF
-
           tag    = tag + 1
           rcount = rcount + 1
@@ -629,8 +598,8 @@
              ar%sendindex = noindex
           ENDIF
-
 !
 !--       Maximum of 1024 outstanding requests
-!--       TODO: explain where this maximum comes from (arbitrary?)
+!--       TODO: explain where this maximum comes from (arbitrary?).
+!--       Outstanding = pending? 
           IF ( rcount == 1024 )  THEN
              CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
@@ -651,5 +620,4 @@
 
     ENDDO
-
 !
 !-- Create RMA (one sided communication) window for data buffer child to parent
@@ -670,18 +638,12 @@
     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)
-
+          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
@@ -695,7 +657,5 @@
              ENDIF
           ENDIF
-
        ENDDO
-
     ENDDO
 
@@ -743,5 +703,4 @@
        waittime = t2 - t1
     ENDIF
-
 !
 !-- Wait for buffer is filled.
@@ -753,11 +712,7 @@
 
     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
@@ -765,8 +720,6 @@
              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
@@ -780,19 +733,13 @@
              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) =                  &
@@ -800,9 +747,6 @@
                 myindex = myindex+ar%a_dim(1)
              ENDDO
-
-          ENDIF
-
+          ENDIF
        ENDDO
-
     ENDDO
 
@@ -849,29 +793,20 @@
 
     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) =                            &
@@ -879,11 +814,7 @@
                 myindex = myindex + ar%a_dim(1)
              ENDDO
-
-          ENDIF
-
+          ENDIF
        ENDDO
-
-    ENDDO
-
+    ENDDO
 !
 !-- TODO: Fence might do it, test later
Index: /palm/trunk/SOURCE/pmc_general_mod.f90
===================================================================
--- /palm/trunk/SOURCE/pmc_general_mod.f90	(revision 2598)
+++ /palm/trunk/SOURCE/pmc_general_mod.f90	(revision 2599)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Some cleanup and commenting improvements only.
+! 
+! 2101 2017-01-05 16:42:31Z suehring
 !
 ! 2000 2016-08-20 18:09:15Z knoop
@@ -153,4 +156,6 @@
  CONTAINS
 
+
+   
  SUBROUTINE pmc_g_setname( mychild, couple_index, aname )
 
@@ -170,10 +175,8 @@
 !-- Set name of array in arraydef structure
     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
        ape%array_list(ape%nr_arrays)%coupleindex = couple_index
-
     ENDDO
 
@@ -196,8 +199,6 @@
 
     n = SIZE(array,2)
-
     DO  j = 1, n-1
        DO  i = j+1, n
-
           IF ( array(sort_ind,i) < array(sort_ind,j) )  THEN
              tmp = array(:,i)
@@ -205,5 +206,4 @@
              array(:,j) = tmp
           ENDIF
-
        ENDDO
     ENDDO
Index: /palm/trunk/SOURCE/pmc_handle_communicator_mod.f90
===================================================================
--- /palm/trunk/SOURCE/pmc_handle_communicator_mod.f90	(revision 2598)
+++ /palm/trunk/SOURCE/pmc_handle_communicator_mod.f90	(revision 2599)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Separate peer communicator peer_comm introduced for MPI_INTERCOMM_CREATE.
+! Some cleanup and commenting improvements. 
+! 
+! 2516 2017-10-04 11:03:04Z suehring
 ! Remove tabs
 ! 
@@ -127,5 +131,5 @@
     PUBLIC  pmc_status_ok, pmc_status_error
 
-    INTEGER, PARAMETER, PUBLIC ::  pmc_error_npes        = 1  !< illegal number of PEs
+    INTEGER, PARAMETER, PUBLIC ::  pmc_error_npes        = 1  !< illegal number of processes
     INTEGER, PARAMETER, PUBLIC ::  pmc_namelist_error    = 2  !< error(s) in nestpar namelist
     INTEGER, PARAMETER, PUBLIC ::  pmc_no_namelist_found = 3  !< no couple layout namelist found
@@ -144,5 +148,6 @@
     INTEGER, PUBLIC ::  m_model_rank          !<
     INTEGER, PUBLIC ::  m_model_npes          !<
-    INTEGER         ::  m_parent_remote_size  !< number of parent PEs
+    INTEGER         ::  m_parent_remote_size  !< number of processes in the parent model 
+    INTEGER         ::  peer_comm             !< peer_communicator for inter communicators
 
     INTEGER, DIMENSION(pmc_max_models), PUBLIC ::  m_to_child_comm    !< communicator to the child(ren)
@@ -200,5 +205,5 @@
     CALL MPI_COMM_SIZE( MPI_COMM_WORLD, m_world_npes, istat )
 !
-!-- Only PE 0 of root model reads
+!-- Only process 0 of root model reads
     IF ( m_world_rank == 0 )  THEN
 
@@ -210,5 +215,5 @@
        THEN
 !
-!--       Calculate start PE of every model
+!--       Determine the first process id of each model
           start_pe(1) = 0
           DO  i = 2, m_ncpl+1
@@ -217,6 +222,6 @@
 
 !
-!--       The number of cores provided with the run must be the same as the
-!--       total sum of cores required by all nest domains
+!--       The sum of numbers of processes requested by all the domains
+!--       must be equal to the total number of processes of the run
           IF ( start_pe(m_ncpl+1) /= m_world_npes )  THEN
              WRITE ( message_string, '(2A,I6,2A,I6,A)' )                        &
@@ -231,7 +236,8 @@
     ENDIF
 !
-!-- Broadcast the read status. This synchronises all other PEs with PE 0 of
-!-- the root model. Without synchronisation, they would not behave in the
-!-- correct way (e.g. they would not return in case of a missing NAMELIST)
+!-- Broadcast the read status. This synchronises all other processes with 
+!-- process 0 of the root model. Without synchronisation, they would not 
+!-- behave in the correct way (e.g. they would not return in case of a
+!-- missing NAMELIST).
     CALL MPI_BCAST( pmc_status, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat )
 
@@ -254,7 +260,6 @@
     ENDIF
 
-    CALL MPI_BCAST( m_ncpl,          1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat)
-    CALL MPI_BCAST( start_pe, m_ncpl+1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat)
-
+    CALL MPI_BCAST( m_ncpl,          1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat )
+    CALL MPI_BCAST( start_pe, m_ncpl+1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat )
 !
 !-- Broadcast coupling layout
@@ -277,5 +282,4 @@
     CALL MPI_BCAST( nesting_datatransfer_mode, LEN(nesting_datatransfer_mode),  &
                     MPI_CHARACTER, 0, MPI_COMM_WORLD, istat )
-
 !
 !-- Assign global MPI processes to individual models by setting the couple id
@@ -288,5 +292,4 @@
     ENDDO
     m_my_cpl_rank = m_world_rank - start_pe(i)
-
 !
 !-- MPI_COMM_WORLD is the communicator for ALL models (MPI-1 approach).
@@ -296,10 +299,9 @@
                          istat )
 !
-!-- Get size and rank of the model running on this PE
+!-- Get size and rank of the model running on this process
     CALL  MPI_COMM_RANK( comm, m_model_rank, istat )
     CALL  MPI_COMM_SIZE( comm, m_model_npes, istat )
-
-!
-!-- Broadcast (from PE 0) the parent id and id of every model
+!
+!-- Broadcast (from process 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,              &
@@ -308,5 +310,4 @@
                        MPI_COMM_WORLD, istat )
     ENDDO
-
 !
 !-- Save the current model communicator for pmc internal use
@@ -314,39 +315,36 @@
 
 !
-!-- Create intercommunicator between parent and children.
+!-- Create intercommunicator between the parent and children.
 !-- MPI_INTERCOMM_CREATE creates an intercommunicator between 2 groups of
 !-- different colors.
-!-- The grouping was done above with MPI_COMM_SPLIT
+!-- The grouping was done above with MPI_COMM_SPLIT.
+!-- A duplicate of MPI_COMM_WORLD is created and used as peer communicator 
+!-- (peer_comm) for MPI_INTERCOMM_CREATE.
+    CALL MPI_COMM_DUP( MPI_COMM_WORLD, peer_comm, ierr ) 
     DO  i = 2, m_ncpl
-
        IF ( m_couplers(i)%parent_id == m_my_cpl_id )  THEN
 !
-!--       Collect parent PEs.
-!--       Every model exept the root model has a parent model which acts as
-!--       parent model. Create an intercommunicator to connect current PE to
-!--       all children PEs
+!--       Identify all children models of the current model and create 
+!--       inter-communicators to connect between the current model and its 
+!--       children models.
           tag = 500 + i
-          CALL MPI_INTERCOMM_CREATE( comm, 0, MPI_COMM_WORLD, start_pe(i),      &
+          CALL MPI_INTERCOMM_CREATE( comm, 0, peer_comm, start_pe(i),           &
                                      tag, m_to_child_comm(i), istat)
           childcount = childcount + 1
           activeparent(i) = 1
-
        ELSEIF ( i == m_my_cpl_id)  THEN
 !
-!--       Collect children PEs.
-!--       Every model except the root model has a parent model. 
-!--       Create an intercommunicator to connect current PE to all parent PEs
+!--       Create an inter-communicator to connect between the current 
+!--       model and its parent model.    
           tag = 500 + i
-          CALL MPI_INTERCOMM_CREATE( comm, 0, MPI_COMM_WORLD,                   &
+          CALL MPI_INTERCOMM_CREATE( comm, 0, peer_comm,                        &
                                      start_pe(m_couplers(i)%parent_id),         &
                                      tag, m_to_parent_comm, istat )
        ENDIF
-
     ENDDO
-
-!
-!-- If I am parent, count the number of children that I have
+!
+!-- If I am a parent, count the number of children I have.
 !-- Although this loop is symmetric on all processes, the "activeparent" flag
-!-- is true (==1) on the respective individual PE only.
+!-- is true (==1) on the respective individual process only.
     ALLOCATE( pmc_parent_for_child(childcount+1) )
 
@@ -362,5 +360,5 @@
     IF ( m_my_cpl_id > 1 )  THEN
        CALL MPI_COMM_REMOTE_SIZE( m_to_parent_comm, m_parent_remote_size,       &
-                                  istat)
+                                  istat )
     ELSE
 !
@@ -369,10 +367,10 @@
     ENDIF
 !
-!-- Set myid to non-tero value except for the root domain. This is a setting
+!-- Set myid to non-zero value except for the root domain. This is a setting
 !-- for the message routine which is called at the end of pmci_init. That
 !-- routine outputs messages for myid = 0, only. However, myid has not been
-!-- assigened so far, so that all PEs of the root model would output a
-!-- message. To avoid this, set myid to some other value except for PE0 of the
-!-- root domain.
+!-- assigened so far, so that all processes of the root model would output a
+!-- message. To avoid this, set myid to some other value except for process 0 
+!-- of the root domain.
     IF ( m_world_rank /= 0 )  myid = 1
 
@@ -401,8 +399,8 @@
     INTEGER, INTENT(OUT), OPTIONAL ::  npe_total           !<
 
-    INTEGER ::  requested_cpl_id  !<
-
-    REAL(wp), INTENT(OUT), OPTIONAL ::  lower_left_x  !<
-    REAL(wp), INTENT(OUT), OPTIONAL ::  lower_left_y  !<
+    INTEGER ::  requested_cpl_id                           !<
+
+    REAL(wp), INTENT(OUT), OPTIONAL ::  lower_left_x       !<
+    REAL(wp), INTENT(OUT), OPTIONAL ::  lower_left_y       !<
 
 !
@@ -416,5 +414,4 @@
        requested_cpl_id = m_my_cpl_id
     ENDIF
-
 !
 !-- Return the requested information
@@ -459,5 +456,5 @@
 
  SUBROUTINE read_coupling_layout( nesting_datatransfer_mode, nesting_mode,      &
-                                  pmc_status )
+      pmc_status )
 
     IMPLICIT NONE
@@ -481,5 +478,4 @@
 
     pmc_status = pmc_status_ok
-
 !
 !-- Open the NAMELIST-file and read the nesting layout
@@ -487,33 +483,25 @@
     READ ( 11, nestpar, IOSTAT=istat )
 !
-!-- Set filepointer to the beginning of the file. Otherwise PE0 will later
+!-- Set filepointer to the beginning of the file. Otherwise process 0 will later
 !-- be unable to read the inipar-NAMELIST
     REWIND ( 11 )
 
     IF ( istat < 0 )  THEN
-
 !
 !--    No nestpar-NAMELIST found
        pmc_status = pmc_no_namelist_found
-
        RETURN
-
     ELSEIF ( istat > 0 )  THEN
-
 !
 !--    Errors in reading nestpar-NAMELIST
        pmc_status = pmc_namelist_error
        RETURN
-
-    ENDIF
-
+    ENDIF
 !
 !-- Output location message
     CALL location_message( 'initialize communicators for nesting', .FALSE. )
-
-!
-!-- Assign the layout to the internally used variable
+!
+!-- Assign the layout to the corresponding internally used variable m_couplers
     m_couplers = domain_layouts
-
 !
 !-- Get the number of nested models given in the nestpar-NAMELIST
@@ -521,5 +509,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
@@ -529,7 +517,5 @@
           ENDIF
        ENDIF
-
     ENDDO
-
 !
 !-- Make sure that all domains have equal lower left corner in case of vertical
Index: /palm/trunk/SOURCE/pmc_interface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 2598)
+++ /palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 2599)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Some cleanup and commenting improvements only.
+! 
+! 2582 2017-10-26 13:19:46Z hellstea
 ! Resetting of e within buildings / topography in pmci_parent_datatrans removed
 ! as unnecessary since e is not anterpolated, and as incorrect since it overran
Index: /palm/trunk/SOURCE/pmc_mpi_wrapper_mod.f90
===================================================================
--- /palm/trunk/SOURCE/pmc_mpi_wrapper_mod.f90	(revision 2598)
+++ /palm/trunk/SOURCE/pmc_mpi_wrapper_mod.f90	(revision 2599)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Some cleanup and commenting improvements only.
+! 
+! 2101 2017-01-05 16:42:31Z suehring
 !
 ! 2000 2016-08-20 18:09:15Z knoop
@@ -142,7 +145,8 @@
     INTEGER, INTENT(OUT)              ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_SEND( buf, n, MPI_INTEGER, parent_rank, tag, m_to_parent_comm,     &
-                   ierr)
+                   ierr )
 
  END SUBROUTINE pmc_send_to_parent_integer
@@ -160,4 +164,5 @@
     INTEGER, INTENT(OUT)               ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_RECV( buf, n, MPI_INTEGER, parent_rank, tag, m_to_parent_comm,     &
@@ -178,4 +183,5 @@
     INTEGER, INTENT(OUT)                :: ierr         !<
 
+    
     ierr = 0
     CALL MPI_SEND( buf, n, MPI_INTEGER, parent_rank, tag, m_to_parent_comm,     &
@@ -196,4 +202,5 @@
     INTEGER, INTENT(OUT)               ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_SEND( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm, ierr )
@@ -213,4 +220,5 @@
     INTEGER, INTENT(OUT)                ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_RECV( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm,        &
@@ -231,4 +239,5 @@
     INTEGER, INTENT(OUT)                 ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_SEND( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm, ierr )
@@ -265,4 +274,5 @@
     INTEGER, INTENT(OUT)                   ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_SEND( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm, ierr )
@@ -282,4 +292,5 @@
     INTEGER, INTENT(OUT)                    ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_RECV( buf, n, MPI_REAL, parent_rank, tag, m_to_parent_comm,        &
@@ -302,4 +313,5 @@
     INTEGER, INTENT(OUT)              ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_SEND( buf, n, MPI_INTEGER, child_rank, tag,                        &
@@ -322,4 +334,5 @@
     INTEGER, INTENT(OUT)                 ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_RECV( buf, n, MPI_INTEGER, child_rank, tag,                        &
@@ -342,4 +355,5 @@
     INTEGER, INTENT(OUT)                 ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_RECV( buf, n, MPI_INTEGER, child_rank, tag,                        &
@@ -362,4 +376,5 @@
     INTEGER, INTENT(OUT)               ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_SEND( buf, n, MPI_REAL, child_rank, tag,                           &
@@ -382,4 +397,5 @@
     INTEGER, INTENT(OUT)                  ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_RECV( buf, n, MPI_REAL, child_rank, tag,                           &
@@ -402,4 +418,5 @@
     INTEGER, INTENT(OUT)                 ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_SEND( buf, n, MPI_REAL, child_rank, tag,                           &
@@ -422,4 +439,5 @@
     INTEGER, INTENT(OUT)                  ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_RECV( buf, n, MPI_REAL, child_rank, tag,                           &
@@ -431,5 +449,5 @@
 
  SUBROUTINE pmc_send_to_child_real_r3( child_id, buf, n, child_rank, tag,       &
-                                       ierr)
+                                       ierr )
 
     IMPLICIT NONE
@@ -442,4 +460,5 @@
     INTEGER, INTENT(OUT)                   ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_SEND( buf, n, MPI_REAL, child_rank, tag,                           &
@@ -462,4 +481,5 @@
     INTEGER, INTENT(OUT)                    ::  ierr         !<
 
+    
     ierr = 0
     CALL MPI_RECV( buf, n, MPI_REAL, child_rank, tag,                           & 
@@ -511,4 +531,5 @@
     INTEGER ::  myerr   !<
 
+    
     IF ( PRESENT( comm ) )  THEN
        mycomm = comm
@@ -540,5 +561,5 @@
 
 !
-!-- PE 0 on parent broadcast to all child PEs
+!-- Process 0 on parent broadcast to all child processes
     IF ( PRESENT( child_id ) )  THEN
 
@@ -581,4 +602,5 @@
     TYPE(C_PTR)                    ::  p_myind  !<
 
+    
     winsize = idim1 * C_SIZEOF( ierr )
 
@@ -605,4 +627,5 @@
     TYPE(C_PTR)                    :: p_myind  !<
 
+    
     winsize = idim1 * wp
 
@@ -623,4 +646,5 @@
     REAL(kind=wp) :: pmc_time  !<
 
+    
     pmc_time = MPI_WTIME()
 
Index: /palm/trunk/SOURCE/pmc_parent_mod.f90
===================================================================
--- /palm/trunk/SOURCE/pmc_parent_mod.f90	(revision 2598)
+++ /palm/trunk/SOURCE/pmc_parent_mod.f90	(revision 2599)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Some cleanup and commenting improvements only.
+! 
+! 2101 2017-01-05 16:42:31Z suehring
 !
 ! 2000 2016-08-20 18:09:15Z knoop
@@ -192,5 +195,5 @@
 
 !
-!--    Intra communicater is used for MPI_GET
+!--    Intra communicator is used for MPI_GET
        CALL MPI_INTERCOMM_MERGE( children(childid)%inter_comm, .FALSE.,         &
                                  children(childid)%intra_comm, istat )
@@ -232,27 +235,20 @@
 
      IF ( m_model_rank == 0 )  THEN
-
-!
-!--     Sort to ascending parent PE order
+!
+!--     Sort to ascending parent process order
         CALL pmc_sort( index_list, 6 )
-
         is = 1
         DO  ip = 0, m_model_npes-1
-
-!
-!--        Split into parent PEs
+!
+!--        Split into parent processes
            ie = is - 1
-
-!
-!--        There may be no entry for this PE
+!
+!--        There may be no entry for this process
            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
@@ -260,7 +256,6 @@
               ian =  0
            ENDIF
-
-!
-!--        Send data to other parent PEs
+!
+!--        Send data to other parent processes
            IF ( ip == 0 )  THEN
               indchildren(childid)%nrpoints = ian
@@ -279,13 +274,9 @@
            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) )
@@ -294,7 +285,5 @@
                           MPI_STATUS_IGNORE, istat)
         ENDIF
-
      ENDIF
-
      CALL set_pe_index_list( childid, children(childid),                        &
                              indchildren(childid)%index_list_2d,                &
@@ -328,11 +317,10 @@
 
     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
+!
+!-- Array names are the same on all children processes, so take first
+!-- process to get the name
     ape => children(childid)%pes(1)
 
     IF ( next_array_in_list > ape%nr_arrays )  THEN
-
 !
 !--    All arrays are done
@@ -343,5 +331,4 @@
     ar => ape%array_list(next_array_in_list)
     myname = ar%name
-
 !
 !-- Return true if legal array
@@ -413,5 +400,4 @@
 
     array_adr = C_LOC(array)
-
 !
 !-- In PALM's pointer version, two indices have to be stored internally.
@@ -469,5 +455,4 @@
     rcount  = 0
     bufsize = 8
-
 !
 !-- First stride: compute size and set index
@@ -493,8 +478,7 @@
           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?
+!--       TODO: what does this limit mean? Does outstanding mean pending?
           IF ( rcount == 1024 )  THEN
              CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr )
@@ -505,5 +489,4 @@
           bufsize = bufsize + arlen
           ar%sendsize = arlen
-
        ENDDO
 
@@ -513,5 +496,4 @@
 
     ENDDO
-
 !
 !-- Create RMA (One Sided Communication) window for data buffer parent to
@@ -530,9 +512,7 @@
                          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
@@ -555,20 +535,14 @@
        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
@@ -576,5 +550,4 @@
           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) )
@@ -583,9 +556,6 @@
           ENDIF
           ar%recvindex = myindex
-
         ENDDO
-
-    ENDDO
-
+    ENDDO
 !
 !-- Create RMA (one sided communication) data buffer.
@@ -596,16 +566,12 @@
 
     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
 
@@ -654,14 +620,9 @@
 
     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 )
@@ -671,7 +632,5 @@
                 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 )
@@ -682,11 +641,7 @@
                 myindex = myindex + ar%a_dim(4)
              ENDDO
-
           ENDIF
-
         ENDDO
-
-    ENDDO
-
+    ENDDO
 !
 !-- Buffer is filled
@@ -727,5 +682,4 @@
 
     t1 = pmc_time()
-
 !
 !-- Wait for child to fill buffer
@@ -733,5 +687,4 @@
     t2 = pmc_time() - t1
     IF ( PRESENT( waittime ) )  waittime = t2
-
 !
 !-- TODO: check next statement
@@ -741,11 +694,8 @@
 
     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
 
@@ -755,15 +705,12 @@
              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
+!
+!--          Child processes are located behind parent process
              target_pe = ip - 1 + m_model_npes
              CALL MPI_WIN_LOCK( MPI_LOCK_SHARED, target_pe, 0,                  &
@@ -774,8 +721,6 @@
                                   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
@@ -783,7 +728,5 @@
                 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
@@ -792,9 +735,6 @@
                 myindex = myindex + ar%a_dim(4)
              ENDDO
-
           ENDIF
-
        ENDDO
-
     ENDDO
 
@@ -832,5 +772,5 @@
 
 !
-!-- Set array for child inter PE 0
+!-- Set array for child inter process 0
     IMPLICIT NONE
 
@@ -849,5 +789,4 @@
 
     DO  i = 1, children(childid)%inter_npes
-
        ape => children(childid)%pes(i)
        ar  => ape%array_list(next_array_in_list)
@@ -855,5 +794,4 @@
        ar%a_dim  = dims
        ar%data   = array_adr
-
        IF ( PRESENT( second_adr ) )  THEN
           ar%po_data(1) = array_adr
@@ -863,5 +801,4 @@
           ar%po_data(2) = C_NULL_PTR
        ENDIF
-
     ENDDO
 
@@ -885,16 +822,11 @@
 
     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
 
@@ -931,16 +863,15 @@
 
 !
-!-- First, count entries for every remote child PE
+!-- First, count entries for every remote child process
     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
+       rempe = index_list(5,j) + 1   ! process number on remote process
        ape => mychild%pes(rempe)
-       ape%nrele = ape%nrele + 1     ! Increment number of elements for this child PE
+       ape%nrele = ape%nrele + 1     ! Increment number of elements for this child process
     ENDDO
 
@@ -951,5 +882,4 @@
 
     remind = 0
-
 !
 !-- Second, create lists
@@ -963,35 +893,29 @@
        ape%locind(ind)%j = index_list(2,j)
     ENDDO
-
-!
-!-- Prepare number of elements for children PEs
+!
+!-- Prepare number of elements for children processes
     CALL pmc_alloc_mem( rldef, mychild%inter_npes*2 )
-
-!
-!-- Number of child PEs * size of INTEGER (i just arbitrary INTEGER)
+!
+!-- Number of child processes * 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
-
+    rldef(1) = 0            ! index on remote process 0
+    rldef(2) = remind(1)    ! number of elements on remote process 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
-
+       rldef(i2)   = rldef(i2-2) + rldef(i2-1) * 2  ! index on remote process
+       rldef(i2+1) = remind(i)                      ! number of elements on remote process
+    ENDDO
 !
 !-- Close window to allow child to access data
     CALL MPI_WIN_FENCE( 0, indwin, ierr )
-
 !
 !-- Child has retrieved data
@@ -1000,5 +924,4 @@
     i2 = 2 * mychild%inter_npes - 1
     winsize = ( rldef(i2) + rldef(i2+1) ) * 2
-
 !
 !-- Make sure, MPI_ALLOC_MEM works
@@ -1013,9 +936,8 @@
 !-- 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
+       rempe = index_list(5,j) + 1    ! process number on remote process
        ape => mychild%pes(rempe)
        i2    = rempe * 2 - 1
@@ -1025,9 +947,7 @@
        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
