Index: palm/trunk/SOURCE/CURRENT_MODIFICATIONS
===================================================================
--- palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 200)
+++ palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 206)
@@ -1,5 +1,15 @@
 New:
 ---
+Restart runs on SGI-ICE are working (mrun).
+2d-decomposition is default on SGI-ICE systems. (init_pegrid)
 
+Ocean-atmosphere coupling realized with MPI-1. mrun adjusted for this case
+(-Y option). Adjustments in mrun, mbuild, and subjob for lcxt4.
+
+
+check_for_restart, check_parameters, init_dvrp, init_pegrid, local_stop, modules, palm, surface_coupler, timestep
+Makefile, mrun, mbuild, subjob
+
+New: init_coupling
 
 
@@ -8,6 +18,8 @@
 
 
-
 Errors:
 ------
 
+Bugfix: error in zu index in case of section_xy = -1 (header)
+
+header
Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 200)
+++ palm/trunk/SOURCE/Makefile	(revision 206)
@@ -4,11 +4,13 @@
 # Actual revisions:
 # -----------------
-# +plant_canopy_model, inflow_turbulence
-#
-# +surface_coupler
+# +init_coupling
 #
 # Former revisions:
 # -----------------
 # $Id$
+#
+# 151 2008-03-07 13:42:18Z raasch
+# +plant_canopy_model, inflow_turbulence
+# +surface_coupler
 #
 # 96 2007-06-04 08:07:41Z raasch
@@ -56,6 +58,6 @@
 	fft_xy.f90 flow_statistics.f90 global_min_max.f90 header.f90 \
 	impact_of_latent_heat.f90 inflow_turbulence.f90 init_1d_model.f90 \
-	init_3d_model.f90 init_advec.f90 init_cloud_physics.f90 init_dvrp.f90 \
-	init_grid.f90 init_ocean.f90 init_particles.f90 init_pegrid.f90 \
+	init_3d_model.f90 init_advec.f90 init_cloud_physics.f90 init_coupling.f90 \
+	init_dvrp.f90 init_grid.f90 init_ocean.f90 init_particles.f90 init_pegrid.f90 \
 	init_pt_anomaly.f90 init_rankine.f90 init_slope.f90 \
 	interaction_droplets_ptq.f90 local_flush.f90 local_getenv.f90 \
@@ -89,5 +91,5 @@
 	flow_statistics.o global_min_max.o header.o impact_of_latent_heat.o \
 	inflow_turbulence.o init_1d_model.o init_3d_model.o init_advec.o init_cloud_physics.o \
-	init_dvrp.o init_grid.o init_ocean.o init_particles.o init_pegrid.o \
+	init_coupling.o init_dvrp.o init_grid.o init_ocean.o init_particles.o init_pegrid.o \
 	init_pt_anomaly.o init_rankine.o init_slope.o \
 	interaction_droplets_ptq.o local_flush.o local_getenv.o local_stop.o \
@@ -188,4 +190,5 @@
 init_advec.o: modules.o
 init_cloud_physics.o: modules.o
+init_coupling.o: modules.o
 init_dvrp.o: modules.o
 init_grid.o: modules.o
@@ -245,3 +248,2 @@
 write_compressed.o: modules.o
 write_var_list.o: modules.o
-
Index: palm/trunk/SOURCE/check_for_restart.f90
===================================================================
--- palm/trunk/SOURCE/check_for_restart.f90	(revision 200)
+++ palm/trunk/SOURCE/check_for_restart.f90	(revision 206)
@@ -4,5 +4,5 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Implementation of an MPI-1 coupling: replaced myid with target_id
 !
 ! Former revisions:
@@ -64,9 +64,9 @@
 !-- Output that job will be terminated
     IF ( terminate_run  .AND.  myid == 0 )  THEN
-       PRINT*, '*** WARNING: run will be terminated because it is running out', &
-                    ' of job cpu limit'
+       PRINT*, '*** WARNING: run will be terminated because it is running', &
+                    ' out of job cpu limit'
        PRINT*, '             remaining time:         ', remaining_time, ' s'
-       PRINT*, '             termination time needed:', termination_time_needed,&
-                    ' s'
+       PRINT*, '             termination time needed:', &
+                             termination_time_needed, ' s'
     ENDIF
 
