source: branches/libIGCM_CESMEP/libIGCM_config/libIGCM_config.ksh @ 1554

Last change on this file since 1554 was 1554, checked in by ssenesi, 20 months ago

Handle C-ESM-EP atlas in post-processing

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