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

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