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

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

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

  • before : if pb, removing initial files expect for PROD simulation.
  • now : if pb, exit of the job (no remonving of inital files) in all cases (DEVT, TEST, PROD).
  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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