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

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