source: trunk/libIGCM/libIGCM_ensemble/libIGCM_ensemble.ksh @ 1143

Last change on this file since 1143 was 1066, checked in by sdipsl, 10 years ago
  • fix a typo
  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Revision Author Date
File size: 51.7 KB
RevLine 
[677]1#!/bin/ksh
2
3#**************************************************************
[1026]4# Author: Sebastien Denvil, Sonia Labetoulle, Nicolas Lebas, Sebastien Nguyen
[1001]5# Contact: Nicolas.Lebas__at__locean-ipsl.upmc.fr
[679]6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
[677]9# IPSL (2012)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
[1026]12# >>> Date ensemble <<<
13# Author: Nicolas Lebas (adapted from Sonia Labetoulle)
14# Contact: Nicolas.Lebas__at__locean-ipsl.upmc.fr
15# IPSL (2014)
16#
17# >>> Add 3D perturbation maps to oceanic restart <<<
18# Author: Sebastien Nguyen
19# Contact: Sebastien.Nguyen__at__locean-ipsl.upmc.fr
20# IPSL (2014)
21#
[677]22#**************************************************************
23
[1001]24# Read which ensemble type are active
25function IGCM_ensemble_Init
[677]26{
[1001]27  IGCM_debug_PushStack "IGCM_ensemble_Init"
[677]28
[1007]29  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB active
30  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE active
31  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PARAMETRIC active
32
[1026]33  IGCM_debug_Print 1 "Ens_PERTURB ACTIVE     = ${ensemble_Ens_PERTURB_active}"
34  IGCM_debug_Print 1 "Ens_DATE ACTIVE        = ${ensemble_Ens_DATE_active}"
[1001]35  IGCM_debug_Print 1 "Ens_PARAMETRIC ACTIVE  = ${ensemble_Ens_PARAMETRIC_active}"
36  echo ""
[1007]37
[1001]38  IGCM_debug_PopStack "IGCM_ensemble_Init"
39}
40
41# Set Alphanumerical variables ajust to member nb
42function IGCM_ensemble_SetAlpha
43{
44  IGCM_debug_PushStack "IGCM_ensemble_SetAlpha"
[1007]45
[679]46  set -A Alpha      A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
47  set -A AlphaMonth a b c d e f g h i j k l
48
[1001]49  IGCM_debug_PopStack "IGCM_ensemble_SetAlpha"
50}
51
52############### Perturb ENSEMBLE #################
53function IGCM_ensemble_CastInit
54{
55  IGCM_debug_PushStack "IGCM_ensemble_CastInit"
56
[679]57  IGCM_sys_Mkdir ${RUN_DIR}
58
59  IGCM_sys_Cp ${SUBMIT_DIR}/config.card   ${RUN_DIR}
60  IGCM_sys_Cp ${SUBMIT_DIR}/ensemble.card ${RUN_DIR}
61  IGCM_sys_Cp ${SUBMIT_DIR}/Job_*         ${RUN_DIR}
62  IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${RUN_DIR}
[1001]63  if [ -f ${SUBMIT_DIR}/Qsub.* ]; then
[1026]64    IGCM_sys_Cp ${SUBMIT_DIR}/Qsub.*        ${RUN_DIR}
[1001]65  fi
[1007]66  if [ -f ${SUBMIT_DIR}/Qclean.* ]; then
[1026]67    IGCM_sys_Cp ${SUBMIT_DIR}/Qclean.*      ${RUN_DIR}
[1007]68  fi
69
[742]70  # Useful?
71  #if [ -f  ${SUBMIT_DIR}/CreatedDir.txt ] ; then
72  #  IGCM_sys_Cp ${SUBMIT_DIR}/CreatedDir.txt ${RUN_DIR}
73  #fi
74  # Useful?
[1007]75  #if [ -f  ${SUBMIT_DIR}/Qsub.sh ] ; then
76  #  IGCM_sys_Cp ${SUBMIT_DIR}/Qsub.sh ${RUN_DIR}
[742]77  #fi
[1026]78  echo ${PWD}
79
80  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB active
[1007]81  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB NAME
82  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB BEGIN_INIT
83  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB END_INIT
84  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB PERIODICITY
85  IGCM_card_DefineArrayFromOption    ${F_CFG_ENS} Ens_PERTURB NONPERIODIC
86  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB LENGTH
87  IGCM_card_DefineArrayFromOption    ${F_CFG_ENS} Ens_PERTURB LENGTH_NONPERIODIC
88  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB MEMBER
[1026]89  IGCM_card_DefineArrayFromOption    ${F_CFG_ENS} Ens_PERTURB MEMBER_LIST
90  IGCM_card_DefineArrayFromOption    ${F_CFG_ENS} Ens_PERTURB MEMBER_NAMESLIST
91  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB MEMBER_INITFROM
92  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB MEMBER_INITPATH
[1007]93  IGCM_card_DefineArrayFromOption    ${F_CFG_ENS} Ens_PERTURB PERTURB_BIN
94  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB INITFROM
95  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB INITPATH
[1001]96  IGCM_card_DefineVariableFromOption config.card UserChoices JobName
[679]97  IGCM_card_DefineVariableFromOption config.card UserChoices TagName
98  IGCM_card_DefineVariableFromOption config.card UserChoices CalendarType
99  IGCM_card_DefineArrayFromSection   config.card ListOfComponents
100
[737]101  echo
[1001]102  IGCM_debug_Print 1 "[Ens_PERTURB]"
103  IGCM_debug_Print 1 "ACTIVE            = ${ensemble_Ens_PERTURB_active}"
[679]104  IGCM_debug_Print 1 "NAME              = ${ensemble_Ens_PERTURB_NAME}"
[1001]105  IGCM_debug_Print 1 "BEGIN_INIT        = ${ensemble_Ens_PERTURB_BEGIN_INIT}"
106  IGCM_debug_Print 1 "END_INIT          = ${ensemble_Ens_PERTURB_END_INIT}"
107  IGCM_debug_Print 1 "PERIODICITY       = ${ensemble_Ens_PERTURB_PERIODICITY}"
[679]108  IGCM_debug_Print 1 "NONPERIODIC       = ${ensemble_Ens_PERTURB_NONPERIODIC[*]}"
[1001]109  IGCM_debug_Print 1 "LENGTH             = ${ensemble_Ens_PERTURB_LENGTH}"
110  IGCM_debug_Print 1 "LENGTH_NONPERIODIC = ${ensemble_Ens_PERTURB_LENGTH_NONPERIODIC[*]}"
[679]111  IGCM_debug_Print 1 "MEMBER            = ${ensemble_Ens_PERTURB_MEMBER}"
[1026]112  IGCM_debug_Print 1 "MEMBER_LIST       = ${ensemble_Ens_PERTURB_MEMBER_LIST[*]}"
113  IGCM_debug_Print 1 "MEMBER_NAMESLIST  = ${ensemble_Ens_PERTURB_MEMBER_NAMESLIST[*]}"
114  IGCM_debug_Print 1 "MEMBER_INITFROM   = ${ensemble_Ens_PERTURB_MEMBER_INITFROM}"
115  IGCM_debug_Print 1 "MEMBER_INITPATH   = ${ensemble_Ens_PERTURB_MEMBER_INITPATH}"
[679]116  IGCM_debug_Print 1 "PERTURB_BIN       = ${ensemble_Ens_PERTURB_PERTURB_BIN[*]}"
117  IGCM_debug_Print 1 "INITFROM          = ${ensemble_Ens_PERTURB_INITFROM}"
[680]118  IGCM_debug_Print 1 "INITPATH          = ${ensemble_Ens_PERTURB_INITPATH}"
[1001]119  IGCM_debug_Print 1 "JobName           = ${config_UserChoices_JobName}"
[679]120  IGCM_debug_Print 1 "TagName           = ${config_UserChoices_TagName}"
121  IGCM_debug_Print 1 "CalendarType      = ${config_UserChoices_CalendarType}"
122  IGCM_debug_Print 1 "ListOfComponents  = ${config_ListOfComponents[*]}"
[1007]123
[679]124  PerturbExe=${ensemble_Ens_PERTURB_PERTURB_BIN[0]}
125
[1026]126  case ${PerturbExe} in
127  AddNoise)
128    PerturbComp=${ensemble_Ens_PERTURB_PERTURB_BIN[1]}
129    PerturbFile=${ensemble_Ens_PERTURB_PERTURB_BIN[2]}
130    PerturbVar=${ensemble_Ens_PERTURB_PERTURB_BIN[3]}
131    PerturbAmp=${ensemble_Ens_PERTURB_PERTURB_BIN[4]}
[1007]132
[1026]133    IGCM_debug_Print 1 "PerturbExe  = ${PerturbExe}"
134    IGCM_debug_Print 1 "PerturbFile = ${PerturbFile}"
135    IGCM_debug_Print 1 "PerturbComp = ${PerturbComp}"
136    IGCM_debug_Print 1 "PerturbVar  = ${PerturbVar}"
137    IGCM_debug_Print 1 "PerturbAmp  = ${PerturbAmp}"
138    ;;
139  AddPertu3DOCE)
140    PerturbComp=${ensemble_Ens_PERTURB_PERTURB_BIN[1]}
141    PerturbFile=${ensemble_Ens_PERTURB_PERTURB_BIN[2]}
142    PerturbVar=${ensemble_Ens_PERTURB_PERTURB_BIN[3]}
143    PerturbMask=${ensemble_Ens_PERTURB_PERTURB_BIN[4]}
144
145    IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_PERTURB MASKPATH
146
147    IGCM_debug_Print 1 "PerturbExe  = ${PerturbExe}"
148    IGCM_debug_Print 1 "PerturbFile = ${PerturbFile}"
149    IGCM_debug_Print 1 "PerturbComp = ${PerturbComp}"
150    IGCM_debug_Print 1 "PerturbVar  = ${PerturbVar}"
151    IGCM_debug_Print 1 "PerturbMask = ${PerturbMask}"
152    IGCM_debug_Print 1 "MASK PATH   = ${ensemble_Ens_PERTURB_MASKPATH}"
153    ;;
154  esac
155
[1001]156  IGCM_ensemble_SetAlpha ${ensemble_Ens_PERTURB_MEMBER}
[1007]157
[680]158  # A few checks Period case:
[679]159
[1001]160  # ... Check PERIODICITY ...
161  case ${ensemble_Ens_PERTURB_PERIODICITY} in
[1026]162  NONE)
[737]163    IGCM_debug_Print 1 "periodic start not active"
[736]164    CastPeriodicStart=false
[679]165    ;;
[680]166  *[Yy]|*[Mm])
[736]167    CastPeriodicStart=true
[1001]168    IGCM_debug_Print 1 "Periodic length : ${ensemble_Ens_PERTURB_PERIODICITY}" ;;
[679]169  *)
[1001]170    IGCM_debug_Exit "IGCM_ensemble_CastInit ${ensemble_Ens_PERTURB_PERIODICITY} : invalid PERIODICITY"
[680]171    IGCM_debug_Exit "Choose a value in *Y or *M"
[679]172    IGCM_debug_Verif_Exit ;;
173  esac
[1026]174  # ... Check LENGTH ...
[1001]175  case ${ensemble_Ens_PERTURB_LENGTH} in
[680]176  *[Yy]|*[Mm])
[1001]177    IGCM_debug_Print 1 "Periodic duration : ${ensemble_Ens_PERTURB_LENGTH}" ;;
[679]178  *)
[1001]179    IGCM_debug_Exit "IGCM_ensemble_CastInit ${ensemble_Ens_PERTURB_LENGTH} invalid LENGTH"
[680]180    IGCM_debug_Exit "Choose a value in choose in *Y or *M"
[679]181    IGCM_debug_Verif_Exit ;;
182  esac
183
[736]184  # A few checks for the Non-Periodic case:
[680]185  DateNum=0
[1026]186  while [ ${DateNum} -lt ${#ensemble_Ens_PERTURB_NONPERIODIC[*]} ] ; do
[680]187
[1001]188    # - Check LENGTH_NONPERIODIC
[1026]189    case ${ensemble_Ens_PERTURB_LENGTH_NONPERIODIC[${DateNum}]} in
[735]190    _0_)
[737]191      IGCM_debug_Print 1 "non-periodic start not active"
[736]192      CastNonPeriodicStart=false
[680]193      ;;
194    *[Yy]|*[Mm])
[1026]195      IGCM_debug_Print 1 "Non-periodic duration : ${ensemble_Ens_PERTURB_LENGTH_NONPERIODIC[${DateNum}]}"
[736]196      CastNonPeriodicStart=true
[680]197      ;;
198    *)
[1026]199      IGCM_debug_Exit "IGCM_ensemble_CastInit ${ensemble_Ens_PERTURB_LENGTH_NONPERIODIC[${DateNum}]} : invalid LENGTH"
[680]200      IGCM_debug_Exit "choose in *Y or *M"
201      IGCM_debug_Verif_Exit ;;
202    esac
203    (( DateNum = DateNum + 1 ))
204  done
205
[1026]206  # A few checks for the MEMBER_LIST case:
207  case ${ensemble_Ens_PERTURB_MEMBER_LIST[0]} in
208  _0_)
209    IGCM_debug_Print 1 "list of perturbation maps not active"
210    CastMemberList=false
211    ;;
212  *)
213    if [ ${CastPeriodicStart} = "true" ] ; then
214      IGCM_debug_Exit "list of perturbation maps for periodic start not implemented, will stop execution"
215      IGCM_debug_Verif_Exit
216    elif [ ${CastNonPeriodicStart} = "true" ] ; then
217      IGCM_debug_Exit "list of perturbation maps for non periodic start not implemented, will stop execution"
218      IGCM_debug_Verif_Exit
219    fi
220
221    # test that MEMBER_NAMESLIST and MEMBER_LIST have the same size
222
223    if [ ${#ensemble_Ens_PERTURB_MEMBER_LIST[*]} -ne ${#ensemble_Ens_PERTURB_MEMBER_NAMESLIST[*]} ] ; then
224      IGCM_debug_Exit "number of elements in MEMBER_LIST and MEMBER_NAMESLIST differ"
225      IGCM_debug_Verif_Exit
226    fi
227
228    IGCM_debug_Print 1 "list of perturbation maps : ${ensemble_Ens_PERTURB_MEMBER_LIST[*]}"
229    IGCM_debug_Print 1 "list of members names : ${ensemble_Ens_PERTURB_MEMBER_NAMESLIST[*]}"
230    CastMemberList=true
231    ;;
232  esac
233
234#  IGCM_debug_Exit "fin du test MEMBER_LIST"
235#  IGCM_debug_Verif_Exit
236
[864]237  # Need to know all the restart filename of the component we will apply the noise to
238  IGCM_card_DefineArrayFromOption config.card ListOfComponents ${PerturbComp}
239  eval compname=\${config_ListOfComponents_${PerturbComp}[0]} > /dev/null 2>&1
240
241  # Target the component's card we apply the noise to
242  card=${SUBMIT_DIR}/COMP/${compname}.card
243
244  # Read the restart file list. To be used later
245  IGCM_card_DefineArrayFromOption ${card} RestartFiles List
246  ListFilesName=${compname}_RestartFiles_List
247  eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
248  eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
249
250  # Check
251  IGCM_debug_Print 1 "Nb Restart Files  = ${NbFiles}"
252
[680]253  IGCM_debug_PopStack "IGCM_ensemble_CastInit"
254}
255
256function IGCM_ensemble_CastPeriodicStarts
257{
258  IGCM_debug_PushStack "IGCM_ensemble_CastPeriodicStarts"
259
[736]260  [ ${CastPeriodicStart} = false ] && return
261
[737]262  echo
263  IGCM_debug_Print 1 "Manage periodic starts"
264
[680]265#.. Manage periodic starts ..
266#   ======================
267
[679]268# ... Loop over DateBegin ...
[1001]269  eval DateBegin=\${ensemble_Ens_PERTURB_BEGIN_INIT}
[679]270
[1001]271  while [ ${DateBegin} -le ${ensemble_Ens_PERTURB_END_INIT} ] ; do
[679]272    IGCM_date_GetYearMonth ${DateBegin} year month
273
[1001]274  # - Determine number of day(s) in PERIODICITY
275    PeriodLengthInDays=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${ensemble_Ens_PERTURB_PERIODICITY} )
[680]276
[1001]277  # - Determine number of day(s) in LENGTH
278    DureeLengthInDays=$(( $( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${ensemble_Ens_PERTURB_LENGTH} ) - 1 ))
[679]279
280  # - Determine DateEnd
281    (( DateEnd = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${DureeLengthInDays} ) ))
282
283  # - Build directory name
[1001]284    IGCM_ensemble_CastDirectoryName ${ensemble_Ens_PERTURB_NAME} ${ensemble_Ens_PERTURB_PERIODICITY} $year $month $StartDir
[679]285
286  # - Determine RestartDate
287    (( Offset = -1 ))
288    (( RestartDate = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${Offset} ) ))
289
290    IGCM_debug_Print 2 "${DateBegin} => ${DateEnd} : ${StartDir}"
[888]291    echo "${DateBegin} ${DateEnd} ${StartDir}" >> ${RUN_DIR}/CreatedDir.txt
[679]292
293  # - Create directory for current DateBegin
294    if [ ! -d  ${StartDir} ] ; then
295      IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}
296      IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}
297      ln -s ../../.resol .
298      ln -s ../../.libmpi .
299      IGCM_sys_Cd ${RUN_DIR}
300    fi
301
[870]302  # - Create directory to store modified restart files
[737]303    RestartDir=${STORAGE}/IGCM_IN/${config_UserChoices_TagName}/${StartDir}
[680]304    IGCM_sys_MkdirArchive ${RestartDir}
[679]305
306  # - Loop over members
307    i=0
308    while [ $i -lt ${ensemble_Ens_PERTURB_MEMBER} ] ; do
309      MemberDir="${StartDir}${Alpha[$i]}"
[737]310      echo
[679]311      IGCM_debug_Print 3 "${MemberDir}"
312
313      JobName="Job_${MemberDir}"
314
315    # * Create directory if it doesn't exist and copy/link files
316      if [ ! -d  ${SUBMIT_DIR}/${StartDir}/${MemberDir} ] ; then
317        IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}/${MemberDir}
318        IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}/${MemberDir}
319        ln -s ../../COMP
320        ln -s ../../PARAM
321        ln -s ../../POST
[1001]322        ln -s ../../DRIVER
[679]323        IGCM_sys_Cd ${RUN_DIR}
324        IGCM_sys_Cp config.card run.card.init ${SUBMIT_DIR}/${StartDir}/${MemberDir}
[1001]325        IGCM_sys_Cp Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/${StartDir}/${MemberDir}/${JobName}
[679]326
[742]327        # Dump command to be lauched
[1007]328        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qsub.${StartDir}.sh
329        echo "${SUBMIT} ${JobName} ; cd -"     >> ${RUN_DIR}/Qsub.${StartDir}.sh
[1001]330
[1007]331        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
332        echo "${libIGCM}/clean_month.job ; cd -"     >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
333
334        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
335        echo "${libIGCM}/clean_year.job ; cd -"     >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
336
337        # * Update files : config.card, Job_, COMP/comp.card
338        IGCM_ensemble_CastFilesUpdate ${DateBegin} ${DateEnd} ${RestartDate}
339
340        # * Apply noise on restart file
341        IGCM_ensemble_CastPerturbFile
[679]342      fi
[1007]343
[679]344      (( i = i + 1 ))
345    done
346
[742]347    # Done. Save ${StartDir} submission text file
[1007]348    IGCM_sys_Cp ${RUN_DIR}/Qsub.${StartDir}.sh ${SUBMIT_DIR}
349    IGCM_sys_Cp ${RUN_DIR}/Qclean.month.${StartDir}.sh ${SUBMIT_DIR}
350    IGCM_sys_Cp ${RUN_DIR}/Qclean.year.${StartDir}.sh ${SUBMIT_DIR}
[742]351
[679]352  # - Next DateBegin
353    echo "$DateBegin  $PeriodLengthInDays"
[1001]354    case ${ensemble_Ens_PERTURB_PERIODICITY} in
[680]355    *[Yy]|*[Mm])
[679]356      (( DateBegin = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${PeriodLengthInDays} ) ))
357      ;;
358    esac
359    echo "New DateBegin = $DateBegin"
360    echo "========================================================================"
361  done
362  IGCM_debug_PopStack "IGCM_ensemble_CastPeriodicStarts"
363}
364
365function IGCM_ensemble_CastNonPeriodicStarts
366{
367  IGCM_debug_PushStack "IGCM_ensemble_CastNonPeriodicStarts"
368
369  #.. Manage non periodic starts => Loop over DateBegin ..
370  #   ==========================
371
[736]372  [ ${CastNonPeriodicStart} = false ] && return
373
[737]374  echo
375  IGCM_debug_Print 1 "Manage non periodic starts"
376
[679]377  DateNum=0
378# ... Loop over ensemble_Ens_PERTURB_NONPERIODIC ...
379  echo ">${DateNum}<"
380  echo ">${#ensemble_Ens_PERTURB_NONPERIODIC[*]}<"
[1026]381  while [ ${DateNum} -lt ${#ensemble_Ens_PERTURB_NONPERIODIC[*]} ] ; do
382    DateBegin=${ensemble_Ens_PERTURB_NONPERIODIC[${DateNum}]}
383    Duree=${ensemble_Ens_PERTURB_LENGTH_NONPERIODIC[${DateNum}]}
[679]384    echo ">${DateBegin}<"
385    echo ">${Duree}<"
[680]386
[1001]387  # - Determine number of day(s) in LENGTH_NONPERIODIC
[679]388    IGCM_date_GetYearMonth ${DateBegin} year month
[680]389    DureeLengthInDays=$(( $( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${Duree} ) - 1 ))
[679]390
391  # - Build directory name
392    echo "========================================================================"
393    echo "ensemble_Ens_PERTURB_NAME = ${ensemble_Ens_PERTURB_NAME}"
394    IGCM_ensemble_CastDirectoryName ${ensemble_Ens_PERTURB_NAME} ${Duree} $year $month $StartDir
395
396  # - Determine DateEnd
397    (( DateEnd = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${DureeLengthInDays} ) ))
398    echo ">${DateEnd}<"
399    echo "tout va bien 1"
400
401  # - Determine RestartDate
402    (( Offset = -1 ))
403    (( RestartDate = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${Offset} ) ))
404
405    IGCM_debug_Print 2 "${DateBegin} => ${DateEnd} : ${StartDir}"
406
407  # -  Does $StartDir already exist ?
408    #echo "tout va bien 2" ${StartDir}
409    if [ ! -d ${SUBMIT_DIR}/${StartDir} ] ; then
410      echo "create dir"
411      IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}
412      IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}
413      ln -s ../../.resol .
414      ln -s ../../.libmpi .
415      IGCM_sys_Cd ${RUN_DIR}
[888]416      echo "${DateBegin} ${DateEnd} ${StartDir}" >> ${RUN_DIR}/CreatedDir.txt
[679]417    fi
[888]418    PeriodDateEnd=$( grep -m1 ${StartDir} ${RUN_DIR}/CreatedDir.txt | cut -f2 -d\  )
[679]419
420  # - Create directory in which to store new restart files if it does'nt already exist
[737]421    RestartDir=${STORAGE}/IGCM_IN/${config_UserChoices_TagName}/${StartDir}
[680]422    IGCM_sys_MkdirArchive ${RestartDir}
[679]423
424  # - Loop over members
425    i=0
426    while [ $i -lt ${ensemble_Ens_PERTURB_MEMBER} ] ; do
427      MemberDir="${StartDir}${Alpha[$i]}"
428      IGCM_debug_Print 3 "${MemberDir}"
429
430      JobName="Job_${MemberDir}"
431
432    # * Create directory if it doesn't exist and copy files
433      if [ ! -d  ${SUBMIT_DIR}/${StartDir}/${MemberDir} ] ; then
434        IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}/${MemberDir}
435        #IGCM_sys_Cp -r COMP/ PARAM/ ${StartDir}/${MemberDir}
436        IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}/${MemberDir}
437        ln -s ../../COMP
438        ln -s ../../PARAM
439        ln -s ../../POST
[1001]440        ln -s ../../DRIVER
[679]441        IGCM_sys_Cd ${RUN_DIR}
442        IGCM_sys_Cp config.card run.card.init ${SUBMIT_DIR}/${StartDir}/${MemberDir}
[1001]443        IGCM_sys_Cp Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/${StartDir}/${MemberDir}/Job_${MemberDir}
[679]444
[742]445        # Dump command to be lauched
[1007]446        echo "cd ${StartDir}/${MemberDir}/ ;"  >> Qsub.${StartDir}.sh
447        echo "${SUBMIT} ${JobName} ; cd -"     >> Qsub.${StartDir}.sh
[679]448
[1007]449        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
450        echo "${libIGCM}/clean_month.job ; cd -"     >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
451
452        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
453        echo "${libIGCM}/clean_year.job ; cd -"     >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
454
455        # * Update files : config.card, Job_, COMP/comp.card
456        echo "${PeriodDateEnd} ? ${DateEnd}"
457        if [ ${PeriodDateEnd} -gt ${DateEnd} ] ; then
[1026]458          DateEnd=${PeriodDateEnd}
[1007]459        fi
460        IGCM_ensemble_CastFilesUpdate ${DateBegin} ${DateEnd} ${RestartDate}
461
462        # * Apply noise on restart file
463        IGCM_ensemble_CastPerturbFile
[679]464      fi
[1007]465
[679]466      (( i = i + 1 ))
467    done
468
[742]469    # Done. Save ${StartDir} submission text file
[1007]470    IGCM_sys_Cp ${RUN_DIR}/Qsub.${StartDir}.sh ${SUBMIT_DIR}
471    IGCM_sys_Cp ${RUN_DIR}/Qclean.month.${StartDir}.sh ${SUBMIT_DIR}
472    IGCM_sys_Cp ${RUN_DIR}/Qclean.year.${StartDir}.sh ${SUBMIT_DIR}
[742]473
[679]474    (( DateNum = DateNum + 1 ))
475  done
476  IGCM_debug_PopStack "IGCM_ensemble_CastNonPeriodicStarts"
477}
478
[1026]479function IGCM_ensemble_CastMemberList
480{
481  IGCM_debug_PushStack "IGCM_ensemble_CastMemberList"
482
483  if [ ${CastMemberList} = false ] ; then
484    IGCM_debug_PopStack "IGCM_ensemble_CastMemberList"
485    return
486  fi
487
488  echo
489  IGCM_debug_Print 1 "Manage members list"
490
491#.. Manage members list ..
492#   ======================
493
494  # DateBegin
495  eval DateBegin=\${ensemble_Ens_PERTURB_BEGIN_INIT}
496
497  IGCM_date_GetYearMonth ${DateBegin} year month
498
499  # - Determine number of day(s) in LENGTH
500  DureeLengthInDays=$(( $( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${ensemble_Ens_PERTURB_LENGTH} ) - 1 ))
501
502  # - Determine DateEnd
[1066]503  DateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${DureeLengthInDays} )
[1026]504
505  # bad hack enforce yearly for parent directory name
506  # - Build directory name
507  IGCM_ensemble_CastDirectoryName ${ensemble_Ens_PERTURB_NAME} 1Y $year $month $StartDir
508
509  # - Determine RestartDate
510  (( Offset = -1 ))
[1066]511  RestartDate=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${Offset} )
[1026]512
513  IGCM_debug_Print 2 "${DateBegin} => ${DateEnd} : ${StartDir}"
514  echo "${DateBegin} ${DateEnd} ${StartDir}" >> ${RUN_DIR}/CreatedDir.txt
515
516  # - Create directory for current DateBegin
517  if [ ! -d  ${StartDir} ] ; then
518    IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}
519    IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}
520    ln -s ../../.resol .
521    ln -s ../../.libmpi .
522    IGCM_sys_Cd ${RUN_DIR}
523  fi
524
525  # - Create directory to store modified restart files
526  RestartDir=${STORAGE}/IGCM_IN/${config_UserChoices_TagName}/${StartDir}
527  IGCM_sys_MkdirArchive ${RestartDir}
528
529  # - Loop over members
530  i=0
531  nbmember=${#ensemble_Ens_PERTURB_MEMBER_LIST[*]}
532  while [ $i -lt $nbmember ] ; do
533    MemberDir=${ensemble_Ens_PERTURB_MEMBER_NAMESLIST[${i}]}
534    MemberVec=${ensemble_Ens_PERTURB_MEMBER_LIST[${i}]}
535
536    JobName="Job_${MemberDir}"
537    echo
538    IGCM_debug_Print 3 "${MemberDir}"
539
540    # * Create directory if it doesn't exist and copy/link files
541    if [ ! -d  ${SUBMIT_DIR}/${StartDir}/${MemberDir} ] ; then
542      IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}/${MemberDir}
543      IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}/${MemberDir}
544      ln -s ../../COMP
545      ln -s ../../PARAM
546      ln -s ../../POST
547      ln -s ../../DRIVER
548      IGCM_sys_Cd ${RUN_DIR}
549      IGCM_sys_Cp config.card run.card.init ${SUBMIT_DIR}/${StartDir}/${MemberDir}
550      IGCM_sys_Cp Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/${StartDir}/${MemberDir}/${JobName}
551
552      # Dump command to be lauched
553      echo "cd ${StartDir}/${MemberDir}/ ;"     >> ${RUN_DIR}/Qsub.${StartDir}.sh
554      echo "${SUBMIT} ${JobName} ; cd -"        >> ${RUN_DIR}/Qsub.${StartDir}.sh
555
556      echo "cd ${StartDir}/${MemberDir}/ ;"     >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
557      echo "${libIGCM}/clean_month.job ; cd -"  >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
558
559      echo "cd ${StartDir}/${MemberDir}/ ;"     >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
560      echo "${libIGCM}/clean_year.job ; cd -"   >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
561
562      # * Update files : config.card, Job_, COMP/comp.card
563      IGCM_ensemble_CastFilesUpdate ${DateBegin} ${DateEnd} ${RestartDate}
564
565      # * Apply noise on restart file
566      IGCM_ensemble_CastPerturbFile
567    fi
568
569    (( i = i + 1 ))
570  done
571
572  # Done. Save ${StartDir} submission text file
573  IGCM_sys_Cp ${RUN_DIR}/Qsub.${StartDir}.sh ${SUBMIT_DIR}
574  IGCM_sys_Cp ${RUN_DIR}/Qclean.month.${StartDir}.sh ${SUBMIT_DIR}
575  IGCM_sys_Cp ${RUN_DIR}/Qclean.year.${StartDir}.sh ${SUBMIT_DIR}
576
577  IGCM_debug_PopStack "IGCM_ensemble_CastMemberList"
578}
579
[679]580function IGCM_ensemble_CastFilesUpdate
581{
582  IGCM_debug_PushStack "IGCM_ensemble_CastFilesUpdate"
583
[677]584  # Debug Print :
585  echo
[679]586  IGCM_debug_Print 1 "IGCM_ensemble_CastFilesUpdate :"
[677]587
588  HumanDateBegin=$(   IGCM_date_ConvertFormatToHuman ${1} )
589  HumanDateEnd=$(     IGCM_date_ConvertFormatToHuman ${2} )
590  HumanRestartDate=$( IGCM_date_ConvertFormatToHuman ${3} )
591  # ==> config.card
592  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleRun 'y'
593  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleName ${ensemble_Ens_PERTURB_NAME}
594  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleDate ${StartDir}
595
596  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card UserChoices JobName   ${MemberDir}
597  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card UserChoices DateBegin ${HumanDateBegin}
598  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card UserChoices DateEnd   ${HumanDateEnd}
599  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Restarts OverRule "n"
600
[742]601  for comp in ${config_ListOfComponents[*]} ; do
602    IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${comp} Restart "y"
603    IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${comp} RestartDate ${HumanRestartDate}
604    IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${comp} RestartJobName ${ensemble_Ens_PERTURB_INITFROM}
605    IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${comp} RestartPath ${ensemble_Ens_PERTURB_INITPATH}
[677]606  done
[742]607
[677]608  # ==> Job
[1001]609  sed -e "s/\(#.*\)${config_UserChoices_JobName}\( *#.*\)/\1${MemberDir} \2/"            \
610      -e "s/\(#.*Script_Output_\)${config_UserChoices_JobName}\(\.*\)/\1${MemberDir}\2/" \
[1026]611      -e "s/^PeriodNb=.*/PeriodNb=60/"                                                   \
[742]612      ${SUBMIT_DIR}/${StartDir}/${MemberDir}/Job_${MemberDir} > Job_${MemberDir}.tmp
613  IGCM_sys_Mv Job_${MemberDir}.tmp ${SUBMIT_DIR}/${StartDir}/${MemberDir}/Job_${MemberDir}
[738]614
[679]615  IGCM_debug_PopStack "IGCM_ensemble_CastFilesUpdate"
[677]616}
617
[679]618function IGCM_ensemble_CastDirectoryName
[677]619{
[679]620  IGCM_debug_PushStack "IGCM_ensemble_CastDirectoryName"
[677]621
622  #.. Debug Print ..
623  echo
[679]624  IGCM_debug_Print 1 "IGCM_ensemble_CastDirectoryName :"
[677]625  echo
626
627  Name=$1
628  Duree=$2
629  year=$3
630  month=$4
631
632  # - Build directory name
633  case ${Duree} in
[1026]634  *Y|*y)
635    siecle="$( echo $year | cut -c1-2 )"
636    siecle=$( (( $siecle - 18 )) )
637    StartYear="${siecle}$( echo $year | cut -c3-4 )"
638    StartDir="${Name}${StartYear}"
639    ;;
640  *M|*m)
641    echo $month
642    siecle="$( echo $year | cut -c1-2 )"
643    siecle=$( (( $siecle - 18 )) )
644    StartYear="${siecle}$( echo $year | cut -c3-4 )"
645    StartMonth="${AlphaMonth[ (( 10#${month} - 1 )) ]}"
646    StartDir="${Name}${StartYear}${StartMonth}"
647    ;;
[677]648  esac
649
[679]650  IGCM_debug_PopStack "IGCM_ensemble_CastDirectoryName"
[677]651}
652
[679]653function IGCM_ensemble_CastPerturbFile
[677]654{
[679]655  IGCM_debug_PushStack "IGCM_ensemble_CastPerturbFile"
[677]656
[1026]657  typeset i i_ j
658  typeset -Z4 j4
659  typeset file_out file_out_
[864]660
[677]661  #.. Debug Print ..
662  echo
[679]663  IGCM_debug_Print 1 "IGCM_ensemble_CastPerturbFile :"
[677]664
665  #.. FileIn ? => RestartDate ..
666  DirIn="${ensemble_Ens_PERTURB_INITPATH}/${ensemble_Ens_PERTURB_INITFROM}/${PerturbComp}/Restart"
[738]667  DirInTar="${ensemble_Ens_PERTURB_INITPATH}/${ensemble_Ens_PERTURB_INITFROM}/RESTART"
668  FileIn="${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${PerturbFile}"
[677]669  DirOut="${RestartDir}/${MemberDir}/${PerturbComp}/Restart"
670
671  # * Create member restart directory
672  IGCM_sys_TestDirArchive ${DirOut}
673  RET=$?
674  if [ $RET -gt 0 ] ; then
675    IGCM_sys_MkdirArchive ${DirOut}
676  fi
677
[738]678  FileOut="${MemberDir}_${RestartDate}_${PerturbFile}"
[864]679  IGCM_debug_Print 1 "FileIn  = ${DirIn}/${FileIn}"
[738]680  IGCM_debug_Print 1 "FileOut = ${DirOut}/${FileOut}.nc"
681
682  IGCM_sys_TestFileArchive ${DirOut}/${FileOut}.nc
[677]683  RET=$?
684  if [ $RET -gt 0 ] ; then
[737]685
[738]686    # * Look for the restart file we apply the noise to
[737]687
[864]688    # restart file list pertaining to the component we apply the noise to
689    # but not being the precise restart file we will apply the noise to
690    unset OtherFileInList
691    # generic restart filename list (like flxat, sstoc, restart, ...)
692    unset OtherGenericList
693
694    if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then
695      (( i=0 ))
696      until [ $i -ge ${NbFiles} ]; do
697
698        (( i_ = i+1 ))
699        eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
700        eval file_out=${file_out_}
701
702        generic_restart_file_name_out=$( basename ${file_out} .nc )
703
704        if [ ! ${generic_restart_file_name_out} = ${PerturbFile} ] ; then
705          set +A OtherFileInList ${OtherFileInList[*]} ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic_restart_file_name_out}\*.nc
706          set +A OtherGenericList ${OtherGenericList[*]} ${generic_restart_file_name_out}
707        fi
708
709        (( i=i+3 ))
710      done
711    fi
712    # How many restart files other than the one we will apply the noise to
713    NbOtherFiles=${#OtherGenericList[*]}
714
[738]715    ##########################
716    # TO BE A FUNCTION BEGIN #
717    ##########################
[677]718
[738]719    if [ $( IGCM_sys_TestFileBuffer ${DirIn}/${FileIn}*.nc ; echo $? ) = 0 ] ; then
720      IGCM_debug_Print 3 "Buffered restart"
721      Buffered=true
722      Archived=false
723      Tared=false
724      nb_restart_file=$(IGCM_sys_CountFileBuffer ${DirIn}/${FileIn}_????.nc)
725    elif [ $( IGCM_sys_TestFileArchive ${DirIn}/${FileIn}*.nc ; echo $? ) = 0 ] ; then
726      IGCM_debug_Print 3 "Archived restart"
727      Buffered=false
728      Archived=true
729      Tared=false
730      nb_restart_file=$(IGCM_sys_CountFileArchive ${DirIn}/${FileIn}_????.nc)
731    else
732      IGCM_debug_Print 3 "Tared restart"
733      Buffered=false
734      Archived=false
735      Tared=true
[864]736
[738]737      # Look for the tar file we want if we did not found it already
[888]738      for PotentialTarFile in $( find ${ensemble_Ens_PERTURB_INITPATH}/${ensemble_Ens_PERTURB_INITFROM}/RESTART -name "${ensemble_Ens_PERTURB_INITFROM}_*restart*.tar" -print ) ; do
739        IsMatching=$( echo ${PotentialTarFile##*/} | sed "s:_restart::" | sed "s:^${ensemble_Ens_PERTURB_INITFROM}_::" | sed "s:\.tar$::" | gawk -F_ -v restartdate=${RestartDate} '{if (($1 <= restartdate) && ($2 >= restartdate)) {print $1"_"$2}}' )
[864]740        if [ ! X${IsMatching} = X ] ; then
741          TarFileFound=${PotentialTarFile}
742          break
743        fi
744      done
745
746      # Extract relevant restart files
747      IGCM_debug_Print 1 "tar xvf ${TarFileFound} ${PerturbComp}_${FileIn}*.nc ${OtherFileInList[*]}"
748      tar xvf ${TarFileFound} ${PerturbComp}_${FileIn}*.nc ${OtherFileInList[*]}
[738]749      nb_restart_file=$( IGCM_sys_CountFileBuffer ${PerturbComp}_${FileIn}_????.nc )
750    fi
751
[864]752    # Move around and perturb restart files so as to be able to start hindcast/forecast simulation members
[738]753    if [ ${nb_restart_file} -gt 1 ] ; then
754      j=0
[864]755      until [ $j -ge ${nb_restart_file} ]; do
[738]756        j4=${j}
757        if [ X${Buffered} = Xtrue ] ; then
758          IGCM_sys_GetBuffer ${DirIn}/${FileIn}_${j4}.nc ${RUN_DIR}/${FileOut}_${j4}.nc
[864]759
760          cd ${DirOut}
761          for generic in ${OtherGenericList[*]} ; do
762            ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${MemberDir}_${RestartDate}_${generic}_${j4}.nc
763          done
764          cd -
765
[738]766        elif [ X${Archived} = Xtrue ] ; then
767          IGCM_sys_Get ${DirIn}/${FileIn}_${j4}.nc ${RUN_DIR}/${FileOut}_${j4}.nc
[864]768
769          for generic in ${OtherGenericList[*]} ; do
770            IGCM_sys_RshArchive "cd ${DirOut} ; ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${MemberDir}_${RestartDate}_${generic}_${j4}.nc"
771          done
772
[738]773        elif [ X${Tared} = Xtrue ] ; then
[1026]774          IGCM_debug_Print 2 "IGCM_sys_Mv ${PerturbComp}_${FileIn}_${j4}.nc ${RUN_DIR}/${FileOut}_${j4}.nc"
[738]775          IGCM_sys_Mv ${PerturbComp}_${FileIn}_${j4}.nc ${RUN_DIR}/${FileOut}_${j4}.nc
[864]776
777          for generic in ${OtherGenericList[*]} ; do
778            IGCM_sys_Mv ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${DirOut}/${MemberDir}_${RestartDate}_${generic}_${j4}.nc
779          done
780
[738]781        fi
782        (( j=j+1 ))
783      done
784    else
785      if [ X${Buffered} = Xtrue ] ; then
786        IGCM_sys_GetBuffer ${DirIn}/${FileIn}.nc ${RUN_DIR}/${FileOut}.nc
[864]787
788        cd ${DirOut}
789        for generic in ${OtherGenericList[*]} ; do
790          ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${MemberDir}_${RestartDate}_${generic}.nc
791        done
792        cd -
793
[738]794      elif [ X${Archived} = Xtrue ] ; then
795        IGCM_sys_Get ${DirIn}/${FileIn}.nc ${RUN_DIR}/${FileOut}.nc
[864]796
797        for generic in ${OtherGenericList[*]} ; do
798          IGCM_sys_RshArchive "cd ${DirOut} ; ln -s ${DirIn}/${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${MemberDir}_${RestartDate}_${generic}.nc"
799        done
800
[738]801      elif [ X${Tared} = Xtrue ] ; then
[1026]802        IGCM_debug_Print 2 "IGCM_sys_Mv ${PerturbComp}_${FileIn}.nc ${RUN_DIR}/${FileOut}.nc"
[738]803        IGCM_sys_Mv ${PerturbComp}_${FileIn}.nc ${RUN_DIR}/${FileOut}.nc
[864]804
805        for generic in ${OtherGenericList[*]} ; do
[1026]806          IGCM_debug_Print 2 "IGCM_sys_Mv ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${DirOut}/${MemberDir}_${RestartDate}_${generic}.nc"
[864]807          IGCM_sys_Mv ${PerturbComp}_${ensemble_Ens_PERTURB_INITFROM}_${RestartDate}_${generic}.nc ${DirOut}/${MemberDir}_${RestartDate}_${generic}.nc
808        done
809
[738]810      fi
811    fi
812
813    ########################
814    # TO BE A FUNCTION END #
815    ########################
816
[1026]817# treat the perturbation on different components by looking at the executable name
[737]818
[1026]819    case ${PerturbExe} in
820    (AddNoise)
821      IGCM_sys_Chmod 644 ${RUN_DIR}/${FileOut}.nc
822
823      IGCM_debug_Print 1 "${PerturbExe} ${RUN_DIR}/${FileOut}.nc ${PerturbVar} ${PerturbAmp}"
824      echo
825
826      ${PerturbExe} ${RUN_DIR}/${FileOut}.nc ${PerturbVar} ${PerturbAmp}  > /dev/null 2>&1
827      if [ $? -ne 0 ] ; then
828        IGCM_debug_Exit "Abend $( basename ${PerturbExe} )"
829        IGCM_debug_Verif_Exit
830      fi
831      IGCM_sys_Put_Out ${RUN_DIR}/${FileOut}.nc ${DirOut}/ 644
832      ;;
833    (AddPertu3DOCE)
834      # where to find the pattern we apply to the restart
835      PatternFile=${ensemble_Ens_PERTURB_MEMBER_INITPATH}/${ensemble_Ens_PERTURB_MEMBER_INITFROM}/${MemberVec}.nc
836
837      # where to find the land mask for the grid
838      MaskFile=${ensemble_Ens_PERTURB_MASKPATH}/${PerturbMask}
839
840      # if there is multiple restart files rebuild restart file
841      if [ ${nb_restart_file} -gt 1 ] ; then
842        IGCM_debug_Print 1 "rebuild files ${FileOut}_????.nc"
843        IGCM_sys_rebuild ${RUN_DIR}/${FileOut}.nc ${RUN_DIR}/${FileOut}_????.nc
844      fi
845
846      # there is now a single restart file
847      IGCM_sys_Chmod 644 ${RUN_DIR}/${FileOut}.nc
848
849      IGCM_debug_Print 1 "${PerturbExe} ${RUN_DIR}/${FileOut}.nc ${PerturbVar} ${PatternFile} ${MaskFile}"
850      echo
851
852      # add pattern to restart file on variable PerturbVar
853      ${PerturbExe} ${RUN_DIR}/${FileOut}.nc ${PerturbVar} ${PatternFile} ${MaskFile}  > /dev/null 2>&1
854      if [ $? -ne 0 ] ; then
855        IGCM_debug_Exit "Abend $( basename ${PerturbExe} )"
856        IGCM_debug_Verif_Exit
857      fi
858      IGCM_sys_Put_Out ${RUN_DIR}/${FileOut}.nc ${DirOut}/ 644
859     ;;
860    esac
861
[677]862  fi
863
864  #.. Update config.card..
865  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${PerturbComp} Restart "y"
866  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${PerturbComp} RestartDate    ${HumanRestartDate}
867  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${PerturbComp} RestartJobName ${MemberDir}
868  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${PerturbComp} RestartPath    ${RestartDir}/
[1001]869  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleType "Ens_PERTURB"
[1007]870
[679]871  IGCM_debug_PopStack "IGCM_ensemble_CastPerturbFile"
[677]872}
[1001]873
874############### Date ENSEMBLE #################
875function IGCM_ensemble_DateInit
876{
877  IGCM_debug_PushStack "IGCM_ensemble_DateInit"
878
879  IGCM_sys_Mkdir ${RUN_DIR}
880
881  IGCM_sys_Cp ${SUBMIT_DIR}/config.card   ${RUN_DIR}
882  IGCM_sys_Cp ${SUBMIT_DIR}/ensemble.card ${RUN_DIR}
883  IGCM_sys_Cp ${SUBMIT_DIR}/Job_*         ${RUN_DIR}
884  IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${RUN_DIR}
885  if [ -f ${SUBMIT_DIR}/Qsub.* ]; then
[1026]886    IGCM_sys_Cp ${SUBMIT_DIR}/Qsub.*        ${RUN_DIR}
[1001]887  fi
[1007]888  if [ -f ${SUBMIT_DIR}/Qclean.* ]; then
[1026]889    IGCM_sys_Cp ${SUBMIT_DIR}/Qclean.*      ${RUN_DIR}
[1007]890  fi
891
892  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE active
893  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE NAME
894  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE BEGIN_INIT
895  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE BEGIN_RESTART
896  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE END_INIT
897  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE PERIODICITY
898  IGCM_card_DefineArrayFromOption    ${F_CFG_ENS} Ens_DATE NONPERIODIC
899  IGCM_card_DefineArrayFromOption    ${F_CFG_ENS} Ens_DATE RESTART_NONPERIODIC
900  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE LENGTH
901  IGCM_card_DefineArrayFromOption    ${F_CFG_ENS} Ens_DATE LENGTH_NONPERIODIC
902  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE INITFROM
903  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE INITFROM_NONPERIODIC
904  IGCM_card_DefineVariableFromOption ${F_CFG_ENS} Ens_DATE INITPATH
[1001]905  IGCM_card_DefineVariableFromOption config.card UserChoices JobName
906  IGCM_card_DefineVariableFromOption config.card UserChoices TagName
907  IGCM_card_DefineVariableFromOption config.card UserChoices CalendarType
908  IGCM_card_DefineArrayFromSection   config.card ListOfComponents
909
910  echo
911  IGCM_debug_Print 1 "[Ens_DATE]"
[1007]912  IGCM_debug_Print 1 "ACTIVE               = ${ensemble_Ens_DATE_active}"
913  IGCM_debug_Print 1 "NAME                 = ${ensemble_Ens_DATE_NAME}"
914  IGCM_debug_Print 1 "BEGIN_INIT           = ${ensemble_Ens_DATE_BEGIN_INIT}"
915  IGCM_debug_Print 1 "END_INIT             = ${ensemble_Ens_DATE_END_INIT}"
916  IGCM_debug_Print 1 "PERIODICITY          = ${ensemble_Ens_DATE_PERIODICITY}"
917  IGCM_debug_Print 1 "BEGIN_RESTART        = ${ensemble_Ens_DATE_BEGIN_RESTART}"
918  IGCM_debug_Print 1 "NONPERIODIC          = ${ensemble_Ens_DATE_NONPERIODIC[*]}"
919  IGCM_debug_Print 1 "RESTART_NONPERIODIC  = ${ensemble_Ens_DATE_RESTART_NONPERIODIC[*]}"
920  IGCM_debug_Print 1 "LENGTH               = ${ensemble_Ens_DATE_LENGTH}"
921  IGCM_debug_Print 1 "LENGTH_NONPERIODIC   = ${ensemble_Ens_DATE_LENGTH_NONPERIODIC[*]}"
922  IGCM_debug_Print 1 "INITFROM             = ${ensemble_Ens_DATE_INITFROM}"
923  IGCM_debug_Print 1 "INITFROM_NONPERIODIC = ${ensemble_Ens_DATE_INITFROM_NONPERIODIC[*]}"
924  IGCM_debug_Print 1 "INITPATH             = ${ensemble_Ens_DATE_INITPATH}"
925  IGCM_debug_Print 1 "JobName              = ${config_UserChoices_JobName}"
926  IGCM_debug_Print 1 "TagName              = ${config_UserChoices_TagName}"
927  IGCM_debug_Print 1 "CalendarType         = ${config_UserChoices_CalendarType}"
928  IGCM_debug_Print 1 "ListOfComponents     = ${config_ListOfComponents[*]}"
[1001]929  echo ""
[1007]930
[1001]931  ensemble_Ens_DATE_MEMBER=1 # actually use only 1 member
932  IGCM_ensemble_SetAlpha ${ensemble_Ens_DATE_MEMBER}
[1007]933
[1001]934  IGCM_debug_Print 1 "Check args..."
935  DatePeriodicStart=false
936  DateNonPeriodicStart=false
[1007]937
[1001]938  # ... Check LENGTH ...
939  case ${ensemble_Ens_DATE_LENGTH} in
940  *[Yy]|*[Mm])
941    IGCM_debug_Print 1 "Default simulation duration : ${ensemble_Ens_DATE_LENGTH}" ;;
942  *)
943    IGCM_debug_Exit "IGCM_ensemble_DateInit ${ensemble_Ens_DATE_LENGTH} invalid LENGTH"
944    IGCM_debug_Exit "Choose a value in choose in *Y or *M"
945    IGCM_debug_Verif_Exit ;;
946  esac
947
948  # ***************************************
949  # A few checks Period case:
950  # ***************************************
951  # if all Periodic params are not filled: desactivate Periodic mode
952  totalPeriodArgs=4
953  periodFillArgs=0
[1007]954
[1001]955  if [[ X${ensemble_Ens_DATE_BEGIN_RESTART} != "X" ]]; then
[1026]956    (( periodFillArgs = periodFillArgs + 1 ))
[1001]957  fi
[1007]958
[1001]959  if [[ X${ensemble_Ens_DATE_BEGIN_INIT} != "X" ]]; then
[1026]960    (( periodFillArgs = periodFillArgs + 1 ))
[1001]961  fi
962
963  if [[ X${ensemble_Ens_DATE_END_INIT} != "X" ]]; then
[1026]964    (( periodFillArgs = periodFillArgs + 1 ))
[1001]965  fi
966
967  if [[ X${ensemble_Ens_DATE_PERIODICITY} != "X" ]]; then
[1026]968    (( periodFillArgs = periodFillArgs + 1 ))
[1007]969
[1026]970    # ... Check PERIODICITY ...
971    case ${ensemble_Ens_DATE_PERIODICITY} in
972    *[Yy]|*[Mm])
973      IGCM_debug_Print 1 "Periodic length : ${ensemble_Ens_DATE_PERIODICITY}" ;;
974    *)
975      IGCM_debug_Exit "IGCM_ensemble_DateInit ${ensemble_Ens_DATE_PERIODICITY} : invalid PERIODICITY"
976      IGCM_debug_Exit "Choose a value in *Y or *M"
977      IGCM_debug_Verif_Exit ;;
978    esac
[1001]979  fi # if periodicity
[1007]980
[1001]981  if [[ ${periodFillArgs} = ${totalPeriodArgs} ]]; then
[1026]982    DatePeriodicStart=true
[1001]983  else
[1026]984    if [[ ${periodFillArgs} = 0 ]]; then
985      IGCM_debug_Print 1 "Periodic start NOT ACTIVE"
986      DatePeriodicStart=false
987    else
988      IGCM_debug_Exit "IGCM_ensemble_DateInit missing arguments for Periodic mode!"
989      IGCM_debug_Exit "Get only ${periodFillArgs} on ${totalPeriodArgs} args. Check ${F_CFG_ENS} file."
990      IGCM_debug_Verif_Exit
991    fi
[1001]992  fi
[1007]993
[1001]994  # ***************************************
995  # A few checks for the Non-Periodic case:
996  # ***************************************
997  if [[ ${#ensemble_Ens_DATE_NONPERIODIC[*]} != ${#ensemble_Ens_DATE_RESTART_NONPERIODIC[*]} ]] ; then
[1026]998    IGCM_debug_Exit "IGCM_ensemble_DateInit: NONPERIODIC and RESTART_NONPERIODIC lists have different sizes"
999    IGCM_debug_Verif_Exit
[1001]1000  fi
[1007]1001
[1001]1002  if [[ ${#ensemble_Ens_DATE_NONPERIODIC[*]} > 0 ]] && [[ ${ensemble_Ens_DATE_NONPERIODIC[*]} != _0_ ]]; then
[1026]1003    DateNonPeriodicStart=true
[1007]1004
[1026]1005    # Use LENGTH if no NONPERIODIC_LENGTH given
1006    if [[ ${#ensemble_Ens_DATE_LENGTH_NONPERIODIC[*]} < ${#ensemble_Ens_DATE_NONPERIODIC[*]} ]] ; then
1007      IGCM_debug_Print 1 "WARNING: LENGTH_NONPERIODIC is not fill (or not correctly). Use LENGTH value '${ensemble_Ens_DATE_LENGTH}' for all NONPERIODIC runs"
1008      DateNum=0
1009      while [ ${DateNum} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; do
1010        ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]=${ensemble_Ens_DATE_LENGTH}
1011        (( DateNum = DateNum + 1 ))
1012      done
1013    fi
[1007]1014
[1026]1015    # Use INITFROM if no NONPERIODIC_INITFROM given
1016    if [ ${#ensemble_Ens_DATE_INITFROM_NONPERIODIC[*]} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; then
1017      IGCM_debug_Print 1 "WARNING: INITFROM_NONPERIODIC is not fill (or not correctly). Use INITFROM value '${ensemble_Ens_DATE_INITFROM}' for all NONPERIODIC runs"
1018      DateNum=0
1019      while [ ${DateNum} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; do
1020        ensemble_Ens_DATE_INITFROM_NONPERIODIC[${DateNum}]=${ensemble_Ens_DATE_INITFROM}
1021        (( DateNum = DateNum + 1 ))
1022      done
1023    fi
[1001]1024  else
[1026]1025    IGCM_debug_Print 1 "Non-Periodic start NOT ACTIVE"
1026    DateNonPeriodicStart=false
[1001]1027  fi
[1007]1028
[1001]1029  if [[ ${DateNonPeriodicStart} = true ]]; then
[1026]1030    DateNum=0
1031    while [ ${DateNum} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; do
1032      # - Check LENGTH_NONPERIODIC
1033      case ${ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]} in
1034      *[Yy]|*[Mm])
1035        IGCM_debug_Print 1 "Non-periodic duration ${DateNum}: ${ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]}"
1036        ;;
1037      *)
1038        IGCM_debug_Exit "IGCM_ensemble_DateInit ${ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]} : invalid NON PERIODIC LENGTH"
1039        IGCM_debug_Exit "choose in *Y or *M"
1040        IGCM_debug_Verif_Exit ;;
1041      esac
[1001]1042
[1026]1043      # - Check RESTART_NONPERIODIC
1044      case ${ensemble_Ens_DATE_RESTART_NONPERIODIC[${DateNum}]} in
1045      _0_)
1046        IGCM_debug_Exit "IGCM_ensemble_DateInit ${ensemble_Ens_DATE_RESTART_NONPERIODIC[${DateNum}]} : invalid NON PERIODIC RESTART"
1047        IGCM_debug_Verif_Exit ;;
1048      esac
[1007]1049
[1026]1050      (( DateNum = DateNum + 1 ))
1051    done
[1001]1052  fi # DateNonPeriodicStart = true
[1007]1053
[1001]1054  IGCM_debug_PopStack "IGCM_ensemble_DateInit"
1055}
1056
1057function IGCM_ensemble_DatePeriodicStarts
1058{
1059  IGCM_debug_PushStack "IGCM_ensemble_DatePeriodicStarts"
1060
1061  [ ${DatePeriodicStart} = false ] && return
1062
1063  echo
1064  IGCM_debug_Print 1 ">>>  MANAGE PERIODIC STARTS  <<<"
1065
1066#.. Manage periodic starts ..
1067#   ======================
1068
1069  # - Build directory name
1070  StartDir="${ensemble_Ens_DATE_NAME}"
[1007]1071
[1001]1072  # - Create directory for current DateBegin
1073  if [ ! -d  ${StartDir} ] ; then
[1026]1074    IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}
1075    IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}
1076    ln -s ../../.resol .
1077    ln -s ../../.libmpi .
1078    IGCM_sys_Cd ${RUN_DIR}
[1001]1079  fi
[1007]1080
[1001]1081  # ... Loop over DateBegin ...
1082  eval DateBegin=\${ensemble_Ens_DATE_BEGIN_INIT}
1083  eval RestartDate=\${ensemble_Ens_DATE_BEGIN_RESTART}
1084
[1007]1085  DateNum=0
[1001]1086  while [ ${DateBegin} -le ${ensemble_Ens_DATE_END_INIT} ] ; do
1087    IGCM_date_GetYearMonth ${DateBegin} year month
[1007]1088
[1001]1089    echo "========================================================================"
1090    echo "New DateBegin = $DateBegin"
[1007]1091
[1001]1092  # - Determine number of day(s) in PERIODICITY
1093    PeriodLengthInDays=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${ensemble_Ens_DATE_PERIODICITY} )
[1007]1094
[1001]1095  # - Determine number of day(s) in LENGTH
1096    DureeLengthInDays=$(( $( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${ensemble_Ens_DATE_LENGTH} ) - 1 ))
1097
1098  # - Determine DateEnd
1099    (( DateEnd = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${DureeLengthInDays} ) ))
[1007]1100
[1001]1101    IGCM_debug_Print 2 "${DateBegin} => ${DateEnd} : ${StartDir}"
1102    echo "${DateBegin} ${DateEnd} ${StartDir}" >> ${RUN_DIR}/CreatedDir.txt
[1007]1103
[1001]1104  # - Loop over members (default =1 no member)
1105    i=0
1106    while [ $i -lt ${ensemble_Ens_DATE_MEMBER} ] ; do
[1007]1107      MemberDir="${ensemble_Ens_DATE_NAME}${DateNum}${Alpha[$i]}_per"
[1001]1108      echo
1109      IGCM_debug_Print 3 "${MemberDir}"
[1007]1110
[1001]1111      JobName="Job_${MemberDir}"
1112
1113    # * Create directory if it doesn't exist and copy/link files
1114      if [ ! -d  ${SUBMIT_DIR}/${StartDir}/${MemberDir} ] ; then
1115        IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1116        IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1117        ln -s ../../COMP
1118        ln -s ../../PARAM
1119        ln -s ../../POST
1120        ln -s ../../DRIVER
1121        IGCM_sys_Cd ${RUN_DIR}
1122        IGCM_sys_Cp config.card run.card.init ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1123        IGCM_sys_Cp Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/${StartDir}/${MemberDir}/${JobName}
[1007]1124
[1001]1125        # Dump command to be lauched
[1007]1126        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qsub.${StartDir}.sh
1127        echo "${SUBMIT} ${JobName} ; cd -"     >> ${RUN_DIR}/Qsub.${StartDir}.sh
1128
1129        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
1130        echo "${libIGCM}/clean_month.job ; cd -"     >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
1131
1132        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
1133        echo "${libIGCM}/clean_year.job ; cd -"     >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
1134
1135        # * Update files : config.card, Job_, COMP/comp.card
1136        IGCM_ensemble_DateFilesUpdate ${DateBegin} ${DateEnd} ${RestartDate}
[1001]1137      fi
[1007]1138
[1001]1139      (( i = i + 1 ))
1140    done
1141
1142  # - Next DateBegin & RestartDate
1143    echo "$DateBegin  $PeriodLengthInDays"
1144    case ${ensemble_Ens_DATE_PERIODICITY} in
1145    *[Yy]|*[Mm])
1146      (( DateBegin =   $( IGCM_date_AddDaysToGregorianDate ${DateBegin}   ${PeriodLengthInDays} ) ))
1147      (( RestartDate = $( IGCM_date_AddDaysToGregorianDate ${RestartDate} ${PeriodLengthInDays} ) ))
1148      ;;
1149    esac
1150
[1007]1151    (( DateNum = DateNum + 1 )) # increment number of restart date
[1001]1152  done
1153
1154  # Done. Save ${StartDir} submission text file
[1007]1155  IGCM_sys_Cp ${RUN_DIR}/Qsub.${StartDir}.sh ${SUBMIT_DIR}
1156  IGCM_sys_Cp ${RUN_DIR}/Qclean.month.${StartDir}.sh ${SUBMIT_DIR}
1157  IGCM_sys_Cp ${RUN_DIR}/Qclean.year.${StartDir}.sh ${SUBMIT_DIR}
1158
[1001]1159  IGCM_debug_PopStack "IGCM_ensemble_DatePeriodicStarts"
1160}
1161
1162function IGCM_ensemble_DateNonPeriodicStarts
1163{
1164  IGCM_debug_PushStack "IGCM_ensemble_DateNonPeriodicStarts"
1165
1166  #.. Manage non periodic starts => Loop over DateBegin ..
1167  #   ==========================
1168
1169  [ ${DateNonPeriodicStart} = false ] && return
1170
1171  echo
1172  IGCM_debug_Print 1 ">>>  MANAGE NON PERIODIC STARTS  <<<"
1173
1174  # - Build directory name
1175  echo ""
1176  echo "========================================================================"
1177  echo "ensemble_Ens_DATE_NAME = ${ensemble_Ens_DATE_NAME}"
1178  StartDir="${ensemble_Ens_DATE_NAME}"
1179
1180  # -  Does $StartDir already exist ?
1181  if [ ! -d ${SUBMIT_DIR}/${StartDir} ] ; then
[1026]1182    IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}
1183    IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}
1184    ln -s ../../.resol .
1185    ln -s ../../.libmpi .
1186    IGCM_sys_Cd ${RUN_DIR}
[1001]1187  fi
[1007]1188
[1001]1189  DateNum=0
1190  # ... Loop over ensemble_Ens_DATE_NONPERIODIC ...
[1026]1191  while [ ${DateNum} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; do
1192    DateBegin=${ensemble_Ens_DATE_NONPERIODIC[${DateNum}]}
1193    Duree=${ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]}
1194    RestartDate=${ensemble_Ens_DATE_RESTART_NONPERIODIC[${DateNum}]}
1195    InitFrom=${ensemble_Ens_DATE_INITFROM_NONPERIODIC[${DateNum}]}
[1007]1196
[1001]1197  # - Determine number of day(s) in LENGTH_NONPERIODIC
1198    IGCM_date_GetYearMonth ${DateBegin} year month
1199    DureeLengthInDays=$(( $( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${Duree} ) - 1 ))
1200
1201  # - Determine DateEnd
1202    (( DateEnd = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${DureeLengthInDays} ) ))
[1007]1203
[1001]1204    IGCM_debug_Print 2 "${DateBegin} => ${DateEnd} : ${StartDir}"
[1007]1205    echo "${DateBegin} ${DateEnd} ${StartDir}" >> ${RUN_DIR}/CreatedDir.txt
1206
[1001]1207    PeriodDateEnd=$( grep -m1 ${StartDir} ${RUN_DIR}/CreatedDir.txt | cut -f2 -d\  )
[1007]1208
[1001]1209  # - Loop over members
1210    i=0
1211    while [ $i -lt ${ensemble_Ens_DATE_MEMBER} ] ; do
[1007]1212      MemberDir="${ensemble_Ens_DATE_NAME}${DateNum}${Alpha[$i]}"
[1001]1213      IGCM_debug_Print 3 "${MemberDir}"
[1007]1214
[1001]1215      JobName="Job_${MemberDir}"
1216
1217    # * Create directory if it doesn't exist and copy files
1218      if [ ! -d  ${SUBMIT_DIR}/${StartDir}/${MemberDir} ] ; then
1219        IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1220        IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1221        ln -s ../../COMP
1222        ln -s ../../PARAM
1223        ln -s ../../POST
1224        ln -s ../../DRIVER
1225        IGCM_sys_Cd ${RUN_DIR}
1226        IGCM_sys_Cp config.card run.card.init ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1227        IGCM_sys_Cp Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/${StartDir}/${MemberDir}/Job_${MemberDir}
1228
1229        # Dump command to be lauched
[1007]1230        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qsub.${StartDir}.sh
1231        echo "${SUBMIT} ${JobName} ; cd -"     >> ${RUN_DIR}/Qsub.${StartDir}.sh
[1001]1232
[1007]1233        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
1234        echo "${libIGCM}/clean_month.job ; cd -"     >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
1235
1236        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
1237        echo "${libIGCM}/clean_year.job ; cd -"     >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
1238
1239        # * Update files : config.card, Job_, COMP/comp.card
1240        IGCM_ensemble_DateFilesUpdate ${DateBegin} ${DateEnd} ${RestartDate} ${InitFrom}
[1001]1241      fi
[1007]1242
[1001]1243      (( i = i + 1 ))
1244    done
1245
1246    # Done. Save ${StartDir} submission text file
[1007]1247    IGCM_sys_Cp ${RUN_DIR}/Qsub.${StartDir}.sh ${SUBMIT_DIR}
1248    IGCM_sys_Cp ${RUN_DIR}/Qclean.month.${StartDir}.sh ${SUBMIT_DIR}
1249    IGCM_sys_Cp ${RUN_DIR}/Qclean.year.${StartDir}.sh ${SUBMIT_DIR}
[1001]1250
1251    (( DateNum = DateNum + 1 ))
1252  done
1253
1254  # Done. Save ${StartDir} submission text file
[1007]1255  IGCM_sys_Cp ${RUN_DIR}/Qsub.${StartDir}.sh ${SUBMIT_DIR}
1256  IGCM_sys_Cp ${RUN_DIR}/Qclean.month.${StartDir}.sh ${SUBMIT_DIR}
1257  IGCM_sys_Cp ${RUN_DIR}/Qclean.year.${StartDir}.sh ${SUBMIT_DIR}
1258
[1001]1259  IGCM_debug_PopStack "IGCM_ensemble_DateNonPeriodicStarts"
1260}
1261
1262function IGCM_ensemble_DateFilesUpdate
1263{
1264  IGCM_debug_PushStack "IGCM_ensemble_DateFilesUpdate"
1265
1266  # Debug Print :
1267  echo
1268  IGCM_debug_Print 1 "IGCM_ensemble_DateFilesUpdate :"
1269
1270  HumanDateBegin=$(   IGCM_date_ConvertFormatToHuman ${1} )
1271  HumanDateEnd=$(     IGCM_date_ConvertFormatToHuman ${2} )
1272  HumanRestartDate=$( IGCM_date_ConvertFormatToHuman ${3} )
[1007]1273  if [[ X${4} != "X" ]]; then
[1026]1274    initFrom=${4} # non periodic config (INITFROM could be different between members)
[1007]1275  else
[1026]1276    initFrom=${ensemble_Ens_DATE_INITFROM} # periodic (same INITFROM value)
[1007]1277  fi
1278
[1001]1279  # ==> config.card
1280  # [ENSEMBLE]
1281  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleRun 'y'
1282  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleName ${ensemble_Ens_DATE_NAME}
1283  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleDate ${HumanDateBegin}
1284  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleType "Ens_DATE"
[1007]1285
[1001]1286  # [UserChoices]
1287  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card UserChoices JobName   ${MemberDir}
1288  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card UserChoices DateBegin ${HumanDateBegin}
1289  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card UserChoices DateEnd   ${HumanDateEnd}
[1007]1290
[1001]1291  # [Restarts]
1292  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Restarts OverRule "y"
1293  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Restarts RestartDate ${HumanRestartDate}
[1007]1294  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Restarts RestartJobName ${initFrom}
[1001]1295  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Restarts RestartPath ${ensemble_Ens_DATE_INITPATH}
1296
1297    # [ATM/OCE/...]
1298  for comp in ${config_ListOfComponents[*]} ; do
1299    IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${comp} Restart "n"
1300  done
[1007]1301  unset initFrom
1302
[1001]1303  # ==> Job
1304  sed -e "s/\(#.*\)${config_UserChoices_JobName}\( *#.*\)/\1${MemberDir} \2/"            \
1305      -e "s/\(#.*Script_Output_\)${config_UserChoices_JobName}\(\.*\)/\1${MemberDir}\2/" \
[1026]1306      -e "s/^PeriodNb=.*/PeriodNb=60/"                                                   \
[1001]1307      ${SUBMIT_DIR}/${StartDir}/${MemberDir}/Job_${MemberDir} > Job_${MemberDir}.tmp
1308  IGCM_sys_Mv Job_${MemberDir}.tmp ${SUBMIT_DIR}/${StartDir}/${MemberDir}/Job_${MemberDir}
1309
1310  IGCM_debug_PopStack "IGCM_ensemble_DateFilesUpdate"
1311}
1312
1313############### Parametric ENSEMBLE #################
Note: See TracBrowser for help on using the repository browser.