@@ -80,6 +80,8 @@
 
        terminate_coupled = 3
-       CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER, myid,  0, &
-                          terminate_coupled_remote, 1, MPI_INTEGER, myid,  0, &
+       CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,          &
+                          target_id, 0,                                      &
+                          terminate_coupled_remote, 1, MPI_INTEGER,          &
+                          target_id, 0,                                      &
                           comm_inter, status, ierr )
     ENDIF
@@ -107,5 +109,6 @@
                                        'settings of'
              PRINT*, '                 restart_time / dt_restart'
-             PRINT*, '                 new restart time is: ', time_restart, ' s'
+             PRINT*, '                 new restart time is: ', time_restart, &
+                                       ' s'
           ENDIF
 !
@@ -114,6 +117,6 @@
 !--       informed of another termination reason (terminate_coupled > 0) before,
 !--       or vice versa (terminate_coupled_remote > 0).
-          IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0  .AND. &
-               terminate_coupled_remote == 0)  THEN
+          IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0  &
+               .AND.  terminate_coupled_remote == 0 )  THEN
 
              IF ( dt_restart /= 9999999.9 )  THEN
@@ -122,8 +125,9 @@
                 terminate_coupled = 5
              ENDIF
-             CALL MPI_SENDRECV(                                                 &
-                            terminate_coupled,        1, MPI_INTEGER, myid,  0, &
-                            terminate_coupled_remote, 1, MPI_INTEGER, myid,  0, &
-                            comm_inter, status, ierr )
+             CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER,    &
+                                target_id,  0,                               &
+                                terminate_coupled_remote, 1, MPI_INTEGER,    &
+                                target_id,  0,                               &
+                                comm_inter, status, ierr )
           ENDIF
        ELSE
Index: palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- palm/trunk/SOURCE/check_parameters.f90	(revision 200)
+++ palm/trunk/SOURCE/check_parameters.f90	(revision 206)
@@ -4,5 +4,6 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Implementation of an MPI-1 coupling: replaced myid with target_id, 
+! deleted __mpi2 directives
 !
 ! Former revisions:
@@ -139,7 +140,9 @@
           CALL local_stop
        ENDIF
-#if defined( __parallel )  &&  defined( __mpi2 )
-       CALL MPI_SEND( dt_coupling, 1, MPI_REAL, myid, 11, comm_inter, ierr )
-       CALL MPI_RECV( remote, 1, MPI_REAL, myid, 11, comm_inter, status, ierr )
+#if defined( __parallel )
+       CALL MPI_SEND( dt_coupling, 1, MPI_REAL, target_id, 11, comm_inter, &
+                      ierr )
+       CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 11, comm_inter, &
+                      status, ierr )
        IF ( dt_coupling /= remote )  THEN
           IF ( myid == 0 )  THEN
@@ -151,7 +154,7 @@
        ENDIF
        IF ( dt_coupling <= 0.0 )  THEN
-          CALL MPI_SEND( dt_max, 1, MPI_REAL, myid, 19, comm_inter, ierr )
-          CALL MPI_RECV( remote, 1, MPI_REAL, myid, 19, comm_inter, status, &
-               ierr )
+          CALL MPI_SEND( dt_max, 1, MPI_REAL, target_id, 19, comm_inter, ierr )
+          CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 19, comm_inter, &
+                         status, ierr )
           dt_coupling = MAX( dt_max, remote )
           IF ( myid == 0 )  THEN
@@ -162,6 +165,8 @@
           ENDIF
        ENDIF
-       CALL MPI_SEND( restart_time, 1, MPI_REAL, myid, 12, comm_inter, ierr )
-       CALL MPI_RECV( remote, 1, MPI_REAL, myid, 12, comm_inter, status, ierr )
+       CALL MPI_SEND( restart_time, 1, MPI_REAL, target_id, 12, comm_inter, &
+                      ierr )
+       CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 12, comm_inter, &
+                      status, ierr )
        IF ( restart_time /= remote )  THEN
           IF ( myid == 0 )  THEN
@@ -172,6 +177,8 @@
           CALL local_stop
        ENDIF
