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

Last change on this file since 1572 was 1561, checked in by ssenesi, 21 months ago

Cesmep : fix case AtEnd?

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