Index: dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/README
===================================================================
--- dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/README	(revision 3978)
+++ dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/README	(revision 3978)
@@ -0,0 +1,57 @@
+Overview
+========
+
+This directory contains :
+* .def files for DYNAMICO and LMDZ5
+* .xml files for XIOS
+* scripts
+
+You can safely modify all *.def and *.xml or replace them with your own files, EXCEPT :
+* iodef.xml
+* icosa.xml
+* context_lmdz.xml
+* run.def
+* start.def
+
+The above files CAN NOT be used 'as is' because they contain keywords that must be replaced by acceptable values. This substitution is made by the scripts described below (see "Procedure"). The keywords are :
+    CE0L         : true if the simulation is a 'CE0L' run that creates the limit.nc file
+    FIRST        : true if the simulation is the first run in a series (after a 'CE0L' run)
+    NEXT	 : true if the simulation is a restart of a run of type 'FIRST' or 'NEXT'
+    DOM_OUT      : dom_glo if CE0L, dom_regular otherwise
+    USING_SERVER : false if CE0L, true otherwise
+    ETAT0        : start_file if NEXT, held_suarez otherwise
+    IFLAG_PHYS   : 103 if CE0L, 1 otherwise
+    READ_START	 : no if CE0L, yes otherwise
+
+For 'CE0L' XIOS is run in 'attached' mode. In server mode, xios_server.exe would hang after the dynamico_lmdz.exe MPI processes have aborted. 
+For 'START' and 'NEXT', XIOS is run in server mode for flexibility. Especially it allows to restart with a different number of processors, which is not possible in attached mode.
+
+Notice that the definitions of start.def have the highest priority since start.def is the last *.def file included in run.def .
+
+Procedure
+=========
+0 - First of all define a few environment variables 
+  ARCH : This will select appropriate machine-specific parts of the scripts, especially when generating the shell script to be submitted to the batch scheduler
+  ESM_ROOT : the directory containing the ICOSA_LMDZ directory
+> export ARCH=X64_CURIE
+> export ESM_ROOT=$PWD/../..
+
+1 - Edit the .def and .xml files if you want settings that differ from the basis that is proposed here. DO NOT TOUCH the files mentioned above.
+
+2 - In order to create a run of type 'ce0l' :
+> ./prepare ce0l MYDIR0 STORE0
+This will create STORE0 and MYDIR0 if necessary and populate MYDIR0 with .xml and .def files, as well as a batch job 'job.sh' to be submitted (on CURIE) as :
+ccc_msub job.sh .
+After successful completion, STORE0 contains all *.nc files produced by the run, especially limit.nc
+
+3 - In order to create a one-year run of type 'first'
+> ./prepare first STORE0 MYDIR1 STORE1
+This will create STORE1 and MYDIR1 if necessary and populate MYDIR1 with .xml and .def files, as well as a batch job 'job.sh'. This batch job copies input files from STORE0. Submit MYDIR1/job.sh . After successful completion, STORE1 contains all *.nc files produced by the run, especially start.nc
+
+4 - In order to create a one-year run of type NEXT, type
+./prepare first STORE0 STOREPREV MYDIR2 STORE2
+This will create STORE2 and MYDIR2 if necessary and populate MYDIR2 with .xml and .def files, as well as a batch job 'job.sh'. This batch job copies input files from STORE0 and STOREPREV. Submit MYDIR2/job.sh .
+
+Example
+=======
+See example.sh for an example (works on Curie).
Index: dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/context_lmdz.xml
===================================================================
--- dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/context_lmdz.xml	(revision 3973)
+++ dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/context_lmdz.xml	(revision 3978)
@@ -167,5 +167,5 @@
     </domain_group>
 
-    <domain id="regular" ni_glo="96" nj_glo="95" type="rectilinear"  >
+    <domain id="dom_regular" ni_glo="96" nj_glo="95" type="rectilinear"  >
       <generate_rectilinear_domain/>
       <interpolate_domain order="1"/>
@@ -200,5 +200,5 @@
     </domain>
     