-       CALL MPI_SEND( dt_restart, 1, MPI_REAL, myid, 13, comm_inter, ierr )
-       CALL MPI_RECV( remote, 1, MPI_REAL, myid, 13, comm_inter, status, ierr )
+       CALL MPI_SEND( dt_restart, 1, MPI_REAL, target_id, 13, comm_inter, &
+                      ierr )
+       CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 13, comm_inter, &
+                      status, ierr )
        IF ( dt_restart /= remote )  THEN
           IF ( myid == 0 )  THEN
@@ -182,6 +189,7 @@
           CALL local_stop
        ENDIF
-       CALL MPI_SEND( end_time, 1, MPI_REAL, myid, 14, comm_inter, ierr )
-       CALL MPI_RECV( remote, 1, MPI_REAL, myid, 14, comm_inter, status, ierr )
+       CALL MPI_SEND( end_time, 1, MPI_REAL, target_id, 14, comm_inter, ierr )
+       CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 14, comm_inter, &
+                      status, ierr )
        IF ( end_time /= remote )  THEN
           IF ( myid == 0 )  THEN
@@ -192,6 +200,7 @@
           CALL local_stop
        ENDIF
-       CALL MPI_SEND( dx, 1, MPI_REAL, myid, 15, comm_inter, ierr )
-       CALL MPI_RECV( remote, 1, MPI_REAL, myid, 15, comm_inter, status, ierr )
+       CALL MPI_SEND( dx, 1, MPI_REAL, target_id, 15, comm_inter, ierr )
+       CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 15, comm_inter, &
+                      status, ierr )
        IF ( dx /= remote )  THEN
           IF ( myid == 0 )  THEN
@@ -202,6 +211,7 @@
           CALL local_stop
        ENDIF
-       CALL MPI_SEND( dy, 1, MPI_REAL, myid, 16, comm_inter, ierr )
-       CALL MPI_RECV( remote, 1, MPI_REAL, myid, 16, comm_inter, status, ierr )
+       CALL MPI_SEND( dy, 1, MPI_REAL, target_id, 16, comm_inter, ierr )
+       CALL MPI_RECV( remote, 1, MPI_REAL, target_id, 16, comm_inter, &
+                      status, ierr )
        IF ( dy /= remote )  THEN
           IF ( myid == 0 )  THEN
@@ -212,7 +222,7 @@
           CALL local_stop
        ENDIF
-       CALL MPI_SEND( nx, 1, MPI_INTEGER, myid, 17, comm_inter, ierr )
-       CALL MPI_RECV( iremote, 1, MPI_INTEGER, myid, 17, comm_inter, status, &
-            ierr )
+       CALL MPI_SEND( nx, 1, MPI_INTEGER, target_id, 17, comm_inter, ierr )
+       CALL MPI_RECV( iremote, 1, MPI_INTEGER, target_id, 17, comm_inter, &
+                      status, ierr )
        IF ( nx /= iremote )  THEN
           IF ( myid == 0 )  THEN
@@ -223,7 +233,7 @@
           CALL local_stop
        ENDIF
-       CALL MPI_SEND( ny, 1, MPI_INTEGER, myid, 18, comm_inter, ierr )
-       CALL MPI_RECV( iremote, 1, MPI_INTEGER, myid, 18, comm_inter, status, &
-            ierr )
+       CALL MPI_SEND( ny, 1, MPI_INTEGER, target_id, 18, comm_inter, ierr )
+       CALL MPI_RECV( iremote, 1, MPI_INTEGER, target_id, 18, comm_inter, &
+                      status, ierr )
        IF ( ny /= iremote )  THEN
           IF ( myid == 0 )  THEN
@@ -237,13 +247,13 @@
     ENDIF
 
-#if defined( __parallel )  &&  defined( __mpi2 )
+#if defined( __parallel )
 !
 !-- Exchange via intercommunicator
     IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
-       CALL MPI_SEND( humidity, &
-            1, MPI_LOGICAL, myid, 19, comm_inter, ierr )
+       CALL MPI_SEND( humidity, 1, MPI_LOGICAL, target_id, 19, comm_inter, &
+                      ierr )
     ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
-       CALL MPI_RECV( humidity_remote, &
-            1, MPI_LOGICAL, myid, 19, comm_inter, status, ierr )
+       CALL MPI_RECV( humidity_remote, 1, MPI_LOGICAL, target_id, 19, &
+                      comm_inter, status, ierr )
     ENDIF
 #endif
