source: branches/libIGCM_pack/libIGCM_config/libIGCM_config.ksh @ 1588

Last change on this file since 1588 was 1588, checked in by aclsce, 12 months ago

Use of specific pack frequency per file
Changed behaviour in case of pb in pack_output :

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