-    <domain id="dom_out" domain_ref="dom_glo"/>
+    <domain id="dom_out" domain_ref="DOM_OUT"/>
  
   </domain_definition>
Index: dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/example.sh
===================================================================
--- dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/example.sh	(revision 3978)
+++ dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/example.sh	(revision 3978)
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+function cmd_create()
+{
+    export ESM_ROOT="$PWD/../../"
+    export ARCH=X64_CURIE
+    STORE_ROOT="$STOREDIR/aquaplanet"
+    STORE0L="$STORE_ROOT/ce0l"
+    for DIR in ce0l year01 year02 ; do
+	rm -rf $DIR $STORE_ROOT/$DIR
+    done
+    ./prepare.sh ce0l                                ce0l   "$STORE0L"
+    ./prepare.sh first $STORE0L                      year01 "$STORE_ROOT/year01"
+    ./prepare.sh next  $STORE0L "$STORE_ROOT/year01" year02 "$STORE_ROOT/year02"
+}
+
+function submit_X64_CURIE()
+{
+    EXP=$1 ; shift
+    CMD="ccc_msub $* $EXP/job.sh"
+    MSG=$($CMD)
+    echo "$CMD : $MSG"
+    JOBID=$( echo "$MSG" | awk '{print $NF}' )
+    DEP="-a $JOBID"
+}
+
+function cmd_submit()
+{
+    DEP=""
+    submit_$ARCH ce0l
+    submit_$ARCH year01 $DEP
+    submit_$ARCH year02 $DEP
+}
+
+function cmd_()
+{
+echo
+}
+
+echo "Your command : $0 $*"
+echo "Usage : $0 [create|submit]"
+ARCH=X64_CURIE
+cmd_$1
Index: dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/iodef.xml
===================================================================
--- dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/iodef.xml	(revision 3973)
+++ dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/iodef.xml	(revision 3978)
@@ -10,5 +10,5 @@
 
         	<variable_group id="parameters" >
-        		<variable id="using_server" type="bool">true</variable>
+        		<variable id="using_server" type="bool">USING_SERVER</variable>
         		<variable id="info_level" type="int">100</variable>
         	</variable_group>
