Index: /palm/trunk/DOC/app/chapter_3.9.html
===================================================================
--- /palm/trunk/DOC/app/chapter_3.9.html	(revision 205)
+++ /palm/trunk/DOC/app/chapter_3.9.html	(revision 206)
@@ -28,5 +28,5 @@
 PALM includes a so-called turbulence recycling method which allows a
 turbulent inflow with non-cyclic horizontal boundary conditions. The
-method follows the one described by Lund et al. (1998, J. Comp. Phys., <span style="font-weight: bold;">140</span>, 233-258), modified by Kataoka and Mizuno (2002, Wind and Structures, <span style="font-weight: bold;">5</span>, 379-392). The method is switched on by setting the initial parameter <a href="chapter_4.1.html#turbulent_inflow">turbulent_inflow</a> = <span style="font-style: italic;">.TRUE.</span>.</p><p style="line-height: 100%;">The turbulent signal A'(y,z) to be imposed at the left inflow boundary is taken from the simulation at a fixed distance x<sub>r</sub> from the inflow (given by parameter <a href="chapter_4.1.html#recycling_width">recycling_width</a>): A'(y,z) = A(x<sub>r</sub>,y,z) - <span style="font-weight: bold;">A(z)</span>, where <span style="font-weight: bold;">A(z)</span>
+method follows the one described by Lund et al. (1998, J. Comp. Phys., <span style="font-weight: bold;">140</span>, 233-258), modified by Kataoka and Mizuno (2002, Wind and Structures, <span style="font-weight: bold;">5</span>, 379-392). The method is switched on by setting the initial parameter <a href="chapter_4.1.html#turbulent_inflow">turbulent_inflow</a> = <span style="font-style: italic;">.TRUE.</span>.</p><p style="line-height: 100%;">The turbulent signal A'(y,z) to be imposed at the left inflow boundary is taken from the same simulation at a fixed distance x<sub>r</sub> from the inflow (given by parameter <a href="chapter_4.1.html#recycling_width">recycling_width</a>): A'(y,z) = A(x<sub>r</sub>,y,z) - <span style="font-weight: bold;">A(z)</span>, where <span style="font-weight: bold;">A(z)</span>
 is the horizontal average between the inflow boundary and the recycling
 plane. The turbulent quantity A'(y,z) is then added to a mean inflow
@@ -39,5 +39,15 @@
 horizontal average from this precursor run is used as the mean inflow
 profile for the main run, the wall-normal velocity component must point
-into the domain at every grid point and its magnitude should be large enough in order to guarantee an inflow even if a turbulence signal is added.</li><li>Since the main run requires &nbsp;...</li><li>The
+into the domain at every grid point and its magnitude should be large
+enough in order to guarantee an inflow even if a turbulence signal is
+added.<br></li><li>The
+main run requires&nbsp;from the precursor run&nbsp;the mean profiles to
+be used at the inflow. For this, the horizontally and temporally
+averaged mean profiles as provided with the standard PALM output are
+used. The user has to set parameters <a href="chapter_4.2.html#dt_data_output_pr">dt_data_output_pr</a>, <a href="chapter_4.2.html#averaging_interval">averaging_interval</a>,
+etc. for the precursor run appropriately, so that an output is done at
+the end of the precursor run. The profile information is then contained
+in the restart (binary) file created at the end of the precursor run
+and can be used by the main run. <span style="font-weight: bold;">It is very important that the mean profiles at the end of the precursor run are in a stationary or quasi-stationary state</span>, because otherwise it may not be justified to use them as constant profiles at the inflow. <span style="font-weight: bold;">Also, turbulence at the end of the precursor run should be fully developed. </span>Otherwise, the main run would need an additional spinup-time at the beginning to get the turbulence to its final stage.<br></li><li>The
 main run has to read the binary data from the precursor run .... &nbsp;
 &nbsp; set bc_lr = 'dirichlet/radiation' ... &nbsp;
