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

Last change on this file since 1147 was 1147, checked in by sdipsl, 9 years ago

broken ensemble. Tentative fix for Agathe. Ensemble are broken since r1057...
broken rebuild station due to changes in LMDZ station files. Tentative fix for Lidia.

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