Index: dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/prepare.sh
===================================================================
--- dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/prepare.sh	(revision 3978)
+++ dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/prepare.sh	(revision 3978)
@@ -0,0 +1,262 @@
+#!/bin/bash
+
+#---------------------- Arguments ------------------
+
+function fullpath() {
+    mkdir -p $(dirname "$1")
+    echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
+}
+
+function readargs_ce0l() {
+    MYDIR=$(fullpath $2)
+    MYSTORE=$(fullpath $3)
+    mkdir -p $MYDIR
+    mkdir -p $MYSTORE
+    ln -sf $MYSTORE $MYDIR/store 
+    echo "ce0l : MYDIR=$MYDIR MYSTORE=$MYSTORE"
+}
+
+function readargs_first() {
+    STORE0=$(fullpath $2)
+    MYDIR=$(fullpath $3)
+    MYSTORE=$(fullpath $4)
+    mkdir -p $MYDIR
+    mkdir -p $MYSTORE
+    ln -sf $STORE0 $MYDIR/store0 
+    ln -sf $MYSTORE $MYDIR/store 
+}
+
+function readargs_next() {
+    STORE0=$(fullpath $2)
+    STOREPREV=$(fullpath $3)
+    MYDIR=$(fullpath $4)
+    MYSTORE=$(fullpath $5)
+    mkdir -p $MYDIR
+    mkdir -p $MYSTORE
+    ln -sf $STORE0 $MYDIR/store0 
+    ln -sf $STOREPREV $MYDIR/store_prev 
+    ln -sf $MYSTORE $MYDIR/store 
+}
+
+function check_env()
+{
+    if [ "$ARCH" == "" ] ; then
+	echo 'You must define environment variables ARCH and ESM_ROOT'
+	exit 1
+    fi
+    if [ "$ESM_ROOT" == "" ] ; then
+	echo 'You must define environment variables ARCH and ESM_ROOT'
+	exit 1
+    fi
+    XIOS_SERVER="${ESM_ROOT}/XIOS/bin/xios_server.exe"
+    if [ ! -f "${XIOS_SERVER}" ]; then
+	echo "${XIOS_SERVER} not found, check that ESM_ROOT=$ESM_ROOT points to the correct location"
+    fi
+    
+}
+
+#---------------- Keyword substitution -------------
+
+function def() {
+    echo "s/$1/$2/g"
+}
+
+function sed_ce0l() {
+    def USING_SERVER false
+    def DOM_OUT dom_glo
+    def CE0L yes
+    def READ_START no
+    def IFLAG_PHYS 103
+    def ETAT0 held_suarez
+}
+
+function sed_first() {
+    def USING_SERVER true
+    def DOM_OUT dom_regular
+    def CE0L no
+    def READ_START yes
+    def IFLAG_PHYS 1
+    def ETAT0 held_suarez
+}
+
+function sed_next() {
+    def USING_SERVER true
+    def DOM_OUT dom_regular
+    def CE0L no
+    def READ_START yes
+    def IFLAG_PHYS 1
+    def ETAT0 start_file
+}
+
+#------------ Batch jobs : machine-independent prologues and epilogues  --------------
+
+function prologue_all() {
+cat <<EOF 
+cd ${MYDIR}
+rm -rf gcm.log *.nc xios_*.err xios_*.out gcm.log logs
+
+cat <<END  > killme.sh
+#!/bin/bash
+ccc_mdel \${BRIDGE_MSUB_JOBID}
+END
+chmod a+x killme.sh
+
+ulimit -s unlimited
+
+EOF
+cat $ESM_ROOT/ICOSA_LMDZ/arch.env
+}
+
+function prologue_first() {
+cat <<EOF 
+cp -f store0/limit.nc store0/startphy.nc .
+EOF
+}
+
+function prologue_next() {
+cat <<EOF 
+cp -f store0/limit.nc .
+cp -f store_prev/restartphy.nc startphy.nc
+cp -f store_prev/restart.nc start.nc
+EOF
+}
+
+function epilogue_ce0l(){
+    cat <<EOF
+# save useful files
+mv limit.nc startphy.nc store/
+EOF
+}
+
+function epilogue_first(){
+    cat <<EOF
+# remove input files to avoid storing them a few lines below
+rm -f limit.nc startphy.nc
+# save useful files
+mv restartphy.nc restart.nc store/
+EOF
+}
+
+function epilogue_next(){
+    cat <<EOF
+# remove input files to avoid storing them a few lines below
+rm -f limit.nc startphy.nc start.nc
+# save useful files
+mv restartphy.nc restart.nc store/
+EOF
+}
+
+function epilogue_all() {
+    cat <<EOF
+cp *.def *.xml job.sh store/
+mv apbp.nc hist*.nc xios_*.err xios_*.out gcm.log store/
+ls -l > store/ls
+# cleanup
+rm -f *.nc
+EOF
+}
+
+#------------ Batch jobs : machine-dependent main script : X64_CURIE  --------------
+
+function batch_X64_CURIE_ce0l() {
+cat <<EOF
+#!/bin/bash
+## Request name
+#MSUB -r aqua_ce0l_mpi
+#MSUB -q standard 
+#MSUB -A gen7548
+#MSUB -x
+## Number of tasks (=MPI processes) to use
+#MSUB -n 16
+## Elapsed time limit in seconds
+#MSUB -T 600
+## Quality of Service required (long [3 days], normal [1 day], test [30 min])
+#MSUB -Q normal
+
+$( prologue_all )
+date > gcm.log
+export OMP_NUM_THREADS=1
+ccc_mprun $ICOSA_LMDZ >> gcm.log
+date >> gcm.log
+$( epilogue_ce0l )
+$( epilogue_all )
+EOF
+}
+
+function batch_X64_CURIE_first() {
+batch_X64_CURIE first
+}
+
+function batch_X64_CURIE_next() {
+batch_X64_CURIE next
+}
+
+function batch_X64_CURIE() { # $1 = first or next
+cat <<EOF
+#!/bin/bash
+## Request name
+#MSUB -r aqua_$1_mpi
+#MSUB -q standard 
+#MSUB -A gen7548
+#MSUB -x
+## Number of tasks (=MPI processes) to use
+#MSUB -n 176
+## Elapsed time limit in seconds
+#MSUB -T 7200
+## Quality of Service required (long [3 days], normal [1 day], test [30 min])
+#MSUB -Q normal
+
+$( prologue_all )
+$( prologue_$1 )
+date > gcm.log
+export OMP_NUM_THREADS=1
+ccc_mprun -f mpmd.conf >> gcm.log
+date >> gcm.log
+$( epilogue_$1 )
+$( epilogue_all )
+EOF
+
+cat <<EOF > $MYDIR/mpmd.conf
+160 $ICOSA_LMDZ
+16 $XIOS_SERVER
+EOF
+
+}
+
+#--------------------- Main --------------------
+
+echo
+echo
+echo "Your command : $0 $*"
+echo "Working directory : $PWD"
+
+check_env || exit 1
+
+XIOS_SERVER=$(fullpath "$ESM_ROOT/XIOS/bin/xios_server.exe")
+ICOSA_LMDZ=$(fullpath "$ESM_ROOT/ICOSA_LMDZ/bin/icosa_lmdz.exe")
+
+TYPE=$1
+readargs_$TYPE $*
+
+# avoid destroying xml and def files in case of mistake
+chmod a-w *.def *.xml
+
+MYSED=$(mktemp)
+sed_$TYPE > $MYSED
+cat $MYSED
+for FILE in *.def *.xml ; do
+    sed -f $MYSED $FILE > $MYDIR/$FILE
+done
+rm -f $MYSED
+
+chmod u+w *.def *.xml
+
+cd $MYDIR
+batch_${ARCH}_${TYPE} > job.sh
+
+#ls -l $MYDIR
+grep using_server iodef.xml
+grep dom_out context_lmdz.xml
+for KEY in read_start iflag_phys etat0 run_length; do
+    grep $KEY *.def
+done
Index: dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/run.def
===================================================================
--- dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/run.def	(revision 3973)
+++ dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/run.def	(revision 3978)
@@ -6,8 +6,8 @@
 INCLUDEDEF=orchidee.def
 INCLUDEDEF=output.def
