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

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