source: trunk/libIGCM/libIGCM_config/libIGCM_config.ksh

Last change on this file was 1634, checked in by falletti, 3 months ago

Add of a check of month and day in DateBegin? and DateEnd? (they must be -le than 12 and than 31, respectively). This is done at the beginning of the run.

  • 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: 64.8 KB
RevLine 
[2]1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
[373]5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
[2]9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#===================================
[726]15function IGCM_config_CommonConfiguration
16{
17  IGCM_debug_PushStack "IGCM_config_CommonConfiguration" $@
18
19  # Debug Print :
[769]20  [ ${Verbosity} -gt 0 ] && echo
[726]21  IGCM_debug_Print 1 "IGCM_config_CommonConfiguration" $@
22
23  # config.card path
[1242]24  configCardPath=$1
[726]25
26  #==================================
[1244]27  typeset option auxprint
[726]28
29  #==================================
30  # Read UserChoices section:
[769]31  [ ${Verbosity} -gt 0 ] && echo
[726]32  IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
33
[1242]34  IGCM_card_DefineArrayFromSection ${configCardPath} UserChoices
[726]35  for option in ${config_UserChoices[*]} ; do
[1242]36    IGCM_card_DefineVariableFromOption ${configCardPath} UserChoices ${option}
[726]37    eval auxprint=\${config_UserChoices_${option}}
38    IGCM_debug_Print 3 "${option} : ${auxprint}"
39  done
40
[1486]41  # Set variables with shorter names on some variables which 
42  # are used in the executable name in config.card
43  ResolAtm=${config_UserChoices_ResolAtm}
44  ResolOce=${config_UserChoices_ResolOce}
[1488]45  ConfChem=${config_UserChoices_ConfChem}
[1486]46  OptMode=${config_UserChoices_OptMode}
[1599]47  ConfigType=${config_UserChoices_ConfigType}
48 
[726]49  #==================================
50  # Read Ensemble section:
[769]51  [ ${Verbosity} -gt 0 ] && echo
[726]52  IGCM_debug_Print 1 "DefineArrayFromOption  : config_Ensemble"
53
[1242]54  IGCM_card_DefineArrayFromSection ${configCardPath} Ensemble
[726]55  for option in ${config_Ensemble[*]} ; do
[1242]56    IGCM_card_DefineVariableFromOption ${configCardPath} Ensemble ${option}
[726]57    eval auxprint=\${config_Ensemble_${option}}
58    IGCM_debug_Print 3 "${option} : ${auxprint}"
59  done
60
61  #==================================
62  # Read Post section:
[769]63  [ ${Verbosity} -gt 0 ] && echo
[726]64  IGCM_debug_Print 1 "DefineArrayFromOption : config_Post"
65
[1242]66  IGCM_card_DefineArrayFromSection ${configCardPath} Post
[726]67  for option in ${config_Post[*]} ; do
[1242]68    IGCM_card_DefineVariableFromOption ${configCardPath} Post ${option}
[726]69    eval auxprint=\${config_Post_${option}}
70    IGCM_debug_Print 3 "${option} : ${auxprint}"
71  done
[769]72  [ ${Verbosity} -gt 0 ] && echo
[726]73
[728]74  #==================================
75  # Define default value to keep compatibility with previous card: means before changes due to TGCC
76  # Apply some overrules to ensure proper usage of computing centres resources
[804]77  #
[1516]78
79  # if RebuildFrequency is not define in config.card - we initilize it to NONE
80  if [ X${config_Post_RebuildFrequency} = X ] ; then
81      config_Post_RebuildFrequency=NONE
82  fi
83
[728]84  if [ X${PackDefault} = Xtrue ] ; then
85    if [ X${config_UserChoices_SpaceName} = XTEST ]; then
86      # TEST simulations will not be packed and will stay on SCRATCHDIR filesystem
87      IGCM_debug_Print 1 "SpaceName=TEST. OVERRULE PackFrequency to NONE"
88      config_Post_PackFrequency=NONE
89    else
90      # Default to RebuildFrequency if nothing has been set up related to PackFrequency
91      [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
92    fi
93  else
94    # If we DO NOT apply pack in this computing center
95    config_Post_PackFrequency=NONE
96  fi
97
[726]98  #====================================================
[1057]99  # Define ARCHIVE : Dedicated to large files
100  # Define STORAGE : Dedicated to small/medium files
101  # Define R_OUT   : Output tree located on ARCHIVE
[1150]102  # Define R_BUF   : Output tree located on STORAGE (files waiting treatment, or file lcoation when SpaceName=!PROD)
[1057]103  # Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
[1150]104  # Define R_TMP   : A temporary space used by IGCM_debug_send_AMQP_msg__MAILTUNNEL. Must be persistent in between jobs
[1057]105  IGCM_sys_defineArchives
106
107  #====================================================
[726]108  # R_SAVE : Job output directory
109  # R_BUFR : Job output buffered directory
[1431]110  # R_CMIP : Job output directory for CMIP6 standard files
[726]111
112  if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
113    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
[1565]114
115    if ( [ X${config_Post_StorageCMIP} = XSCRATCH ] || [ X${config_Post_StorageCMIP} = Xscratch ] ) ; then
116      IGCM_debug_Print 1 "LIBIGCM CONFIG:: SCRATCH R_BUF=${R_BUF}"
117      StoreCMIP=${R_BUF}
118    elif ( [ X${config_Post_StorageCMIP} = XSTORE ] || [ X${config_Post_StorageCMIP} = Xstore ] ) ; then
119      IGCM_debug_Print 1 "LIBIGCM CONFIG:: SCRATCH R_OUT=${R_OUT}"
120      StoreCMIP=${R_OUT}
[726]121    else
[1565]122      IGCM_debug_Print 1 "LIBIGCM CONFIG:: ELSE CMIP_BUF=${CMIP6_BUF}"
123      StoreCMIP=${CMIP6_BUF}
124    fi
125    # Ensemble cases (default all members outputs in same directory)
126    if ( [ ! X${config_Ensemble_EnsembleName} = X ] ) ; then
127      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}
128      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}
129      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}
130      R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}
131      R_CMIP=${StoreCMIP}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}
132      IGCM_debug_Print 1 "LIBIGCM CONFIG:: ENSEMBLE R_CMIP=${R_CMIP}"
133
134      # PERTURB Ensemble Outputs
135      if ( [ X${config_Ensemble_EnsembleType} = XEns_PERTURB ] ) ; then
136        if ( [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
137          R_SAVE=${R_SAVE}/${config_Ensemble_EnsembleDate}/${FreeName}
138          R_FIGR=${R_FIGR}/${config_Ensemble_EnsembleDate}/${FreeName}
139          R_BUFR=${R_BUFR}/${config_Ensemble_EnsembleDate}/${FreeName}
140          R_DODS=${R_DODS}/${config_Ensemble_EnsembleDate}/${FreeName}
141          R_CMIP=${R_CMIP}/${config_Ensemble_EnsembleDate}/${FreeName}
142        else
143          R_SAVE=${R_SAVE}/${FreeName}
144          R_FIGR=${R_FIGR}/${FreeName}
145          R_BUFR=${R_BUFR}/${FreeName}
146          R_DODS=${R_DODS}/${FreeName}
147          R_CMIP=${R_CMIP}/${FreeName}
148        fi
149      # DATE Ensemble Outputs
150      elif ( [ X${config_Ensemble_EnsembleType} = XEns_DATE ] ) ; then
151        R_FIGR=${R_FIGR}/${FreeName}
152        R_BUFR=${R_BUFR}/${FreeName}
153        R_DODS=${R_DODS}/${FreeName}
154        IGCM_debug_Print 1 "LIBIGCM CONFIG:: ENSEMBLE DATE R_CMIP=${R_CMIP}"
155        if ( [ X${config_Ensemble_EnsembleMergeSave} = X ] || [ X${config_Ensemble_EnsembleMergeSave} = Xn ] || 
156             [ X${config_Ensemble_EnsembleMergeSave} = Xno ] ) ; then
157          # One SAVE directory per member, else common output dir for all members
158          R_SAVE=${R_SAVE}/${FreeName}
159          R_CMIP=${R_CMIP}/${FreeName}
160          IGCM_debug_Print 1 "LIBIGCM CONFIG:: ENSEMBLE DATE MERGE R_CMIP=${R_CMIP}"
161        fi
162      fi
163    else
[726]164      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
165      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
166      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
167      R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
[1565]168      R_CMIP=${StoreCMIP}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
[726]169    fi
170  else
171    if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
172      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
173      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
174      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
175      R_DODS=${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
176    else
177      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
178      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
179      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
180      R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName}
181    fi
182  fi
[1565]183 
184  IGCM_debug_Print 1 "LIBIGCM CONFIG:: R_CMIP = ${R_CMIP}"
185 
[782]186  #====================================================
[1110]187  # Define R_OUT_KSH : Storage place for job output
188  # Define R_OUT_EXE : Storage place for binary used during simulation
189  R_OUT_KSH=${R_SAVE}/Out
190  R_OUT_EXE=${R_SAVE}/Exe
191
192  #====================================================
193  # Define R_BUF_KSH : Buffer place for job output
194  # Define R_BUF_EXE : Buffer place for binary used during simulation
195  R_BUF_KSH=${R_BUFR}/Out
196  R_BUF_EXE=${R_BUFR}/Exe
197
198  #====================================================
[1077]199  # Define REBUILD_DIR : where we store files needing rebuild process
[1031]200  REBUILD_DIR=${R_BUFR}/REBUILD
201  if [ ! X${TaskType} = Xchecking ] ; then
202    IGCM_sys_MkdirWork ${REBUILD_DIR}
[782]203  fi
204
[903]205  #====================================================
206  # DodsCopy : apply default value if not defined
207  if ( [ X${config_Post_DodsCopy} = X${NULL_STR} ] || [ X${config_Post_DodsCopy} = X ] ) ; then
208    config_Post_DodsCopy=TRUE
209  fi
210
[1115]211  #====================================================
[1366]212  # AtlasIPSL : apply default value if not defined
213  if ( [ X${config_Post_AtlasIPSL} = X${NULL_STR} ] || [ X${config_Post_AtlasIPSL} = X ] ) ; then
[1497]214    config_Post_AtlasIPSL=FALSE
[1366]215  fi
216
217  #====================================================
[1373]218  # ParserXIOS : apply default value if not defined
219  if ( [ X${config_Post_ParserXIOS} = X${NULL_STR} ] || [ X${config_Post_ParserXIOS} = X ] ) ; then
[1421]220    config_Post_ParserXIOS=FALSE
[1373]221  fi
222
223  #====================================================
[1335]224  # MetricsPCMDI : apply default value if not defined
225  if ( [ X${config_Post_MetricsPCMDI} = X${NULL_STR} ] || [ X${config_Post_MetricsPCMDI} = X ] ) ; then
226    config_Post_MetricsPCMDI=FALSE
227  fi
[1598]228  #====================================================
229  # Cesmep : apply default value FALSE if not defined, and if TRUE
230  # or *Y set it based on an adhoc algorithm
231  if ( [ X${config_Post_Cesmep} = X${NULL_STR} ] || [ X${config_Post_Cesmep} = XNONE ] || \
232       [ X${config_Post_Cesmep} = X ] || [ X${config_Post_Cesmep} = XFALSE ] ) ; then
233    config_Post_Cesmep=FALSE
[1604]234  elif [ X${config_Post_Cesmep} = XTRUE ]  ; then
[1598]235      if ([ ! X${config_Post_SeasonalFrequency} = XNONE ] && [ ! X${config_Post_SeasonalFrequency} = X ] ) ; then
236          config_Post_Cesmep="SE"
237      elif ([ ! X${config_Post_TimeSeriesFrequency} = XNONE ] && [ ! X${config_Post_TimeSeriesFrequency} = X ] ) ; then
238          config_Post_Cesmep="TS"
239      elif ([ ! X${config_Post_PackFrequency} = XNONE ] && [ ! X${config_Post_PackFrequency} = X ] ) ; then
240          config_Post_Cesmep="Pack"
241      else
242          # This covers case SpaceName=TEST with no SE nor TS (nor Pack)
243          config_Post_Cesmep=AtEnd
244      fi
245  fi
246  #
247  if [ X${config_Post_Cesmep} != XFALSE ] ; then
[1604]248      if ( [ X${config_Post_CesmepPeriod} != X${NULL_STR} ] && [ X${config_Post_CesmepPeriod} != X ] ) ; then
249          CesmepPeriod=${config_Post_CesmepPeriod%Y}
[1633]250          if [ $config_Post_CesmepPeriod = 12M ] ; then
251              CesmepPeriod=1
252          fi
[1604]253      fi
[1598]254      if [ X${config_Post_Cesmep} = XSE ] ; then
255          if ([ X${config_Post_SeasonalFrequency} = XNONE ] || [ X${config_Post_SeasonalFrequency} = X ] ) ; then
256              IGCM_debug_Exit "Cannot use SE for Cesmep : SE post-processing is not active"
257          else
258              [ -z $CesmepPeriod ] && CesmepPeriod=${config_Post_SeasonalFrequency%Y}
259          fi
260      elif [ X${config_Post_Cesmep} = XTS ] ; then
261          if ([ X${config_Post_TimeSeriesFrequency} = XNONE ] || [ X${config_Post_TimeSeriesFrequency} = X ] ) ; then
262              IGCM_debug_Exit "Cannot use TS for Cesmep : TS post-processing is not active"
263          else
264              [ -z $CesmepPeriod ] && CesmepPeriod=${config_Post_TimeSeriesFrequency%Y}
265          fi
266      elif [ X${config_Post_Cesmep} = XPack ] ; then
267          if ([ X${config_Post_PackFrequency} = XNONE ] || [ X${config_Post_PackFrequency} = X ] ) ; then
268              IGCM_debug_Exit "Cannot use Packed output for Cesmep : Pack post-processing is not active"
269          else
270              [ -z $CesmepPeriod ] && CesmepPeriod=${config_Post_PackFrequency%Y}
271          fi
272      elif [ X${config_Post_Cesmep} != XAtEnd ] ; then
[1604]273          IGCM_debug_Exit "config.card's Post section's value for Cesmep (${config_Post_Cesmep}) is invalid; use SE, TS, Pack, AtEnd or TRUE"
[1598]274      else
275          [ -z $CesmepPeriod ] && CesmepPeriod=0
276      fi
[1335]277
[1598]278      if ( [ X${config_Post_CesmepComparison} = XNONE ] || [ X${config_Post_CesmepComparison} = X ] ) ; then
279          config_Post_CesmepComparison=run_comparison
280      fi
281     
282      if ( [ X${config_Post_CesmepCode} = XNONE ] || [ X${config_Post_CesmepCode} = X ] ) ; then
283          if ( [ X"${SYSTEM}" == "Xirene" ] || [ X"${SYSTEM}" == "Xirene-amd" ] ); then
284              config_Post_CesmepCode=/ccc/cont003/home/igcmg/igcmg/Tools/cesmep
285          elif ( [ X"${SYSTEM}" == "Xjeanzay" ] ); then
286              config_Post_CesmepCode=/gpfswork/rech/psl/commun/Tools/cesmep
287          elif ( [ X"${SYSTEM}" == "Xmesoipsl" ] ); then
288              config_Post_CesmepCode=/net/nfs/tools/Users/SU/jservon/cesmep_installs/cesmep_for_libIGCM
[1633]289          else
[1598]290              IGCM_debug_Exit "Cannot locate a default C-ESM-EP code on $SYSTEM, please set CesmepCode in section Post"
291          fi
292      fi
[1633]293     
[1598]294      if ( [ X${config_Post_CesmepSlices} = XNONE ] || [ X${config_Post_CesmepSlices} = X ] ) ; then
295          config_Post_CesmepSlices=8
296      fi
[1609]297      if ( [ X${config_Post_CesmepSlicesDuration} != X${NULL_STR} ] && [ X${config_Post_CesmepSlicesDuration} != X ] &&\
298         [ X${config_Post_CesmepSlicesDuration} != XNONE ] ) ; then
[1604]299          CesmepSlicesDuration=${config_Post_CesmepSlicesDuration%Y}
300      else
301          CesmepSlicesDuration=$CesmepPeriod
302      fi
[1606]303      if [ $CesmepSlicesDuration -gt $CesmepPeriod ]; then
304          IGCM_debug_Exit "C-ESM-EP : you cannot set a CesmepSlicesDuration ($CesmepSlicesDuration) longer than CesmepPeriod ($CesmepPeriod)"
305      fi
306      if [ X${config_Post_CesmepReferences} = X${NULL_STR} ] || [ X${config_Post_CesmepReferences} = XNONE ] || \
307             [ X${config_Post_CesmepReferences} = X ] ; then
308          config_Post_CesmepReferences=NONE
309      fi
[1633]310      if [ X${config_Post_CesmepInputFrequency} = X${NULL_STR} ] || [ X${config_Post_CesmepInputFrequency} = XNONE ] || \
311             [ X${config_Post_CesmepInputFrequency} = X ] ; then
312          config_Post_CesmepInputFrequency=monthly
313      fi
[1598]314  fi
[1335]315  #====================================================
[1204]316  # IgnoreNonMonotonic : apply default value if not defined
317  if ( [ X${config_Post_IgnoreNonMonotonic} = X${NULL_STR} ] || [ X${config_Post_IgnoreNonMonotonic} = X ] ) ; then
318    config_Post_IgnoreNonMonotonic=FALSE
319  fi
320
321  #====================================================
[1395]322  # LightRestartPack : apply default value if not defined
323  if ( [ X${config_Post_LightRestartPack} = X${NULL_STR} ] || [ X${config_Post_LightRestartPack} = X ] ) ; then
324    config_Post_LightRestartPack=FALSE
325  fi
326
327  #====================================================
[1535]328  # dr2xmlIPSL : apply default value if not defined
329  if ( [ X${config_Post_dr2xmlIPSL} = X${NULL_STR} ] || [ X${config_Post_dr2xmlIPSL} = X ] ) ; then
330    config_Post_dr2xmlIPSL=FALSE
331  fi
332
333
334  #====================================================
[1115]335  # Define StackFileLocation : directory where we store stack files
336  # Define StackFileName : stack file containing call tree and instrumentation
337  # Stack file containing call tree will be stored there.
338  if ( $DEBUG_debug ) ; then
339    StackFileLocation=${StackFileLocation:=${R_BUF_KSH}}
340    [ ! -d ${StackFileLocation} ] && mkdir -p ${StackFileLocation}
341    if [ X${TaskType} = Xcomputing ]; then
342      StackFileName=computing.stack.$$
343    elif [ X${TaskType} = Xpost-processing ]; then
344      StackFileName=${Script_Post_Output}.stack.$$
345    elif [ X${TaskType} = Xchecking ]; then
346      StackFileName=checking.stack.$$
347    else
348      IGCM_debug_Exit "IGCM_config_CommonConfiguration unknown TaskType : ${TaskType}"
349      IGCM_debug_Verif_Exit
350    fi
351
352    # This boolean will trigger the filling of the stack
353    # Only now we know where things should be ...
[1127]354    # We don't fill the stack when we perform checking task
355    if [ ! X${TaskType} = Xchecking ] ; then
356      ActivateStackFilling=true
357    fi
[1115]358  fi
359
[726]360  IGCM_debug_PopStack "IGCM_config_CommonConfiguration"
361}
362
363#===================================
[2]364function IGCM_config_Initialize
365{
[544]366  IGCM_debug_PushStack "IGCM_config_Initialize"
[2]367
[544]368  # Debug Print :
369  echo
370  IGCM_debug_Print 1 "IGCM_config_Initialize"
[2]371
[544]372  # Test modipsl tree existence.
373  IGCM_sys_TestDir ${MODIPSL}
374  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
375  IGCM_sys_TestDir ${libIGCM}
376  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
377  IGCM_sys_TestDir ${R_EXE}
378  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
379  IGCM_sys_TestDir ${SUBMIT_DIR}
380  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
[2]381
[544]382  if ( $DEBUG_debug ) ; then
383    echo "Keep trace of inital SUBMIT_DIR : "
384    ls -lta ${SUBMIT_DIR}
385  fi
[144]386
[544]387  #==================================
[619]388  # Read ListOfComponents section:
[726]389  echo
390  IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
391
[544]392  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents
393  for comp in ${config_ListOfComponents[*]} ; do
394    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
395  done
396  IGCM_debug_Print 3 ${config_ListOfComponents[*]}
[2]397
[544]398  #==================================
[726]399  # Read Executable section:
[544]400  IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable
[619]401
[544]402  #==================================
[726]403  # Read Restarts section:
404  # Restarts : Gerneral rule or local for each component.
405  echo
406  IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts"
407
408  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts
409  for option in ${config_Restarts[*]} ; do
410    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option}
411    eval auxprint=\${config_Restarts_${option}}
412    IGCM_debug_Print 3 "${option} : ${auxprint}"
413  done
414
415  #==================================
416  # Define Job Outputs Name
417  echo
[544]418  IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output"
[939]419  Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'}
[544]420  IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}"
[939]421  Exe_Output=out_execution
[544]422  IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}"
[2]423
[544]424  #===================================================================#
425  # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
426  #             But available to any son functions                    #
427  #===================================================================#
[2]428
[544]429  # Convert yyyy-mm-dd date to gregorian yyyymmdd
430  DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
[619]431  DateEnd=$(   IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd}   )
[1537]432  EndYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateEnd ) / 1000 ))
433  EndYear_p1=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateEnd ) / 1000 + 1 ))
[2]434
[1634]435  # Check month and day good format
436  IGCM_date_GetYearMonthDay $DateBegin date_begin_year date_begin_month date_begin_day
437  IGCM_date_GetYearMonthDay $DateEnd date_end_year date_end_month date_end_day
438  if [ ${date_begin_month} -gt 12 ] || [ ${date_begin_day} -gt 31 ] || [ ${date_end_month} -gt 12 ] || [ ${date_end_day} -gt 31 ] ; then
439          IGCM_debug_Print 1 "Problem with dates in config.card: DateBegin (${DateBegin}) or DateEnd (${DateEnd}) hasve wrong format
440          (must be yyymmdd). You must check that."
441    IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates."
442    IGCM_debug_Verif_Exit
443  fi 
[1537]444
[544]445  # Period Length In Days between DateBegin and DateEnd
446  (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
447  if [ ${ExperienceLengthInDays} -lt 0 ] ; then
448    IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that."
449    IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates."
[619]450    IGCM_debug_Verif_Exit
[544]451  fi
[2]452
[544]453  # Day and Year of Initial State (Given in julian format)
454  InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 ))
455  InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 ))
[1527]456  InitYear_m1=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 - 1 ))
[2]457
[544]458  #================================================================#
459  #                  Test and Prepare directories                  #
460  #================================================================#
[2]461
[544]462  # ==> 4 kinds of input files :
463  #     1) R_INIT  : Initial State Files   (Etat0, carteveg)
464  #     2) R_BC    : Boundary Conditions   (Forcages, lai)
465  #     3) Parameters files (allready define through ${SUBMIT_DIR})
466  #     4) Restarts files   (allready define in IGCM_config_Initialize)
[2]467
[544]468  # Here we offer the possibility to redefine R_INIT, R_BC
[1607]469  # and NbPeriodsPerJob through config.card
[544]470  R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT}
[731]471  echo
[1607]472  IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and NbPeriodsPerJob"
[1373]473  IGCM_debug_Print 3 "R_IN=${R_IN}"
[544]474  IGCM_debug_Print 3 "R_INIT=${R_INIT}"
475  R_BC=${config_UserChoices_R_BC:=${R_IN}/BC}
476  IGCM_debug_Print 3  "R_BC=${R_BC}"
[1607]477  NbPeriodsPerJob=${config_UserChoices_NbPeriodsPerJob:=${NbPeriodsPerJob}}
478  IGCM_debug_Print 3  "Loop in main Job with ${NbPeriodsPerJob} period(s)"
479 
[771]480  # SD ADA SPECIFIC #
481  #      TO FIX     #
482  #IGCM_sys_TestDirArchive ${R_IN}
483  #[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
[1607]484 
[619]485  if ( ${FirstInitialize} ) ; then
[726]486    IGCM_sys_MkdirArchive   ${R_SAVE}
[805]487    [ ! ${config_Post_PackFrequency} = NONE ] && IGCM_sys_Mkdir ${R_BUFR}
[544]488  else
489    IGCM_sys_TestDirArchive ${R_SAVE}
490    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive ${R_SAVE}"
[2]491
[805]492    if [ ! ${config_Post_PackFrequency} = NONE ] ; then
493      IGCM_sys_TestDir ${R_BUFR}
494      [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir ${R_BUFR}"
495    fi
[545]496
[1220]497    # Test state of run in run.card. Will schedule an exit if another process setted it to "Fatal"
498    IGCM_config_StateCheck
[619]499
[1220]500    # And EXIT if not OK
501    IGCM_debug_Verif_Exit
[544]502  fi
[2]503
[544]504  #====================================================
[619]505  # Experience type : DEB(ug), DEV(elopment), RUN
[544]506  if [ X${JobType} != XRUN ] ; then
507    echo
508    echo "===================================================="
509    echo "libIGCM JOB is NOT in RUN type mode."
510    echo "!! OUTPUT files will NOT be PROTECTED !!"
511    echo "Be carefull : you can ERASE the result of this job !"
[128]512
[544]513    case ${JobType} in
514    DEB)
515      echo "DEBUG mode : activation of 'set -vx' mode."
516      echo "DEBUG mode : no protection for output files."
517      echo "DEBUG mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
518      ;;
519    DEV)
520      echo "DEVelopment mode : no protection for output files."
521      echo "DEVelopment mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
522      ;;
523    esac
[166]524
[544]525    if ( [ X${config_Post_RebuildFrequency} != XNONE ] && [ ${DRYRUN} -eq 0 ] ) ; then
526      if [ X${config_Post_RebuildFrequency} != X${config_UserChoices_PeriodLength} ] ; then
[619]527        echo "------------"
528        echo "WARNING : Job is NOT in RUN mode then we will force REBUILD Frequency"
[786]529        echo "          to PeriodLength : ${config_UserChoices_PeriodLength}"
[619]530        echo "------------"
531        config_Post_RebuildFrequency=${config_UserChoices_PeriodLength}
[544]532      fi
[128]533    fi
[544]534    echo "===================================================="
535    echo
536  fi
[128]537
[544]538  IGCM_debug_PopStack "IGCM_config_Initialize"
[2]539}
540
541#===================================
[890]542function IGCM_config_DaysInPeriodLength
[118]543{
[890]544  IGCM_debug_PushStack "IGCM_config_DaysInPeriodLength"
[118]545
[544]546  typeset i
[124]547
[544]548  # Determine number of day(s) in PeriodLength :
549  case ${config_UserChoices_PeriodLength} in
550  *Y|*y)
[619]551    PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' )
[731]552    echo
[544]553    IGCM_debug_Print 2 "Number of years for PeriodLength : ${PeriodLengthInYears}"
554    PeriodLengthInDays=0
555    i=0
[619]556    until [ $i -ge $PeriodLengthInYears ] ; do
557      (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) ))
558      (( i=i+1 ))
559    done
[544]560    ;;
561  *M|*m)
[619]562    PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' )
[731]563    echo
[544]564    IGCM_debug_Print 2 "Number of months for PeriodLength : ${PeriodLengthInMonths}"
565    PeriodLengthInDays=0
566    i=0
[619]567    until [ $i -ge $PeriodLengthInMonths ] ; do
[829]568      if [ $(( 10#${month} + ${i} )) -lt 13 ] ; then
569        (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( 10#${month} + ${i} )) ) ))
[619]570      else
[829]571        (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( 10#${month} + ${i} - 12 )) ) ))
[619]572      fi
573      (( i=i+1 ))
574    done
[544]575    ;;
[619]576  *D|*d)
[544]577    PeriodLengthInMonths=0
[731]578    PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' )
579    echo
580    IGCM_debug_Print 2 "Number of days for PeriodLength : ${PeriodLengthInDays}";;
[619]581  *)
[890]582    IGCM_debug_Exit "IGCM_config_DaysInPeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D."
[544]583    IGCM_debug_Verif_Exit ;;
584  esac
[118]585
[890]586  IGCM_debug_PopStack "IGCM_config_DaysInPeriodLength"
[380]587}
[118]588
[380]589#===================================
[890]590function IGCM_config_DateCoherency
[891]591{
[890]592  IGCM_debug_PushStack "IGCM_config_DateCoherency"
593
594  echo
595  IGCM_debug_Print 1 "IGCM_config_DateCoherency"
596  echo
597
598  typeset Length VerifiedPeriodDateBegin VerifiedPeriodDateEnd
599
600  # check coherency between (PeriodDateBegin, PeriodDateEnd) and (DateBegin, CumulPeriod, PeriodLength)
601  # DateBegin + CumulPeriod*PeriodLength = PeriodDateBegin
602  echo
[922]603
[890]604  case ${config_UserChoices_PeriodLength} in
605  *Y|*y)
606    Length=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} $(( ${CumulPeriod} * ${PeriodLengthInYears} ))Y )
607    ;;
608  *M|*m)
609    Length=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} $(( ${CumulPeriod} * ${PeriodLengthInMonths} ))M )
610    ;;
611  *D|*d)
612    Length=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} $(( ${CumulPeriod} * ${PeriodLengthInDays} ))D )
613    ;;
614  esac
[892]615  VerifiedPeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${Length}-1 )
[890]616
[892]617  if [ ${VerifiedPeriodDateEnd} != ${PeriodDateEnd} ] ; then
618    IGCM_debug_Print 1 "From run.card PeriodDateEnd is not consistent with DateBegin and CumulPeriod."
619    IGCM_debug_Print 1 "We have DateBegin = ${DateBegin}"
620    IGCM_debug_Print 1 "We have CumulPeriod = ${CumulPeriod}"
621    IGCM_debug_Print 1 "We have PeriodDateEnd = ${PeriodDateEnd}"
622    IGCM_debug_Print 1 "We have VerifiedPeriodDateEnd = ${VerifiedPeriodDateEnd}"
623    IGCM_debug_Print 1 "You must have change run.card in an inconsistent way."
624
625    IGCM_debug_Exit "STOP here to avoid further issues."
626  fi
627
[890]628  # PeriodDateBegin + PeriodLength = PeriodDateEnd
629  VerifiedPeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${VerifiedPeriodDateEnd} $(( ${PeriodLengthInDays} * -1 )) )
630
631  IGCM_debug_PopStack "IGCM_config_DateCoherency"
632}
633
[1220]634#===================================
635function IGCM_config_StateCheck
636{
637  IGCM_debug_PushStack "IGCM_config_StateCheck"
[890]638
[1220]639    #Test state of run in run.card
640    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
641
642    if [ ${run_Configuration_PeriodState} = "Fatal" ] ; then
643      echo
644      IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
[1280]645      IGCM_debug_Print 1 "Check the overall status of your simulation by visiting this page:"
[1510]646      IGCM_debug_Print 1 "https://hermes.ipsl.upmc.fr/static/simulation.detail.html?uid=${simuid}"
[1372]647      IGCM_debug_Print 1 "Then try running ${libIGCM}/clean_PeriodLenght.job to clean latest failed period"
648      IGCM_debug_Print 1 "Or try running ${libIGCM}/clean_latestPackperiod.job to clean lastest pack period."
649      IGCM_debug_Print 1 "Or use ${libIGCM}/purge_simulation.job to delete the full simulation."
[1220]650      IGCM_debug_Exit
[1280]651    elif [ $( echo ${run_Configuration_PeriodState} | grep Fatal | wc -l ) -eq 1 ] ; then
652      echo
653      IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
654      IGCM_debug_Print 1 "Compute jobs has been stop because at least the above mentionned post-processing jobs fails."
655      IGCM_debug_Print 1 "Check post-processing jobs carefully by visiting this page:"
[1510]656      IGCM_debug_Print 1 "https://hermes.ipsl.upmc.fr/static/simulation.detail.html?uid=${simuid}"
[1280]657      IGCM_debug_Print 1 "Please visit that page to see how to fix issues:"
658      IGCM_debug_Print 1 "https://forge.ipsl.jussieu.fr/igcmg_doc/wiki/DocGmonitor"
[1372]659      IGCM_debug_Print 1 "Then try running ${libIGCM}/clean_PeriodLenght.job to clean latest failed period"
660      IGCM_debug_Print 1 "Or try running ${libIGCM}/clean_latestPackperiod.job to clean latest pack period."
661      IGCM_debug_Print 1 "Or use ${libIGCM}/purge_simulation.job to delete the full simulation."
[1280]662      IGCM_debug_Exit
[1220]663    fi
664
665  IGCM_debug_PopStack "IGCM_config_StateCheck"
666}
667
[890]668#===================================
[380]669function IGCM_config_Check
670{
[544]671  IGCM_debug_PushStack "IGCM_config_Check"
[380]672
[544]673  # If one of the following modulo is not zero :
674  # we will issue an error then explain and exit in
675  # AA_job IGCM_debug_Verif_Exit call before binary submission
[380]676
[544]677  echo
678  IGCM_debug_Print 1 "IGCM_config_Check"
679  echo
680
681  typeset i
682
[554]683  # Check RebuildFrequency against key frequencies : PeriodLength ; PackFrequency ; TimeSeriesFrequency ; SeasonalFrequency
[545]684  if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
[544]685    AsynchronousRebuild=true
686    IGCM_debug_Print 1 "Asynchronous rebuild has been activated."
[380]687    echo
[544]688    # modulo (RebuildFrequency and PeriodLength/TimeSeriesFrequency/SeasonalFrequency) must be zero
689    IGCM_debug_Print 1 "Check coherence between RebuildFrequency and PeriodLength"
690    IGCM_post_CheckModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength
[554]691    IGCM_debug_Print 1 "Check coherence between PackFrequency and RebuildFrequency"
692    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_Post_RebuildFrequency
[544]693    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and RebuildFrequency"
694    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_RebuildFrequency
695    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and RebuildFrequency"
696    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_RebuildFrequency
697  else
698    AsynchronousRebuild=false
699    IGCM_debug_Print 1 "Asynchronous rebuild has not been activated"
700    IGCM_debug_Print 1 "Proceed with standard post-treatment pathway"
[380]701    echo
[554]702    #modulo (PeriodLength and TimeSeriesFrequency/SeasonalFrequency) must be zero
[544]703    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PeriodLength"
704    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_UserChoices_PeriodLength
705    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PeriodLength"
706    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency   config_UserChoices_PeriodLength
707  fi
[380]708
[619]709  # Check PackFrequency against other key frequencies
[554]710  # Modulo (PackFrequency and TimeSeriesFrequency/SeasonalFrequency and PeriodLenght) must be zero
711  if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
712    Pack=true
713    #
714    IGCM_debug_Print 1 "Check coherence between PackFrequency and PeriodLength"
715    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_UserChoices_PeriodLength
716    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PackFrequency"
717    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_PackFrequency
718    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PackFrequency"
719    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_PackFrequency
720  else
721    Pack=false
722  fi
[1603]723  # Loop over components
724  for comp in ${config_ListOfComponents[*]} ; do
725   
726    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
727    eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1
728    card=${SUBMIT_DIR}/COMP/${compname}.card
729    IGCM_card_DefineArrayFromOption ${card} OutputFiles List
730    ListFilesName=${compname}_OutputFiles_List
731    eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1
732    if [ X${FileName0} != X${NULL_STR} ] ; then
733        eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1
734                   
735        (( i=0 ))
736        until [ $i -ge $NbFiles ]; do
737            (( i_ = i+3 ))
738            eval Testvar_=\${${ListFilesName}[$i_]} > /dev/null 2>&1
739            eval Testvar=${Testvar_}
740            if [[ ${Testvar} =~ [0-9][DMY]$ ]] ; then
741                IGCM_debug_Print 1 "Check coherence between PackFrequency and specific pack frequencies"
742                DaysTemp1=$( IGCM_date_DaysInPreviousPeriod ${DateBegin} ${Testvar} )
743                DaysTemp2=$( IGCM_date_DaysInPreviousPeriod ${DateBegin} ${config_Post_PackFrequency} )
744                if [ ${DaysTemp2} -lt ${DaysTemp1} ] ; then
745                    IGCM_debug_Print 1 "PackFrequency in config.card is smaller than the specific pack frequency"
746                    IGCM_debug_Print 1 "we found in ${compname}.card"
747                    IGCM_debug_Exit "ERROR You have to modify the PackFrequency in config.card to be always greater or equal to specific pack frequencies defined in comp.card"
748                    IGCM_debug_Verif_Exit
749                fi
750                ((i = i+4))
751            else
752                ((i = i+3))
753            fi
754        done
755    fi
756  done
[554]757
[890]758  # modulo (TimeSeriesFrequency and all Chunck2D) must be zero
[544]759  NbJob=${#CHUNCK2D_SIZE[@]}
760  i=0
761  until [ $i -ge $NbJob ]; do
762    value=${CHUNCK2D_SIZE[${i}]}
[1214]763    IGCM_debug_Print 1 "Check coherence between ${CHUNCK2D_NAME[${i}]} Chunck2D frequency and TimeSeriesFrequency"
[544]764    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
[619]765    case ${value} in
766    *Y|*y) ;;
[786]767    *)
768      IGCM_debug_Print 1 "All ChunckJob2D frequency must be expressed in year *Y|*y in comp.card"
[544]769      IGCM_debug_Exit "This will stop the job" ;;
770    esac
771    (( i=i+1 ))
772  done
[387]773
[890]774  # modulo (TimeSeriesFrequency and all Chunck3D) must be zero
[544]775  NbJob=${#CHUNCK3D_SIZE[@]}
776  i=0
777  until [ $i -ge $NbJob ]; do
778    value=${CHUNCK3D_SIZE[${i}]}
[1214]779    IGCM_debug_Print 1 "Check coherence between ${CHUNCK3D_NAME[${i}]} Chunck3D frequency and TimeSeriesFrequency"
[544]780    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
[619]781    case ${value} in
782    *Y|*y) ;;
[786]783    *)
784      IGCM_debug_Print 1 "All ChunckJob3D frequency must be expressed in year *Y|*y in comp.card"
[544]785      IGCM_debug_Exit "This will stop the job" ;;
786    esac
787    (( i=i+1 ))
788  done
[380]789
[890]790  # check to be sure there is enough space on temporary filesystems to run
[731]791  echo
[651]792  IGCM_debug_Print 1 "Check if there is enough space on temporary filesystem"
793  IGCM_sys_check_quota
794
[933]795  # check to be sure that RUN_DIR_PATH, that will be removed is not pointing to an important directory
796  echo
797  IGCM_debug_Print 1 "Check where RUN_DIR_PATH variable is pointing to"
798  IGCM_sys_check_path
799
800
[544]801  IGCM_debug_PopStack "IGCM_config_Check"
[118]802}
803
804#===================================
[1242]805function IGCM_config_ConfigureExecution
[1230]806{
[1242]807  IGCM_debug_PushStack " IGCM_config_ConfigureExecution"
[1230]808
[1250]809  #echo
[1242]810  IGCM_debug_Print 1 " IGCM_config_ConfigureExecution"
[1250]811  #echo
[1230]812
[1242]813  typeset ExeNameIn ExeNameFirst CompNameFirst configCardPath comp i
[1230]814  typeset tempvar tempvarMPI tempvarNOD NbElts NbExec
815
[1242]816  # config.card path
817  configCardPath=$1
818
[1235]819  coreNumber=0
820  mpiTasks=0
[1238]821  openMPthreads=0
[1230]822  NbExec=0
823
824  OK_PARA_MPI=false
825  OK_PARA_OMP=false
826  OK_PARA_NOD=false
827  OK_PARA_MPMD=false
828
829  for comp in ${config_ListOfComponents[*]} ; do
830
[1242]831    # Manage component executable
832    IGCM_card_DefineArrayFromOption ${configCardPath} Executable ${comp}
833
[1230]834    eval ExeNameIn=\${config_Executable_${comp}[0]}
835
836    # NO order in config.card for parallelized values !
837    # just use suffix : MPI , OMP and NOD (for number of NODes.)
838
839    # NOD is the number of NODes allocated
840    eval ${comp}_PROC_NOD=0
841
842    # MPI is the number of MPI processus per nodes
843    eval ${comp}_PROC_MPI=0
844
845    # OMP is the number of OpenMP threads per MPI processus
846    eval ${comp}_PROC_OMP=0
847
[1528]848    # DEP is the factor to increase the number of cores per process
849    eval ${comp}_PROC_DEP=0
850
851    # DEDICATED is the flag to activate the use of dedicated node for XIOS server only
852    eval ${comp}_OK_DEDICATED=0
853
[1230]854    # Only if we really have an executable for the component :
855    if ( [ "X${ExeNameIn}" != X\"\" ] && [ "X${ExeNameIn}" != "Xinca.dat" ] ) ; then
856
[1250]857      IGCM_debug_Print 1 ${comp}
858
[1230]859      # Keep the first executable found and the first CompName
[1486]860      eval ExeNameFirst=${ExeNameIn}
[1230]861      CompNameFirst=${comp}
862
863      # Are we a second executable?
864      (( NbExec = NbExec + 1 ))
865
866      # set 1 MPI task, 1 OpenMP thread and 1 node as default
867      eval ${comp}_PROC_MPI=1
868      eval ${comp}_PROC_OMP=1
869      eval ${comp}_PROC_NOD=1
[1528]870      eval ${comp}_PROC_DEP=1
[1230]871
872      eval NbElts=\${#config_Executable_${comp}[@]}
[1252]873      if [ ${NbElts} -gt 2 ] ; then
[1230]874        #
875        # CURRENT METHOD TO SPECIFY MPI AND OMP RESSOURCES
876        #
877        i=2
878        while [ ${i} -lt ${NbElts} ] ; do
879          eval tempvar=\${config_Executable_${comp}[${i}]}
880          IGCM_debug_Print 2 ${tempvar}
881
882          if [ X${tempvar} = X ] ; then
883            IGCM_debug_Print 2 "Error reading MPI/OMP parameters !!!"
884            IGCM_debug_Exit "Check your config.card. Exit now"
885            IGCM_debug_Verif_Exit
886          fi
887
888          case ${tempvar} in
889          *[mM][pP][iI]*)
890            # Read MPI parameter for composante
891            eval ${comp}_PROC_MPI=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/MPI//" )
892            OK_PARA_MPI=true;;
893          *[oO][mM][pP]*)
894            # Read OMP parameter for composante
895            eval ${comp}_PROC_OMP=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/OMP//" )
896            ;;
897          *[nN][oO][dD]*)
898            # Read NOD (NumBer of Nodes) parameter for composante
899            eval ${comp}_PROC_NOD=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/NOD//" )
900            OK_PARA_NOD=true
901            OK_PARA_MPI=true
902            ;;
[1528]903            *[dD][eE][pP]*)
904            # Read DEP parameter for composante
905            eval ${comp}_PROC_DEP=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/DEP//" )
906            ;;
907            *[dD][eE][dD][iI][cC][aA][tT][eE][dD]*)
908            # Read DEDICATED parameter for composante
909            eval ${comp}_OK_DEDICATED=1
[1230]910          esac
911          (( i = i + 1 ))
912        done
913      else
914        #
[1250]915        # BACKWARD COMPATIBILITY NOT SUPPORTED ANYMORE
[1230]916        #
[1253]917        IGCM_debug_Exit "You are using a deprecated ressources specification mechanism in your config.card"
918        IGCM_debug_Exit "Please check : https://forge.ipsl.jussieu.fr/igcmg_doc/wiki/DocEsetup#ThesectionExecutable"
[1270]919        IGCM_debug_Exit "Please modify ${configCardPath}"
[1252]920        exit
[1230]921      fi
[1426]922      if [ ${comp}_PROC_NOD -gt 1 ] ; then
923            if ( [ ${comp}_PROC_MPI -gt 1 ] && [ ${comp}_PROC_OMP -gt 1 ] ) ; then
924              IGCM_debug_Print 2 "Error using MPI/OMP/NOD parameters !!!"
925              IGCM_debug_Exit "It is not allowed to use MPI and OMP and NOD parameters for the same component"
926              IGCM_debug_Exit "Check your config.card. Exit now"
927              IGCM_debug_Verif_Exit
928            fi
929            if [ "${comp}" != "IOS" ] ; then
930              IGCM_debug_Print 2 "Error using NOD parameter !!!"
931              IGCM_debug_Exit "NOD parameter is only available for IOS component "
932              IGCM_debug_Exit "Check your config.card. Exit now"
933              IGCM_debug_Verif_Exit
934            fi
935      fi
[1528]936      if ( [ ${comp}_OK_DEDICATED -eq 1 ] && [ "${comp}" != "IOS" ] ) ; then
937            IGCM_debug_Print 2 "Error using DEDICATED parameter !!!"
938            IGCM_debug_Exit "DEDICATED parameter is only available for IOS component "
939            IGCM_debug_Exit "Check your config.card. Exit now"
940            IGCM_debug_Verif_Exit
941      fi
[1426]942
[1230]943      eval tempvarMPI=\${${comp}_PROC_MPI}
944      eval tempvarNOD=\${${comp}_PROC_NOD}
945      eval tempvarOMP=\${${comp}_PROC_OMP}
[1528]946      eval tempvarDEP=\${${comp}_PROC_DEP}
[1230]947
948      # set OMP mode if more than 1 OMP thread.
949      [ ${tempvarOMP} -ge 2 ] && OK_PARA_OMP=true
950
[1238]951      # Number of OMP threads
952      [ ${openMPthreads} -lt ${tempvarOMP} ] && openMPthreads=${tempvarOMP}
953
[1235]954      # SUM UP NUMBER OF CORES
[1426]955      if [ ${comp}_PROC_NOD -gt 1 ] ; then 
956          (( coreNumber = coreNumber + tempvarNOD * NB_CORE_PER_NODE ))
957      else
[1528]958          (( coreNumber = coreNumber + tempvarMPI * tempvarNOD * tempvarOMP * tempvarDEP ))
[1426]959      fi
[1235]960      # SUM UP NUMBER OF MPI TASKS
961      (( mpiTasks = mpiTasks + tempvarMPI * tempvarNOD ))
[1230]962    fi
963  done
964
[1248]965  # MANDATORY FOR THE OPA9.DRIVER. USED TO EDIT OPA NAMELIST
966  # WE SHOULD PLANIFY NUM_PROC_??? DEPRECATION
967  NUM_PROC_CPL=${CPL_PROC_MPI}
968  NUM_PROC_OCE=${OCE_PROC_MPI}
969  NUM_PROC_ATM=${ATM_PROC_MPI}
970
[1230]971  # set MPMD mode if more than 2 executable names.
972  [ ${NbExec} -ge 2 ] && OK_PARA_MPMD=true 
973
974  # Define the execution type we are running in
[1255]975  if ( ${OK_PARA_MPMD} ) ; then
976    if ( ${OK_PARA_MPI} ) ; then
[1238]977      # MPMD always implies MPI
[1230]978      executionType=1
979    fi
[1255]980    if ( ${OK_PARA_OMP} ) ; then
[1238]981      # MPMD + MPI/OMP
[1230]982      executionType=2
983    fi
984  else
[1255]985    if ( ( ${OK_PARA_MPI} ) && ( ${OK_PARA_OMP} ) ) ; then
[1238]986      # SPMD + MPI/OMP
[1230]987      executionType=3
[1255]988    elif ( ( ${OK_PARA_MPI} ) && ( ! ${OK_PARA_OMP} ) ) ; then
[1230]989      # SPMD + MPI only
990      executionType=4
[1255]991    elif ( ( ! ${OK_PARA_MPI} ) && ( ${OK_PARA_OMP} ) ) ; then
[1230]992      # SPMD + OMP only
993      executionType=5
[1255]994    elif ( ( ! ${OK_PARA_MPI} ) && ( ! ${OK_PARA_OMP} ) ) ; then
[1230]995      # SEQUENTIAL THEN
996      executionType=6
[1235]997      coreNumber=1
[1230]998    fi
999  fi
1000
[1235]1001  IGCM_debug_Print 1 "MPI/OMP treatment coreNumber = ${coreNumber}"
[1242]1002  IGCM_debug_Print 1 "MPI/OMP treatment mpiTasks = ${mpiTasks}"
1003  IGCM_debug_Print 1 "MPI/OMP treatment openMPthreads = ${openMPthreads}"
1004  IGCM_debug_Print 1 "MPI/OMP treatment executionType = ${executionType}"
[1230]1005
[1242]1006  IGCM_debug_PopStack "IGCM_config_ConfigureExecution"
[1230]1007}
1008
1009#===================================
[2]1010function IGCM_config_PeriodStart
1011{
[544]1012  IGCM_debug_PushStack "IGCM_config_PeriodStart"
[2]1013
[544]1014  echo
1015  IGCM_debug_Print 1 "IGCM_config_PeriodStart"
1016  echo
[2]1017
[544]1018  if ( ${FirstInitialize} ) ; then
1019    #================================================#
1020    #         Initialize date/period information     #
1021    #================================================#
[2]1022
[890]1023    IGCM_date_GetYearMonthDay ${DateBegin} year month day
1024    IGCM_config_DaysInPeriodLength
[2]1025
[939]1026    PeriodDateBegin=${DateBegin}
[544]1027    PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) )
[939]1028    CumulPeriod=1
[2]1029
[544]1030    #=================================================#
1031    #              Write updated run.card             #
1032    #=================================================#
[2]1033
[544]1034    #Correct run.card Configuration for this period
1035    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
1036    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
1037    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
1038    if [ X$( grep "SubmitPath" ${SUBMIT_DIR}/run.card ) != X ] ; then
1039      IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration SubmitPath ${SUBMIT_DIR}
1040    fi
[427]1041
[544]1042    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
[619]1043
[544]1044  else
1045    #================================================#
1046    #         The file run.card allready exist       #
1047    #================================================#
[2]1048
[1220]1049    # Test state of run in run.card. Will schedule an exit if another process setted it to "Fatal"
1050    IGCM_config_StateCheck
1051    # And EXIT if not OK
1052    IGCM_debug_Verif_Exit
[2]1053
[544]1054    #===================================#
[786]1055    #        Read updated run.card      #
[544]1056    #===================================#
[2]1057
[544]1058    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
1059    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
1060    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
[2]1061
[544]1062    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
1063    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
[939]1064    CumulPeriod=${run_Configuration_CumulPeriod}
[2]1065
[1028]1066    LastPeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate $( IGCM_date_ConvertFormatToGregorian ${PeriodDateBegin} ) -1 )
[471]1067
[544]1068    if [ ${Period} = 1 ]; then
[910]1069      # save last Job output and current run.card
1070      typeset Potential
1071      IGCM_sys_Cd ${SUBMIT_DIR}
1072      #
1073      IGCM_debug_Print 2 "Save previous ksh job output"
1074      for Potential in $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.[0-9][0-9][0-9][0-9][0-9][0-9] ) ; do
1075        if [ X${Pack} = Xtrue ] ; then
[1397]1076          ( IGCM_sys_TestFileBuffer  ${R_BUF_KSH}/${Potential} ) || IGCM_sys_Cp ${Potential} ${R_BUF_KSH}/${Potential}.$$
[910]1077        else
[1410]1078          ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${Potential} ) || IGCM_sys_Put_Out ${Potential} ${R_OUT_KSH}/${Potential}.$$ NOMOVE
1079          IGCM_debug_Print 1 "Save of previous ksh job output is not done for Pack=false"
[910]1080        fi
1081      done
[1407]1082
[910]1083      #
1084      IGCM_debug_Print 2 "Save current run.card"
[544]1085      IGCM_card_CheckConflict run.card
[1392]1086
[634]1087      if [ X${Pack} = Xtrue ] ; then
[1397]1088        IGCM_sys_Cp ${SUBMIT_DIR}/run.card ${R_BUF_KSH}/run.card
[634]1089      else
[1410]1090        IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/run.card NOMOVE
1091        IGCM_debug_Print 1 "Save of run.card is not done for Pack=false"
[634]1092      fi
[910]1093      #
[544]1094      IGCM_sys_Cd ${RUN_DIR}
1095    else
1096      unset FileToBeDeleted
1097    fi
[2]1098
[892]1099    # Determine number of day(s) in PeriodLength
[544]1100    IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
[890]1101    IGCM_config_DaysInPeriodLength
[2]1102
[892]1103    # Check coherency between (PeriodDateBegin, PeriodDateEnd) and (DateBegin, CumulPeriod, PeriodLength)
1104    IGCM_config_DateCoherency
1105    # And EXIT if not OK
1106    IGCM_debug_Verif_Exit
1107
[1220]1108    # Test state of run in run.card. Will schedule an exit if another process setted it to "Fatal"
1109    IGCM_config_StateCheck
1110    # And EXIT if not OK
1111    IGCM_debug_Verif_Exit
1112
1113    # We can say we are "Running" now.
[544]1114    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
[890]1115  fi
[2]1116
[544]1117  # BEGIN: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
1118  # Compute year_m1 and year_p1 (year minus 1Y and year plus 1Y)
1119  year_m1=$(( year - 1 ))
[619]1120  year_p1=$(( year + 1 ))
[544]1121  # Compute month_m1 (month minus 1M)
1122  # Compute yyyymm_m1 (yyyymm minus 1M)
[829]1123  month_m1=$(( 10#${month} - 1 ))
[544]1124  if [ ${month_m1} = 0 ]; then
1125    month_m1=12
1126    yyyymm_m1=${year_m1}12
1127  elif [ ${month_m1} -le 9 ]; then
1128    month_m1=0${month_m1}
1129    yyyymm_m1=${year}${month_m1}
1130  else
1131    yyyymm_m1=${year}${month_m1}
1132  fi
1133  # Compute month_p1 (month plus 1M)
1134  # Compute yyyymm_p1 (yyyymm plus 1M)
[829]1135  month_p1=$(( 10#${month} + 1 ))
[544]1136  if [ ${month_p1} = 13 ]; then
1137    month_p1=01
1138    yyyymm_p1=${year_p1}01
1139  elif [ ${month_p1} -le 9 ]; then
1140    month_p1=0${month_p1}
1141    yyyymm_p1=${year}${month_p1}
1142  else
1143    yyyymm_p1=${year}${month_p1}
1144  fi
[522]1145
[1546]1146
[799]1147  #===================================================================#
1148  # Calculate CyclicYear to be used for looping over a given forcing  #
1149  # period. Add CyclicBegin and CyclicEnd in config.card UserChoices. #
1150  #===================================================================#
1151
1152  # To use the variable CyclicYear, one must add in config.card CyclicBegin and CyclicEnd.
1153  # CyclicBegin is the first year in the cycle. CyclicEnd is the last year included in the cycle.
1154  if ( [ ! X${config_UserChoices_CyclicBegin} = X ] && [ ! X${config_UserChoices_CyclicEnd} = X ] ) ; then
1155    CycleNb=$(( ${config_UserChoices_CyclicEnd} - ${config_UserChoices_CyclicBegin} + 1 ))
[1546]1156    #CyclicYear_p1=  #NOTDEFINED
1157 
[819]1158    # For current year
1159    yeartmp=$year
1160    diffy=$(( $yeartmp - ${config_UserChoices_CyclicBegin} ))
1161    while [ $diffy -lt 0 ] ; do
1162      yeartmp=$(( ${yeartmp} + ${CycleNb} ))
1163      diffy=$(( $yeartmp - ${config_UserChoices_CyclicBegin} ))
1164    done
1165    CyclicYear=$(( ( ${diffy} % ${CycleNb} ) + ${config_UserChoices_CyclicBegin} ))
1166
1167    # For next coming year
[1546]1168    CyclicYear_p1=$(( CyclicYear + 1 ))
[819]1169
[1546]1170    # For previous year
1171    CyclicYear_m1=$(( CyclicYear - 1 ))
1172
1173    IGCM_debug_Print 1 "CyclicYear   = ${CyclicYear}, current year=$year"
1174    IGCM_debug_Print 1 "CyclicYear_p1 = ${CyclicYear_p1}, CyclicYear_m1 = ${CyclicYear_m1} "
[799]1175  else
1176    CyclicYear="ERROR_CyclicYear_Variable_Not_Defined"
[812]1177    CyclicYear_p1="ERROR_CyclicYear_p1_Variable_Not_Defined"
[819]1178    IGCM_debug_Print 1 "CyclicYear wont be use without adding CyclicBegin and CyclicEnd in config.card"
[799]1179  fi
1180
[544]1181  # END: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
[522]1182
[544]1183  #===================================================================#
1184  # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
[786]1185  #             But available to any son functions                    #
[544]1186  #===================================================================#
[2]1187
[544]1188  # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !)
1189  (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 ))
[2]1190
[544]1191  # Debug Print :
[731]1192  echo
[544]1193  IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution"
1194  IGCM_debug_Print 1 "Year of simulation      : ${year}"
1195  IGCM_debug_Print 1 "Month of simulation     : ${month}"
1196  IGCM_debug_Print 1 "PeriodLengthInDays      : ${PeriodLengthInDays}"
1197  IGCM_debug_Print 1 "PeriodDateBegin         : ${PeriodDateBegin}"
1198  IGCM_debug_Print 1 "PeriodDateEnd           : ${PeriodDateEnd}"
1199  IGCM_debug_Print 1 "SimulationLengthInDays  : ${SimulationLengthInDays}"
1200  IGCM_debug_Print 1 "ExperienceLengthInDays  : ${ExperienceLengthInDays}"
[2]1201
[544]1202  #================================================================#
1203  #         Prepare variables available for comp_finalyze          #
1204  #================================================================#
[2]1205
[544]1206  # Period for save files
[939]1207  DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd}
[2]1208
[544]1209  # Prefix for save files of this period
[939]1210  PREFIX=${config_UserChoices_JobName}_${DatesPeriod}
[2]1211
[544]1212  # List of files that will be deleted in RUN_DIR after run
1213  [ -f stack ] && FileToBeDeleted[0]="stack"
[2]1214
[544]1215  # Test if the same run as already been saved :
1216  if [ X${JobType} = XRUN ] ; then
1217    if [ ${DRYRUN} -le 0 ] ; then
1218      if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then
[1372]1219        IGCM_debug_Exit "IGCM_config_PeriodStart" "You are currently re-running an old job."
1220        IGCM_debug_Print 1 "Because of readonly permissions, you can't re-run a job when saved files"
[619]1221        IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or "
[1372]1222        IGCM_debug_Print 1 " the whole ${R_SAVE} tree. See different clean_*.job in ${libIGCM} directory."
[619]1223        IGCM_debug_Print 1 " This exit has been initiated because at least ${R_BUF_KSH}/${PREFIX}_${Exe_Output} exists."
1224        IGCM_debug_Verif_Exit
[544]1225      fi
[2]1226    fi
[544]1227  else
1228    if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then
1229      IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. Allowed in DEBUG or DEV mode."
1230    fi
1231  fi
[128]1232
[939]1233  #================================================================#
1234  #       Prepare variables available for binary execution         #
[1009]1235  #       Call function for creation of run script                 #
1236  #       Only done once per job                                   #
[939]1237  #================================================================#
[616]1238
[1009]1239  if [ ${Period} -eq 1 ]; then
[1230]1240    # Define the execution context (MPMD, SPMD, MPI/OMP ...)
[1242]1241    IGCM_config_ConfigureExecution ${SUBMIT_DIR}/config.card
[1230]1242    # Create the execution script for the current context
[1009]1243    IGCM_sys_build_execution_scripts
1244  fi
[616]1245
[544]1246  ExecutionFail=false
[473]1247
[1332]1248  # Update the rabbitMQ queue
1249  IGCM_debug_BigBro_Update
1250
[544]1251  IGCM_debug_PopStack "IGCM_config_PeriodStart"
[2]1252}
1253
1254#===================================
[523]1255function IGCM_config_SaveSourceModifications
1256{
[544]1257  IGCM_debug_PushStack "IGCM_config_SaveSourceModifications"
[523]1258
[544]1259  typeset ExeOutDateMax listVarEnv
1260  ExeOutDateMax=$1
[523]1261
[544]1262  listVarEnv="ExeOutDateMax,R_OUT_EXE,PREFIX,SUBMIT_DIR"
1263  IGCM_sys_RshMaster "\
[545]1264    . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh; \
[544]1265    export ExeOutDateMax=${ExeOutDateMax};\
[545]1266    export R_OUT_EXE=${R_OUT_EXE};\
1267    export PREFIX=${PREFIX};\
1268    export SUBMIT_DIR=${SUBMIT_DIR};\
1269    export listVarEnv=${listVarEnv};\
1270    Script_Output=out_SaveSourceModifications;\
1271    IGCM_sys_Qsub ${libIGCM}/SaveSourceModifications.job ${ExeOutDateMax} ${R_OUT_EXE} ${PREFIX} ${SUBMIT_DIR}"
[523]1272
[544]1273  IGCM_debug_PopStack "IGCM_config_SaveSourceModifications"
[523]1274}
1275
1276#===================================
[2]1277function IGCM_config_PeriodEnd
1278{
[544]1279  IGCM_debug_PushStack "IGCM_config_PeriodEnd"
[2]1280
[544]1281  echo
1282  IGCM_debug_Print 1 "IGCM_config_PeriodEnd"
1283  echo
[2]1284
[622]1285  if [ ${DRYRUN} -le 1 ] ; then
[457]1286
[622]1287    IGCM_debug_Print 1 "Check components binary : size and creation date"
[2]1288
[622]1289    typeset LS_comp LS_bin ExeDate ExeCpuLog NextExeSize LastCompExeSize
1290    typeset comp i
1291    typeset ExeNameIn ExeNameOut UpdateExe ExeSecDateMax
[2]1292
[622]1293    #==================================#
1294    #        Get last Exe Size         #
1295    #==================================#
[2]1296
[622]1297    (( i=0 ))
1298    if ( ${FirstInitialize} ) ; then
1299      run_Log_LastExeSize=""
1300      for comp in ${config_ListOfComponents[*]} ; do
1301        run_Log_LastExeSize[$i]=0
1302        (( i=i+1 ))
1303      done
1304    else
1305      IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize
1306    fi
1307    #==================================#
1308    #         And Build ExeDate        #
1309    #==================================#
[2]1310
[622]1311    # ExeDate = ATM_Jun_12_09:34-SRF_Jun_12_09:34-OCE_Jun_12_09:34-ICE_Jun_12_09:34-CPL_Jun_12_09:33
1312    # Would be nice to have next line but no way to format ls output (need to ls -l --time-style "+%Y-%m-%dT%H:%M")
1313    # ExeDate = ATM_2009-06-12T09:34+SRF_2009-06-12T09:34+OCE_2009-06-12T09:34+ICE_2009-06-12T09:34+CPL_2009-06-12T09:34
1314    ExeDate=""
1315    NextExeSize="( "
1316    (( i=0 ))
1317    UpdateExe=false
1318    (( ExeSecDateMax = 0 ))
1319    for comp in ${config_ListOfComponents[*]} ; do
[2]1320
[622]1321      IGCM_debug_Print 3 ${comp}
[2]1322
[622]1323      eval ExeNameIn=\${config_Executable_${comp}[0]}
1324      eval ExeNameOut=\${config_Executable_${comp}[1]}
1325      # Only if we really have an executable for the component :
1326      if [ X${ExeNameIn} = X\"\" ] ; then
1327        # If there is no exe file for this component
1328        (( ExeSize=0 ))
[619]1329      else
[1486]1330        eval ExeNameIn=${ExeNameIn}
[939]1331        LS_bin=${R_EXE}/${ExeNameIn}
[622]1332        IGCM_sys_FileSize ${LS_bin} ExeSize
1333
1334        set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} )
1335        if [ X${ExeDate} = X ] ; then
1336          # First component exe date
1337          ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]}
1338        else
1339          ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]}
1340        fi
1341        ExeDate=${ExeDate}_${LS_comp[7]}
[619]1342      fi
[2]1343
[622]1344      if [ ${i} -eq 0 ] ; then
1345        # First component
1346        NextExeSize="( "${ExeSize}
[619]1347      else
[622]1348        NextExeSize=${NextExeSize}", "${ExeSize}
[619]1349      fi
[939]1350      LastCompExeSize=${run_Log_LastExeSize[$i]}
[622]1351      (( i=i+1 ))
[523]1352
[622]1353      if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then
1354        if ( ${FirstInitialize} ) ; then
1355          IGCM_debug_Print 1 "Save first ${ExeNameIn} in ${R_OUT_EXE} !"
1356        else
1357          IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !"
1358          IGCM_debug_Print 1 "Save latest ${ExeNameIn} in ${R_OUT_EXE} !"
[939]1359          FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut}
[622]1360        fi
[939]1361        IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw
[622]1362        UpdateExe=true
1363
[691]1364        # SD : switch off for now
1365        #IGCM_sys_GetDate_FichWork ${LS_bin} ExeSecDate
1366        #if [ $ExeSecDateMax -lt $ExeSecDate ] ; then
1367        #  ExeSecDateMax=$ExeSecDate
1368        #fi
[619]1369      fi
[622]1370    done
[2]1371
[622]1372    # SD : switch off for now
1373    #if ( ${UpdateExe} ) ; then
1374    #  echo "Launch SaveSourceModifications."
1375    #  IGCM_config_SaveSourceModifications ${ExeSecDateMax}
1376    #fi
[523]1377
[622]1378    NextExeSize=${NextExeSize}" )"
1379    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}"
[457]1380
[622]1381    if [ ${DRYRUN} -le 1 ] ; then
1382      tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt
1383      ExeCpuLog=$( gawk -f ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt )
1384      RET=$?
1385      if [ $RET -eq 0 ] ; then
1386        # ExeCpuLog variable contents 5 fields
1387        echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" |   \
1388          gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \
[544]1389            $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card
[622]1390      fi
[939]1391      FileToBeDeleted[${#FileToBeDeleted[@]}]=${Exe_Output}_tail.txt
[619]1392    fi
[622]1393
[619]1394  fi
[2]1395
[1041]1396  #==================================#
1397  #         Save Job output          #
1398  #==================================#
1399  if [ X${Pack} = Xtrue ] ; then
1400    IGCM_sys_PutBuffer_Out ${Exe_Output} ${R_BUF_KSH}/${PREFIX}_${Exe_Output}
1401  else
1402    IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output}
1403  fi
1404  FileToBeDeleted[${#FileToBeDeleted[@]}]=${Exe_Output}
1405
[622]1406  # All was right ? no ? then we stop.
[619]1407  IGCM_debug_Verif_Exit
[2]1408
[622]1409  # If all was OK, we can delete all files not necessary for next Job
[619]1410  echo
1411  IGCM_debug_Print 1 "Files that will be deleted before next period-run : "
[2]1412
[619]1413  if [ ${DRYRUN} -le 2 ] ; then
1414    for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done
1415  else
1416    echo ${FileToBeDeleted[@]}
1417  fi
[2]1418
[922]1419  # Send some accounting element to the user if CumulPeriod=3
1420  if [ ${CumulPeriod} -eq 3 ] ; then
1421    echo
1422    RealCpuTime=$( echo ${ExeCpuLog} | gawk '{print $3}' )
1423
[1235]1424    consumeHoursPerPeriod=$( echo "scale=6;${RealCpuTime}*${coreNumber}/3600" | bc )
[922]1425
1426    consumeHoursPerWholeSimulation=$( echo "scale=6;${consumeHoursPerPeriod}/${PeriodLengthInDays}*${ExperienceLengthInDays}" | bc )
1427
[1630]1428    # Only continue if jobWarnaingDelay has been set in libIGCM_sys
1429    if [ ! X${jobWarningDelay} = X ] ; then
1430      recommendedNbPeriodsPerJob=$( echo "scale=6;${jobWarningDelay}/3600/${consumeHoursPerPeriod}*${coreNumber}" | bc )
1431      IGCM_debug_Print 1 "Send email containing some accounting information : "
1432      IGCM_sys_SendMail Accounting
1433    fi
[922]1434  fi
1435
[622]1436  #=================================================#
1437  #         Modification of libIGCM behaviour       #
1438  #=================================================#
[119]1439
[622]1440  # To use this function, one must copy libIGCM.card from ${libIGCM} directory
1441  # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card,
1442  # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop.
[619]1443  if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then
1444    echo
1445    echo "########################################################################"
1446    echo "!!!                 Modification of libIGCM behaviour                !!!"
1447    echo
[119]1448
[619]1449    IGCM_debug_Print 1 "DefineArrayFromOption  : libIGCM_UserChanges in libIGCM.card"
1450    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges
1451    IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]}
[119]1452
[622]1453    # Special treatments for libIGCM internals
[619]1454    for option in ${libIGCM_UserChanges[*]} ; do
1455      IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option}
[119]1456
[619]1457      echo "We will change : ${option}."
1458      eval echo "Previous value : " \${${option}}
1459      eval echo "Change to : " \${libIGCM_UserChanges_${option}}
[119]1460
[619]1461      eval ${option}=\${libIGCM_UserChanges_${option}}
[119]1462
[619]1463      case ${option} in
1464      config_UserChoices_DateEnd)
1465        IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd
1466        DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
1467
[622]1468        # Period Length In Days between DateBegin and DateEnd
[619]1469        (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
1470        if [ ${ExperienceLengthInDays} -lt 0 ] ; then
1471          IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that."
[939]1472          IGCM_debug_Exit "IGCM_PeriodEnd have wrong dates."
[619]1473          IGCM_debug_Verif_Exit
1474        fi
1475        ;;
1476      config_UserChoices_PeriodLength)
1477        IGCM_debug_Print 1  "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}"
1478        ;;
[1607]1479      NbPeriodsPerJob)
1480        IGCM_debug_Print 1  "Loop in main Job with ${NbPeriodsPerJob} period(s)"
[619]1481        ;;
1482      config_Post_RebuildFrequency)
1483        IGCM_debug_Print 1  "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure"
1484        IGCM_post_Configure
1485        ;;
1486      config_Post_TimeSeriesFrequency)
[653]1487        IGCM_debug_Print 1  "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Configure"
[619]1488        IGCM_post_Configure
1489        ;;
1490      config_Post_SeasonalFrequency)
[653]1491        IGCM_debug_Print 1  "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Configure"
[619]1492        IGCM_post_Configure
1493        ;;
1494      esac
1495    done
[119]1496
[619]1497    echo
1498    echo "########################################################################"
1499    echo
[544]1500  fi
[119]1501
[544]1502  #=================================================#
1503  #         Determine next computed period          #
1504  #=================================================#
[2]1505
[544]1506  PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 )
1507  IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
1508  year_m1=$(( year - 1 ))
1509  year_p1=$(( year + 1 ))
[890]1510  IGCM_config_DaysInPeriodLength
[544]1511  PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) )
[2]1512
[544]1513  # Debug Print :
1514  echo
1515  IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution"
1516  IGCM_debug_Print 1 "PeriodDateBegin       : ${PeriodDateBegin}"
1517  IGCM_debug_Print 1 "PeriodDateEnd         : ${PeriodDateEnd}"
1518  IGCM_debug_Print 1 "PeriodLengthInDays    : ${PeriodLengthInDays}"
[2]1519
[544]1520  PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} )
1521  PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} )
[2]1522
[544]1523  (( CumulPeriod = CumulPeriod + 1 ))
[2]1524
[544]1525  # Debug Print :
1526  echo
1527  IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}"
1528  IGCM_debug_Print 3 "PeriodDateEnd Human   : ${PeriodDateEnd}"
1529  IGCM_debug_Print 3 "CumulPeriod           : ${CumulPeriod}"
[2]1530
[544]1531  #=================================================#
[786]1532  #             Write updated run.card              #
[544]1533  #=================================================#
[2]1534
[544]1535  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
1536  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
1537  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
[2]1538
[544]1539  if ( ${FirstInitialize} ) ; then
1540    # It's no more the first time
1541    FirstInitialize=false
1542  fi
[446]1543
[544]1544  IGCM_debug_PopStack "IGCM_config_PeriodEnd"
[2]1545}
1546
1547#===================================
1548function IGCM_config_Finalize
1549{
[544]1550  IGCM_debug_PushStack "IGCM_config_Finalize"
[2]1551
[544]1552  echo
1553  IGCM_debug_Print 1 "IGCM_config_Finalize"
1554  echo
[2]1555
[1220]1556  # Test state of run in run.card. Will schedule an exit if another process setted it to "Fatal"
1557  IGCM_config_StateCheck
1558
1559  # And EXIT if not OK
1560  IGCM_debug_Verif_Exit
1561
[544]1562  if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then
1563    #==========================#
1564    # End of entire simulation #
1565    #==========================#
[1189]1566    simulationIsOver=true
[2]1567
[544]1568    # Mail notification
1569    IGCM_sys_SendMail
1570    #
1571    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed"
[920]1572    #
[544]1573    IGCM_debug_Print 1 "Normal End of computation."
[873]1574
[544]1575  else
1576    #=================#
1577    # Submit next job #
1578    #=================#
[1189]1579    simulationIsOver=false
[2]1580
[544]1581    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
[2]1582
[544]1583    # Name of next Ksh Script output :
[939]1584    Script_Output=${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )
[2]1585
[544]1586    IGCM_debug_Print 1 "Submit next job"
[922]1587    # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR
1588    IGCM_sys_Cd ${SUBMIT_DIR}
[544]1589    # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName}
1590    ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l )
1591    [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) )
[861]1592    # Submit next job and come back
[544]1593    IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}
[861]1594    IGCM_sys_Cd -
[544]1595  fi
[154]1596
[804]1597  # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_JobName}.${$}
[544]1598  # Only for production run (No clean up in DEV or DEB mode)
1599  # and command sent from .. directory.
1600  IGCM_sys_Cd ..
[943]1601  [ X${JobType} = XRUN ] && IGCM_sys_RmRunDir -rf ${RUN_DIR_PATH}
[544]1602
[1189]1603  # Inform the rabbitMQ queue
1604  IGCM_debug_BigBro_Finalize
[1076]1605
[544]1606  IGCM_debug_PopStack "IGCM_config_Finalize"
[2]1607}
1608
1609#===================================
Note: See TracBrowser for help on using the repository browser.