Index: /palm/trunk/SCRIPTS/.mrun.config.default
===================================================================
--- /palm/trunk/SCRIPTS/.mrun.config.default	(revision 205)
+++ /palm/trunk/SCRIPTS/.mrun.config.default	(revision 206)
@@ -53,5 +53,5 @@
 %sgi_feature       ice                                        lcsgih parallel
 #%remote_username   <replace by your HLRN username>            lcsgih parallel
-%compiler_name     mpif90                                     lcsgih parallel
+%compiler_name     ifort                                      lcsgih parallel
 %compiler_name_ser ifort                                      lcsgih parallel
 %cpp_options       -DMPI_REAL=MPI_DOUBLE_PRECISION:-DMPI_2REAL=MPI_2DOUBLE_PRECISION:-D__netcdf:-D__netcdf_64bit   lcsgih parallel
@@ -59,5 +59,5 @@
 %netcdf_lib        -L/sw/dataformats/netcdf/3.6.2/lib:-lnetcdf:-lnetcdff      lcsgih parallel
 %fopts             -g:-w:-xT:-O3:-cpp:-openmp:-r8:-ftz:-fno-alias:-no-prec-div:-no-prec-sqrt:-ip:-nbs:-convert:little_endian  lcsgih parallel
-%lopts             -g:-w:-xT:-O3:-cpp:-openmp:-r8:-ftz:-fno-alias:-no-prec-div:-no-prec-sqrt:-ip:-nbs:-Vaxlib:-i-dynamic      lcsgih parallel
+%lopts             -g:-w:-xT:-O3:-cpp:-openmp:-r8:-ftz:-fno-alias:-no-prec-div:-no-prec-sqrt:-ip:-nbs:-Vaxlib:-i-dynamic:-lmpi   lcsgih parallel
 #%tmp_data_catalog  /gfs1/work/<replace by your HLRN username>/palm_restart_data      lcsgih parallel
 #%tmp_user_catalog  /gfs1/tmp/<replace by your HLRN username>                         lcsgih parallel
@@ -65,5 +65,5 @@
 %sgi_feature       ice                                        lcsgih parallel debug
 #%remote_username   <replace by your HLRN username>            lcsgih parallel debug
-%compiler_name     mpif90                                     lcsgih parallel debug
+%compiler_name     ifort                                      lcsgih parallel debug
 %compiler_name_ser ifort                                      lcsgih parallel debug
 %cpp_options       -DMPI_REAL=MPI_DOUBLE_PRECISION:-DMPI_2REAL=MPI_2DOUBLE_PRECISION:-D__netcdf:-D__netcdf_64bit   lcsgih parallel debug
@@ -71,5 +71,5 @@
 %netcdf_lib        -L/sw/dataformats/netcdf/3.6.2/lib:-lnetcdf:-lnetcdff      lcsgih parallel debug
 %fopts             -C:-fpe0:-debug:-traceback:-g:-w:-xT:-O0:-cpp:-r8:-ftz:-fno-alias:-no-prec-div:-no-prec-sqrt:-ip:-nbs:-convert:little_endian  lcsgih parallel debug
-%lopts             -C:-fpe0:-debug:-traceback:-g:-w:-xT:-O0:-cpp:-r8:-ftz:-fno-alias:-no-prec-div:-no-prec-sqrt:-ip:-nbs:-Vaxlib:-i-dynamic      lcsgih parallel debug
+%lopts             -C:-fpe0:-debug:-traceback:-g:-w:-xT:-O0:-cpp:-r8:-ftz:-fno-alias:-no-prec-div:-no-prec-sqrt:-ip:-nbs:-Vaxlib:-lmpi           lcsgih parallel debug
 #%tmp_data_catalog  /gfs1/work/<replace by your HLRN username>/palm_restart_data      lcsgih parallel debug
 #%tmp_user_catalog  /gfs1/tmp/<replace by your HLRN username>                         lcsgih parallel debug
Index: /palm/trunk/SCRIPTS/mbuild
===================================================================
--- /palm/trunk/SCRIPTS/mbuild	(revision 205)
+++ /palm/trunk/SCRIPTS/mbuild	(revision 206)
@@ -94,4 +94,5 @@
      # 21/07/08 - Siggi - mainprog (executable) is added to the tar-file
      #                    ({mainprog}_current_version)
