Index: palm/trunk/SOURCE/pmc_mpi_wrapper_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_mpi_wrapper_mod.f90	(revision 1851)
+++ palm/trunk/SOURCE/pmc_mpi_wrapper_mod.f90	(revision 1900)
@@ -1,3 +1,3 @@
-MODULE pmc_mpi_wrapper
+ MODULE pmc_mpi_wrapper
 
 !--------------------------------------------------------------------------------!
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! re-formatted to match PALM style
 ! 
 ! Former revisions:
@@ -50,5 +50,5 @@
 
 #if defined( __parallel )
-   use, intrinsic :: iso_c_binding
+    USE, INTRINSIC ::  ISO_C_BINDING
 
 #if defined( __mpifh )
@@ -57,500 +57,563 @@
     USE MPI
 #endif
-   USE  kinds
-   USE  PMC_handle_communicator, ONLY: m_to_server_comm, m_to_client_comm, m_model_comm, m_model_rank
-   IMPLICIT none
-   PRIVATE
-   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_Bcast
-      MODULE PROCEDURE PMC_Bcast_INTEGER
-      MODULE PROCEDURE PMC_Bcast_character
-   END INTERFACE PMC_Bcast
-
-   INTERFACE PMC_Inter_Bcast
-      MODULE PROCEDURE PMC_Inter_Bcast_INTEGER_1
-   END INTERFACE PMC_Inter_Bcast
-
-   INTERFACE PMC_Alloc_mem
-      MODULE PROCEDURE PMC_Alloc_mem_INTEGER_1
-      MODULE PROCEDURE PMC_Alloc_mem_Real_1
-   END INTERFACE PMC_Alloc_mem
-
-   INTERFACE PMC_TIME
-      MODULE PROCEDURE PMC_TIME
-   END INTERFACE PMC_TIME
-
-   PUBLIC PMC_Send_to_Server, PMC_Recv_from_Server
-   PUBLIC PMC_Send_to_Client, PMC_Recv_from_Client
-   PUBLIC PMC_Bcast, PMC_Inter_Bcast, PMC_Alloc_mem
-   PUBLIC PMC_TIME
-
-CONTAINS
-
-   SUBROUTINE  PMC_Send_to_Server_INTEGER (buf, n, Server_rank, tag, ierr)
-      IMPLICIT     none
-      INTEGER, DIMENSION(:), INTENT(IN)         :: buf
-      INTEGER, INTENT(IN)                       :: n
-      INTEGER, INTENT(IN)                       :: Server_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, ierr)
-    
-      return
-   END SUBROUTINE  PMC_Send_to_Server_INTEGER
-
-   SUBROUTINE  PMC_Recv_from_Server_INTEGER (buf, n, Server_rank, tag, ierr)
-      IMPLICIT     none
-      INTEGER, DIMENSION(:), INTENT(OUT)        :: buf
-      INTEGER, INTENT(IN)                       :: n
-      INTEGER, INTENT(IN)                       :: Server_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, &
-         MPI_STATUS_IGNORE, ierr)
-
-      return
-   END SUBROUTINE  PMC_Recv_from_Server_INTEGER
-
-   SUBROUTINE  PMC_Send_to_Server_INTEGER_2 (buf, n, Server_rank, tag, ierr)
-      IMPLICIT     none
-      INTEGER, DIMENSION(:,:), INTENT(IN)       :: buf
-      INTEGER, INTENT(IN)                       :: n
-      INTEGER, INTENT(IN)                       :: Server_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, ierr)
-
-      return
-   END SUBROUTINE  PMC_Send_to_Server_INTEGER_2
-
-   SUBROUTINE  PMC_Send_to_Server_real_r1 (buf, n, Server_rank, tag, ierr)
-
-      IMPLICIT     none
-
-      REAL(wp), DIMENSION(:), INTENT(IN) ::  buf
-      INTEGER, INTENT(IN)                ::  n
-      INTEGER, INTENT(IN)                ::  Server_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)
-
-      return
-   END SUBROUTINE  PMC_Send_to_Server_real_r1
-
-   SUBROUTINE  PMC_Recv_from_Server_real_r1 (buf, n, Server_rank, tag, ierr)
-
-      IMPLICIT     none
-
-      REAL(wp), DIMENSION(:), INTENT(OUT) ::  buf
-      INTEGER, INTENT(IN)                 ::  n
-      INTEGER, INTENT(IN)                 ::  Server_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,     &
-                     MPI_STATUS_IGNORE, ierr)
-
-      return
-   END SUBROUTINE  PMC_Recv_from_Server_real_r1
-
-   SUBROUTINE  PMC_Send_to_Server_real_r2 (buf, n, Server_rank, tag, ierr)
-
-      IMPLICIT     none
-
-      REAL(wp), DIMENSION(:,:), INTENT(IN) ::  buf
-      INTEGER, INTENT(IN)                  ::  n
-      INTEGER, INTENT(IN)                  ::  Server_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)
-
-      return
-   END SUBROUTINE  PMC_Send_to_Server_real_r2
-
-   SUBROUTINE  PMC_Recv_from_Server_real_r2 (buf, n, Server_rank, tag, ierr)
-
-      IMPLICIT     none
-
-      REAL(wp), DIMENSION(:,:), INTENT(OUT) ::  buf
-      INTEGER, INTENT(IN)                   ::  n
-      INTEGER, INTENT(IN)                   ::  Server_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, &
-         MPI_STATUS_IGNORE, ierr)
-
-      return
-   END SUBROUTINE  PMC_Recv_from_Server_real_r2
-
-   SUBROUTINE  PMC_Send_to_Server_real_r3 (buf, n, Server_rank, tag, ierr)
-
-      IMPLICIT     none
-
-      REAL(wp), DIMENSION(:,:,:), INTENT(IN) ::  buf
-      INTEGER, INTENT(IN)                    ::  n
-      INTEGER, INTENT(IN)                    ::  Server_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)
-
-      return
-   END SUBROUTINE  PMC_Send_to_Server_real_r3
-
-   SUBROUTINE  PMC_Recv_from_Server_real_r3 (buf, n, Server_rank, tag, ierr)
-
-      IMPLICIT     none
-
-      REAL(wp), DIMENSION(:,:,:), INTENT(OUT) ::  buf
-      INTEGER, INTENT(IN)                     ::  n
-      INTEGER, INTENT(IN)                     ::  Server_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, &
-         MPI_STATUS_IGNORE, ierr)
-
-      return
-   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
-      INTEGER, DIMENSION(:), INTENT(IN)         :: buf
-      INTEGER, INTENT(IN)                       :: n
-      INTEGER, INTENT(IN)                       :: Client_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)
-
-      return
-   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
-      INTEGER, DIMENSION(:), INTENT(INOUT)      :: buf
-      INTEGER, INTENT(IN)                       :: n
-      INTEGER, INTENT(IN)                       :: Client_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)
-
-      return
-   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
-      INTEGER, DIMENSION(:,:), INTENT(OUT)      :: buf
-      INTEGER, INTENT(IN)                       :: n
-      INTEGER, INTENT(IN)                       :: Client_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)
-
-      return
-   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
-      REAL(wp), DIMENSION(:), INTENT(IN) ::  buf
-      INTEGER, INTENT(IN)                ::  n
-      INTEGER, INTENT(IN)                ::  Client_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)
-
-      return
-   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
-      REAL(wp), DIMENSION(:), INTENT(INOUT) ::  buf
-      INTEGER, INTENT(IN)                   ::  n
-      INTEGER, INTENT(IN)                   ::  Client_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)
-
-      return
-   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
-      REAL(wp), DIMENSION(:,:), INTENT(IN) ::  buf
-      INTEGER, INTENT(IN)                  ::  n
-      INTEGER, INTENT(IN)                  ::  Client_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)
-
-      return
-   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
-      REAL(wp), DIMENSION(:,:), INTENT(OUT) ::  buf
-      INTEGER, INTENT(IN)                   ::  n
-      INTEGER, INTENT(IN)                   ::  Client_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)
-
-      return
-   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
-      REAL(wp), DIMENSION(:,:,:), INTENT(IN) ::  buf
-      INTEGER, INTENT(IN)                    ::  n
-      INTEGER, INTENT(IN)                    ::  Client_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)
-
-      return
-   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
-      REAL(wp), DIMENSION(:,:,:), INTENT(OUT) ::  buf
-      INTEGER, INTENT(IN)                     :: n
-      INTEGER, INTENT(IN)                     :: Client_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)
-
-      return
-   END SUBROUTINE  PMC_Recv_from_Client_real_r3
-
-   SUBROUTINE  PMC_Bcast_INTEGER (buf, root_pe, comm, ierr)
-      IMPLICIT     none
-      INTEGER, INTENT(INOUT)                      :: buf
-      INTEGER, INTENT(IN)                         :: root_pe
-      INTEGER, INTENT(IN),optional                :: comm
-      INTEGER, INTENT(OUT),optional               :: ierr
-      !-- local variables
-      INTEGER                                     :: myComm
-      INTEGER                                     :: myErr
-
-      if(present (comm))  then
-         myComm = comm
-      else
-         myComm = m_model_comm
-      end if
-
-      CALL MPI_Bcast (buf, 1, MPI_INTEGER, root_pe, myComm, myErr)
-
-      if(present (ierr))  then
-         ierr = myErr
-      end if
-
-      return
-   END SUBROUTINE  PMC_Bcast_INTEGER
-
-   SUBROUTINE  PMC_Bcast_character (buf, root_pe, comm, ierr)
-      IMPLICIT     none
-      character(len=*), INTENT(INOUT)             :: buf
-      INTEGER, INTENT(IN)                         :: root_pe
-      INTEGER, INTENT(IN),optional                :: comm
-      INTEGER, INTENT(OUT),optional               :: ierr
-      !-- local variables
-      INTEGER                                     :: myComm
-      INTEGER                                     :: myErr
-
-      if(present (comm))  then
-         myComm = comm
-      else
-         myComm = m_model_comm
-      end if
-
-      CALL MPI_Bcast (buf, len(buf), MPI_Character, root_pe, myComm, myErr)
-
-      if(present (ierr))  then
-         ierr = myErr
-      end if
-
-      return
-   END SUBROUTINE  PMC_Bcast_character
-
-   SUBROUTINE  PMC_Inter_Bcast_INTEGER_1 (buf, Client_id, ierr)
-      IMPLICIT     none
-      INTEGER, INTENT(INOUT),DIMENSION(:)         :: buf
-      INTEGER, INTENT(IN),optional                :: Client_id
-      INTEGER, INTENT(OUT),optional               :: ierr
-      !-- local variables
-      INTEGER                                     :: myComm
-      INTEGER                                     :: myErr
-      INTEGER                                     :: root_pe
-
-      !   PE 0 Server Broadcast to all Client PE's
-
-      if(present (Client_id))  then
-         myComm  = m_to_client_comm(Client_id)
-         if(m_model_rank == 0)  then
-            root_pe = MPI_ROOT
-         else
-            root_pe = MPI_PROC_NULL
-         end if
-      else
-         myComm  = m_to_server_comm
-         root_pe = 0
-      end if
-
-      CALL MPI_Bcast (buf, size(buf), MPI_INTEGER, root_pe, myComm, myErr)
-
-      if(present (ierr))  then
-         ierr = myErr
-      end if
-
-      return
-   END SUBROUTINE  PMC_Inter_Bcast_INTEGER_1
-
-!  Allocate  Memory with MPI_Alloc_mem using intermediate C-pointer
-
-   SUBROUTINE  PMC_Alloc_mem_INTEGER_1 (iarray, idim1)
-      IMPLICIT     none
-      INTEGER,DIMENSION(:),POINTER,INTENT(INOUT) :: iarray
-      INTEGER,INTENT(IN)                         :: idim1
-
-      Type(c_ptr)                             :: p_myInd
-      INTEGER,DIMENSION(1)                    :: aShape
-      INTEGER(KIND=MPI_ADDRESS_KIND)          :: WinSize
-      INTEGER                                 :: ierr
-
-      WinSize = idim1*c_sizeof(ierr)                          ! Length of INTEGER
-
-      CALL MPI_Alloc_mem  (WinSize , MPI_INFO_NULL, p_myInd, ierr);
-      aShape(1) = idim1
-      CALL c_f_pointer(p_myInd,iarray,aShape)
-
-      return
-   END SUBROUTINE  PMC_Alloc_mem_INTEGER_1
-
-   SUBROUTINE  PMC_Alloc_mem_Real_1 (array, idim1, base_ptr)
-      IMPLICIT     none
-      REAL(kind=wp),DIMENSION(:),POINTER,INTENT(INOUT) :: array
-      INTEGER(idp),INTENT(IN)                          :: idim1
-      Type(c_ptr),INTENT(OUT),optional                 :: base_ptr
-
-
-      Type(c_ptr)                             :: p_myInd
-      INTEGER,DIMENSION(1)                    :: aShape
-      INTEGER(KIND=MPI_ADDRESS_KIND)          :: WinSize
-      INTEGER                                 :: ierr
-
-      WinSize = idim1*wp                          ! Length of INTEGER
-
-      CALL MPI_Alloc_mem  (WinSize , MPI_INFO_NULL, p_myInd, ierr);
-      aShape(1) = idim1
-      CALL c_f_pointer(p_myInd,array,aShape)
-
-      if(present(base_ptr))   then
-         base_ptr = p_myInd
-      end if
-
-      return
-   END SUBROUTINE  PMC_Alloc_mem_Real_1
-
-   FUNCTION PMC_TIME ()
-      REAL(kind=wp)          :: PMC_TIME
-
-      PMC_TIME = MPI_Wtime ()
-
-      return
-
-    END FUNCTION PMC_TIME
+
+    USE kinds
+    USE pmc_handle_communicator,                                               &
+        ONLY: m_model_comm, m_model_rank, m_to_server_comm, m_to_client_comm
+
+    IMPLICIT NONE
+
+    PRIVATE
+    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_bcast
+       MODULE PROCEDURE pmc_bcast_integer
+       MODULE PROCEDURE pmc_bcast_character
+    END INTERFACE pmc_bcast
+
+    INTERFACE pmc_inter_bcast
+       MODULE PROCEDURE pmc_inter_bcast_integer_1
+    END INTERFACE pmc_inter_bcast
+
+    INTERFACE pmc_alloc_mem
+       MODULE PROCEDURE pmc_alloc_mem_integer_1
+       MODULE PROCEDURE pmc_alloc_mem_Real_1
+    END INTERFACE pmc_alloc_mem
+
+    INTERFACE pmc_time
+       MODULE PROCEDURE pmc_time
+    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,       &
+           pmc_time
+
+ CONTAINS
+
+
+ SUBROUTINE pmc_send_to_server_integer( buf, n, server_rank, tag, ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, DIMENSION(:), INTENT(IN) ::  buf          !<
+    INTEGER, INTENT(IN)               ::  n            !<
+    INTEGER, INTENT(IN)               ::  server_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,    &
+                   ierr)
+
+ END SUBROUTINE pmc_send_to_server_integer
+
+
+
+ SUBROUTINE pmc_recv_from_server_integer( buf, n, server_rank, tag, ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, DIMENSION(:), INTENT(OUT) ::  buf          !<
+    INTEGER, INTENT(IN)                ::  n            !<
+    INTEGER, INTENT(IN)                ::  server_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,    &
+                   MPI_STATUS_IGNORE, ierr )
+
+ END SUBROUTINE pmc_recv_from_server_integer
+
+
+
+ SUBROUTINE pmc_send_to_server_integer_2( buf, n, server_rank, tag, ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, DIMENSION(:,:), INTENT(IN) :: buf          !<
+    INTEGER, INTENT(IN)                 :: n            !<
+    INTEGER, INTENT(IN)                 :: server_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,    &
+                   ierr )
+
+ END SUBROUTINE pmc_send_to_server_integer_2
+
+
+
+ SUBROUTINE pmc_send_to_server_real_r1( buf, n, server_rank, tag, ierr )
+
+    IMPLICIT NONE
+
+    REAL(wp), DIMENSION(:), INTENT(IN) ::  buf          !<
+    INTEGER, INTENT(IN)                ::  n            !<
+    INTEGER, INTENT(IN)                ::  server_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 )
+
+    IMPLICIT NONE
+
+    REAL(wp), DIMENSION(:), INTENT(OUT) ::  buf          !<
+    INTEGER, INTENT(IN)                 ::  n            !<
+    INTEGER, INTENT(IN)                 ::  server_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,       &
+                   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 )
+
+    IMPLICIT NONE
+
+    REAL(wp), DIMENSION(:,:), INTENT(IN) ::  buf          !<
+    INTEGER, INTENT(IN)                  ::  n            !<
+    INTEGER, INTENT(IN)                  ::  server_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 )
+
+    IMPLICIT NONE
+
+    REAL(wp), DIMENSION(:,:), INTENT(OUT) ::  buf          !<
+    INTEGER, INTENT(IN)                   ::  n            !<
+    INTEGER, INTENT(IN)                   ::  server_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,       &
+                   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 )
+
+    IMPLICIT NONE
+
+    REAL(wp), DIMENSION(:,:,:), INTENT(IN) ::  buf          !<
+    INTEGER, INTENT(IN)                    ::  n            !<
+    INTEGER, INTENT(IN)                    ::  server_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 )
+
+    IMPLICIT NONE
+
+    REAL(wp), DIMENSION(:,:,:), INTENT(OUT) ::  buf          !<
+    INTEGER, INTENT(IN)                     ::  n            !<
+    INTEGER, INTENT(IN)                     ::  server_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,       &
+                   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    !<
+    INTEGER, DIMENSION(:), INTENT(IN) ::  buf          !<
+    INTEGER, INTENT(IN)               ::  n            !<
+    INTEGER, INTENT(IN)               ::  client_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    !<
+    INTEGER, DIMENSION(:), INTENT(INOUT) ::  buf          !<
+    INTEGER, INTENT(IN)                  ::  n            !<
+    INTEGER, INTENT(IN)                  ::  client_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    !<
+    INTEGER, DIMENSION(:,:), INTENT(OUT) ::  buf          !<
+    INTEGER, INTENT(IN)                  ::  n            !<
+    INTEGER, INTENT(IN)                  ::  client_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    !<
+    REAL(wp), DIMENSION(:), INTENT(IN) ::  buf          !<
+    INTEGER, INTENT(IN)                ::  n            !<
+    INTEGER, INTENT(IN)                ::  client_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    !<
+    REAL(wp), DIMENSION(:), INTENT(INOUT) ::  buf          !<
+    INTEGER, INTENT(IN)                   ::  n            !<
+    INTEGER, INTENT(IN)                   ::  client_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    !<
+    REAL(wp), DIMENSION(:,:), INTENT(IN) ::  buf          !<
+    INTEGER, INTENT(IN)                  ::  n            !<
+    INTEGER, INTENT(IN)                  ::  client_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    !<
+    REAL(wp), DIMENSION(:,:), INTENT(OUT) ::  buf          !<
+    INTEGER, INTENT(IN)                   ::  n            !<
+    INTEGER, INTENT(IN)                   ::  client_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    !<
+    REAL(wp), DIMENSION(:,:,:), INTENT(IN) ::  buf          !<
+    INTEGER, INTENT(IN)                    ::  n            !<
+    INTEGER, INTENT(IN)                    ::  client_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    !<
+    REAL(wp), DIMENSION(:,:,:), INTENT(OUT) ::  buf          !<
+    INTEGER, INTENT(IN)                     ::  n            !<
+    INTEGER, INTENT(IN)                     ::  client_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
+
+
+
+ SUBROUTINE pmc_bcast_integer( buf, root_pe, comm, ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(INOUT)         ::  buf      !<
+    INTEGER, INTENT(IN)            ::  root_pe  !<
+    INTEGER, INTENT(IN), OPTIONAL  ::  comm     !<
+    INTEGER, INTENT(OUT), OPTIONAL ::  ierr     !<
+
+    INTEGER ::  mycomm  !<
+    INTEGER ::  myerr   !<
+
+
+    IF ( PRESENT( comm ) )  THEN
+       mycomm = comm
+    ELSE
+       mycomm = m_model_comm
+    ENDIF
+
+    CALL MPI_BCAST( buf, 1, MPI_INTEGER, root_pe, mycomm, myerr )
+
+    IF ( PRESENT( ierr ) )  THEN
+       ierr = myerr
+    ENDIF
+
+ END SUBROUTINE pmc_bcast_integer
+
+
+
+ SUBROUTINE pmc_bcast_character( buf, root_pe, comm, ierr )
+
+    IMPLICIT NONE
+
+    CHARACTER(LEN=*), INTENT(INOUT) ::  buf      !<
+    INTEGER, INTENT(IN)             ::  root_pe  !<
+    INTEGER, INTENT(IN), OPTIONAL   ::  comm     !<
+    INTEGER, INTENT(OUT), OPTIONAL  ::  ierr     !<
+
+    INTEGER ::  mycomm  !<
+    INTEGER ::  myerr   !<
+
+    IF ( PRESENT( comm ) )  THEN
+       mycomm = comm
+    ELSE
+       mycomm = m_model_comm
+    ENDIF
+
+    CALL MPI_BCAST( buf, LEN(buf), MPI_CHARACTER, root_pe, mycomm, myerr )
+
+    IF ( PRESENT( ierr ) )  THEN
+       ierr = myerr
+    ENDIF
+
+ END SUBROUTINE pmc_bcast_character
+
+
+
+ SUBROUTINE pmc_inter_bcast_integer_1( buf, client_id, ierr )
+
+    IMPLICIT NONE
+
+    INTEGER, INTENT(INOUT),DIMENSION(:) ::  buf        !<
+    INTEGER, INTENT(IN),optional        ::  client_id  !<
+    INTEGER, INTENT(OUT),optional       ::  ierr       !<
+
+    INTEGER ::  mycomm   !<
+    INTEGER ::  myerr    !<
+    INTEGER ::  root_pe  !<
+
+!
+!-- PE 0 server broadcast to all client PEs
+    IF ( PRESENT( client_id ) )  THEN
+
+       mycomm = m_to_client_comm(client_id)
+
+       IF ( m_model_rank == 0 )  THEN
+          root_pe = MPI_ROOT
+       ELSE
+          root_pe = MPI_PROC_NULL
+       ENDIF
+
+    ELSE
+       mycomm  = m_to_server_comm
+       root_pe = 0
+    ENDIF
+
+    CALL MPI_BCAST( buf, SIZE( buf ), MPI_INTEGER, root_pe, mycomm, myerr )
+
+    IF ( PRESENT( ierr ) )  THEN
+       ierr = myerr
+    ENDIF
+
+ END SUBROUTINE pmc_inter_bcast_integer_1
+
+
+
+ SUBROUTINE pmc_alloc_mem_integer_1( iarray, idim1 )
+!
+!-- Allocate memory with MPI_ALLOC_MEM using intermediate C-pointer
+
+    IMPLICIT NONE
+
+    INTEGER, DIMENSION(:), POINTER, INTENT(INOUT) ::  iarray  !<
+    INTEGER, INTENT(IN)                           ::  idim1   !<
+
+    INTEGER, DIMENSION(1)          ::  ashape   !<
+    INTEGER(KIND=MPI_ADDRESS_KIND) ::  winsize  !<
+    INTEGER                        ::  ierr     !<
+
+    TYPE(C_PTR)                    ::  p_myind  !<
+
+    winsize = idim1 * C_SIZEOF( ierr )
+
+    CALL MPI_ALLOC_MEM( winsize, MPI_INFO_NULL, p_myind, ierr )
+    ashape(1) = idim1
+    CALL C_F_POINTER( p_myind, iarray, ashape )
+
+ END SUBROUTINE pmc_alloc_mem_integer_1
+
+
+
+ SUBROUTINE pmc_alloc_mem_real_1( array, idim1, base_ptr )
+
+    IMPLICIT NONE
+
+    INTEGER(idp), INTENT(IN)                            ::  idim1     !<
+    REAL(KIND=wp), DIMENSION(:), POINTER, INTENT(INOUT) ::  array     !<
+    TYPE(C_PTR), INTENT(OUT), OPTIONAL                  ::  base_ptr  !<
+
+    INTEGER, DIMENSION(1)          :: ashape   !<
+    INTEGER(KIND=MPI_ADDRESS_KIND) :: winsize  !<
+    INTEGER                        :: ierr     !<
+
+    TYPE(C_PTR)                    :: p_myind  !<
+
+    winsize = idim1 * wp
+
+    CALL MPI_ALLOC_MEM( winsize , MPI_INFO_NULL, p_myind, ierr )
+    ashape(1) = idim1
+    CALL C_F_POINTER( p_myind, array, ashape )
+
+    IF ( PRESENT( base_ptr ) )  THEN
+       base_ptr = p_myind
+    ENDIF
+
+ END SUBROUTINE pmc_alloc_mem_Real_1
+
+
+
+ FUNCTION pmc_time()
+
+    REAL(kind=wp) :: pmc_time  !<
+
+    pmc_time = MPI_WTIME()
+
+  END FUNCTION pmc_time
 
 #endif
