source: branches/libIGCM_CESMEP/libIGCM_config/libIGCM_config.ksh

Last change on this file was 1585, checked in by ssenesi, 12 months ago

merge branch libIGCM_CESMEP with trunk that handles RedHat8 on Irene

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