+     # 02/10/08 - Siggi - adapted for lcxt4
 
 
@@ -729,4 +730,5 @@
         (lcsgih)         remote_addres=130.75.4.102;;
         (lctit)          remote_addres=172.17.75.161;;
+        (lcxt4)          remote_addres=129.177.20.113;;
         (decalpha)       remote_addres=165.132.26.56;;
         (ibmb)           remote_addres=130.73.230.10;;
@@ -1235,5 +1237,5 @@
                 ssh  ${remote_username}@${remote_addres} "[[ ! -d ${remote_md} ]]  &&  (echo \"  *** ${remote_md} will be created\"; mkdir -p  ${remote_md})"
              else
-                   # TIT ERLAUBT NUR DIE AUSFÜHRUNG GANZ BESTIMMTER KOMMANDOS
+                   # TIT ERLAUBT NUR DIE AUSFï¿œHRUNG GANZ BESTIMMTER KOMMANDOS
                    # MIT SSH, DESHALB AUFRUF PER PIPE
                 print "[[ ! -d ${remote_md} ]]  &&  (echo \"  *** ${remote_md} will be created\"; mkdir -p  ${remote_md})"  |  ssh ${remote_username}@${remote_addres}  2>&1
@@ -1241,5 +1243,5 @@
              if [[ $local_host = decalpha ]]
              then
-                   # DECALPHA BENUTZT BEI NICHTANGABE DES VOLLSTÄNDIGEN PFADES
+                   # DECALPHA BENUTZT BEI NICHTANGABE DES VOLLSTï¿œNDIGEN PFADES
                    # IRGENDEIN ANDERES SCP (WAS NICHT FUNKTIONIERT). AUSSERDEM
                    # KOENNEN DOLLAR-ZEICHEN NICHT BENUTZT WERDEN
@@ -1258,5 +1260,5 @@
                 ssh  ${remote_username}@${remote_addres}  "cd ${remote_md}; [[ -f ${mainprog}_current_version.tar ]]  &&  tar -xf  ${mainprog}_current_version.tar"
              else
-                   # TIT ERLAUBT NUR DIE AUSFÜHRUNG GANZ BESTIMMTER KOMMANDOS
+                   # TIT ERLAUBT NUR DIE AUSFï¿œHRUNG GANZ BESTIMMTER KOMMANDOS
                    # MIT SSH, DESHALB AUFRUF PER PIPE
                 print  "cd ${remote_md}; [[ -f ${mainprog}_current_version.tar ]]  &&  tar -xf  ${mainprog}_current_version.tar"  |  ssh  ${remote_username}@${remote_addres}  2>&1
@@ -1270,5 +1272,5 @@
                 ssh  ${remote_username}@${remote_addres}  "cd ${remote_md}; tar -xf  ${mainprog}_sources.tar"
              else
-                   # TIT ERLAUBT NUR DIE AUSFÜHRUNG GANZ BESTIMMTER KOMMANDOS
+                   # TIT ERLAUBT NUR DIE AUSFï¿œHRUNG GANZ BESTIMMTER KOMMANDOS
                    # MIT SSH, DESHALB AUFRUF PER PIPE
                 print  "cd ${remote_md}; tar -xf  ${mainprog}_sources.tar"  |  ssh  ${remote_username}@${remote_addres}  2>&1
@@ -1319,4 +1321,9 @@
                    print "cd ${remote_md}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  ${remote_username}@${remote_addres} 2>&1 | tee ${remote_host}_last_make_protokoll
                 done
+
+             elif [[ $remote_host = lcxt4 ]]
+             then
+
+                print "cd ${remote_md}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  ${remote_username}@${remote_addres} 2>&1 | tee ${remote_host}_last_make_protokoll
 
              else
@@ -1357,5 +1364,5 @@
                 ssh  ${remote_username}@${remote_addres}  "cd ${remote_md}; chmod u+w *; tar -cf  ${mainprog}_current_version.tar  ${mainprog}  *.f90 *.o *.mod"
              else
