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

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