Index: palm/trunk/SOURCE/header.f90
===================================================================
--- palm/trunk/SOURCE/header.f90	(revision 200)
+++ palm/trunk/SOURCE/header.f90	(revision 206)
@@ -4,5 +4,5 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Bugfix: error in zu index in case of section_xy = -1
 !
 ! Former revisions:
@@ -703,5 +703,9 @@
                 slices = TRIM( slices ) // TRIM( section_chr ) // '/'
 
-                WRITE (coor_chr,'(F10.1)')  zu(section(i,1))
+                IF ( section(i,1) == -1 )  THEN
+                   WRITE (coor_chr,'(F10.1)')  -1.0
+                ELSE
+                   WRITE (coor_chr,'(F10.1)')  zu(section(i,1))
+                ENDIF
                 coor_chr = ADJUSTL( coor_chr )
                 coordinates = TRIM( coordinates ) // TRIM( coor_chr ) // '/'
Index: palm/trunk/SOURCE/init_coupling.f90
===================================================================
--- palm/trunk/SOURCE/init_coupling.f90	(revision 206)
+++ palm/trunk/SOURCE/init_coupling.f90	(revision 206)
@@ -0,0 +1,113 @@
+  SUBROUTINE init_coupling
+
+!------------------------------------------------------------------------------!
+! Actual revisions:
+! -----------------
+! 
+!
+! Former revisions:
+! ------------------
+! $Id$
+!
+! Description:
+! ------------
+! Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is
+! called.
+!------------------------------------------------------------------------------!
+
+    USE pegrid
+    USE control_parameters
+
+    IMPLICIT NONE
+
+!
+!-- Local variables
+    INTEGER               ::  i, inter_color
+    INTEGER, DIMENSION(:) ::  bc_data(0:2) = 0
+
+!
+!-- Get information about the coupling mode from the environment variable
+!-- which has been set by the mpiexec command.
+!-- This method is currently not used because the mpiexec command is not
+!-- available on some machines
+!    CALL local_getenv( 'coupling_mode', 13, coupling_mode, i )
+!    IF ( i == 0 )  coupling_mode = 'uncoupled'
+!    IF ( coupling_mode == 'ocean_to_atmosphere' )  coupling_char = '_O'
+
+!
+!-- Get information about the coupling mode from standard input (PE0 only) and
+!-- distribute it to the other PEs. If __mpi2 was defined, suggest a 
+!-- coupling via MPI-2. Otherwise initate a coupling using MPI-1 only.
+!-- In this case, distribute PEs to 2 new communicators.
+!-- ATTENTION: numprocs will be reset according to the new communicators
+    IF ( myid == 0 )  THEN
+       READ (*,*,ERR=10,END=10)  coupling_mode, bc_data(1), bc_data(2)
+10     CONTINUE
+
+#if defined( __mpi2 )
+       IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' )  THEN
+          i = 1
+       ELSEIF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' )  THEN
+          i = 2
+       ELSE
+          i = 0
+       ENDIF
+#else
+       IF ( TRIM( coupling_mode ) == 'coupled_run' )  THEN
+          i = 1
+       ELSE
+          i = 0
+       ENDIF
+#endif
+    bc_data(0) = i
+    ENDIF
+
+    CALL MPI_BCAST( bc_data(0), 3, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr )
+    i = bc_data(0)
+
+#if defined ( __mpi2 )
+    IF ( i == 0 )  THEN
+       coupling_mode = 'uncoupled'
+    ELSEIF ( i == 1 )  THEN
+       coupling_mode = 'atmosphere_to_ocean'
+    ELSEIF ( i == 2 )  THEN
+       coupling_mode = 'ocean_to_atmosphere'
+    ENDIF
+    target_id = myid
+#else
+    IF ( i == 0 ) THEN
+       coupling_mode = 'uncoupled'
+    ELSE
+       comm_inter = MPI_COMM_WORLD
+
+       IF ( myid < bc_data(1) ) THEN
+          inter_color = 0
+          numprocs = bc_data(1)
+       ELSE
+          inter_color = 1
+          numprocs = bc_data(2)
+       ENDIF
+!
+!--    Calculate the target PE for coupling and set up the new communicators.
+!--    Currently only 1:1 topologies are supported.
+       target_id = myid - ISIGN( numprocs, inter_color - 1 )
+       IF ( inter_color == 0 ) THEN
+          coupling_mode = 'atmosphere_to_ocean'
+       ELSE
+          coupling_mode = 'ocean_to_atmosphere'
+       ENDIF
+       CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr )
+       comm2d = comm_palm
+
+!
+!--    Write a flag file for the ocean model and the other atmosphere
+!--    processes.
+       OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' )
+       WRITE ( 90, '(''TRUE'')' )
+       CLOSE ( 90 )
+    ENDIF
+#endif
+
+    IF ( coupling_mode == 'ocean_to_atmosphere' )  coupling_char = '_O'
+
+ END SUBROUTINE init_coupling
Index: palm/trunk/SOURCE/init_dvrp.f90
===================================================================
--- palm/trunk/SOURCE/init_dvrp.f90	(revision 200)
+++ palm/trunk/SOURCE/init_dvrp.f90	(revision 206)
@@ -7,5 +7,5 @@
 ! TEST: print* statements
 ! ToDo: checking of mode_dvrp for legal values is not correct