-                   # TIT ERLAUBT NUR DIE AUSFÜHRUNG GANZ BESTIMMTER KOMMANDOS
+                   # TIT ERLAUBT NUR DIE AUSFï¿œHRUNG GANZ BESTIMMTER KOMMANDOS
                    # MIT SSH, DESHALB AUFRUF PER PIPE
                 print  "cd ${remote_md}; chmod u+w *; tar -cf  ${mainprog}_current_version.tar  ${mainprog}  *.f90 *.o *.mod"  |  ssh  ${remote_username}@${remote_addres}  2>&1
@@ -1385,5 +1392,5 @@
                 ssh  ${remote_username}@${remote_addres} "[[ ! -d ${remote_ud} ]]  &&  (echo \"  *** ${remote_ud} will be created\"; mkdir -p  ${remote_ud}); [[ ! -d ${remote_ud}/../SCRIPTS ]]  &&  (echo \"  *** ${remote_ud}/../SCRIPTS will be created\"; mkdir -p ${remote_ud}/../SCRIPTS)"
              else
-                   # TIT ERLAUBT NUR DIE AUSFÜHRUNG GANZ BESTIMMTER KOMMANDOS
+                   # TIT ERLAUBT NUR DIE AUSFï¿œHRUNG GANZ BESTIMMTER KOMMANDOS
                    # MIT SSH, DESHALB AUFRUF PER PIPE
                 print "[[ ! -d ${remote_ud} ]]  &&  (echo \"  *** ${remote_ud} will be created\"; mkdir -p  ${remote_ud}); [[ ! -d ${remote_ud}/../SCRIPTS ]]  &&  (echo \"  *** ${remote_ud}/../SCRIPTS will be created\"; mkdir -p  ${remote_ud}/../SCRIPTS)"  |  ssh ${remote_username}@${remote_addres}  2>&1
@@ -1393,5 +1400,5 @@
              if [[ $local_host = decalpha ]]
              then
-                   # DECALPHA BENUTZT BEI NICHTANGABE DES VOLLSTÄNDIGEN PFADES
+                   # DECALPHA BENUTZT BEI NICHTANGABE DES VOLLSTï¿œNDIGEN PFADES
                    # IRGENDEIN ANDERES SCP (WAS NICHT FUNKTIONIERT). AUSSERDEM
                    # KOENNEN DOLLAR-ZEICHEN NICHT BENUTZT WERDEN
@@ -1409,5 +1416,5 @@
              if [[ $local_host = decalpha ]]
              then
-                   # DECALPHA BENUTZT BEI NICHTANGABE DES VOLLSTÄNDIGEN PFADES
+                   # DECALPHA BENUTZT BEI NICHTANGABE DES VOLLSTï¿œNDIGEN PFADES
                    # IRGENDEIN ANDERES SCP (WAS NICHT FUNKTIONIERT). AUSSERDEM
                    # KOENNEN DOLLAR-ZEICHEN NICHT BENUTZT WERDEN
Index: /palm/trunk/SCRIPTS/mrun
===================================================================
--- /palm/trunk/SCRIPTS/mrun	(revision 205)
+++ /palm/trunk/SCRIPTS/mrun	(revision 206)
@@ -154,4 +154,5 @@
      # 08/08/08 - Marcus - typo removed in lcxt4 branch
      # 17/09/08 - Siggi  - restart mechanism adjusted for lcsgi
+     # 02/10/09 - BjornM - argument "-Y" modified, adjustments for coupled runs
  
     # VARIABLENVEREINBARUNGEN + DEFAULTWERTE
@@ -171,4 +172,6 @@
  cond2="" 
  config_file=.mrun.config
+ coupled_dist=""
+ coupled_mode="mpi1"
  cpp_opts=""
  cpp_options=""
@@ -219,4 +222,6 @@
  node_usage=default
  numprocs=""
+ numprocs_atmos=0
+ numprocs_ocean=0
  OOPT=""
  openmp=false
@@ -262,5 +267,5 @@
 
  typeset -i  iec=0 iic=0 iin=0 ioc=0 iout=0 memory=0 stagein_anz=0 stageout_anz=0
