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

Last change on this file since 1659 was 1659, checked in by aclsce, 3 months ago

Merged with branches/libIGCM_PREPOST to split main Job into 3 Jobs (prerun, compute and postrun) on JeanZay? supercomputer at IDRIS.
Prerun and postrun run on prepost partition to have access to STORE space.

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