-#INCLUDEDEF=gcm.def
 INCLUDEDEF=config.def
 INCLUDEDEF=run_icosa.def
 INCLUDEDEF=earth_const.def
+INCLUDEDEF=start.def
 
 ## Type de calendrier utilise
@@ -19,6 +19,6 @@
 anneeref=1980
 
-## nb jour du run (LMDZ only)
-nday=1
+# Deactivate annual cycle
+solarlong0 = 1000.
 
 ## Remise a zero de la date initiale
@@ -26,13 +26,2 @@
 ## niveau d'impression de controle
 prt_level=0
-
-#physique : iflag_phy 1 : standard avec redemarage : 101 start aquaplanet 
-#iflag_phys=1
-iflag_phys=101
-
-## avec ou sans fichiers de demarrage (start.nc, startphy.nc) ?
-## (sans fichiers de demarrage, initialisation des champs par iniacademic
-##  dans la dynamique)
-read_start=n
-
-create_etat0_limit=no
Index: dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/run_icosa.def
===================================================================
--- dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/run_icosa.def	(revision 3973)
+++ dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/run_icosa.def	(revision 3978)
@@ -1,4 +1,2 @@
-INCLUDEDEF=earth_const.def
-mpi_threading_mode=funneled
 # ------------------------------- Mesh ---------------------------------
 
@@ -10,6 +8,6 @@
 
 # sub splitting of main rhombus : integer (default=1)
-nsplit_i=2
-nsplit_j=2
+nsplit_i=4
+nsplit_j=4
 omp_level_size=1
 
@@ -20,19 +18,8 @@
 disvert=std
 
