Ignore:
Timestamp:
May 30, 2024, 2:36:54 PM (4 months ago)
Author:
abarral
Message:

(WIP) continue refactoring setup.sh

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BOL/LMDZ_Setup_amaury/setup.sh

    r4954 r4955  
    6767
    6868# /!\ DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING /!\
     69
     70function enable_groupe {  # In job scripts, sed platform-specific headers
     71  local file="$1"
     72  local platform
     73
     74  case ${hostname:0:5} in
     75    jean-) platform="JZ";;
     76    *) echo "Warning: $hostname is not a known job platform (ignore if running locally)"; return 0;;
     77  esac
     78
     79  sed -i'' -e "s/^#@$platform//" "$file"
     80}
    6981
    7082function load_install_lib {
     
    225237  chmod +x install_lmdz_options.$$.sh
    226238  echo "Running install_lmdz_options.$$.sh"
    227   ./install_lmdz_options.$$.sh
     239  gcm=$MODEL/$(./install_lmdz_options.$$.sh | tee /dev/tty | tail -n 1 | sed -n "s:.* executable is \(.*\.e\).*:\1:p")
    228240  mv install_lmdz.sh install_lmdz.$$.sh
    229241  cd "$local"
    230242}
    231243
    232 function setup_def {  # modify various .def (+ xios xml as needed)
     244function setup_def {  # modify various .def in ./DEF (+ xios xml as needed)
    233245  cd "$local"
    234246
     
    252264  ######################################################################
    253265  # Changements dans les fichiers DEF/*def
    254   # (ils vont se repercuter dans les repertoires de simulation $local/$SIM et de run $WRK)
     266  # (ils vont se repercuter dans les repertoires de simulation $local/$SIM et de run $SIMRUNDIR)
    255267  ######################################################################
    256268
     
    287299  #   cf options veget, aerosols, cosp, xios
    288300  #---------------------------------------------------------------------
    289   if [[ $veget = NONE ]]; then  VEGET="n"; else VEGET="y"; fi
     301  if [[ $veget = none ]]; then  VEGET="n"; else VEGET="y"; fi
    290302  sed -i'' -e 's/VEGET=.*.$/VEGET='$VEGET'/' DEF/config.def
    291303
     
    332344  ######################################################################
    333345  # Si on tourne avec XIOS, mise a jour des fichiers context et field* dans XMLfilesLMDZ
    334   # (ils vont se repercuter dans les repertoires de simulation $local/$SIM et de run $WRK)
     346  # (ils vont se repercuter dans les repertoires de simulation $local/$SIM et de run $SIMRUNDIR)
    335347  ######################################################################
    336348  if [[ $xios = y ]]; then
     
    341353}
    342354
    343 function setup_init { # Verification de l'existance de l'état initial et compilation eventuelle pour sa creation
     355function setup_ce0l { # Verification de l'existance de l'état initial, compilation eventuelle pour sa creation
    344356  if [[ ! -d $INIT ]]; then
    345357    if [[ $init = 0 ]]; then
     
    352364      if ! ./compile_ce0l.sh &> ce0l.log; then echo "STOP: ce0l compilation failed, see $MODEL/ce0l.log"; exit 1; fi
    353365      echo "Compiled ce0l"
     366      ce0l=${gcm/gcm/ce0l}
    354367
    355368      cd "$local"
     
    360373}
    361374
     375function setup_simu {
     376  SIMRUNDIR=$SIMRUNTOPDIR
     377  mkdir -p "$SIMRUNDIR"
     378  cd "$SIMRUNDIR"
     379  echo "La simulation s'exécutera sur $SIMRUNDIR"
     380
     381  #####################################################################
     382  # Creation du repertoire $SIM s'il n'existe pas deja
     383  #####################################################################
     384  if [[ ! -d $local/$SIM ]]; then
     385    mkdir "$local/$SIM"
     386    cd "$local"
     387
     388    # Edit reb.sh
     389    cp reb.sh "$local/$SIM/reb.sh"; chmod +x "$local/$SIM/reb.sh"
     390    sed -i'' -e "s:^rebuild=.*.$:rebuild=$LMDZD/$LMDZname/modipsl/bin/rebuild:" \
     391    -e "s/@@groupe/$GROUPE/" "$local/$SIM/reb.sh"
     392    enable_groupe "$local/$SIM/reb.sh"
     393
     394    # Copy .def
     395    cp lmdz_env.sh "$local/$SIM/"
     396    mkdir "$local/$SIM/DEF"; cp DEF/*def DEF/namelis* "$local/$SIM/DEF/"
     397    #Pour XIOS, respectivement COSP, copier aussi les fichiers *xml / *txt
     398    if [[ $cosp = "y" ]]; then cp DEF/cosp*txt "$local/$SIM/DEF/"; fi
     399    if [[ $xios = "y" ]]; then
     400       cp DEF/XMLfilesLMDZ/*xml "$local/$SIM/DEF/"
     401       if [[ $veget != 'none' ]]; then cp DEF/XMLfilesOR$veget/*xml "$local/$SIM/DEF/"; fi
     402    fi
     403    chmod u+w "$local/$SIM"/DEF/*
     404
     405    # Gestion du calendrier
     406    #######################
     407    cd "$SIM"
     408    sed -i'' -e "s/anneeref=.*.$/anneeref=$yearini/" DEF/run.def
     409    if [[ $freq = "yr" ]]; then date=$yearini; else date=$mthini; fi
     410    echo "$date a faire" >| etat
     411
     412    # Recuperation des fichiers : executable initiaux et forcages
     413    #############################################################
     414    echo "date: $date"
     415    for f in start startphy; do
     416      inf=../$INIT/$f.$date.nc
     417      if [[ -f $inf || $init = 1 ]]; then ln -s "$inf" ./; else echo "STOP: $inf missing"; exit ; fi;
     418    done
     419    for f in sechiba stomate; do
     420      if [[ -f ../$INIT/start_$f.$date.nc ]]; then ln -sf "../$INIT/start_$f.$date.nc" .; fi
     421    done
     422    cp "$gcm" gcm.e
     423  fi
     424  cd "$local"/..
     425
     426  #####################################################################
     427  echo "Modification du script de lancement"
     428  #####################################################################
     429  local cput
     430  if [[ $freq = "yr" ]]; then cput="04:00:00"; else cput="01:00:00"; fi
     431  local isotopes="n"
     432  if [[ $phylmd = "lmdiso" ]]; then isotopes="y"; fi
     433  sed -e "s/@@groupe/$GROUPE/" \
     434  -e "s/NOM_SIMU/$SIM/" \
     435  -e "s/time=.*.$/time=$cput/" \
     436  -e "s/ntasks=.*.$/ntasks=$mpi/" \
     437  -e "s/cpus-per-task=.*.$/cpus-per-task=$omp/" \
     438  -e "s/nthreads=.*./nthreads=$omp/" \
     439  -e "s/MAINDIR=.*.$/MAINDIR=$(basename "$SIMRUNTOPDIR")/" \
     440  -e "s:STORED=.*.*:STORED=$SIMRESDIR:" \
     441  -e "s:SCRATCHD=.*.*:SCRATCHD=$(dirname "$SIMRUNTOPDIR"):" \
     442  -e "s/stopsim=.*.$/stopsim=$stopsim/" \
     443  -e "s/^veget=.*.$/veget=$veget/" \
     444  -e "s/^aerosols=.*.$/aerosols=$aerosols/" \
     445  -e "s/^isotopes=.*.$/isotopes=$isotopes/" \
     446  -e "s/^climato=.*.$/climato=$climato/" \
     447  -e "s/^ok_guide=.*.$/ok_guide=$ok_guide/" \
     448  "$local/script_SIMU" >| "$SIMRUNDIR/tmp_$SIM"
     449
     450  enable_groupe "$SIMRUNDIR/tmp_$SIM"
     451
     452  if [[ $testmode = "y" ]]; then
     453    sed -i'' -e "s/time=.*.$/time=00:30:00/" -e "s/#nday=1/nday=1/" -e "s/#@TESTQ//" "$SIMRUNTOPDIR/tmp_$SIM"
     454  fi
     455}
     456
     457function fetch_simu_init_files {
     458  #####################################################################
     459  echo "Recuperation eventuelle de certains fichiers sur $LMDZ_INIT"
     460  #####################################################################
     461  mkdir -p "$LMDZ_INIT"
     462
     463  #-------------------------------------------------------------------
     464  # Fichiers ORCHIDEE
     465  #-------------------------------------------------------------------
     466  get="myget 3DInputData/Orchidee/"
     467  cd "$LMDZ_INIT";
     468  for file in "PFTmap_IPCC_2000.nc" "cartepente2d_15min.nc" "routing.nc" "routing_simple.nc" "lai2D.nc" "soils_param.nc" "woodharvest_2000.nc" "PFTmap_15PFT.v1_2000.nc"; do
     469    if [[ ! -f $file ]]; then ${get}$file; fi
     470  done
     471  cd - > /dev/null
     472  # Additionnal files needed for ORCHIDEE trunk post-CMIP6
     473  if [[ $veget = 7994 && ! -f $LMDZ_INIT/soil_bulk_and_ph.nc ]]; then
     474    cd "$LMDZ_INIT"
     475    ${get}soil_bulk_and_ph.nc; ${get}NITROGEN_for_ORtrunk.tar
     476    tar -xvf NITROGEN_for_ORtrunk.tar; cd - > /dev/null
     477  fi
     478  #-------------------------------------------------------------------
     479  # Fichiers aerosols/chimie
     480  #-------------------------------------------------------------------
     481  if [[ $aerosols = "clim" ]]; then
     482    get="myget 3DInputData/AerChem/"
     483    #liste_get="aerosols1850_from_inca.nc aerosols2000_from_inca.nc"
     484    #aerosols9999_from_inca.nc est un lien vers aerosols1995_2014_ensavg_from_inca.nc
     485    cd "$LMDZ_INIT"
     486    for file in "aerosols1850_from_inca.nc" "aerosols9999_from_inca.nc"; do
     487      if [[ ! -f $file ]]; then ${get}$file; fi
     488    done
     489    cd - > /dev/null
     490  fi
     491  # For SPLA
     492  #-------------------
     493  # Dans ${LMDZ_INIT} on cree folder SPLA_Init et dedans le INITIAL
     494  # Pour l'instant on copie là-dedans de chez Binta les fichiers a la res zoomNaf;
     495  # plus tard on y recupererea des fichiers a haute resolution reguliere depuis http:/LMDZ,
     496  # a regrider ensuite par un script interp_fichiers_spla.sh (comme pour aerosols="clim")
     497  # Les fichiers (regrides, sauf SOILSPEC.data utilise tel quel) seront mis dans $MAINDIR/INPUT_SPLA (equivalent de INPUT_DUST)
     498  if [[ $aerosols = "spla" ]]; then
     499    mkdir -p "${LMDZ_INIT}/SPLA_Init"; mkdir -p "$LMDZ_INIT/SPLA_Init/INITIAL"
     500    get="cp -p /gpfsstore/rech/gzi/rgzi027/ergon/BIBIAERO/INPUTS_DUST/INITIAL/"
     501    liste_get="wth.dat cly.dat donnees_lisa.nc SOILSPEC.data \
     502                 carbon_emissions.nc sulphur_emissions_antro.nc  \
     503                 sulphur_emissions_nat.nc  sulphur_emissions_volc.nc"
     504
     505    cd "$LMDZ_INIT/SPLA_Init/INITIAL"
     506    for file in $liste_get; do
     507      if [[ ! -f $file ]]; then ${get}$file .; fi
     508    done
     509    cd - > /dev/null
     510    ###
     511    #Cas particulier des fichiers mensuels dust.nc :A DECIDER :
     512    #C'est entre le cas des aerosols.clim= 1 seul fichier, annuel,
     513    # et le cas des vents guidage, pré-interpolés avec era2gcm pour toute la periode, dans MAINDIR/GUIDE.
     514    # On pourrait (a)demander de precalculer dust.nc aussi, dans MAINDIR/INPUT_SPLA - avec un script à adapter de Jeronimo. Rien a mettre dans SPLA_Init alors.
     515    # Ou (b) fournir dans SPLA_Init les 12 mois d'un dust.nc climato (an 2006 pour nous ici) à la res EC, et faire juste le regrid vers MAINDIR/INPUT_SPLA
     516    #ICI pour l'instant je copie les fichiers de chez Binta (repositoire==http...) dans LMDZ_INIT/SPLA_Init, avec test sur mois 01
     517
     518    if [[ ! -d ${LMDZ_INIT}/SPLA_Init/PERIOD0001 ]]; then
     519      if [[ ${hostname:0:5} != "jean-" ]]; then echo "PERIOD001 (aerosols=spla) IS ONLY AVAILABLE ON JEANZAY FOR NOW, CONTACT SUPPORT"; exit 1; fi
     520      cp -pr /gpfsstore/rech/gzi/rgzi027/ergon/BIBIAERO/INPUTS_DUST/PERIOD* "$LMDZ_INIT/SPLA_Init/.";
     521    fi
     522   #A la fin on doit avoir dans SPLA_Init les fichiers initiaux dans INITIAL plus les repertoires PERIOD00MM contenant dust.nc
     523   #Cela doit se retrouver dans script_SIMU qui les copie dans le repertoire de run sur $SCRATCH
     524  fi
     525  #-------------------------------------------------------------------
     526  # Fichiers Init
     527  #-------------------------------------------------------------------
     528  get="myget 3DInputData/Init/"
     529  liste_get="alb_bg_modisopt_2D_ESA_v2.nc reftemp.nc"
     530  cd "$LMDZ_INIT"
     531  for file in $liste_get; do
     532    if [[ ! -f $LMDZ_INIT/$file ]]; then ${get}$file; fi
     533  done
     534  cd - > /dev/null
     535}
     536
     537function run_sim_or_init {
     538  cd "$local"
     539  if [[ $init = 1 ]]; then
     540    #####################################################################
     541    echo "Creation de l etat initial"
     542    #####################################################################
     543
     544    # Creation du repertoire INIT et mise en place de liens logiques vers les starts
     545    # en anticipation de leur création :
     546    mkdir "$local/$INIT"; cd "$local/$INIT"
     547    for an in $mthini $yearini; do for f in start startphy; do ln -s "$f.nc" "$f.$an.nc"; done; done
     548
     549    # Creation du repertoire INIT temporaire et rapatriement des fichiers necessaires
     550    if [[ -d $SIMRUNDIR/$INIT ]]; then mv "$SIMRUNDIR/$INIT" "$SIMRUNDIR/$INIT$$"; fi
     551    mkdir "$SIMRUNDIR/$INIT"; cp -r "$local/DEF" "$SIMRUNDIR/$INIT/"
     552    cd "$SIMRUNDIR/$INIT"; cp DEF/*.def .; cp "$local/lmdz_env.sh" .
     553    if [[ $xios = "y" ]]; then
     554      cp DEF/XMLfilesLMDZ/*xml .
     555      if [[ $veget != 'none' ]]; then cp DEF/XMLfilesOR$veget/*xml .; fi
     556    fi
     557    sed -e "s/anneeref=.*.$/anneeref=$yearini/" DEF/run.def >| run.def
     558
     559    #-------------------------------------------------------------------
     560    # Fichiers Limit
     561    #-------------------------------------------------------------------
     562    local yrs suf
     563    if [[ $climato = 0 ]]; then
     564      # calend est choisi plus haut dans "Changements dans les fichiers DEF/*def" et ecrit dans $MAINDIR/DEF/run.def
     565      yrini=$(echo "$mthini" | cut -c-4)
     566      yrend=$(echo "$mthend" | cut -c-4)
     567      yrs=""; yr=$yrini
     568      while [[ $yr -le $yrend ]]; do yrs="$yrs $yr"; (( yr = yr + 1 )); done
     569      suf="360x180_"
     570    else
     571      yrs=2000
     572      suf="1x1_clim"
     573    fi
     574
     575    get="myget 3DInputData/Limit/"
     576    liste_get="Albedo.nc Relief.nc Rugos.nc landiceref.nc"
     577    for yr in $yrs; do
     578       if [[ $climato = 0 ]]; then sufyr=$suf$yr; else sufyr=$suf; fi
     579       liste_get="$liste_get amipbc_sic_$sufyr.nc amipbc_sst_$sufyr.nc"
     580    done
     581    echo LISTEGET "$liste_get"
     582    for file in $liste_get; do
     583      cd "$LMDZ_INIT"
     584      if [[ ! -f $LMDZ_INIT/$file ]]; then ${get}$file; fi
     585      cd - > /dev/null
     586      ln -s "$LMDZ_INIT/$file" .
     587    done
     588    #-------------------------------------------------------------------
     589    # ECDYN
     590    #-------------------------------------------------------------------
     591    get="myget 3DInputData/Init/"
     592    if [[ ! -f $LMDZ_INIT/ECDYN.nc ]]; then cd "$LMDZ_INIT"; ${get}ECDYN.nc; cd - > /dev/null; fi
     593    ln -s "$LMDZ_INIT"/ECDYN.nc .
     594    ln -sf ECDYN.nc ECPHY.nc
     595
     596    # Creation du script d'initialisation
     597    cat << ...eod >| tmp
     598#!/bin/bash
     599#@JZ#JeanZay
     600#@JZ#SBATCH --job-name=Init         # nom du job
     601#@JZ#SBATCH -A "$GROUPE"@cpu
     602#@JZ#SBATCH --ntasks=1             # Nombre de processus MPI
     603#@JZ#SBATCH --cpus-per-task=16     # nombre de threads OpenMP
     604#@JZ# /!\ Attention, la ligne suivante est trompeuse mais dans le vocabulaire
     605#@JZ# de Slurm "multithread" fait bien référence à l'hyperthreading.
     606#@JZ#SBATCH --hint=nomultithread   # 1 thread par coeur physique (pas d'hyperthreading)
     607#@JZ#SBATCH --time=00:10:00            # Temps d’exécution maximum demandé (HH:MM:SS)
     608#@JZ#SBATCH --output=Init%j.out     # Nom du fichier de sortie
     609#@JZ#SBATCH --error=Init%j.out      # Nom du fichier d'erreur (ici commun avec la sortie)
     610#@JZ# To submit to dev queue; "time" (above) must be max 2h
     611#@JZ# #SBATCH --qos=qos_cpu-dev
     612
     613# ANCIEN MULTI STEP  case \${LOADL_STEP_NAME} in
     614
     615# ANCIEN MULTI STEP   init )
     616
     617if [ ! -f lmdz_env.sh ]; then echo "manque fichier lmdz_env.sh"; ls; exit 1; fi
     618. lmdz_env.sh
     619ulimit -s unlimited
     620export OMP_STACKSIZE=800M
     621export OMP_NUM_THREADS=1
     622cd $SIMRUNDIR/$INIT
     623echo "Executable : $ce0l"
     624for yr in $yrs; do
     625  if [ $climato = 0 ]; then sufyr=$suf\$yr; else sufyr=$suf; fi
     626  ln -sf amipbc_sic_\$sufyr.nc amipbc_sic_1x1.nc
     627  ln -sf amipbc_sst_\$sufyr.nc amipbc_sst_1x1.nc
     628  sed -e 's/anneeref=.*.$/anneeref='\$yr'/' DEF/run.def >| run.def
     629  echo Starting initialisation
     630  $RUNCMD 1 $ce0l
     631  if [ $climato = 0 ]; then mv limit.nc limit.\$yr.nc; fi
     632done
     633# ANCIEN MULTI STEP   ;;
     634
     635# ANCIEN MULTI STEP   interp )
     636if [ $aerosols = clim ]; then
     637cp $local/interp_aerosols.sh .; chmod +x interp_aerosols.sh
     638# Les aerosols de l'annee 2000 ont ete remplaces par "9999" qui pointe vers un fichier moyen sur 1995-2014
     639#for year in 2000 1850; do  ./interp_aerosols.sh \$year; done
     640#mv aerosols.2000.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
     641for year in 9999 1850; do ./interp_aerosols.sh \$year; done
     642mv aerosols.9999.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
     643fi
     644
     645# AS : S'il etait possible d'automatiser l'interpolation de l'input SPLA, ce serait a lancer ici
     646#en attendant, on passe au paragraphe suivant où on copie les fichiers à la res ZoomNaf depuis $LMDZ_INIT/SPLA_Init
     647#if [ $aerosols = spla ]; then
     648#cp $local/futur script interp_aerosols_SPLA.sh .; chmod +x interp_aerosols_SPLA.sh
     649#for file in...; do  ./interp_aerosols_SPLA.sh \$year; done
     650#etc etc etc ...
     651#fi
     652
     653# Copy initial and forcing files in $local/$INIT and $local/$LIMIT; also in $local/INPUT_SPLA if $aerosols=spla
     654for f in sta* limit.nc gri*nc; do cp \$f $local/$INIT/\$f; done
     655mkdir -p $local/$LIMIT
     656for f in limit*.nc ; do cp \$f $local/$LIMIT/\$f; done
     657if [ $aerosols = clim ]; then  for f in aerosols[.0-9]*nc; do cp \$f $local/$LIMIT/\$f; done; fi
     658#
     659if [ $aerosols = spla ]; then
     660 #mkdir -p $local/INPUT_SPLA; pour l'instant on copie $LMDZ_INIT/SPLA_Init en block
     661 if [ ! -d $local/INPUT_SPLA ]; then cp -pr $LMDZ_INIT/SPLA_Init $local/INPUT_SPLA; fi
     662fi
     663cd $SIMRUNDIR
     664...eod
     665    if [[ $ok_guide != "y" ]]; then # Running first simulation automatically except for nudging
     666      cat << ...eod >> tmp
     667       $SUBMITCMD tmp_$SIM
     668...eod
     669    fi
     670    cat << ...eod >> tmp
     671  # ANCIEN MULTI STEP   esac
     672...eod
     673    enable_groupe tmp
     674    echo "###############################################################################"
     675    echo "Submitting initialisation job <$SUBMITCMD tmp> from $(pwd)"
     676    chmod +x tmp
     677    $SUBMITCMD tmp
     678    echo "###############################################################################"
     679
     680  else #case [ $init != 1 ]
     681     cd "$SIMRUNDIR"
     682     echo "###############################################################################"
     683     echo "Submitting job tmp_$SIM"
     684     echo "$SUBMITCMD tmp_$SIM"
     685     $SUBMITCMD "tmp_$SIM"
     686     echo '###############################################################################'
     687  fi
     688}
     689
    362690# Set up the appropriate environment
    363691source lmdz_env.sh
    364692
    365 # TODO Amaury: commented-out for now
     693# TODO Amaury: commented-out for now // /!\ check w/ Adriana: "groupe@cpu" never appears in seasonal.sh...
    366694## Pour les post-traitements
    367695#sed -i'' -e "s/groupe@cpu/$groupe@cpu/" seasonal.sh
     
    375703install_model
    376704setup_def
    377 setup_init
     705setup_ce0l
     706setup_simu
     707fetch_simu_init_files
     708run_sim_or_init
    378709
    379710exit 1
     
    383714#-------------------------------------------------------
    384715if [[ $rad = "ecrad" && ! -d ecrad_data ]]; then
    385     cd "$local"; wget https://lmdz.lmd.jussieu.fr/pub/3DInputData/ecrad/ecrad_data.tar; tar xvf ecrad_data.tar; cd -
     716    cd "$local"; wget https://lmdz.lmd.jussieu.fr/pub/3DInputData/ecrad/ecrad_data.tar; tar xvf ecrad_data.tar; cd - > /dev/null
    386717fi
    387718
    388719if [[ $rad = "ecrad" && $aerosols != "n" && $mysvn -lt 4489 ]] ; then echo "Les aerosols tropospheriques ne sont pas pris en charge par ecrad avant LMDZ rev 4489, ici rev est $mysvn"; exit 1; fi
    389 
    390 
    391 
    392 
    393 
    394 
    395 
    396 
    397 
    398 
    399 
    400 MAINDIR=`basename \`pwd\``
    401720
    402721# EXIT after (install and) compilation if we are on jean-zay-pp instead of jean-zay !
    403722hostname=`hostname`
    404723if [ ${hostname:0:11} = "jean-zay-pp" ]; then
    405  echo "You are on jean-zay-pp, here you only can install and compile the model, not run it" 
     724 echo "You are on jean-zay-pp, here you only can install and compile the model, not run it"
    406725 echo "If you want to run a simulation, log in to jean-zay and launch main.sh again, without install"
    407726 echo `date`
     
    409728fi
    410729
    411 ######################################################################
    412 # On cree sur le SCRATCHD un repertoire de travail avec le meme
    413 # nom que le repertoire local
    414 ######################################################################
    415 . ./lmdz_env.sh
    416 WRK=$SCRATCHD/$MAINDIR
    417 mkdir -p $WRK
    418 cd $WRK
    419 echo La simulation s executera sur $SCRATCHD/$MAINDIR
    420 
    421 #####################################################################
    422 # Creation du repertoire $SIM s'il n'existe pas deja
    423 #####################################################################
    424 
    425 if [ ! -d $local/$SIM ]; then
    426 mkdir $local/$SIM
    427 cd $local
    428 sed -e 's:^rebuild=.*.$:rebuild='$LMDZD/$LMDZname/modipsl/bin/rebuild':' -e 's/groupe@cpu/'$groupe'@cpu/' reb.sh  >| $local/$SIM/reb.sh; chmod +x $local/$SIM/reb.sh
    429 cp lmdz_env.sh $local/$SIM/
    430 mkdir $local/$SIM/DEF; cp DEF/*def DEF/namelis* $local/$SIM/DEF/
    431 #Pour XIOS, respectivement COSP, copier aussi les fichiers *xml / *txt
    432 if [ $cosp = y ]; then cp DEF/cosp*txt $local/$SIM/DEF/; fi
    433 if [ $xios = y ]; then
    434    cp DEF/XMLfilesLMDZ/*xml $local/$SIM/DEF/
    435    if [ $veget != 'NONE' ]; then cp DEF/XMLfilesOR$veget/*xml $local/$SIM/DEF/; fi
    436 fi
    437 chmod u+w $local/$SIM/DEF/*
    438 
    439 # Gestion du calendrier
    440 #######################
    441 sed -e 's/anneeref=.*.$/anneeref='$yearini'/' \
    442     DEF/run.def >| $local/$SIM/DEF/run.def
    443 cd $SIM
    444 if [ "$freq" = "yr" ]; then date=$yearini; else date=$mthini; fi
    445 echo $date a faire >| etat
    446 
    447 # Recuperation des fichiers : executable initiaux et forcages
    448 #############################################################
    449 echo $date
    450 for f in start startphy; do inf=../$INIT/$f.$date.nc; if [ -f $inf -o $init = 1 ]; then ln -s $inf ./; else echo $inf inexistant; exit; fi; done
    451 for f in sechiba stomate; do if [ -f ../$INIT/start_$f.$date.nc ]; then ln -sf  ../$INIT/start_$f.$date.nc .; fi; done
    452 cp $gcm gcm.e
    453 fi  # fin de " if [ ! -d $local/$SIM ]"
    454 cd $local/..
    455 
    456 # Choix du "time limit" pour le job
    457 ###################################
    458 if [ "$freq" = "yr" ]; then cput=04:00:00; else cput=01:00:00; fi
    459 
    460 #####################################################################
    461 echo Modification du script de lancement
    462 ###################################################################/$S
    463 sed -e 's/stopsim=.*.$/stopsim='$stopsim'/' -e 's/^veget=.*.$/veget='$veget'/' -e 's/orchidee_rev=.*.$/orchidee_rev='$orchidee_rev'/' -e 's/^aerosols=.*.$/aerosols='$aerosols'/' -e 's/^isotopes=.*.$/isotopes='$isotopes'/' -e 's/NOM_SIMU/'$SIM'/' -e 's/time=.*.$/time='$cput'/' -e 's/MAINDIR=.*.$/MAINDIR='$MAINDIR'/' -e 's:STORED=.*.*:STORED='$STORED':'  -e 's:SCRATCHD=.*.*:SCRATCHD='$SCRATCHD':' -e 's/ntasks=.*.$/ntasks='$mpi'/' -e 's/cpus-per-task=.*.$/cpus-per-task='$omp'/' -e 's/nthreads=.*./nthreads='$omp'/' -e 's/^climato=.*.$/climato='$climato'/' -e 's/^ok_guide=.*.$/ok_guide='$ok_guide'/' -e 's/groupe@cpu/'$groupe'@cpu/' $local/script_SIMU >| $WRK/tmp_$SIM
    464 
    465 if [ "$testmode" = "y" ]; then
    466   sed -i -e 's/time=.*.$/time=00:30:00/' -e 's/#nday=1/nday=1/' -e 's/#[[:space:]]#SBATCH[[:space:]]--qos=qos_cpu-dev/#SBATCH --qos=qos_cpu-dev/' $WRK/tmp_$SIM
    467 fi
    468 
    469 if [ $climato = 0 ]; then
    470 # calend est choisi plus haut dans "Changements dans les fichiers DEF/*def" et ecrit dans $MAINDIR/DEF/run.def
    471 yrini=`echo $mthini | cut -c-4`
    472 yrend=`echo $mthend | cut -c-4`
    473 yrs=""; yr=$yrini; while [ $yr -le $yrend ]; do yrs="$yrs $yr"; (( yr = $yr + 1 )); done
    474 suf=360x180_
    475 else
    476 yrs=2000
    477 suf=1x1_clim
    478 fi
    479 
    480 
    481 #####################################################################
    482    echo Recuperation eventuelle de certains fichiers sur LMDZ_Init
    483 #####################################################################
    484 
    485 if [ ! -d $LMDZ_Init ]; then mkdir $LMDZ_Init; fi
    486 
    487 #-------------------------------------------------------------------
    488 # Fichiers ORCHIDEE
    489 #-------------------------------------------------------------------
    490 get="myget 3DInputData/Orchidee/"
    491 liste_get="PFTmap_IPCC_2000.nc cartepente2d_15min.nc "
    492 liste_get+="routing.nc routing_simple.nc lai2D.nc soils_param.nc "
    493 liste_get+="woodharvest_2000.nc PFTmap_15PFT.v1_2000.nc"
    494 for file in $liste_get; do
    495   if [ ! -f $LMDZ_Init/$file ]; then cd $LMDZ_Init; ${get}$file; cd -; fi
    496 done
    497 # Additionnal files needed for ORCHIDEE trunk post-CMIP6
    498 if [ $veget = 7994 -a ! -f $LMDZ_Init/soil_bulk_and_ph.nc ]; then
    499   cd $LMDZ_Init
    500   ${get}soil_bulk_and_ph.nc; ${get}NITROGEN_for_ORtrunk.tar
    501   tar -xvf NITROGEN_for_ORtrunk.tar; cd -
    502 fi
    503 #-------------------------------------------------------------------
    504 # Fichiers aerosols/chimie
    505 #-------------------------------------------------------------------
    506 if [ $aerosols = clim ]; then
    507   get="myget 3DInputData/AerChem/"
    508   #liste_get="aerosols1850_from_inca.nc aerosols2000_from_inca.nc"
    509   #aerosols9999_from_inca.nc est un lien vers aerosols1995_2014_ensavg_from_inca.nc
    510   liste_get="aerosols1850_from_inca.nc aerosols9999_from_inca.nc"
    511   for file in $liste_get; do
    512     if [ ! -f $LMDZ_Init/$file ]; then cd $LMDZ_Init; ${get}$file; cd -; fi
    513   done
    514 fi
    515 
    516 # For SPLA
    517 #-------------------
    518 # Dans ${LMDZ_Init} on cree folder SPLA_Init et dedans le INITIAL
    519 # Pour l'instant on copie là-dedans de chez Binta les fichiers a la res zoomNaf;
    520 # plus tard on y recupererea des fichiers a haute resolution reguliere depuis http:/LMDZ,
    521 # a regrider ensuite par un script interp_fichiers_spla.sh (comme pour aerosols="clim")
    522 # Les fichiers (regrides, sauf SOILSPEC.data utilise tel quel) seront mis dans $MAINDIR/INPUT_SPLA (equivalent de INPUT_DUST)
    523 if [ $aerosols = spla ]; then
    524   if [ ! -d ${LMDZ_Init}/SPLA_Init ]; then mkdir ${LMDZ_Init}/SPLA_Init; mkdir $LMDZ_Init/SPLA_Init/INITIAL; fi
    525   get="cp -p /gpfsstore/rech/gzi/rgzi027/ergon/BIBIAERO/INPUTS_DUST/INITIAL/"
    526   liste_get="wth.dat cly.dat donnees_lisa.nc SOILSPEC.data \
    527                carbon_emissions.nc sulphur_emissions_antro.nc  \
    528                sulphur_emissions_nat.nc  sulphur_emissions_volc.nc"
    529 
    530   for file in $liste_get; do
    531     if [ ! -f $LMDZ_Init/SPLA_Init/INITIAL/$file ]; then cd $LMDZ_Init/SPLA_Init/INITIAL; ${get}$file .; cd -; fi
    532   done
    533 ###
    534   #Cas particulier des fichiers mensuels dust.nc :A DECIDER :
    535   #C'est entre le cas des aerosols.clim= 1 seul fichier, annuel,
    536   # et le cas des vents guidage, pré-interpolés avec era2gcm pour toute la periode, dans MAINDIR/GUIDE.
    537   # On pourrait (a)demander de precalculer dust.nc aussi, dans MAINDIR/INPUT_SPLA - avec un script à adapter de Jeronimo. Rien a mettre dans SPLA_Init alors.
    538   # Ou (b) fournir dans SPLA_Init les 12 mois d'un dust.nc climato (an 2006 pour nous ici) à la res EC, et faire juste le regrid vers MAINDIR/INPUT_SPLA
    539   #ICI pour l'instant je copie les fichiers de chez Binta (repositoire==http...) dans LMDZ_Init/SPLA_Init, avec test sur mois 01
    540 
    541   if [ ! -d ${LMDZ_Init}/SPLA_Init/PERIOD0001 ]; then cp -pr /gpfsstore/rech/gzi/rgzi027/ergon/BIBIAERO/INPUTS_DUST/PERIOD* $LMDZ_Init/SPLA_Init/.; fi
    542 
    543  #A la fin on doit avoir dans SPLA_Init les fichiers initiaux dans INITIAL plus les repertoires PERIOD00MM contenant dust.nc
    544  #Cela doit se retrouver dans script_SIMU qui les copie dans le repertoire de run sur $SCRATCH
    545 
    546 fi #$aerosols = spla
    547 
    548 
    549 #-------------------------------------------------------------------
    550 # Fichiers Init
    551 #-------------------------------------------------------------------
    552 get="myget 3DInputData/Init/"
    553 liste_get="alb_bg_modisopt_2D_ESA_v2.nc reftemp.nc"
    554 for file in $liste_get; do
    555   if [ ! -f $LMDZ_Init/$file ]; then cd $LMDZ_Init; ${get}$file; cd -; fi
    556 done
    557 
    558 cd $local
    559 
    560 
    561 
    562 if [ $init = 1 ]; then
    563    #####################################################################
    564       echo Creation de l etat initial
    565    #####################################################################
    566 
    567    # Creation du repertoire INIT et mise en place de liens logiques vers les starts
    568    # en anticipation de leur création :
    569    mkdir $local/$INIT; cd $local/$INIT
    570    for an in $mthini $yearini; do for f in start startphy; do ln -s $f.nc $f.$an.nc; done; done
    571 
    572    # Creation du repertoire INIT temporaire et rapatriement des fichiers necessaires
    573    if [ -d $WRK/$INIT ]; then mv $WRK/$INIT $WRK/$INIT$$; fi
    574    mkdir $WRK/$INIT;  cp -r $local/DEF $WRK/$INIT/
    575    cd $WRK/$INIT; cp DEF/*.def .; cp $local/lmdz_env.sh .
    576    if [ $xios = y ]; then
    577        cp DEF/XMLfilesLMDZ/*xml . 
    578        if [ $veget != 'NONE' ]; then cp DEF/XMLfilesOR$veget/*xml .; fi
    579    fi
    580    sed -e 's/anneeref=.*.$/anneeref='$yearini'/' DEF/run.def >| run.def
    581 
    582 #-------------------------------------------------------------------
    583 # Fichiers Limit
    584 #-------------------------------------------------------------------
    585    get="myget 3DInputData/Limit/"
    586    liste_get="Albedo.nc Relief.nc Rugos.nc landiceref.nc"
    587    for yr in $yrs; do
    588        if [ $climato = 0 ]; then sufyr=$suf$yr; else sufyr=$suf; fi
    589        liste_get="$liste_get  amipbc_sic_$sufyr.nc amipbc_sst_$sufyr.nc"
    590    done
    591    echo LISTEGET $liste_get
    592    for file in $liste_get; do
    593      if [ ! -f $LMDZ_Init/$file ]; then cd $LMDZ_Init; ${get}$file; cd -; fi
    594      ln -s $LMDZ_Init/$file
    595    done
    596 #-------------------------------------------------------------------
    597 # ECDYN
    598 #-------------------------------------------------------------------
    599    get="myget 3DInputData/Init/"
    600    if [ ! -f $LMDZ_Init/ECDYN.nc ]; then cd $LMDZ_Init; ${get}ECDYN.nc; cd -; fi
    601    ln -s $LMDZ_Init/ECDYN.nc
    602    ln -sf ECDYN.nc ECPHY.nc
    603 
    604 
    605    # Creation du script d'initialisation
    606    cat << ...eod >| tmp
    607 #!/bin/bash
    608 
    609 #SBATCH --job-name=Init         # nom du job
    610 #SBATCH -A "$groupe"@cpu
    611 #SBATCH --ntasks=1             # Nombre de processus MPI
    612 #SBATCH --cpus-per-task=16     # nombre de threads OpenMP
    613 # /!\ Attention, la ligne suivante est trompeuse mais dans le vocabulaire
    614 # de Slurm "multithread" fait bien référence à l'hyperthreading.
    615 #SBATCH --hint=nomultithread   # 1 thread par coeur physique (pas d'hyperthreading)
    616 #SBATCH --time=00:10:00            # Temps d’exécution maximum demandé (HH:MM:SS)
    617 #SBATCH --output=Init%j.out     # Nom du fichier de sortie
    618 #SBATCH --error=Init%j.out      # Nom du fichier d'erreur (ici commun avec la sortie)
    619 # To submit to dev queue; "time" (above) must be max 2h
    620 # #SBATCH --qos=qos_cpu-dev
    621 
    622 # ANCIEN MULTI STEP  case \${LOADL_STEP_NAME} in
    623 
    624 # ANCIEN MULTI STEP   init )
    625 
    626    if [ ! -f lmdz_env.sh ]; then echo manque fichier lmdz_env.sh; ls; exit; fi
    627    . lmdz_env.sh
    628    ulimit -s unlimited
    629    export OMP_STACKSIZE=800M
    630    export OMP_NUM_THREADS=1
    631    cd $WRK/$INIT
    632    echo Executable : $ce0l
    633    for yr in $yrs; do
    634       if [ $climato = 0 ]; then sufyr=$suf\$yr; else sufyr=$suf; fi
    635       ln -sf amipbc_sic_\$sufyr.nc amipbc_sic_1x1.nc
    636       ln -sf amipbc_sst_\$sufyr.nc amipbc_sst_1x1.nc
    637       sed -e 's/anneeref=.*.$/anneeref='\$yr'/' DEF/run.def >| run.def
    638       echo Starting initialisation
    639       $run 1 $ce0l
    640       if [ $climato = 0 ]; then mv limit.nc limit.\$yr.nc; fi
    641    done
    642 # ANCIEN MULTI STEP   ;;
    643 
    644 # ANCIEN MULTI STEP   interp )
    645    if [ $aerosols = clim ]; then
    646     cp $local/interp_aerosols.sh .; chmod +x interp_aerosols.sh
    647     # Les aerosols de l'annee 2000 ont ete remplaces par "9999" qui pointe vers un fichier moyen sur 1995-2014
    648     #for year in 2000 1850; do  ./interp_aerosols.sh \$year; done
    649     #mv aerosols.2000.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
    650     for year in 9999 1850; do ./interp_aerosols.sh \$year; done
    651     mv aerosols.9999.nc aerosols.clim.nc; mv aerosols.1850.nc aerosols.nat.nc
    652    fi
    653 
    654    # AS : S'il etait possible d'automatiser l'interpolation de l'input SPLA, ce serait a lancer ici
    655    #en attendant, on passe au paragraphe suivant où on copie les fichiers à la res ZoomNaf depuis $LMDZ_Init/SPLA_Init
    656    #if [ $aerosols = spla ]; then
    657     #cp $local/futur script interp_aerosols_SPLA.sh .; chmod +x interp_aerosols_SPLA.sh
    658     #for file in...; do  ./interp_aerosols_SPLA.sh \$year; done
    659     #etc etc etc ...
    660    #fi
    661 
    662 # Copy initial and forcing files in $local/$INIT and $local/$LIMIT; also in $local/INPUT_SPLA if $aerosols=spla
    663    for f in sta* limit.nc gri*nc; do cp \$f $local/$INIT/\$f; done
    664    mkdir -p $local/$LIMIT
    665    for f in limit*.nc ; do cp \$f $local/$LIMIT/\$f; done
    666    if [ $aerosols = clim ]; then  for f in aerosols[.0-9]*nc; do cp \$f $local/$LIMIT/\$f; done; fi
    667    #
    668    if [ $aerosols = spla ]; then
    669      #mkdir -p $local/INPUT_SPLA; pour l'instant on copie $LMDZ_Init/SPLA_Init en block
    670      if [ ! -d $local/INPUT_SPLA ]; then cp -pr $LMDZ_Init/SPLA_Init $local/INPUT_SPLA; fi
    671    fi
    672    cd $WRK
    673 ...eod
    674    if [ $ok_guide != y ]; then # Running first simulation automatically except for nudging
    675       cat << ...eod >> tmp
    676          $submit tmp_$SIM
    677 ...eod
    678    fi
    679    cat << ...eod >> tmp
    680 # ANCIEN MULTI STEP   esac
    681 ...eod
    682 
    683    echo '###############################################################################'
    684    echo Submitting initialisation job
    685 pwd
    686    $submit tmp
    687    echo '###############################################################################'
    688 
    689 else
    690 #case [ $init != 1 ]
    691 
    692    cd $WRK
    693    echo '###############################################################################'
    694    echo Submitting job tmp_$SIM
    695    echo $submit tmp_$SIM
    696    $submit tmp_$SIM
    697    echo '###############################################################################'
    698 fi
     730
     731
     732
     733
     734
     735
     736
     737
     738
     739
     740
     741
     742
    699743
    700744
     
    713757   echo Si vous voulez modifier les caracteristiques du job, comme le temps
    714758   echo max ou le nombre de proc, il se trouve sur
    715    echo $SCRATCHD/$MAINDIR/tmp_$SIM
     759   echo $SIMRUNTOPDIR/$MAINDIR/tmp_$SIM
    716760fi
    717761
Note: See TracChangeset for help on using the changeset viewer.