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

Last change on this file since 1491 was 1488, checked in by acosce, 5 years ago

Add possibility to define the chemistry configuration in config.card in order to use it in executable name for new way of compilation (v6.2)

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