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

Last change on this file since 1633 was 1633, checked in by ssenesi, 3 months ago

Manage CesmpInputFrequency?, plus small fixes

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