-!
+! Implementation of a MPI-1 coupling: __mpi2 adjustments for MPI_COMM_WORLD
 ! Former revisions:
 ! -----------------
@@ -49,4 +49,8 @@
     USE pegrid
     USE control_parameters
+
+!
+!-- New coupling
+    USE coupling
 
     IMPLICIT NONE
@@ -600,5 +604,17 @@
     WRITE ( 9, * ) '*** myid=', myid, ' vor DVRP_SPLIT'
     CALL local_flush( 9 )
+
+!
+!-- Adjustment for new MPI-1 coupling. This might be unnecessary.
+#if defined( __mpi2 )
        CALL DVRP_SPLIT( MPI_COMM_WORLD, comm_palm )
+#else
+    IF ( coupling_mode /= 'uncoupled' ) THEN
+       CALL DVRP_SPLIT( comm_inter, comm_palm )
+    ELSE
+       CALL DVRP_SPLIT( MPI_COMM_WORLD, comm_palm )
+    ENDIF
+#endif
+
     WRITE ( 9, * ) '*** myid=', myid, ' nach DVRP_SPLIT'
     CALL local_flush( 9 )
Index: palm/trunk/SOURCE/init_pegrid.f90
===================================================================
--- palm/trunk/SOURCE/init_pegrid.f90	(revision 200)
+++ palm/trunk/SOURCE/init_pegrid.f90	(revision 206)
@@ -4,4 +4,6 @@
 ! Actual revisions:
 ! -----------------
+! Implementation of a MPI-1 coupling: added __parallel within the __mpi2 part
+! 2d-decomposition is default on SGI-ICE systems
 ! ATTENTION: nnz_x undefined problem still has to be solved!!!!!!!!
 ! TEST OUTPUT (TO BE REMOVED) logging mpi2 ierr values
@@ -93,6 +95,7 @@
 !--    Automatic determination of the topology
 !--    The default on SMP- and cluster-hosts is a 1d-decomposition along x
-       IF ( host(1:3) == 'ibm'  .OR.  host(1:3) == 'nec'  .OR. &
-            host(1:2) == 'lc'   .OR.  host(1:3) == 'dec' )  THEN
+       IF ( host(1:3) == 'ibm'  .OR.  host(1:3) == 'nec'      .OR. &
+            ( host(1:2) == 'lc'  .AND.  host(3:5) /= 'sgi' )  .OR. &
+             host(1:3) == 'dec' )  THEN
 
           pdims(1) = numprocs
@@ -540,4 +543,5 @@
 #endif
 
+#if defined( __parallel )
 #if defined( __mpi2 )
 !
@@ -623,4 +627,5 @@
 
     ENDIF
+#endif
 
 !
Index: palm/trunk/SOURCE/local_stop.f90
===================================================================
--- palm/trunk/SOURCE/local_stop.f90	(revision 200)
+++ palm/trunk/SOURCE/local_stop.f90	(revision 206)
@@ -4,6 +4,5 @@
 ! Actual revisions:
 ! -----------------
-! 
-! 
+! Implementation of a MPI-1 coupling: replaced myid with target_id
 !
 ! Former revisions:
@@ -34,4 +33,5 @@
     USE control_parameters
 
+
 #if defined( __parallel )
     IF ( coupling_mode == 'uncoupled' )  THEN
