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

Last change on this file since 1573 was 1565, checked in by nillod, 19 months ago

Adapt ensemble script to 6.2 versions (keep compatibility with 6.1) + add new option to get only one ensemble output directory.

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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