source: trunk/libIGCM/libIGCM_config/libIGCM_config.ksh @ 1604

Last change on this file since 1604 was 1604, checked in by falletti, 6 months ago

C-ESM-EP in libIGCM (for S. Senesi), changes for config.card options: Cesmep option doesn't accept <n>Y anymore ; New option CesmepSlicesDuration?

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