@@ -55,6 +55,6 @@
                 terminate_coupled = 1
                 CALL MPI_SENDRECV( &
-                     terminate_coupled,        1, MPI_INTEGER, myid,  0, &
-                     terminate_coupled_remote, 1, MPI_INTEGER, myid,  0, &
+                     terminate_coupled,        1, MPI_INTEGER, target_id,  0, &
+                     terminate_coupled_remote, 1, MPI_INTEGER, target_id,  0, &
                      comm_inter, status, ierr )
              ENDIF
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 200)
+++ palm/trunk/SOURCE/modules.f90	(revision 206)
@@ -5,5 +5,5 @@
 ! Actual revisions:
 ! -----------------
-! 
+! +target_id
 !
 ! Former revisions:
@@ -973,6 +973,7 @@
 #endif
     CHARACTER(LEN=5)       ::  myid_char = ''
-    INTEGER                ::  id_inflow = 0, id_recycling = 0, myid=0, npex = -1, &
-                               npey = -1, numprocs = 1, numprocs_previous_run = -1,&
+    INTEGER                ::  id_inflow = 0, id_recycling = 0, myid = 0,      &
+                               target_id, npex = -1, npey = -1, numprocs = 1,  &
+                               numprocs_previous_run = -1,                     &
                                tasks_per_node = -9999, threads_per_task = 1
 
Index: palm/trunk/SOURCE/palm.f90
===================================================================
--- palm/trunk/SOURCE/palm.f90	(revision 200)
+++ palm/trunk/SOURCE/palm.f90	(revision 206)
@@ -4,5 +4,6 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Initialization of coupled runs modified for MPI-1 and moved to external
+! subroutine init_coupling
 !
 ! Former revisions:
@@ -77,41 +78,11 @@
     CALL MPI_INIT( ierr )
     CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
+    CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
     comm_palm = MPI_COMM_WORLD
     comm2d    = MPI_COMM_WORLD
-#endif
-
-#if defined( __mpi2 )
-!
-!-- Get information about the coupling mode from the environment variable
-!-- which has been set by the mpiexec command.
-!-- This method is currently not used because the mpiexec command is not
-!-- available on some machines
-!    CALL local_getenv( 'coupling_mode', 13, coupling_mode, i )
-!    IF ( i == 0 )  coupling_mode = 'uncoupled'
-!    IF ( coupling_mode == 'ocean_to_atmosphere' )  coupling_char = '_O'
-
-!
-!-- Get information about the coupling mode from standard input (PE0 only) and
-!-- distribute it to the other PEs
-    CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
-    IF ( myid == 0 )  THEN
-       READ (*,*,ERR=10,END=10)  coupling_mode
-10     IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' )  THEN
-          i = 1
-       ELSEIF ( TRIM( coupling_mode ) ==  'ocean_to_atmosphere' )  THEN
-          i = 2
-       ELSE
-          i = 0
-       ENDIF
-    ENDIF
-    CALL MPI_BCAST( i, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr )
-    IF ( i == 0 )  THEN
-       coupling_mode = 'uncoupled'
-    ELSEIF ( i == 1 )  THEN
-       coupling_mode = 'atmosphere_to_ocean'
-    ELSEIF ( i == 2 )  THEN
-       coupling_mode = 'ocean_to_atmosphere'
-    ENDIF
-    IF ( coupling_mode == 'ocean_to_atmosphere' )  coupling_char = '_O'
+
+!
+!-- Initialize PE topology in case of coupled runs
+    CALL init_coupling
 #endif
 
@@ -124,4 +95,9 @@
     CALL cpu_log( log_point(1), 'total', 'start' )
     CALL cpu_log( log_point(2), 'initialisation', 'start' )
+
+!
+!-- Open a file for debug output
+    WRITE (myid_char,'(''_'',I4.4)')  myid
+    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
 
 !
@@ -132,17 +108,10 @@
 #if defined( __parallel )
     CALL MPI_COMM_RANK( comm_palm, myid, ierr )
-#endif
-
-!
-!-- Open a file for debug output
-    WRITE (myid_char,'(''_'',I4.4)')  myid
-    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
-
-#if defined( __mpi2 )
 !
 !-- TEST OUTPUT (TO BE REMOVED)
     WRITE(9,*) '*** coupling_mode = "', TRIM( coupling_mode ), '"'
     CALL LOCAL_FLUSH( 9 )