-# ncar_dz : model layer thickness in meters: real (default=400) 
-# used if disvert=ncar
-ncar_dz=1000.
-
 # optim_it : mesh optimisation : number of iteration : integer (default=0)
-#optim_it=1000
 optim_it=1000
 
 # ---------------------------------- Time---------------------------------
-
-# scheme type : string ( default='runge_kutta') euler, leapfrog_matsuno, runge_kutta )
-scheme = RK2.5
-
-# matsuno period : integer ( default=5)
-matsuno_period = 5
 
 # timestep : real (default=480s)
@@ -44,18 +31,13 @@
 itau_adv=2
 
-# number of timestep (default 100)
-# itaumax = 10
-
 # run length : real (default=dt*itaumax)
-run_length=864000
-#run_length=31104000
-#run_length=2592000
-#run_length=172800
+#run_length=864000
+run_length=31104000
 
 # output field period : integer (default none)
 write_period=86400
-# write_period=14400
 
 itau_check_conserv=100
+
 # ---------------------------------- Misc --------------------------------
 
@@ -66,30 +48,6 @@
 out_pression_level=85000
 
-# etat0 : initial state : string (default=jablonowsky06) : 
-# jablonowsky06, academic, ncar
-
-#etat0=academic
-etat0=held_suarez
-#etat0=database
-#etat0=start_file
 start_file_name=start
 restart_file_name=restart
-
-# ------------------------------ Dynamics --------------------------------
-
-# caldyn : computation type for gcm equation : string (default=gcm) : gcm, adv
-caldyn=gcm
-
-# caldyn_conserv : string (default=energy) : energy,enstrophy
-caldyn_conserv=energy
-
-# caldyn_exner : scheme for computing Exner function : string (default=direct) : direct,lmdz
-caldyn_exner=direct
-
-# caldyn_hydrostat : scheme for computing geopotential : string (default=direct) : direct,lmdz
-caldyn_hydrostat=direct
-
-# guided_type : string (default=none) : none, ncar
-guided_type=none
 
 # ---------------------------------- Dissipation ---------------------------------
@@ -113,40 +71,8 @@
 niterdivgrad=2
 
-# Rayleigh friction : string (default=none) : none, dcmip2_schaer_noshear, dcmip2_schaer_shear
-rayleigh_friction_type=none
-
 # -------------------------------- Physics -------------------------------------
-
-itau_physics=4
 
 # kind of physics : string : none, dcmip (default=none)
 physics=phys_external
 
-# testcase physics for dcmip : INTEGER : 1, 2 (default=1)
-dcmip_physics=1
-
-# -------------------- parameters for NCAR test cases ------------------------
-
-# NCAR advection test, initial tracer : string ( default='cos_bell')
-# const, slotted_cyl, cos_bell, dbl_cos_bell_q1, dbl_cos_bell_q2, complement, hadley
-ncar_adv_shape=cos_bell
-
-# NCAR advection test, wind field : string (default='deform') : solid, deform, hadley
-ncar_adv_wind=solid
-
-# ncar_T0 : reference temperature for NCAR test cases : real (default=300) 
-# also used by disvert if disvert=ncar
-ncar_T0=300
-
-# ncar_p0 : reference pressure for NCAR test cases : real (default=1e5) 
-# also used by disvert if disvert=ncar
-ncar_p0=1e5
-
-# ncar_disvert_c : exponent for B(eta) : integer (default=1)
-# used by disvert if disvert=ncar
-
-ncar_disvert_c=1
-
-# dcmip 4 testcase : integer (default=1) : 1, 2
-dcmip4_testcase=1
-#-----------------------------------------------------------------------
+itau_physics=4
Index: dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/start.def
===================================================================
--- dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/start.def	(revision 3978)
+++ dynamico_lmdz/aquaplanet/OLD_PHYSIC/RUN_AQUAPLANET_DYNAMICO_LMDZ5/start.def	(revision 3978)
@@ -0,0 +1,6 @@
+# parameters controlling startup of the simulation
+
+iflag_phys=IFLAG_PHYS
+read_start=READ_START
+create_etat0_limit=CE0L
+etat0=ETAT0
