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

Last change on this file since 1284 was 1284, checked in by sdipsl, 8 years ago
  • Can now specify a list of directories containing restart files for the hindcast/forecast initial state generation. NL.
  • 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: 53.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/\(#.*Script_Output_\)${config_UserChoices_JobName}\(\.*\)/\1${MemberDir}\2/" \
618      -e "s/\(#.*\)${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 ${F_CFG_ENS} Ens_DATE INITPATH_NONPERIODIC
914  IGCM_card_DefineVariableFromOption config.card UserChoices JobName
915  IGCM_card_DefineVariableFromOption config.card UserChoices TagName
916  IGCM_card_DefineVariableFromOption config.card UserChoices CalendarType
917  IGCM_card_DefineArrayFromSection   config.card ListOfComponents
918
919  echo
920  IGCM_debug_Print 1 "[Ens_DATE]"
921  IGCM_debug_Print 1 "ACTIVE               = ${ensemble_Ens_DATE_active}"
922  IGCM_debug_Print 1 "NAME                 = ${ensemble_Ens_DATE_NAME}"
923  IGCM_debug_Print 1 "BEGIN_INIT           = ${ensemble_Ens_DATE_BEGIN_INIT}"
924  IGCM_debug_Print 1 "END_INIT             = ${ensemble_Ens_DATE_END_INIT}"
925  IGCM_debug_Print 1 "PERIODICITY          = ${ensemble_Ens_DATE_PERIODICITY}"
926  IGCM_debug_Print 1 "BEGIN_RESTART        = ${ensemble_Ens_DATE_BEGIN_RESTART}"
927  IGCM_debug_Print 1 "NONPERIODIC          = ${ensemble_Ens_DATE_NONPERIODIC[*]}"
928  IGCM_debug_Print 1 "RESTART_NONPERIODIC  = ${ensemble_Ens_DATE_RESTART_NONPERIODIC[*]}"
929  IGCM_debug_Print 1 "LENGTH               = ${ensemble_Ens_DATE_LENGTH}"
930  IGCM_debug_Print 1 "LENGTH_NONPERIODIC   = ${ensemble_Ens_DATE_LENGTH_NONPERIODIC[*]}"
931  IGCM_debug_Print 1 "INITFROM             = ${ensemble_Ens_DATE_INITFROM}"
932  IGCM_debug_Print 1 "INITFROM_NONPERIODIC = ${ensemble_Ens_DATE_INITFROM_NONPERIODIC[*]}"
933  IGCM_debug_Print 1 "INITPATH             = ${ensemble_Ens_DATE_INITPATH}"
934  IGCM_debug_Print 1 "INITPATH_NONPERIODIC = ${ensemble_Ens_DATE_INITPATH_NONPERIODIC[*]}"
935  IGCM_debug_Print 1 "JobName              = ${config_UserChoices_JobName}"
936  IGCM_debug_Print 1 "TagName              = ${config_UserChoices_TagName}"
937  IGCM_debug_Print 1 "CalendarType         = ${config_UserChoices_CalendarType}"
938  IGCM_debug_Print 1 "ListOfComponents     = ${config_ListOfComponents[*]}"
939  echo ""
940
941  ensemble_Ens_DATE_MEMBER=1 # actually use only 1 member
942  IGCM_ensemble_SetAlpha ${ensemble_Ens_DATE_MEMBER}
943
944  IGCM_debug_Print 1 "Check args..."
945  DatePeriodicStart=false
946  DateNonPeriodicStart=false
947
948  # ... Check LENGTH ...
949  case ${ensemble_Ens_DATE_LENGTH} in
950  *[Yy]|*[Mm])
951    IGCM_debug_Print 1 "Default simulation duration : ${ensemble_Ens_DATE_LENGTH}" ;;
952  *)
953    IGCM_debug_Exit "IGCM_ensemble_DateInit ${ensemble_Ens_DATE_LENGTH} invalid LENGTH"
954    IGCM_debug_Exit "Choose a value in choose in *Y or *M"
955    IGCM_debug_Verif_Exit ;;
956  esac
957
958  # ***************************************
959  # A few checks Period case:
960  # ***************************************
961  # if all Periodic params are not filled: desactivate Periodic mode
962  totalPeriodArgs=4
963  periodFillArgs=0
964
965  if [[ X${ensemble_Ens_DATE_BEGIN_RESTART} != "X" ]]; then
966    (( periodFillArgs = periodFillArgs + 1 ))
967  fi
968
969  if [[ X${ensemble_Ens_DATE_BEGIN_INIT} != "X" ]]; then
970    (( periodFillArgs = periodFillArgs + 1 ))
971  fi
972
973  if [[ X${ensemble_Ens_DATE_END_INIT} != "X" ]]; then
974    (( periodFillArgs = periodFillArgs + 1 ))
975  fi
976
977  if [[ X${ensemble_Ens_DATE_PERIODICITY} != "X" ]]; then
978    (( periodFillArgs = periodFillArgs + 1 ))
979
980    # ... Check PERIODICITY ...
981    case ${ensemble_Ens_DATE_PERIODICITY} in
982    *[Yy]|*[Mm])
983      IGCM_debug_Print 1 "Periodic length : ${ensemble_Ens_DATE_PERIODICITY}" ;;
984    *)
985      IGCM_debug_Exit "IGCM_ensemble_DateInit ${ensemble_Ens_DATE_PERIODICITY} : invalid PERIODICITY"
986      IGCM_debug_Exit "Choose a value in *Y or *M"
987      IGCM_debug_Verif_Exit ;;
988    esac
989  fi # if periodicity
990
991  if [[ ${periodFillArgs} = ${totalPeriodArgs} ]]; then
992    DatePeriodicStart=true
993  else
994    if [[ ${periodFillArgs} = 0 ]]; then
995      IGCM_debug_Print 1 "Periodic start NOT ACTIVE"
996      DatePeriodicStart=false
997    else
998      IGCM_debug_Exit "IGCM_ensemble_DateInit missing arguments for Periodic mode!"
999      IGCM_debug_Exit "Get only ${periodFillArgs} on ${totalPeriodArgs} args. Check ${F_CFG_ENS} file."
1000      IGCM_debug_Verif_Exit
1001    fi
1002  fi
1003
1004  # ***************************************
1005  # A few checks for the Non-Periodic case:
1006  # ***************************************
1007  if [[ ${#ensemble_Ens_DATE_NONPERIODIC[*]} != ${#ensemble_Ens_DATE_RESTART_NONPERIODIC[*]} ]] ; then
1008    IGCM_debug_Exit "IGCM_ensemble_DateInit: NONPERIODIC and RESTART_NONPERIODIC lists have different sizes"
1009    IGCM_debug_Verif_Exit
1010  fi
1011
1012  if [[ ${#ensemble_Ens_DATE_NONPERIODIC[*]} > 0 ]] && [[ ${ensemble_Ens_DATE_NONPERIODIC[*]} != _0_ ]]; then
1013    DateNonPeriodicStart=true
1014
1015    # Use LENGTH if no NONPERIODIC_LENGTH given
1016    if [[ ${#ensemble_Ens_DATE_LENGTH_NONPERIODIC[*]} < ${#ensemble_Ens_DATE_NONPERIODIC[*]} ]] ; then
1017      IGCM_debug_Print 1 "WARNING: LENGTH_NONPERIODIC is not fill (or not correctly). Use LENGTH value '${ensemble_Ens_DATE_LENGTH}' for all NONPERIODIC runs"
1018      DateNum=0
1019      while [ ${DateNum} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; do
1020        ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]=${ensemble_Ens_DATE_LENGTH}
1021        (( DateNum = DateNum + 1 ))
1022      done
1023    fi
1024
1025    # Use INITFROM if no INITFROM_NONPERIODIC given
1026    if [ ${#ensemble_Ens_DATE_INITFROM_NONPERIODIC[*]} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; then
1027      IGCM_debug_Print 1 "WARNING: INITFROM_NONPERIODIC is not fill (or not correctly). Use INITFROM value '${ensemble_Ens_DATE_INITFROM}' for all NONPERIODIC runs"
1028      DateNum=0
1029      while [ ${DateNum} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; do
1030        ensemble_Ens_DATE_INITFROM_NONPERIODIC[${DateNum}]=${ensemble_Ens_DATE_INITFROM}
1031        (( DateNum = DateNum + 1 ))
1032      done
1033    fi
1034   
1035    # Use INITPATH if no INITPATH_NONPERIODIC given
1036    if [ ${#ensemble_Ens_DATE_INITPATH_NONPERIODIC[*]} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; then
1037      IGCM_debug_Print 1 "WARNING: INITPATH_NONPERIODIC is not fill (or not correctly). Use INITPATH value '${ensemble_Ens_DATE_INITPATH}' for all NONPERIODIC runs"
1038      DateNum=0
1039      while [ ${DateNum} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; do
1040        ensemble_Ens_DATE_INITPATH_NONPERIODIC[${DateNum}]=${ensemble_Ens_DATE_INITPATH}
1041        (( DateNum = DateNum + 1 ))
1042      done
1043    fi
1044  else
1045    IGCM_debug_Print 1 "Non-Periodic start NOT ACTIVE"
1046    DateNonPeriodicStart=false
1047  fi
1048
1049  if [[ ${DateNonPeriodicStart} = true ]]; then
1050    DateNum=0
1051    while [ ${DateNum} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; do
1052      # - Check LENGTH_NONPERIODIC
1053      case ${ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]} in
1054      *[Yy]|*[Mm])
1055        IGCM_debug_Print 1 "Non-periodic duration ${DateNum}: ${ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]}"
1056        ;;
1057      *)
1058        IGCM_debug_Exit "IGCM_ensemble_DateInit ${ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]} : invalid NON PERIODIC LENGTH"
1059        IGCM_debug_Exit "choose in *Y or *M"
1060        IGCM_debug_Verif_Exit ;;
1061      esac
1062
1063      # - Check RESTART_NONPERIODIC
1064      case ${ensemble_Ens_DATE_RESTART_NONPERIODIC[${DateNum}]} in
1065      _0_)
1066        IGCM_debug_Exit "IGCM_ensemble_DateInit ${ensemble_Ens_DATE_RESTART_NONPERIODIC[${DateNum}]} : invalid NON PERIODIC RESTART"
1067        IGCM_debug_Verif_Exit ;;
1068      esac
1069
1070      (( DateNum = DateNum + 1 ))
1071    done
1072  fi # DateNonPeriodicStart = true
1073
1074  IGCM_debug_PopStack "IGCM_ensemble_DateInit"
1075}
1076
1077function IGCM_ensemble_DatePeriodicStarts
1078{
1079  IGCM_debug_PushStack "IGCM_ensemble_DatePeriodicStarts"
1080
1081  [ ${DatePeriodicStart} = false ] && return
1082
1083  echo
1084  IGCM_debug_Print 1 ">>>  MANAGE PERIODIC STARTS  <<<"
1085
1086#.. Manage periodic starts ..
1087#   ======================
1088
1089  # - Build directory name
1090  StartDir="${ensemble_Ens_DATE_NAME}"
1091
1092  # - Create directory for current DateBegin
1093  if [ ! -d  ${StartDir} ] ; then
1094    IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}
1095    IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}
1096    ln -s ../../.resol .
1097    ln -s ../../.libmpi .
1098    IGCM_sys_Cd ${RUN_DIR}
1099  fi
1100
1101  # ... Loop over DateBegin ...
1102  eval DateBegin=\${ensemble_Ens_DATE_BEGIN_INIT}
1103  eval RestartDate=\${ensemble_Ens_DATE_BEGIN_RESTART}
1104
1105  DateNum=0
1106  while [ ${DateBegin} -le ${ensemble_Ens_DATE_END_INIT} ] ; do
1107    IGCM_date_GetYearMonth ${DateBegin} year month
1108
1109    echo "========================================================================"
1110    echo "New DateBegin = $DateBegin"
1111
1112  # - Determine number of day(s) in PERIODICITY
1113    PeriodLengthInDays=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${ensemble_Ens_DATE_PERIODICITY} )
1114
1115  # - Determine number of day(s) in LENGTH
1116    DureeLengthInDays=$(( $( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${ensemble_Ens_DATE_LENGTH} ) - 1 ))
1117
1118  # - Determine DateEnd
1119    (( DateEnd = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${DureeLengthInDays} ) ))
1120
1121    IGCM_debug_Print 2 "${DateBegin} => ${DateEnd} : ${StartDir}"
1122    echo "${DateBegin} ${DateEnd} ${StartDir}" >> ${RUN_DIR}/CreatedDir.txt
1123
1124  # - Loop over members (default =1 no member)
1125    i=0
1126    while [ $i -lt ${ensemble_Ens_DATE_MEMBER} ] ; do
1127      MemberDir="${ensemble_Ens_DATE_NAME}${DateNum}${Alpha[$i]}_per"
1128      echo
1129      IGCM_debug_Print 3 "${MemberDir}"
1130
1131      JobName="Job_${MemberDir}"
1132
1133    # * Create directory if it doesn't exist and copy/link files
1134      if [ ! -d  ${SUBMIT_DIR}/${StartDir}/${MemberDir} ] ; then
1135        IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1136        IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1137        ln -s ../../COMP
1138        ln -s ../../PARAM
1139        ln -s ../../POST
1140        ln -s ../../DRIVER
1141        IGCM_sys_Cd ${RUN_DIR}
1142        IGCM_sys_Cp config.card run.card.init ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1143        IGCM_sys_Cp Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/${StartDir}/${MemberDir}/${JobName}
1144
1145        # Dump command to be lauched
1146        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qsub.${StartDir}.sh
1147        echo "${SUBMIT} ${JobName} ; cd -"     >> ${RUN_DIR}/Qsub.${StartDir}.sh
1148
1149        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
1150        echo "${libIGCM}/clean_month.job ; cd -"     >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
1151
1152        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
1153        echo "${libIGCM}/clean_year.job ; cd -"     >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
1154
1155        # * Update files : config.card, Job_, COMP/comp.card
1156        IGCM_ensemble_DateFilesUpdate ${DateBegin} ${DateEnd} ${RestartDate}
1157      fi
1158
1159      (( i = i + 1 ))
1160    done
1161
1162  # - Next DateBegin & RestartDate
1163    echo "$DateBegin  $PeriodLengthInDays"
1164    case ${ensemble_Ens_DATE_PERIODICITY} in
1165    *[Yy]|*[Mm])
1166      (( DateBegin =   $( IGCM_date_AddDaysToGregorianDate ${DateBegin}   ${PeriodLengthInDays} ) ))
1167      (( RestartDate = $( IGCM_date_AddDaysToGregorianDate ${RestartDate} ${PeriodLengthInDays} ) ))
1168      ;;
1169    esac
1170
1171    (( DateNum = DateNum + 1 )) # increment number of restart date
1172  done
1173
1174  # Done. Save ${StartDir} submission text file
1175  IGCM_sys_Cp ${RUN_DIR}/Qsub.${StartDir}.sh ${SUBMIT_DIR}
1176  IGCM_sys_Cp ${RUN_DIR}/Qclean.month.${StartDir}.sh ${SUBMIT_DIR}
1177  IGCM_sys_Cp ${RUN_DIR}/Qclean.year.${StartDir}.sh ${SUBMIT_DIR}
1178
1179  IGCM_debug_PopStack "IGCM_ensemble_DatePeriodicStarts"
1180}
1181
1182function IGCM_ensemble_DateNonPeriodicStarts
1183{
1184  IGCM_debug_PushStack "IGCM_ensemble_DateNonPeriodicStarts"
1185
1186  #.. Manage non periodic starts => Loop over DateBegin ..
1187  #   ==========================
1188
1189  [ ${DateNonPeriodicStart} = false ] && return
1190
1191  echo
1192  IGCM_debug_Print 1 ">>>  MANAGE NON PERIODIC STARTS  <<<"
1193
1194  # - Build directory name
1195  echo ""
1196  echo "========================================================================"
1197  echo "ensemble_Ens_DATE_NAME = ${ensemble_Ens_DATE_NAME}"
1198  StartDir="${ensemble_Ens_DATE_NAME}"
1199
1200  # -  Does $StartDir already exist ?
1201  if [ ! -d ${SUBMIT_DIR}/${StartDir} ] ; then
1202    IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}
1203    IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}
1204    ln -s ../../.resol .
1205    ln -s ../../.libmpi .
1206    IGCM_sys_Cd ${RUN_DIR}
1207  fi
1208
1209  DateNum=0
1210  # ... Loop over ensemble_Ens_DATE_NONPERIODIC ...
1211  while [ ${DateNum} -lt ${#ensemble_Ens_DATE_NONPERIODIC[*]} ] ; do
1212    DateBegin=${ensemble_Ens_DATE_NONPERIODIC[${DateNum}]}
1213    Duree=${ensemble_Ens_DATE_LENGTH_NONPERIODIC[${DateNum}]}
1214    RestartDate=${ensemble_Ens_DATE_RESTART_NONPERIODIC[${DateNum}]}
1215    InitFrom=${ensemble_Ens_DATE_INITFROM_NONPERIODIC[${DateNum}]}
1216    InitPath=${ensemble_Ens_DATE_INITPATH_NONPERIODIC[${DateNum}]}
1217
1218  # - Determine number of day(s) in LENGTH_NONPERIODIC
1219    IGCM_date_GetYearMonth ${DateBegin} year month
1220    DureeLengthInDays=$(( $( IGCM_date_DaysInCurrentPeriod ${DateBegin} ${Duree} ) - 1 ))
1221
1222  # - Determine DateEnd
1223    (( DateEnd = $( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${DureeLengthInDays} ) ))
1224
1225    IGCM_debug_Print 2 "${DateBegin} => ${DateEnd} : ${StartDir}"
1226    echo "${DateBegin} ${DateEnd} ${StartDir}" >> ${RUN_DIR}/CreatedDir.txt
1227
1228    PeriodDateEnd=$( grep -m1 ${StartDir} ${RUN_DIR}/CreatedDir.txt | cut -f2 -d\  )
1229
1230  # - Loop over members
1231    i=0
1232    while [ $i -lt ${ensemble_Ens_DATE_MEMBER} ] ; do
1233      MemberDir="${ensemble_Ens_DATE_NAME}${DateNum}${Alpha[$i]}"
1234      IGCM_debug_Print 3 "${MemberDir}"
1235
1236      JobName="Job_${MemberDir}"
1237
1238    # * Create directory if it doesn't exist and copy files
1239      if [ ! -d  ${SUBMIT_DIR}/${StartDir}/${MemberDir} ] ; then
1240        IGCM_sys_Mkdir ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1241        IGCM_sys_Cd ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1242        ln -s ../../COMP
1243        ln -s ../../PARAM
1244        ln -s ../../POST
1245        ln -s ../../DRIVER
1246        IGCM_sys_Cd ${RUN_DIR}
1247        IGCM_sys_Cp config.card run.card.init ${SUBMIT_DIR}/${StartDir}/${MemberDir}
1248        IGCM_sys_Cp Job_${config_UserChoices_JobName} ${SUBMIT_DIR}/${StartDir}/${MemberDir}/Job_${MemberDir}
1249
1250        # Dump command to be lauched
1251        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qsub.${StartDir}.sh
1252        echo "${SUBMIT} ${JobName} ; cd -"     >> ${RUN_DIR}/Qsub.${StartDir}.sh
1253
1254        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
1255        echo "${libIGCM}/clean_month.job ; cd -"     >> ${RUN_DIR}/Qclean.month.${StartDir}.sh
1256
1257        echo "cd ${StartDir}/${MemberDir}/ ;"  >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
1258        echo "${libIGCM}/clean_year.job ; cd -"     >> ${RUN_DIR}/Qclean.year.${StartDir}.sh
1259
1260        # * Update files : config.card, Job_, COMP/comp.card
1261        IGCM_ensemble_DateFilesUpdate ${DateBegin} ${DateEnd} ${RestartDate} ${InitFrom} ${InitPath}
1262      fi
1263
1264      (( i = i + 1 ))
1265    done
1266
1267    # Done. Save ${StartDir} submission text file
1268    IGCM_sys_Cp ${RUN_DIR}/Qsub.${StartDir}.sh ${SUBMIT_DIR}
1269    IGCM_sys_Cp ${RUN_DIR}/Qclean.month.${StartDir}.sh ${SUBMIT_DIR}
1270    IGCM_sys_Cp ${RUN_DIR}/Qclean.year.${StartDir}.sh ${SUBMIT_DIR}
1271
1272    (( DateNum = DateNum + 1 ))
1273  done
1274
1275  # Done. Save ${StartDir} submission text file
1276  IGCM_sys_Cp ${RUN_DIR}/Qsub.${StartDir}.sh ${SUBMIT_DIR}
1277  IGCM_sys_Cp ${RUN_DIR}/Qclean.month.${StartDir}.sh ${SUBMIT_DIR}
1278  IGCM_sys_Cp ${RUN_DIR}/Qclean.year.${StartDir}.sh ${SUBMIT_DIR}
1279
1280  IGCM_debug_PopStack "IGCM_ensemble_DateNonPeriodicStarts"
1281}
1282
1283function IGCM_ensemble_DateFilesUpdate
1284{
1285  IGCM_debug_PushStack "IGCM_ensemble_DateFilesUpdate"
1286
1287  # Debug Print :
1288  echo
1289  IGCM_debug_Print 1 "IGCM_ensemble_DateFilesUpdate :"
1290
1291  HumanDateBegin=$(   IGCM_date_ConvertFormatToHuman ${1} )
1292  HumanDateEnd=$(     IGCM_date_ConvertFormatToHuman ${2} )
1293  HumanRestartDate=$( IGCM_date_ConvertFormatToHuman ${3} )
1294  if [[ X${4} != "X" ]]; then
1295    initFrom=${4} # non periodic config (INITFROM could be different between members)
1296  else
1297    initFrom=${ensemble_Ens_DATE_INITFROM} # periodic (same INITFROM value)
1298  fi
1299
1300  if [[ X${5} != "X" ]]; then
1301    initPath=${5} # non periodic config (INITPATH could be different between members)
1302  else
1303    initPath=${ensemble_Ens_DATE_INITPATH} # periodic (same INITPATH value)
1304  fi
1305 
1306  # ==> config.card
1307  # [ENSEMBLE]
1308  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleRun 'y'
1309  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleName ${ensemble_Ens_DATE_NAME}
1310  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleDate ${HumanDateBegin}
1311  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Ensemble EnsembleType "Ens_DATE"
1312
1313  # [UserChoices]
1314  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card UserChoices JobName   ${MemberDir}
1315  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card UserChoices DateBegin ${HumanDateBegin}
1316  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card UserChoices DateEnd   ${HumanDateEnd}
1317
1318  # [Restarts]
1319  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Restarts OverRule "y"
1320  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Restarts RestartDate ${HumanRestartDate}
1321  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Restarts RestartJobName ${initFrom}
1322  IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card Restarts RestartPath ${initPath}
1323
1324    # [ATM/OCE/...]
1325  for comp in ${config_ListOfComponents[*]} ; do
1326    IGCM_card_WriteOption ${SUBMIT_DIR}/${StartDir}/${MemberDir}/config.card ${comp} Restart "n"
1327  done
1328  unset initFrom
1329
1330  # ==> Job
1331  sed -e "s/\(#.*Script_Output_\)${config_UserChoices_JobName}\(\.*\)/\1${MemberDir}\2/" \
1332      -e "s/\(#.*\)${config_UserChoices_JobName}\(\.*\)/\1${MemberDir} \2/"            \
1333      -e "s/^PeriodNb=.*/PeriodNb=60/"                                                   \
1334      ${SUBMIT_DIR}/${StartDir}/${MemberDir}/Job_${MemberDir} > Job_${MemberDir}.tmp
1335  IGCM_sys_Mv Job_${MemberDir}.tmp ${SUBMIT_DIR}/${StartDir}/${MemberDir}/Job_${MemberDir}
1336
1337  IGCM_debug_PopStack "IGCM_ensemble_DateFilesUpdate"
1338}
1339
1340############### Parametric ENSEMBLE #################
Note: See TracBrowser for help on using the repository browser.