-    print*, '*** PE', myid, '  ', TRIM( coupling_mode )
+    PRINT*, '*** PE', myid, ' Global target PE:', target_id, &
+            TRIM( coupling_mode )
 #endif
 
@@ -220,5 +189,5 @@
 #if defined( __mpi2 )
 !
-!-- Test exchange via intercommunicator
+!-- Test exchange via intercommunicator in case of a MPI-2 coupling
     IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
        i = 12345 + myid
@@ -240,3 +209,2 @@
 
  END PROGRAM palm
-
Index: palm/trunk/SOURCE/surface_coupler.f90
===================================================================
--- palm/trunk/SOURCE/surface_coupler.f90	(revision 200)
+++ palm/trunk/SOURCE/surface_coupler.f90	(revision 206)
@@ -4,5 +4,6 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Implementation of a MPI-1 Coupling: replaced myid with target_id,
+! deleted __mpi2 directives
 !
 ! Former revisions:
@@ -32,7 +33,7 @@
     REAL    ::  simulated_time_remote
 
-#if defined( __parallel )  &&  defined( __mpi2 )
+#if defined( __parallel )
 
-    CALL cpu_log( log_point(39), 'surface_coupler', 'start' )
+       CALL cpu_log( log_point(39), 'surface_coupler', 'start' )
 
 !
@@ -43,7 +44,8 @@
 !-- If necessary, the coupler will be called at the beginning of the next 
 !-- restart run.
-    CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER, myid,  0, &
-                       terminate_coupled_remote, 1, MPI_INTEGER, myid,  0, &
-                       comm_inter, status, ierr )
+    CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER, target_id,  &
+                       0, &
+                       terminate_coupled_remote, 1, MPI_INTEGER, target_id,  &
+                       0, comm_inter, status, ierr )
     IF ( terminate_coupled_remote > 0 )  THEN
        IF ( myid == 0 )  THEN
@@ -64,6 +66,7 @@
 !-- Exchange the current simulated time between the models,
 !-- currently just for testing
