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

Last change on this file since 1599 was 1599, checked in by acosce, 8 months ago

Add definition of UserChoices? ConfigType? in libIGCM (to be used by IPSLESM versions)

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