- typeset -i  cputime i ii iii icycle inode ival jobges jobsek maxcycle minuten nodes pes sekunden tp1
+ typeset -i  cputime i ii iia iii iio icycle inode ival jobges jobsek maxcycle minuten nodes pes sekunden tp1
 
  typeset  -R30 calltime
@@ -381,5 +386,5 @@
     # SHELLSCRIPT-OPTIONEN EINLESEN UND KOMMANDO NEU ZUSAMMENSETZEN, FALLS ES
     # FUER FOLGEJOBS BENOETIGT WIRD
- while  getopts  :a:AbBc:Cd:D:Fg:G:h:H:i:IkK:m:M:n:o:Op:P:q:r:R:s:St:T:u:U:vxX:Y option
+ while  getopts  :a:AbBc:Cd:D:Fg:G:h:H:i:IkK:m:M:n:o:Op:P:q:r:R:s:St:T:u:U:vxX:Y: option
  do
    case  $option  in
@@ -420,5 +425,5 @@
        (x)   do_trace=true;set -x; mc="$mc -x";;
        (X)   numprocs=$OPTARG; mc="$mc -X$OPTARG";;
-       (Y)   run_coupled_model=true; mc="$mc -Y";;
+       (Y)   run_coupled_model=true; coupled_dist=$OPTARG; mc="$mc -Y'$OPTARG'";;
        (\?)  printf "\n  +++ unknown option $OPTARG \n"
              printf "\n  --> type \"$0 ?\" for available options \n"
