Index: /trunk/tools/LMDZ_launch.bash
===================================================================
--- /trunk/tools/LMDZ_launch.bash	(revision 29)
+++ /trunk/tools/LMDZ_launch.bash	(revision 29)
@@ -0,0 +1,199 @@
+#!/bin/bash 
+## e.g. # LMDZ_launch.bash 19790101000000 19800101000000 28 32:32:39 /d4/lflmd/etudes/WRF_LMDZ/lmdz/AR40.0/control
+## e.g. # LMDZ_launch.bash 19790101000000 19800101000000 month 32:32:39 /d4/lflmd/etudes/WRF_LMDZ/lmdz/AR40.0/control
+if test $1 = '-h'; then
+  echo "*********************************"
+  echo "*** Launching LMDZ simulation ***"
+  echo "*********************************"
+  echo "LMDZ_launch.bash [inidate] [enddate] [freq] [dim] [odir]"
+  echo "  [inidate]: initial date [YYYY][MM][DD][HH][MI][SS])" 
+  echo "  [enddate]: final date [YYYY][MM][DD][HH][MI][SS])"
+  echo "  [freq]: frequency restarts [DD] if it is 'month' real month frequency will be used)"
+  echo "  [dim]: dimensions (dimx:dimy:dimz)"
+  echo "  [odir]: folder for the outputs)"
+else
+
+seconds_between_dates() {
+# Functino to provide the seconds between two dates
+  date1=$1
+  date2=$2
+
+  # Date1
+  ##
+  YMD1=${date1:0:8}
+  hours1=${date1:8:2}
+  minutes1=${date1:10:2}
+  seconds1=${date1:12:2}
+  hours1=`(expr $hours1 '*' 3600)`
+  minutes1=`(expr $minutes1 '*' 60)`
+  seconds1=`(expr $hours1 + $minutes1 + $seconds1)`
+  sec1=`(date +%s -u -d"$YMD1 $seconds1 seconds")`
+
+  # Date2
+  ##
+  YMD2=${date2:0:8}
+  hours2=${date2:8:2}
+  minutes2=${date2:10:2}
+  seconds2=${date2:12:2}
+  hours2=`(expr $hours2 '*' 3600)`
+  minutes2=`(expr $minutes2 '*' 60)`
+  seconds2=`(expr $hours2 + $minutes2 + $seconds2)`
+  sec2=`(date +%s -u -d"$YMD2 $seconds2 seconds")`
+  seconds=`(expr $sec2 - $sec1)`
+
+  echo $seconds
+}
+
+create_LMDZnamelist() {
+# Function to create run.def from a LMDZ template
+#   nlistmplt: template of the run.def
+#   id: initial date (in [YYYY][MM][DD][HH][MI][SS] format)
+#   fr: frquency (in days) of the restarts
+
+  nlisttmplt=$1
+  id=$2
+  fr=$3
+
+  day=`date -u "+%j" -d"${id:0:8}"`
+
+  cp ${nlisttmplt} run.def
+  sed -e 's/@freq@/'${fr}'/g' run.def >& tmpA
+  sed -e 's/@iyear@/'${id:0:4}'/g' tmpA >& tmpB
+  sed -e 's/@iday@/'${day}'/g' tmpB >& run.def
+
+  cp config.def.template tmpA
+  sed -e 's/@daysmonth@/'${fr}'/g' tmpA >& config.def
+
+  rm tmpA tmpB
+}
+
+########    #######
+## MAIN
+    #######
+
+  export LD_LIBRARY_PATH=/u/lflmd/bin/gcc_netcdf-4.3.0/lib:${LD_LIBRARY_PATH}
+
+  rootsh=`pwd`
+  errmsg='ERROR -- error -- ERROR -- error'
+
+  inidate=$1
+  enddate=$2
+  freq=$3
+  dim=$4
+  odir=$5
+
+  lmdztmplt='run.def.template'
+
+####### ###### #### ### ## # 
+
+  dimx=`echo ${dim} | tr ':' ' ' | awk '{print $1 - 1}'`
+  dimy=`echo ${dim} | tr ':' ' ' | awk '{print $2 - 1}'`
+  dimz=`echo ${dim} | tr ':' ' ' | awk '{print $3}'`
+
+  export PATH=/u/lflmd/bin/gcc_Python-2.7.5/bin:${PATH}
+  export LD_LIBRARY_PATH=/u/lflmd/bin/gcc_netcdf-4.3.0/lib:/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/mkl/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/tbb/lib/intel64//cc4.1.0_libc2.4_kernel2.6.16.21:/usr/local/lib:/opt/intel/composer_xe_2011_sp1.9.293/debugger/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/mpirt/lib/intel64
+
+  if test ! -f ${lmdztmplt}; then
+    echo $errmsg
+    echo "File '"${lmdztmplt}"' does not exist!!!!"
+    exit
+  fi
+
+  idate=${inidate}
+  isubperiod=1
+
+  rm -r ${odir}/lmdzout
+  rm run_lmdz_??????????????-??????????????.log
+  mkdir -p ${odir}/lmdzout
+
+  while test ${idate} -le ${enddate}; do
+    if test ${freq} = 'month'; then
+      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} 1 month"`
+      secmonths=`seconds_between_dates ${idate} ${nextdate}`
+      freqV=`expr ${secmonths} / 24 / 3600`
+    else
+      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} ${freq} days"`
+      freqV=${freq}
+    fi
+    if test ${nextdate} -gt ${enddate}; then break; fi
+    period=${idate}'-'${nextdate}
+    echo ${isubperiod}" "${period}
+
+    create_LMDZnamelist ${lmdztmplt} ${idate} ${freqV}
+
+    ./lmdz.exe >& ${odir}/run_lmdz_${period}.log
+    elmdz=$?
+
+    if test ${elmdz} -ne 0; then
+      echo ${errmsg}
+      echo "  lmdz.exe failed !!!"
+      cat run_lmdz_${period}.log
+      exit
+    fi
+# Moving outputs
+##
+    mv ${odir}/run_lmdz_${period}.log ${odir}/lmdzout/run_lmdz_${period}.log
+    mv run.def ${odir}/lmdzout/run.def_${period}
+    mv config.def ${odir}/lmdzout/config.def_${period}
+    mv histmth.nc ${odir}/lmdzout/histmth_${period}.nc
+    mv histday.nc ${odir}/lmdzout/histday_${period}.nc
+    mv histins.nc ${odir}/lmdzout/histins_${period}.nc
+
+    if test ${isubperiod} -gt 1; then
+      mv restartphy.nc ${odir}/lmdzout/restartphy_${period}.nc
+      mv restart.nc ${odir}/lmdzout/restart_${period}.nc
+    fi
+    
+    lastdate=${idate}
+    idate=${nextdate}
+    isubperiod=`expr ${isubperiod} + 1`
+
+# end of dates
+  done
+
+  isubperiod=`expr ${isubperiod} + 1`
+  if test ${nextdate} -gt ${enddate} && test ${idate} -ne ${enddate}; then
+    nextdate=${enddate}
+    period=${idate}'-'${nextdate}
+    echo "last: "${period}
+    secmonths=`seconds_between_dates ${idate} ${nextdate}`
+    freqV=`expr ${secmonths} / 24 / 3600`
+    create_LMDZnamelist ${lmdztmplt} ${idate} ${freqV}
+
+    ./lmdz.exe >& ${odir}/run_lmdz_${period}.log
+    ewfr=$?
+    if test ${ewrf} -ne 0; then
+      echo ${errmsg}
+      echo "  lmdz.exe failed !!!"
+      cat run_lmdz_${period}.log
+      exit
+    fi
+# Moving outputs
+##
+    mv ${odir}/run_lmdz_${period}.log ${odir}/lmdzout/run_lmdz_${period}.log
+    mv run.def ${odir}/lmdzout/run.def_${period}
+    mv histmth.nc ${odir}/lmdzout/histmth_${period}.nc
+    mv histday.nc ${odir}/lmdzout/histday_${period}.nc
+    mv histins.nc ${odir}/lmdzout/histins_${period}.nc
+
+    if test ${isubperiod} -gt 1; then
+      mv restartphy.nc ${odir}/lmdzout/restartphy_${period}.nc
+    fi
+  fi
+
+# Post-process LMDZ hist files
+##
+
+  for file in ${odir}/lmdzout/hist*.nc; do
+    filen=`basename ${file}`
+    filenH=`echo ${filen} | tr '.' ' ' | awk '{print $1}'`
+    python ${HOME}/PY/WRFLMDZ_regularout.py -f ${file} -d ${dimx},${dimy} -o ${odir}/lmdzout/${filenH}_reg.nc 
+    rm ${file}
+    d1=`echo ${filen} | tr '_' ' ' | awk '{print $2}' | tr '-' ' ' | awk '{print $1}'`
+    totsecs=`seconds_between_dates 19491201000000 ${d1}`
+
+    python ${HOME}/climatescripts/python/nc_var.py -f ${odir}/lmdzout/${filenH}_reg.nc -o valmod -S sumc,${totsecs} -v time
+    python ${HOME}/climatescripts/python/nc_var.py -f ${odir}/lmdzout/${filenH}_reg.nc -o addvattrk -S 'units|seconds!since!1949-12-01!00:00:00|S' -v time
+  done
+
+fi
Index: /trunk/tools/WRF+LMDZ_launch.bash
===================================================================
--- /trunk/tools/WRF+LMDZ_launch.bash	(revision 29)
+++ /trunk/tools/WRF+LMDZ_launch.bash	(revision 29)
@@ -0,0 +1,278 @@
+#!/bin/bash 
+## g.e. # WRF+LMDZ_launch.bash 19790101000000 19800101000000 28 /d4/lflmd/etudes/WRF_LMDZ/test_phylmd/AR40.0/control
+## g.e. # WRF+LMDZ_launch.bash 19790101000000 19800101000000 month /d4/lflmd/etudes/WRF_LMDZ/test_phylmd/AR40.0/control
+if test $1 = '-h'; then
+  echo "*************************************"
+  echo "*** Launching WRF+LMDZ simulation ***"
+  echo "*************************************"
+  echo "WRF+LMDZ_launch.bash [inidate] [enddate] [freq] [odir]"
+  echo "  [inidate]: initial date [YYYY][MM][DD][HH][MI][SS]" 
+  echo "  [enddate]: final date [YYYY][MM][DD][HH][MI][SS]"
+  echo "  [freq]: frequency restarts [DD] if it is 'month' real month frequency will be used"
+  echo "  [odir]: folder for the outputs"
+  echo "  [restart]: 'true' for a resume a simulation"
+else
+
+seconds_between_dates() {
+# Functino to provide the seconds between two dates
+  date1=$1
+  date2=$2
+
+  # Date1
+  ##
+  YMD1=${date1:0:8}
+  hours1=${date1:8:2}
+  minutes1=${date1:10:2}
+  seconds1=${date1:12:2}
+  hours1=`(expr $hours1 '*' 3600)`
+  minutes1=`(expr $minutes1 '*' 60)`
+  seconds1=`(expr $hours1 + $minutes1 + $seconds1)`
+  sec1=`(date +%s -u -d"$YMD1 $seconds1 seconds")`
+
+  # Date2
+  ##
+  YMD2=${date2:0:8}
+  hours2=${date2:8:2}
+  minutes2=${date2:10:2}
+  seconds2=${date2:12:2}
+  hours2=`(expr $hours2 '*' 3600)`
+  minutes2=`(expr $minutes2 '*' 60)`
+  seconds2=`(expr $hours2 + $minutes2 + $seconds2)`
+  sec2=`(date +%s -u -d"$YMD2 $seconds2 seconds")`
+  seconds=`(expr $sec2 - $sec1)`
+
+  echo $seconds
+}
+
+create_WRFnamelist() {
+# Function to create namelist.input from a nameslit WRF template
+#   nlistmplt: template of the namelist.input
+#   id: initial date ([YYYYMMDDHHMISS] format)
+#   ed: final date ([YYYYMMDDHHMISS] format)
+#   fr: frquency (in days) of the restarts
+#   it: number of sub-period within the simulation experiment
+
+  nlisttmplt=$1
+  id=$2
+  ed=$3
+  fr=$4
+  it=$5
+
+  frH=`expr ${fr} '*' 24`
+
+  dThist=`cat ${nlisttmplt} | grep history_interval | awk '{print $3}' | tr ',' ' ' |\
+     awk '{print $1*60}'`
+
+  secsPeriod=`seconds_between_dates ${id} ${ed}`
+  Nouts=`expr ${secsPeriod} / ${dThist}`
+
+  cp ${nlisttmplt} namelist.input
+  sed -e 's/@iyear@/'${id:0:4}'/g' namelist.input >& tmpA
+  sed -e 's/@imonth@/'${id:4:2}'/g' tmpA >& tmpB
+  sed -e 's/@iday@/'${id:6:2}'/g' tmpB >& tmpA
+  sed -e 's/@ihour@/'${id:8:2}'/g' tmpA >& tmpB
+  sed -e 's/@iminute@/'${id:10:2}'/g' tmpB >& tmpA
+  sed -e 's/@isecond@/'${id:12:2}'/g' tmpA >& tmpB
+
+  sed -e 's/@eyear@/'${ed:0:4}'/g' tmpB >& tmpA
+  sed -e 's/@emonth@/'${ed:4:2}'/g' tmpA >& tmpB
+  sed -e 's/@eday@/'${ed:6:2}'/g' tmpB >& tmpA
+  sed -e 's/@ehour@/'${ed:8:2}'/g' tmpA >& tmpB
+  sed -e 's/@eminute@/'${ed:10:2}'/g' tmpB >& tmpA
+  sed -e 's/@esecond@/'${ed:12:2}'/g' tmpA >& tmpB
+  sed -e 's/@Nouts@/'${Nouts}'/g' tmpB >& tmpA
+  sed -e 's/@freqH@/'${frH}'/g' tmpA >& tmpB
+  if test ${it} -gt 1; then
+    sed -e 's/@restart@/.true./g' tmpB >& namelist.input
+  else
+    sed -e 's/@restart@/.false./g' tmpB >& namelist.input
+  fi
+
+  rm tmpA tmpB
+}
+
+create_LMDZnamelist() {
+# Function to create run.def from a LMDZ template
+#   nlistmplt: template of the run.def
+#   id: initial date (in [YYYY][MM][DD][HH][MI][SS] format)
+#   fr: frquency (in days) of the restarts
+
+  nlisttmplt=$1
+  id=$2
+  fr=$3
+
+  day=`date -u "+%j" -d"${id:0:8}"`
+
+  cp ${nlisttmplt} run.def
+  sed -e 's/@freq@/'${fr}'/g' run.def >& tmpA
+  sed -e 's/@iyear@/'${id:0:4}'/g' tmpA >& tmpB
+  sed -e 's/@iday@/'${day}'/g' tmpB >& run.def
+
+  cp config.def.template tmpA
+  sed -e 's/@daysmonth@/'${fr}'/g' tmpA >& config.def
+
+  rm tmpA tmpB
+}
+
+########    #######
+## MAIN
+    #######
+
+  rootsh=`pwd`
+  errmsg='ERROR -- error -- ERROR -- error'
+
+  inidate=$1
+  enddate=$2
+  freq=$3
+  odir=$4
+  if test $# -eq 5; then
+    restart=$5
+  else
+    restart='false'
+  fi
+
+  wrftmplt=${odir}'/namelist.input.template'
+  lmdztmplt=${odir}'/run.def.template'
+
+####### ###### #### ### ## # 
+
+  export PATH=/u/lflmd/bin/gcc_Python-2.7.5/bin:${PATH}
+  export LD_LIBRARY_PATH=/u/lflmd/bin/gcc_netcdf-4.3.0/lib:/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/mkl/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/tbb/lib/intel64//cc4.1.0_libc2.4_kernel2.6.16.21:/usr/local/lib:/opt/intel/composer_xe_2011_sp1.9.293/debugger/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/mpirt/lib/intel64
+
+  if test ! -f ${wrftmplt}; then
+    echo $errmsg
+    echo "File '"${wrftmplt}"' does not exist!!!!"
+    exit
+  fi
+
+  if test ! -f ${lmdztmplt}; then
+    echo $errmsg
+    echo "File '"${lmdztmplt}"' does not exist!!!!"
+    exit
+  fi
+
+  idate=${inidate}
+  isubperiod=1
+
+  if test ${restart} == 'true'; then
+    echo "Continuing the simulation from the last wrfrst"
+  else
+    rm -r ${odir}/wrfout
+    rm -r ${odir}/lmdzout
+    rm run_wrf_??????????????-??????????????.log
+    mkdir -p ${odir}/wrfout
+    mkdir -p ${odir}/lmdzout
+  fi
+
+  while test ${idate} -le ${enddate}; do
+    if test ${freq} = 'month'; then
+      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} 1 month"`
+      secmonths=`seconds_between_dates ${idate} ${nextdate}`
+      freqV=`expr ${secmonths} / 24 / 3600`
+    else
+      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} ${freq} days"`
+      freqV=${freq}
+    fi
+    if test ${nextdate} -gt ${enddate}; then break; fi
+    period=${idate}'-'${nextdate}
+# Checking for restart
+##
+    runperiod=true
+    if test ${restart} == 'true' && test -f ${odir}/wrfout/wrfrst_d01_${nextdate:0:4}-${nextdate:4:2}-${nextdate:6:2}_${nextdate:8:2}:${nextdate:10:2}:${nextdate:12:2}; then
+      runperiod=false
+      cp ${odir}/wrfout/wrfrst_d01_${idate:0:4}-${idate:4:2}-${idate:6:2}_${idate:8:2}:${idate:10:2}:${idate:12:2} ${odir}
+      echo "  resuming the simulation from: "${idate:0:4}-${idate:4:2}-${idate:6:2}_${idate:8:2}:${idate:10:2}:${idate:12:2}
+    else
+      runperiod=true
+    fi
+
+    if ${runperiod}; then
+      echo "    "${isubperiod}" "${period}
+
+      create_WRFnamelist ${wrftmplt} ${idate} ${nextdate} ${freqV} ${isubperiod}
+      create_LMDZnamelist ${lmdztmplt} ${idate} ${freqV}
+
+      ./wrf.exe >& ${odir}/run_wrf_${period}.log
+      ewrf=$?
+
+      if test ${ewrf} -ne 0; then
+        echo ${errmsg}
+        echo "  wrf.exe failed !!!"
+        cat run_wrf_${period}.log
+        exit
+      fi
+# Moving outputs
+##
+      mv namelist.input ${odir}/wrfout/namelist.input_${period}
+      mv namelist.output ${odir}/wrfout/namelist.output_${period}
+      mv wrfout_d* ${odir}/wrfout
+      mv run_wrf_${period}.log ${odir}/wrfout
+      mv run.def ${odir}/lmdzout/run.def_${period}
+      mv histmth.nc ${odir}/lmdzout/histmth_${period}.nc
+      mv histday.nc ${odir}/lmdzout/histday_${period}.nc
+      mv histins.nc ${odir}/lmdzout/histins_${period}.nc
+
+      if test ${isubperiod} -gt 1; then
+        mv wrfrst*${idate:0:4}-${idate:4:2}-${idate:6:2}* ${odir}/wrfout
+      fi
+    fi
+    
+    lastdate=${idate}
+    idate=${nextdate}
+    isubperiod=`expr ${isubperiod} + 1`
+
+# end of dates
+  done
+
+  isubperiod=`expr ${isubperiod} + 1`
+  if test ${nextdate} -gt ${enddate} && test ${idate} -ne ${enddate}; then
+    nextdate=${enddate}
+    period=${idate}'-'${nextdate}
+    echo "last: "${period}
+    secmonths=`seconds_between_dates ${idate} ${nextdate}`
+    freqV=`expr ${secmonths} / 24 / 3600`
+    create_WRFnamelist ${wrftmplt} ${idate} ${nextdate} ${freqV} ${isubperiod}
+    create_LMDZnamelist ${lmdztmplt} ${idate} ${freqV}
+
+    ./wrf.exe >& ${odir}/run_wrf_${period}.log
+    ewrf=$?
+    if test ${ewrf} -ne 0; then
+      echo ${errmsg}
+      echo "  wrf.exe failed !!!"
+      cat run_wrf_${period}.log
+      exit
+    fi
+# Moving outputs
+##
+    mv namelist.input ${odir}/wrfout/namelist.input_${period}
+    mv namelist.output ${odir}/wrfout/namelist.output_${period}
+    mv wrfout_d* ${odir}/wrfout
+    mv run_wrf_${period}.log ${odir}/wrfout
+    mv run.def ${odir}/lmdzout/run.def_${period}
+    mv histmth.nc ${odir}/lmdzout/histmth_${period}.nc
+    mv histday.nc ${odir}/lmdzout/histday_${period}.nc
+    mv histins.nc ${odir}/lmdzout/histins_${period}.nc
+
+    if test ${isubperiod} -gt 1; then
+      mv wrfrst*${idate:0:4}-${idate:4:2}-${idate:6:2}* ${odir}/wrfout
+    fi
+  fi
+
+# Post-process LMDZ hist files
+##
+
+  dimx=`cat ${odir}/wrfout/namelist.input_${period} | grep e_we | awk '{print $3}' | tr ',' ' ' | awk '{print $1 - 1}'`
+  dimy=`cat ${odir}/wrfout/namelist.input_${period} | grep e_sn | awk '{print $3}' | tr ',' ' ' | awk '{print $1 - 1}'`
+  for file in ${odir}/lmdzout/hist*.nc; do
+    filen=`basename ${file}`
+    filenH=`echo ${filen} | tr '.' ' ' | awk '{print $1}'`
+    python ${HOME}/PY/WRFLMDZ_regularout.py -f ${file} -d ${dimx},${dimy} -o ${odir}/lmdzout/${filenH}_reg.nc 
+    rm ${file}
+    d1=`echo ${filen} | tr '_' ' ' | awk '{print $2}' | tr '-' ' ' | awk '{print $1}'`
+    totsecs=`seconds_between_dates 19491201000000 ${d1}`
+
+    python ${HOME}/climatescripts/python/nc_var.py -f ${odir}/lmdzout/${filenH}_reg.nc -o valmod -S sumc,${totsecs} -v time
+    python ${HOME}/climatescripts/python/nc_var.py -f ${odir}/lmdzout/${filenH}_reg.nc -o addvattrk -S 'units|seconds!since!1949-12-01!00:00:00|S' -v time
+  done
+
+fi
Index: /trunk/tools/WRF_launch.bash
===================================================================
--- /trunk/tools/WRF_launch.bash	(revision 29)
+++ /trunk/tools/WRF_launch.bash	(revision 29)
@@ -0,0 +1,222 @@
+#!/bin/bash
+## g.e # WRF_launch.bash 19791201000000 19810101000000 28 /d4/lflmd/etudes/WRF_LMDZ/WaquaL/WRF/control
+## g.e # WRF_launch.bash 19791201000000 19810101000000 month /d4/lflmd/etudes/WRF_LMDZ/WaquaL/WRF/control
+if test $1 = '-h'; then
+  echo "********************************"
+  echo "*** Launching WRF simulation ***"
+  echo "********************************"
+  echo "WRF_launch.bash [inidate] [enddate] [freq] [odir]"
+  echo "  [inidate]: initial date [YYYY][MM][DD][HH][MI][SS]" 
+  echo "  [enddate]: final date [YYYY][MM][DD][HH][MI][SS]"
+  echo "  [freq]: frequency restarts [DD] if it is 'month' real month frequency will be used"
+  echo "  [odir]: folder for the outputs"
+  echo "  [restart]: 'true' for a resume a simulation"
+else
+
+seconds_between_dates() {
+# Functino to provide the seconds between two dates
+  date1=$1
+  date2=$2
+
+  # Date1
+  ##
+  YMD1=${date1:0:8}
+  hours1=${date1:8:2}
+  minutes1=${date1:10:2}
+  seconds1=${date1:12:2}
+  hours1=`(expr $hours1 '*' 3600)`
+  minutes1=`(expr $minutes1 '*' 60)`
+  seconds1=`(expr $hours1 + $minutes1 + $seconds1)`
+  sec1=`(date +%s -u -d"$YMD1 $seconds1 seconds")`
+
+  # Date2
+  ##
+  YMD2=${date2:0:8}
+  hours2=${date2:8:2}
+  minutes2=${date2:10:2}
+  seconds2=${date2:12:2}
+  hours2=`(expr $hours2 '*' 3600)`
+  minutes2=`(expr $minutes2 '*' 60)`
+  seconds2=`(expr $hours2 + $minutes2 + $seconds2)`
+  sec2=`(date +%s -u -d"$YMD2 $seconds2 seconds")`
+  seconds=`(expr $sec2 - $sec1)`
+
+  echo $seconds
+}
+
+create_WRFnamelist() {
+# Function to create namelist.input from a nameslit WRF template
+#   nlistmplt: template of the namelist.input
+#   id: initial date ([YYYYMMDDHHMISS] format)
+#   ed: final date ([YYYYMMDDHHMISS] format)
+#   fr: frquency (in days) of the restarts
+#   it: number of sub-period within the simulation experiment
+
+  nlisttmplt=$1
+  id=$2
+  ed=$3
+  fr=$4
+  it=$5
+
+  frH=`expr ${fr} '*' 24`
+
+  dThist=`cat ${nlisttmplt} | grep history_interval | awk '{print $3}' | tr ',' ' ' |\
+     awk '{print $1*60}'`
+
+  secsPeriod=`seconds_between_dates ${id} ${ed}`
+  Nouts=`expr ${secsPeriod} / ${dThist}`
+
+  cp ${nlisttmplt} namelist.input
+  sed -e 's/@iyear@/'${id:0:4}'/g' namelist.input >& tmpA
+  sed -e 's/@imonth@/'${id:4:2}'/g' tmpA >& tmpB
+  sed -e 's/@iday@/'${id:6:2}'/g' tmpB >& tmpA
+  sed -e 's/@ihour@/'${id:8:2}'/g' tmpA >& tmpB
+  sed -e 's/@iminute@/'${id:10:2}'/g' tmpB >& tmpA
+  sed -e 's/@isecond@/'${id:12:2}'/g' tmpA >& tmpB
+
+  sed -e 's/@eyear@/'${ed:0:4}'/g' tmpB >& tmpA
+  sed -e 's/@emonth@/'${ed:4:2}'/g' tmpA >& tmpB
+  sed -e 's/@eday@/'${ed:6:2}'/g' tmpB >& tmpA
+  sed -e 's/@ehour@/'${ed:8:2}'/g' tmpA >& tmpB
+  sed -e 's/@eminute@/'${ed:10:2}'/g' tmpB >& tmpA
+  sed -e 's/@esecond@/'${ed:12:2}'/g' tmpA >& tmpB
+  sed -e 's/@Nouts@/'${Nouts}'/g' tmpB >& tmpA
+  sed -e 's/@freqH@/'${frH}'/g' tmpA >& tmpB
+  if test ${it} -gt 1; then
+    sed -e 's/@restart@/.true./g' tmpB >& namelist.input
+  else
+    sed -e 's/@restart@/.false./g' tmpB >& namelist.input
+  fi
+
+  rm tmpA tmpB
+
+}
+
+########    #######
+## MAIN
+    #######
+
+  rootsh=`pwd`
+  errmsg='ERROR -- error -- ERROR -- error'
+
+  inidate=$1
+  enddate=$2
+  freq=$3
+  odir=$4
+  if test $# -eq 5; then
+    restart=$5
+  else
+    restart='false'
+  fi
+
+  wrftmplt=${odir}'/namelist.input.template'
+
+####### ###### #### ### ## # 
+
+  export PATH=/u/lflmd/bin/gcc_Python-2.7.5/bin:${PATH}
+  export LD_LIBRARY_PATH=/u/lflmd/bin/gcc_netcdf-4.3.0/lib:/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/compiler/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/mkl/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/tbb/lib/intel64//cc4.1.0_libc2.4_kernel2.6.16.21:/usr/local/lib:/opt/intel/composer_xe_2011_sp1.9.293/debugger/lib/intel64:/opt/intel/composer_xe_2011_sp1.9.293/mpirt/lib/intel64
+
+  if test ! -f ${wrftmplt}; then
+    echo $errmsg
+    echo "File '"${wrftmplt}"' does not exist!!!!"
+    exit
+  fi
+
+  cd ${odir}
+  rm namelist.input >& /dev/null
+
+  idate=${inidate}
+  isubperiod=1
+
+  if test ${restart} == 'true'; then
+    echo "Continuing the simulation from the last wrfrst"
+  else
+    rm -r ${odir}/wrfout
+    rm run_wrf_??????????????-??????????????.log
+    mkdir -p ${odir}/wrfout
+  fi
+
+  while test ${idate} -le ${enddate}; do
+    if test ${freq} = 'month'; then
+      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} 1 month"`
+      secmonths=`seconds_between_dates ${idate} ${nextdate}`
+      freqV=`expr ${secmonths} / 24 / 3600`
+    else
+      nextdate=`date +%Y%m%d%H%M%S -d"${idate:0:8} ${freq} days"`
+      freqV=${freq}
+    fi
+    if test ${nextdate} -gt ${enddate}; then break; fi
+    period=${idate}'-'${nextdate}
+# Checking for restart
+##
+    runperiod=true
+    if test ${restart} == 'true' && test -f ${odir}/wrfout/wrfrst_d01_${nextdate:0:4}-${nextdate:4:2}-${nextdate:6:2}_${nextdate:8:2}:${nextdate:10:2}:${nextdate:12:2}; then
+      runperiod=false
+    else
+      echo "  resuming the simulation from: "${idate:0:4}-${idate:4:2}-${idate:6:2}_${idate:8:2}:${idate:10:2}:${idate:12:2}
+      cp ${odir}/wrfout/wrfrst_d01_${idate:0:4}-${idate:4:2}-${idate:6:2}_${idate:8:2}:${idate:10:2}:${idate:12:2} ${odir}
+    fi
+
+    if ${runperiod}; then
+      echo "    "${isubperiod}" "${period}
+
+      create_WRFnamelist ${wrftmplt} ${idate} ${nextdate} ${freqV} ${isubperiod}
+
+      ./wrf.exe >& ${odir}/run_wrf_${period}.log
+      ewrf=$?
+
+      if test ${ewrf} -ne 0; then
+        echo ${errmsg}
+        echo "  wrf.exe failed !!!"
+        cat run_wrf_${period}.log
+        exit
+      fi
+# Moving outputs
+##
+      mv namelist.input ${odir}/wrfout/namelist.input_${period}
+      mv namelist.output ${odir}/wrfout/namelist.output_${period}
+      mv wrfout_d* ${odir}/wrfout
+      mv run_wrf_${period}.log ${odir}/wrfout
+
+      if test ${isubperiod} -gt 1; then
+        mv wrfrst*${idate:0:4}-${idate:4:2}-${idate:6:2}* ${odir}/wrfout
+      fi
+    fi
+    
+    lastdate=${idate}
+    idate=${nextdate}
+    isubperiod=`expr ${isubperiod} + 1`
+
+# end of dates
+  done
+
+  isubperiod=`expr ${isubperiod} + 1`
+  if test ${nextdate} -gt ${enddate} && test ${idate} -ne ${enddate}; then
+    nextdate=${enddate}
+    period=${idate}'-'${nextdate}
+    echo "last: "${period}
+    secmonths=`seconds_between_dates ${idate} ${nextdate}`
+    freqV=`expr ${secmonths} / 24 / 3600`
+    create_WRFnamelist ${wrftmplt} ${idate} ${nextdate} ${freqV} ${isubperiod}
+
+    ./wrf.exe >& ${odir}/run_wrf_${period}.log
+    ewrf=$?
+    if test ${ewrf} -ne 0; then
+      echo ${errmsg}
+      echo "  wrf.exe failed !!!"
+      cat run_wrf_${period}.log
+      exit
+    fi
+# Moving outputs
+##
+    mv namelist.input ${odir}/wrfout/namelist.input_${period}
+    mv namelist.output ${odir}/wrfout/namelist.output_${period}
+    mv wrfout_d* ${odir}/wrfout
+    mv run_wrf_${period}.log ${odir}/wrfout
+
+    if test ${isubperiod} -gt 1; then
+      mv wrfrst*${idate:0:4}-${idate:4:2}-${idate:6:2}* ${odir}/wrfout
+    fi
+  fi
+
+fi
Index: /trunk/tools/blank_WRF.bash
===================================================================
--- /trunk/tools/blank_WRF.bash	(revision 29)
+++ /trunk/tools/blank_WRF.bash	(revision 29)
@@ -0,0 +1,63 @@
+#!/bin/bash 
+## g.e. # ./blank_WRF.bash /d4/lflmd/DATA/WRF/WRFV3.3.1 /d4/lflmd/etudes/AquaPlanet/test_eraint
+if test $1 = '-h'; then
+  echo "**************************************"
+  echo "*** Shell to prepare WRF structure ***"
+  echo "***  from the scratch in a folder  ***"
+  echo "**************************************"
+  echo "blank_WRF.bash [WRFfold](folder with serial/dmpar WRFV3 and WPS compilation folders) [WORKfold](working directory)"
+else
+  rootsh=`pwd`
+  WRFfold=$1
+  WORKfold=$2
+
+  # ungrib
+  ## 
+  odir=${WORKfold}/ungrib
+  mkdir -p ${odir}
+  links='ungrib.exe Variable_Tables'
+  for link in ${links}; do
+    rm ${odir}/${link} >& /dev/null
+    ln -s ${WRFfold}/serial/WPS/ungrib/${link} ${odir}
+  done
+  mkdir ${odir}/GribDir
+  ln -s ${WRFfold}/serial/WPS/link_grib.csh ${odir}
+
+  # metgrid 
+  ## 
+  odir=${WORKfold}/metgrid
+  mkdir -p ${odir}
+  links='metgrid.exe METGRID.TBL.ARW'
+  for link in ${links}; do
+    rm ${odir}/${link} >& /dev/null
+    if test ${link:0:3} = 'MET'; then
+      rm ${odir}/METGRID.TBL >& /dev/null
+      ln -s ${WRFfold}/serial/WPS/metgrid/${link} ${odir}/METGRID.TBL
+    else
+      ln -s ${WRFfold}/serial/WPS/metgrid/${link} ${odir}
+    fi
+  done
+
+  # real 
+  ## 
+  odir=${WORKfold}/run
+  mkdir -p ${odir}
+  rm ${odir}/real.exe >& /dev/null
+  ln -s ${WRFfold}/serial/WRFV3/main/real.exe ${odir}
+
+  # wrf 
+  ## 
+  odir=${WORKfold}/run
+  links='wrf.exe CAM co2_trans ETA .TBL .tbl .formatted RRTM tr'
+  for link in ${links}; do
+    rm ${odir}/*${link}* >& /dev/null
+    if test ${link} = 'wrf.exe'; then
+      ln -s ${WRFfold}/serial/WRFV3/main/*${link}* ${odir}/wrf.serial.exe
+      ln -s ${WRFfold}/dmpar/WRFV3/main/*${link}* ${odir}/wrf.dmpar.exe
+    else
+      ln -s ${WRFfold}/serial/WRFV3/run/*${link}* ${odir}
+    fi
+  done
+fi
+
+echo "export LD_LIBRARY_PATH=${HOME}/bin/gcc_netcdf-4.3.0/lib:\${LD_LIBRARY_PATH}"
Index: /trunk/tools/config.def.template
===================================================================
--- /trunk/tools/config.def.template	(revision 29)
+++ /trunk/tools/config.def.template	(revision 29)
@@ -0,0 +1,124 @@
+##############################################################################
+# PARAMETRES ET CLES DE CONFIGURATION LMDZ
+##############################################################################
+# D: Valeur par default
+#
+# Controle des sorties
+#*********************
+OK_journe=y
+OK_mensuel=y
+ok_hf=y
+OK_instan=n
+ok_LES=n
+#ok_regdyn : y/n calcul/non des regymes dynamiques sur regions pre-definies
+ok_regdyn=y
+# A transformer en la ligne ci-dessous quand ce sera compatible avec libIGCM
+phys_out_filekeys=       y       y       n       y       n
+phys_out_filenames=      histmth histday histhf  histins histLES
+phys_out_filetimesteps=  @daysmonth@day   1day    1hr     3hr     6hr
+phys_out_filelevels=     10      10      0       10       4
+phys_out_filetypes=      ave(X)  ave(X)  ave(X)  inst(X) inst(X)
+
+#
+#Couplage avec autres modules
+#******************************
+#option de couplage pour ocean (D:force)
+type_ocean=force
+version_ocean=nemo
+#avec ou sans orchidee (D:n)
+VEGET=n
+#type_run=AMIP, ENSP, clim (D:AMIP)
+type_run=CLIM
+##  Soil Model  ou non               
+soil_model=y
+
+#Code de transfert radiatif
+#**************************
+# ajout de ce flag pour activer/desactiver le rayonnement (MPL)
+# 0 : pas de rayonnement. 1: on active le rayonnement (D=1)
+iflag_radia=1
+## Nombre appels des routines de rayonnements ( par jour)                 
+nbapp_rad=48
+
+# Parametres "orbitaux/ ere geologique"
+#######################################
+#Parametres orbitaux
+#excentricite
+R_ecc=0.016715
+#equinoxe
+R_peri=102.7
+#inclinaison
+R_incl=23.441
+#constante solaire
+solaire=1366.0896
+##  Facteur additif pour l albedo
+pmagic=0.008
+#
+# Taux gaz a effet de serre
+#######################################
+#concentration des gaz (co2 ch4   n2o  cfc11 cfc12)
+#                  (D: 348. 1650. 306.  280.  484.)
+co2_ppm=0.36886500E+03
+#RCO2=co2_ppm * 1.0e-06  * 44.011/28.97= 5.286789092164308E-04
+CH4_ppb=0.17510225E+04
+#RCH4=1.65E-06* 16.043/28.97= 9.137366240938903E-07
+N2O_ppb=0.31585000E+03
+#RN2O=306.E-09* 44.013/28.97= 4.648939592682085E-07
+CFC11_ppt=5.18015181E+01
+#RCFC11=280.E-12* 137.3686/28.97= 1.327690990680013E-09
+CFC12_ppt=0.99862742E+03
+#RCFC12=484.E-12* 120.9140/28.97= 2.020102726958923E-09
+#
+# Parametres effets directs/indirects des "aerosols"
+#######################################
+### ok_ade=y/n   flag Aerosol direct effect
+ok_ade=n
+### ok_aie=y/n   flag Aerosol indirect effect
+ok_aie=n
+### aer_type =   Aerosol variation type : actuel / preind / scenario / annuel
+aer_type=actuel
+###  type of coupled aerosol =1 (default) =2 => bc  only =3 => pom only =4 => seasalt only =5 => dust only =6 => all aerosol
+flag_aerosol=0
+### bl95_b0 =    Parameter in CDNC-maer link (Boucher&Lohmann 1995)
+bl95_b0=1.7
+### bl95_b1 =    Parameter in CDNC-maer link (Boucher&Lohmann 1995)
+bl95_b1=0.2
+#
+# Parametre de lecture de l'ozone
+#######################################
+# Allowed values are 0, 1 and 2
+# 0: do not read an ozone climatology
+# 1: read a single ozone climatology that will be used day and night
+# 2: read two ozone climatologies, the average day and night climatology and the daylight climatology
+read_climoz=0
+#
+# Parametres simulateur COSP (CFMIP Observational Simulator Package)
+#######################################
+### ok_cosp=y/n flag simulateur COSP
+ok_cosp=n
+### freq_COSP = frequence d'appel de COSP en secondes
+freq_COSP=10800.
+### ok_mensuelCOSP=y/n sortir fichier mensuel COSP histmthCOSP.nc, =n pas de fichier histmthCOSP.nc
+ok_mensuelCOSP=y
+### ok_journeCOSP=y/n sortir fichier journalier histdayCOSP.nc, =n pas de fichier histdayCOSP.nc
+ok_journeCOSP=y
+### ok_hfCOSP=y/n, ecrire sorties  haute frequence histhfCOSP.nc, =n pas de fichier histhfCOSP.nc
+ok_hfCOSP=n
+#
+# Parametres simulateur ISCCP
+#######################################
+### ok_isccp=y/n flag simulateur ISCCP
+ok_isccp=n
+### top_height = flag choix calcul nuages par le simulateur en utilisant 
+# -              les donnees IR et/ou VIS et l algorithme ISCCP-D1
+# - top_height = 1 -> algo IR-VIS
+# - top_height = 2 -> identique a 1, mais "ptop(ibox)=pfull(ilev)"
+# - top_height = 3 -> algo IR
+top_height = 1
+### overlap =    Hypothese de Recouvrement (HR) utilisee pour le simulateur ISCCP
+# - overlap=1    Max overlap
+# - overlap=2    Random overlap
+# - overlap=3    Max/Random overlap
+overlap = 3
+#
+
Index: /trunk/tools/content.txt
===================================================================
--- /trunk/tools/content.txt	(revision 29)
+++ /trunk/tools/content.txt	(revision 29)
@@ -0,0 +1,13 @@
+************ content of the folder 'WRF_LMDZ/tools'
+
+.BASH___________________
+blank_WRF.bash: Shell script to prepare WRF folders to run all the WRF framework
+LMDZ_launch.bash: Shell to run a LMDZ simulation
+prepare_compilation.bash: Shell to prepare  a series of folders to run an experiment
+WRF_launch.bash: Shell to run a WRF simulation
+WRF+LMDZ_launch.bash: Shell to run a LMDZ+WRF simulation
+
+TEMPLATE________________
+config.def.template: template file of the LMDZ 'config.def' file
+namelist.input.template: template of the WRF 'namelist.input'
+run.def.template: template file of the LMDZ 'run.def' file
Index: /trunk/tools/namelist.input.template
===================================================================
--- /trunk/tools/namelist.input.template	(revision 29)
+++ /trunk/tools/namelist.input.template	(revision 29)
@@ -0,0 +1,115 @@
+ &time_control
+ run_days                            = 0,
+ run_hours                           = 0,
+ run_minutes                         = 0,
+ run_seconds                         = 0,
+ start_year                          = @iyear@,
+ start_month                         = @imonth@, 
+ start_day                           = @iday@,
+ start_hour                          = @ihour@,
+ start_minute                        = @iminute@,
+ start_second                        = @isecond@,
+ end_year                            = @eyear@,
+ end_month                           = @emonth@, 
+ end_day                             = @eday@,
+ end_hour                            = @ehour@,
+ end_minute                          = @eminute@,
+ end_second                          = @esecond@,
+ history_interval                    = 30,
+ interval_seconds                    = 21600 
+ input_from_file                     = .true.,
+ frames_per_outfile                  = @Nouts@,
+ restart                             = @restart@,
+ restart_interval_h                  = @freqH@,
+ io_form_history                     = 2
+ io_form_restart                     = 2
+ io_form_input                       = 2
+ io_form_boundary                    = 2
+ auxinput4_inname                    = 'wrflowinp_d<domain>'
+ auxinput4_interval                  = 360, 
+ io_form_auxinput4                   = 2
+ override_restart_timers             = .true.
+ debug_level                         = 0
+ /
+
+ &domains
+ time_step                           = 180 
+ time_step_fract_num                 = 00
+ time_step_fract_den                 = 1
+ max_dom                             = 1,
+ e_we                                = 130, 
+ e_sn                                = 110, 
+ e_vert                              = 39,
+ p_top_requested                     = 1000,
+ num_metgrid_levels                  = 38,
+ num_metgrid_soil_levels             = 4,
+ dx                                  = 20000.,
+ dy                                  = 20000.,
+ grid_id                             = 1,   
+ parent_id                           = 0,  
+ i_parent_start                      = 1,  
+ j_parent_start                      = 1,  
+ parent_grid_ratio                   = 1,  
+ parent_time_step_ratio              = 1, 
+ feedback                            = 1,
+ smooth_option                       = 0
+ bottom_top_plus1                    = 39,
+ max_lidar_locs                      = 20,
+ /
+
+ &physics
+ mp_physics                          = 0, 
+ ra_lw_physics                       = 0, 
+ ra_sw_physics                       = 0, 
+ radt                                = 120,
+ sf_sfclay_physics                   = 0, 
+ sf_surface_physics                  = 0, 
+ bl_pbl_physics                      = 0, 
+ bldt                                = 0, 
+ cu_physics                          = 0, 
+ cudt                                = 0, 
+ isfflx                              = 1,
+ ifsnow                              = 0,
+ icloud                              = 1,
+ surface_input_source                = 1,
+ num_soil_layers                     = 5,
+ mp_zero_out                         = 0,
+ sst_update                          = 1
+ /
+
+ &fdda
+ /
+
+ &dynamics
+ diff_opt                            = 0,
+ km_opt                              = 0,
+ damp_opt                            = 3,
+ base_temp                           = 290.
+ zdamp                               = 5000., 
+ dampcoef                            = 0.2,  
+ khdif                               = 0,   
+ kvdif                               = 0,   
+ non_hydrostatic                     = .true.,
+ moist_adv_opt                       = 0,    
+ scalar_adv_opt                      = 0,   
+ chem_adv_opt                        = 0,  
+ tke_adv_opt                         = 0,  
+ fft_filter_lat                      = 75.,
+ w_damping                           = 1,
+ /
+
+ &bdy_control
+  spec_bdy_width           = 5,
+  spec_zone                = 1,
+  relax_zone               = 4,
+  specified                = .true.,
+  nested                   = .false.,
+ /
+
+ &grib2
+ /
+
+ &namelist_quilt
+ nio_tasks_per_group = 0,
+ nio_groups = 1,
+ /
Index: /trunk/tools/run.def.template
===================================================================
--- /trunk/tools/run.def.template	(revision 29)
+++ /trunk/tools/run.def.template	(revision 29)
@@ -0,0 +1,39 @@
+# $Id: run.def 1403 2010-07-01 09:02:53Z fairhead $
+#
+## Fichier de configuration general
+## 
+INCLUDEDEF=physiq.def
+INCLUDEDEF=gcm.def
+INCLUDEDEF=orchidee.def
+INCLUDEDEF=output.def
+INCLUDEDEF=config.def
+## Type de calendrier utilise
+## valeur possible: earth_360d (defaut), earth_365d, earth_366d
+ip_ebil_phy=1
+ip_ebil_dyn=1
+calend=earth_366d
+## Jour de l'etat initial ( = 350  si 20 Decembre ,par expl. ,comme ici )
+dayref=@iday@
+##  Annee de l'etat  initial (   avec  4  chiffres   )
+anneeref=@iyear@
+## Nombre de jours d'integration
+nday=@freq@
+## Remise a zero de la date initiale
+raz_date=1
+## periode de sortie des variables de controle (en pas)
+iconser=20
+## periode d'ecriture du fichier histoire (en jour)
+iecri=1
+## flag de sortie dynzon
+ok_dynzon=n
+## periode de stockage fichier dynzon (en jour)
+periodav= @freq@.
+# Values of solarlong0 are all defaults
+#solarlong0 = 0 
+## activation du calcul d equilibrage de charge
+adjust=n
+## activation du filtre fft
+use_filtre_fft=n
+## niveau d'impression de controle
+prt_level=0
+qsol0=-1.
