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

Last change on this file since 1559 was 1559, checked in by ssenesi, 22 months ago

Improve handling Cesmep

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