-    CALL MPI_SEND( simulated_time, 1, MPI_REAL, myid, 11, comm_inter, ierr )
-    CALL MPI_RECV( simulated_time_remote, 1, MPI_REAL, myid, 11, &
+    CALL MPI_SEND( simulated_time, 1, MPI_REAL, target_id, 11, &
+                   comm_inter, ierr )
+    CALL MPI_RECV( simulated_time_remote, 1, MPI_REAL, target_id, 11, &
                    comm_inter, status, ierr )
     WRITE ( 9, * )  simulated_time, ' remote: ', simulated_time_remote
@@ -78,8 +81,6 @@
        WRITE ( 9, * )  '*** send shf to ocean'
        CALL local_flush( 9 )
-       CALL MPI_SEND( shf(nys-1,nxl-1), ngp_xy, MPI_REAL, myid, 12, &
+       CALL MPI_SEND( shf(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 12, &
                       comm_inter, ierr )
-       WRITE ( 9, * )  '    ready'
-       CALL local_flush( 9 )
 
 !
@@ -88,8 +89,6 @@
           WRITE ( 9, * )  '*** send qsws to ocean'
           CALL local_flush( 9 )
-          CALL MPI_SEND( qsws(nys-1,nxl-1), ngp_xy, MPI_REAL, myid, 13, &
+          CALL MPI_SEND( qsws(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 13, &
                comm_inter, ierr )
-          WRITE ( 9, * )  '    ready'
-          CALL local_flush( 9 )
        ENDIF
 
@@ -98,8 +97,6 @@
        WRITE ( 9, * )  '*** receive pt from ocean'
        CALL local_flush( 9 )
-       CALL MPI_RECV( pt(0,nys-1,nxl-1), 1, type_xy, myid, 14, comm_inter, &
-                      status, ierr )
-       WRITE ( 9, * )  '    ready'
-       CALL local_flush( 9 )
+       CALL MPI_RECV( pt(0,nys-1,nxl-1), 1, type_xy, target_id, 14, &
+                      comm_inter, status, ierr )
 
 !
@@ -107,8 +104,6 @@
        WRITE ( 9, * )  '*** send usws to ocean'
        CALL local_flush( 9 )
-       CALL MPI_SEND( usws(nys-1,nxl-1), ngp_xy, MPI_REAL, myid, 15, &
+       CALL MPI_SEND( usws(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 15, &
                       comm_inter, ierr )
-       WRITE ( 9, * )  '    ready'
-       CALL local_flush( 9 )
 
 !
@@ -116,8 +111,6 @@
        WRITE ( 9, * )  '*** send vsws to ocean'
        CALL local_flush( 9 )
-       CALL MPI_SEND( vsws(nys-1,nxl-1), ngp_xy, MPI_REAL, myid, 16, &
+       CALL MPI_SEND( vsws(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 16, &
                       comm_inter, ierr )
-       WRITE ( 9, * )  '    ready'
-       CALL local_flush( 9 )
 
     ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
@@ -127,8 +120,6 @@
        WRITE ( 9, * )  '*** receive tswst from atmosphere'
        CALL local_flush( 9 )
-       CALL MPI_RECV( tswst(nys-1,nxl-1), ngp_xy, MPI_REAL, myid, 12, &
+       CALL MPI_RECV( tswst(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 12, &
                       comm_inter, status, ierr )
-       WRITE ( 9, * )  '    ready'
-       CALL local_flush( 9 )
 
 !
@@ -138,8 +129,6 @@
           WRITE ( 9, * )  '*** receive qswst_remote from atmosphere'
           CALL local_flush( 9 )
-          CALL MPI_RECV( qswst_remote(nys-1,nxl-1), ngp_xy, MPI_REAL, myid, &
-               13, comm_inter, status, ierr )
-          WRITE ( 9, * )  '    ready'
-          CALL local_flush( 9 )
+          CALL MPI_RECV( qswst_remote(nys-1,nxl-1), ngp_xy, MPI_REAL, &
+                         target_id, 13, comm_inter, status, ierr )
 
           !here tswst is still the sum of atmospheric bottom heat fluxes
@@ -165,8 +154,6 @@
        WRITE ( 9, * )  '*** send pt to atmosphere'
        CALL local_flush( 9 )
-       CALL MPI_SEND( pt(nzt,nys-1,nxl-1), 1, type_xy, myid, 14, comm_inter, &
-                      ierr )
-       WRITE ( 9, * )  '    ready'
-       CALL local_flush( 9 )
+       CALL MPI_SEND( pt(nzt,nys-1,nxl-1), 1, type_xy, target_id, 14, &
+                      comm_inter, ierr )
 
 !
@@ -175,8 +162,6 @@
        WRITE ( 9, * )  '*** receive uswst from atmosphere'
        CALL local_flush( 9 )
-       CALL MPI_RECV( uswst(nys-1,nxl-1), ngp_xy, MPI_REAL, myid, 15, &
+       CALL MPI_RECV( uswst(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 15, &
                       comm_inter, status, ierr )
-       WRITE ( 9, * )  '    ready'
-       CALL local_flush( 9 )
 
 !
@@ -185,8 +170,6 @@
        WRITE ( 9, * )  '*** receive vswst from atmosphere'
        CALL local_flush( 9 )
-       CALL MPI_RECV( vswst(nys-1,nxl-1), ngp_xy, MPI_REAL, myid, 16, &
+       CALL MPI_RECV( vswst(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 16, &
                       comm_inter, status, ierr )
-       WRITE ( 9, * )  '    ready'
-       CALL local_flush( 9 )
 
 !
Index: palm/trunk/SOURCE/timestep.f90
===================================================================
--- palm/trunk/SOURCE/timestep.f90	(revision 200)
+++ palm/trunk/SOURCE/timestep.f90	(revision 206)
@@ -4,5 +4,5 @@
 ! Actual revisions:
 ! -----------------
-! 
+! Implementation of a MPI-1 Coupling: replaced myid with target_id
 !
 ! Former revisions:
@@ -219,6 +219,6 @@
              terminate_coupled = 2
              CALL MPI_SENDRECV( &
-                  terminate_coupled,        1, MPI_INTEGER, myid,  0, &
-                  terminate_coupled_remote, 1, MPI_INTEGER, myid,  0, &
+                  terminate_coupled,        1, MPI_INTEGER, target_id,  0, &
+                  terminate_coupled_remote, 1, MPI_INTEGER, target_id,  0, &
                   comm_inter, status, ierr )
           ENDIF
