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

Last change on this file since 1536 was 1535, checked in by aclsce, 4 years ago

Added functionality to use "CMIP6 light workflow" by activating dr2xmlIPSL variable in config.card.

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