@@ -437,5 +442,5 @@
  then
    (printf "\n  *** mrun can be called as follows:\n"
-    printf "\n      $mrun_script_name  -b -c.. -d.. -D.. -f.. -F -h.. -i.. -I -K.. -m.. -o.. -p.. -r.. -R -s.. -t.. -T.. -v -x -X..  <modus>\n"
+    printf "\n      $mrun_script_name  -b -c.. -d.. -D.. -f.. -F -h.. -i.. -I -K.. -m.. -o.. -p.. -r.. -R -s.. -t.. -T.. -v -x -X.. -Y.. <modus>\n"
     printf "\n      Description of available options:\n"
     printf "\n      Option  Description                              Default-Value"
@@ -475,5 +480,6 @@
     printf "\n        -x    tracing of mrun for debug purposes       ---"
     printf "\n        -X    # of processors (on parallel machines)   1"
-    printf "\n        -Y    run coupled model                        ---"
+    printf "\n        -Y    run coupled model, \"#1 #2\" with" 
+    printf "\n              #1 atmosphere and #2 ocean processors    \"#/2 #/2\" depending on -X"
     printf "\n "
     printf "\n      Possible values of positional parameter <modus>:"
@@ -509,5 +515,5 @@
  while read line
  do
-    if [[ "$line" != ""  ||  $(echo $line | cut -c1) != "#" ]]
+    if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" ]]
     then
        HOSTNAME=`echo $line | cut -d" " -s -f2`
@@ -530,5 +536,4 @@
     locat=localhost; exit
  fi
-
 
 
@@ -586,5 +591,5 @@
     do_remote=true
     case  $host  in
-        (ibm|ibmb|ibmh|ibms|ibmy|nech|neck|lcsgib|lcsgih|lctit|unics)  true;;
+        (ibm|ibmb|ibmh|ibms|ibmy|nech|neck|lcsgib|lcsgih|lctit|unics|lcxt4)  true;;
         (*)  printf "\n"
              printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
@@ -609,4 +614,60 @@
        locat=options; exit
     fi
+ fi
+
+
+      # KOPPLUNGSEIGENSCHAFTEN (-Y) AUSWERTEN UND coupled_mode BESTIMMEN
+ if [[ $run_coupled_model = true ]] 
+ then
+
+    if  [[ -n $coupled_dist ]]
+    then
+
+       numprocs_atmos=`echo $coupled_dist | cut -d" " -s -f1`
+       numprocs_ocean=`echo $coupled_dist | cut -d" " -s -f2`
+
+       if (( $numprocs_ocean + $numprocs_atmos != $numprocs ))
+       then
+
+          printf "\n  +++ number of processors does not fit to specification by \"-Y\"."
+          printf "\n      PEs (total)     : $numprocs"
+          printf "\n      PEs (atmosphere): $numprocs_atmos"
+          printf "\n      PEs (ocean)     : $numprocs_ocean"
+          locat=coupling; exit
+
+          # REARRANGING BECAUSE CURRENTLY ONLY 1:1 TOPOLOGIES ARE SUPPORTED
+          # THIS SHOULD BE REMOVED IN FUTURE
+       elif (( $numprocs_ocean != $numprocs_atmos ))
+       then
+
+          printf "\n  +++ currently only 1:1 topologies are supported"
+          printf "\n      PEs (total)     : $numprocs"
+          printf "\n      PEs (atmosphere): $numprocs_atmos"
+          printf "\n      PEs (ocean)     : $numprocs_ocean"
+          (( numprocs_atmos = $numprocs / 2 ))
+          (( numprocs_ocean = $numprocs / 2 ))
+          printf "\n  +++ rearranged topology to $numprocs_atmos:$numprocs_ocean"
+
+       fi
+
+    else
+
+       (( numprocs_ocean = $numprocs / 2 ))
+       (( numprocs_atmos = $numprocs / 2 ))
+
+    fi
+    coupled_dist=`echo "$numprocs_atmos $numprocs_ocean"`
+
+       # GET coupled_mode FROM THE CONFIG FILE
+    line=""
+    grep  "%cpp_options.*-D__mpi2.*$host" $config_file  >  tmp_mrun
+    while read line
+    do
+       if [[ "$line" != ""  &&  $(echo $line | cut -c1) != "#" &&  ( $(echo $line | cut -d" " -s -f4) = $cond1 || $(echo $line | cut -d" " -s -f4)  = $cond2 ) ]]
+       then
+          coupled_mode="mpi2"
+       fi
+    done < tmp_mrun
+
  fi
 
@@ -705,5 +766,5 @@
                    do_remote=true
                    case  $host  in
-                       (ibm|ibms|ibmy|lcsgib|lcsgih|lctit|nech|neck|unics)  true;;
+                       (ibm|ibms|ibmy|lcsgib|lcsgih|lctit|nech|neck|unics|lcxt4)  true;;
                        (*)  printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
                             printf "\n      is not available"
@@ -960,5 +1021,5 @@
     do_remote=true
     case  $host  in
-        (ibm|ibmb|ibmh|ibms|ibmy|lcsgib|lcsgih|lctit|nech|neck|unics)  true;;
+        (ibm|ibmb|ibmh|ibms|ibmy|lcsgib|lcsgih|lctit|nech|neck|unics|lcxt4)  true;;
         (*)  printf "\n"
              printf "\n  +++ sorry: execution of batch jobs on remote host \"$host\""
@@ -2867,42 +2928,53 @@
                 fi
              else
-                ((  iii = ii / 2 ))
-                echo "atmosphere_to_ocean"  >  runfile_atmos
-                echo "ocean_to_atmosphere"  >  runfile_ocean
-
-                printf "\n      coupled run ($iii atmosphere, $iii ocean)"
+
+                    # currently there is no full MPI-2 support on ICE and XT4
+                (( iia = $numprocs_atmos / $threads_per_task ))
+                (( iio = $numprocs_ocean / $threads_per_task ))
+                printf "\n      coupled run ($iia atmosphere, $iio ocean)"
+                printf "\n      using $coupled_mode coupling"
                 printf "\n\n"
 
-                if [[ $host = lcsgih  ||  $host = lcsgib ]]
+                if [[ $coupled_mode = "mpi2" ]]
                 then
-
-                   mpiexec  -n $iii  a.out  $ROPTS  <  runfile_atmos &
-                   mpiexec  -n $iii  a.out  $ROPTS  <  runfile_ocean &
-#                   head  -n $iii  $PBS_NODEFILE  >  nodefile_atmos
-#                   echo "--- nodefile_atmos:"
-#                   cat nodefile_atmos
-#                   tail  -n $iii  $PBS_NODEFILE  >  nodefile_ocean
-#                   echo "--- nodefile_ocean:"
-#                   cat nodefile_ocean
-#                   export  PBS_NODEFILE=${PWD}/nodefile_atmos
-#                   mpiexec_mpt -np $iii   ./a.out  $ROPTS  <  runfile_atmos &
-#                   export  PBS_NODEFILE=${PWD}/nodefile_ocean
-#                   mpiexec_mpt -np $iii   ./a.out  $ROPTS  <  runfile_ocean &
-
-
-                elif [[ $host = lcxt4 ]]
-                then
-                   aprun  -n $iii  -N $tasks_per_node  a.out < runfile_atmos  $ROPTS  &
-                   aprun  -n $iii  -N $tasks_per_node  a.out < runfile_ocean  $ROPTS  &
+                   echo "atmosphere_to_ocean $iia $iio"  >  runfile_atmos
+                   echo "ocean_to_atmosphere $iia $iio"  >  runfile_ocean
+                   if [[ $host = lcsgih  ||  $host = lcsgib ]]
+                   then
+
+                      mpiexec_mpt -np $iia  ./palm  $ROPTS < runfile_atmos &
+                      mpiexec_mpt -np $iio  ./palm  $ROPTS < runfile_ocean &
+
+                   elif [[ $host = lcxt4 ]]
+                   then
+
+                      aprun  -n $iia  -N $tasks_per_node  a.out < runfile_atmos  $ROPTS  &
+                      aprun  -n $iio  -N $tasks_per_node  a.out < runfile_ocean  $ROPTS  &
+
+                   else
+                          # WORKAROUND BECAUSE mpiexec WITH -env option IS NOT AVAILABLE ON SOME SYSTEMS
+                       mpiexec  -machinefile hostfile  -n $iia  a.out  $ROPTS  <  runfile_atmos &
+                       mpiexec  -machinefile hostfile  -n $iio  a.out  $ROPTS  <  runfile_ocean &
+#                       mpiexec  -machinefile hostfile  -n $iia  -env coupling_mode atmosphere_to_ocean  a.out  $ROPTS  &
+#                       mpiexec  -machinefile hostfile  -n $iio  -env coupling_mode ocean_to_atmosphere  a.out  $ROPTS  &
+                   fi
+                   wait
+
                 else
 
-                      # WORKAROUND BECAUSE mpiexec WITH -env option IS NOT AVAILABLE ON SOME SYSTEMS
-                   mpiexec  -machinefile hostfile  -n $iii  a.out  $ROPTS  <  runfile_atmos &
-                   mpiexec  -machinefile hostfile  -n $iii  a.out  $ROPTS  <  runfile_ocean &
-#                   mpiexec  -machinefile hostfile  -n $iii  -env coupling_mode atmosphere_to_ocean  a.out  $ROPTS  &
-#                   mpiexec  -machinefile hostfile  -n $iii  -env coupling_mode ocean_to_atmosphere  a.out  $ROPTS  &
+                   echo "coupled_run $iia $iio"  >  runfile_atmos
+                   if [[ $host = lcsgih  ||  $host = lcsgib ]]
+                   then
+
+                      mpiexec_mpt  -np $ii  a.out  $ROPTS  <  runfile_atmos
+
+                   elif [[ $host = lcxt4 ]]
+                   then
+
+                      aprun  -n $ii  -N $tasks_per_node  a.out < runfile_atmos  $ROPTS
+
+                   fi
+                   wait
                 fi
-                wait
-             fi
 
 #             if [[ $scirocco = true ]]
@@ -2912,5 +2984,5 @@
 #                mpirun  -machinefile hostfile  -np $ii  a.out  $ROPTS
 #             fi
-
+             fi
           elif [[ $host = decalpha ]]
           then
@@ -3778,5 +3850,5 @@
     [[ $delete_temporary_catalog = false ]]  &&  mrun_com=${mrun_com}" -B"
     [[ $node_usage != default  &&  "$(echo $node_usage | cut -c1-3)" != "sla"  &&  $node_usage != novice ]]  &&  mrun_com=${mrun_com}" -n $node_usage"
-    [[ $run_coupled_model = true ]]  &&  mrun_com=${mrun_com}" -Y"
+    [[ $run_coupled_model = true ]]  &&  mrun_com=${mrun_com}" -Y \"$coupled_dist\""
     if [[ $do_remote = true ]]
     then
Index: /palm/trunk/SCRIPTS/subjob
===================================================================
--- /palm/trunk/SCRIPTS/subjob	(revision 205)
+++ /palm/trunk/SCRIPTS/subjob	(revision 206)
@@ -94,4 +94,6 @@
      # 14/07/08 - Siggi - adjustments for lcsgih
      # 23/09/08 - Gerald- paesano admitted
+     # 02/10/08 - Siggi - PBS adjustments for lcxt4
+
 
 
@@ -646,10 +648,10 @@
 #!/bin/ksh
 #PBS -N $job_name
-#PBS -A nersc
+#PBS -A geofysisk
 #PBS -l walltime=$timestring
 #PBS -l nodes=${nodes}:ppn=$tasks_per_node
 #PBS -l pmem=${memory}mb
 #PBS -m abe
-#PBS -M igore@nersc.no
+#PBS -M bjorn.maronga@student.uib.no
 #PBS -o $remote_dayfile
 #PBS -j oe
@@ -662,10 +664,10 @@
 #!/bin/ksh
 #PBS -N $job_name
-#PBS -A nersc
+#PBS -A geofysisk
 #PBS -l walltime=$timestring
 #PBS -l ncpus=1
 #PBS -l pmem=${memory}mb
 #PBS -m abe
-#PBS -M igore@nersc.no
+#PBS -M bjorn.maronga@student.uib.no
 #PBS -o $remote_dayfile
 #PBS -j oe
@@ -730,12 +732,12 @@
 #PBS -S /bin/ksh
 #PBS -N $job_name
-#PBS -A nersc
+#PBS -A geofysisk
+#PBS -j oe
 #PBS -l walltime=$timestring
 #PBS -l mppwidth=${numprocs}
 #PBS -l mppnppn=${tasks_per_node}
 #PBS -m abe
-#PBS -M igore@nersc.no
+#PBS -M bjorn.maronga@student.uib.no
 #PBS -o $remote_dayfile
-#PBS -e $remote_dayfile
 
 %%END%%
@@ -746,12 +748,12 @@
 #PBS -S /bin/ksh
 #PBS -N $job_name
-#PBS -A nersc
+#PBS -A geofysisk
+#PBS -j oe
 #PBS -l walltime=$timestring
 #PBS -l ncpus=1
 #PBS -l pmem=${memory}mb
 #PBS -m abe
-#PBS -M igore@nersc.no
+#PBS -M bjorn.maronga@student.uib.no
 #PBS -o $remote_dayfile
-#PBS -e $remote_dayfile
 
 %%END%%
@@ -1118,5 +1120,5 @@
           ssh  $remote_addres  -l $remote_user  "cd $job_catalog; $submcom $job_on_remhost; rm $job_on_remhost"
        else
-             # TIT ERLAUBT NUR DIE AUSFÜHRUNG GANZ BESTIMMTER KOMMANDOS
+             # TIT ERLAUBT NUR DIE AUSFï¿œHRUNG GANZ BESTIMMTER KOMMANDOS
              # MIT SSH, DESHALB AUFRUF PER PIPE
              # UEBERGANGSWEISE CHECK, OB N1GE ENVIRONMENT WIRKLICH VERFUEGBAR
Index: /palm/trunk/SOURCE/CURRENT_MODIFICATIONS
===================================================================
--- /palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 205)
+++ /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 205)
+++ /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 205)
+++ /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 205)
+++ /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 205)
+++ /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 205)
+++ /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 205)
+++ /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 205)
+++ /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 205)
+++ /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 205)
+++ /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 205)
+++ /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 205)
+++ /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
