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

Last change on this file since 805 was 805, checked in by sdipsl, 11 years ago
  • Do not create unnecessary directory. see #94
  • 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.6 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  # When Cyclic is active, the simulation MUST start with the same year as the CyclicBegin year.
414  if ( [ ! X${config_UserChoices_CyclicBegin} = X ] && [ ! X${config_UserChoices_CyclicEnd} = X ] ) ; then
415    IGCM_debug_Print 1 "Check coherence between CyclicBegin year and DateBegin year"
416    if [ ${InitYear} -ne ${config_UserChoices_CyclicBegin} ] ; then
417      IGCM_debug_Print 1 "The simulation MUST start with the same year as the CyclicBegin year"
418      IGCM_debug_Exit "Check your CyclicBegin option in config.card UserChoices section"
419    fi
420  fi
421
422  # Check RebuildFrequency against key frequencies : PeriodLength ; PackFrequency ; TimeSeriesFrequency ; SeasonalFrequency
423  if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
424    AsynchronousRebuild=true
425    IGCM_debug_Print 1 "Asynchronous rebuild has been activated."
426    echo
427    # modulo (RebuildFrequency and PeriodLength/TimeSeriesFrequency/SeasonalFrequency) must be zero
428    IGCM_debug_Print 1 "Check coherence between RebuildFrequency and PeriodLength"
429    IGCM_post_CheckModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength
430    IGCM_debug_Print 1 "Check coherence between PackFrequency and RebuildFrequency"
431    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_Post_RebuildFrequency
432    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and RebuildFrequency"
433    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_RebuildFrequency
434    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and RebuildFrequency"
435    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_RebuildFrequency
436  else
437    AsynchronousRebuild=false
438    IGCM_debug_Print 1 "Asynchronous rebuild has not been activated"
439    IGCM_debug_Print 1 "Proceed with standard post-treatment pathway"
440    echo
441    #modulo (PeriodLength and TimeSeriesFrequency/SeasonalFrequency) must be zero
442    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PeriodLength"
443    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_UserChoices_PeriodLength
444    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PeriodLength"
445    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency   config_UserChoices_PeriodLength
446  fi
447
448  # Check PackFrequency against other key frequencies
449  # Modulo (PackFrequency and TimeSeriesFrequency/SeasonalFrequency and PeriodLenght) must be zero
450  if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
451    Pack=true
452    #
453    IGCM_debug_Print 1 "Check coherence between PackFrequency and PeriodLength"
454    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_UserChoices_PeriodLength
455    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PackFrequency"
456    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_PackFrequency
457    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PackFrequency"
458    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_PackFrequency
459  else
460    Pack=false
461  fi
462
463  #modulo (TimeSeriesFrequency and all Chunck2D) must be zero
464  NbJob=${#CHUNCK2D_SIZE[@]}
465  i=0
466  until [ $i -ge $NbJob ]; do
467    value=${CHUNCK2D_SIZE[${i}]}
468    IGCM_debug_Print 1 "Check coherence between All Chunck2D frequency and TimeSeriesFrequency"
469    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
470    case ${value} in
471    *Y|*y) ;;
472    *)
473      IGCM_debug_Print 1 "All ChunckJob2D frequency must be expressed in year *Y|*y in comp.card"
474      IGCM_debug_Exit "This will stop the job" ;;
475    esac
476    (( i=i+1 ))
477  done
478
479  #modulo (TimeSeriesFrequency and all Chunck3D) must be zero
480  NbJob=${#CHUNCK3D_SIZE[@]}
481  i=0
482  until [ $i -ge $NbJob ]; do
483    value=${CHUNCK3D_SIZE[${i}]}
484    IGCM_debug_Print 1 "Check coherence between All Chunck3D frequency and TimeSeriesFrequency"
485    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
486    case ${value} in
487    *Y|*y) ;;
488    *)
489      IGCM_debug_Print 1 "All ChunckJob3D frequency must be expressed in year *Y|*y in comp.card"
490      IGCM_debug_Exit "This will stop the job" ;;
491    esac
492    (( i=i+1 ))
493  done
494
495  #check to be sure there is enough space on temporary filesystems to run
496  echo
497  IGCM_debug_Print 1 "Check if there is enough space on temporary filesystem"
498  IGCM_sys_check_quota
499
500  IGCM_debug_PopStack "IGCM_config_Check"
501}
502
503#===================================
504function IGCM_config_PeriodStart
505{
506  IGCM_debug_PushStack "IGCM_config_PeriodStart"
507
508  echo
509  IGCM_debug_Print 1 "IGCM_config_PeriodStart"
510  echo
511
512  if ( ${FirstInitialize} ) ; then
513    #================================================#
514    #         Initialize date/period information     #
515    #================================================#
516
517    IGCM_date_GetYearMonthDay $DateBegin year month day
518    IGCM_config_Analyse_PeriodLength
519
520    eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1
521    PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) )
522    eval CumulPeriod=1 > /dev/null 2>&1
523
524    #=================================================#
525    #              Write updated run.card             #
526    #=================================================#
527
528    #Correct run.card Configuration for this period
529    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
530    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
531    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
532    if [ X$( grep "SubmitPath" ${SUBMIT_DIR}/run.card ) != X ] ; then
533      IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration SubmitPath ${SUBMIT_DIR}
534    fi
535
536    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
537
538  else
539    #================================================#
540    #         The file run.card allready exist       #
541    #================================================#
542
543    #Test state of run in run.card
544    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
545    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
546      echo
547      IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
548      IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this"
549      echo
550      IGCM_debug_Exit
551      IGCM_debug_Verif_Exit
552    fi
553
554    #===================================#
555    #        Read updated run.card      #
556    #===================================#
557
558    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
559    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
560    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
561    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
562
563    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
564    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
565    eval CumulPeriod="${run_Configuration_CumulPeriod}" > /dev/null 2>&1
566
567    LastPeriodDateEnd=$( echo ${run_Configuration_OldPrefix} | sed -e "s/${config_UserChoices_JobName}_//" )
568
569    typeset LastDate
570    set +A LastDate -- $( echo ${LastPeriodDateEnd} | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1 \2 \3/" )
571    LastYearDateEnd=${LastDate[0]}
572    LastMonthDateEnd=${LastDate[1]}
573    LastDayDateEnd=${LastDate[2]}
574
575    if [ ${Period} = 1 ]; then
576      # save last Job output
577      typeset LastPeriod iLastPeriod Last_Script_Output_Name
578      (( LastPeriod=CumulPeriod-PeriodNb ))
579      iLastPeriod=$( printf "%06d" ${LastPeriod} )
580      Last_Script_Output_Name="${Script_Output_Prefix}_${config_UserChoices_JobName}.${iLastPeriod}"
581      Last_run_card="run.card.${iLastPeriod}"
582      #eval ls -l ${SUBMIT_DIR}/${Last_Script_Output_Name}
583      #eval IGCM_sys_Put_Out ${SUBMIT_DIR}/${Last_Script_Output_Name} ${R_BUF_KSH}/${Last_Script_Output_Name} > /dev/null 2>&1
584      IGCM_debug_Print 2 "Try to save previous ksh job output"
585      IGCM_sys_Cd ${SUBMIT_DIR}/
586      if [ X${Pack} = Xtrue ] ; then
587        IGCM_sys_PutBuffer_Out ${Last_Script_Output_Name} ${R_BUF_KSH}/${Last_Script_Output_Name}.$$ rw
588      else
589        IGCM_sys_Put_Out ${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name}.$$ rw
590      fi
591
592      IGCM_card_CheckConflict run.card
593      if [ X${Pack} = Xtrue ] ; then
594        IGCM_sys_PutBuffer_Out ${SUBMIT_DIR}/run.card ${R_BUF_KSH}/${Last_run_card}.$$ rw
595      else
596        IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/${Last_run_card}.$$ rw
597      fi
598      IGCM_sys_Cd ${RUN_DIR}
599    else
600      unset FileToBeDeleted
601    fi
602
603    IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
604    IGCM_config_Analyse_PeriodLength
605
606    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
607
608  fi
609  OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd}
610
611  # BEGIN: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
612  # Compute year_m1 and year_p1 (year minus 1Y and year plus 1Y)
613  year_m1=$(( year - 1 ))
614  year_p1=$(( year + 1 ))
615  # Compute month_m1 (month minus 1M)
616  # Compute yyyymm_m1 (yyyymm minus 1M)
617  month_m1=$(( month - 1 ))
618  if [ ${month_m1} = 0 ]; then
619    month_m1=12
620    yyyymm_m1=${year_m1}12
621  elif [ ${month_m1} -le 9 ]; then
622    month_m1=0${month_m1}
623    yyyymm_m1=${year}${month_m1}
624  else
625    yyyymm_m1=${year}${month_m1}
626  fi
627  # Compute month_p1 (month plus 1M)
628  # Compute yyyymm_p1 (yyyymm plus 1M)
629  month_p1=$(( month + 1 ))
630  if [ ${month_p1} = 13 ]; then
631    month_p1=01
632    yyyymm_p1=${year_p1}01
633  elif [ ${month_p1} -le 9 ]; then
634    month_p1=0${month_p1}
635    yyyymm_p1=${year}${month_p1}
636  else
637    yyyymm_p1=${year}${month_p1}
638  fi
639  #IGCM_debug_Print 1 "jg 1 month_m1 = ${month_m1} month_p1 = ${month_p1} "
640  #IGCM_debug_Print 1 "jg 1 calculate yyyymm_m1 = ${yyyymm_m1} "
641  #IGCM_debug_Print 1 "jg 1 calculate yyyymm_p1 = ${yyyymm_p1} "
642
643  #===================================================================#
644  # Calculate CyclicYear to be used for looping over a given forcing  #
645  # period. Add CyclicBegin and CyclicEnd in config.card UserChoices. #
646  #===================================================================#
647
648  # To use the variable CyclicYear, one must add in config.card CyclicBegin and CyclicEnd.
649  # CyclicBegin is the first year in the cycle. CyclicEnd is the last year included in the cycle.
650  # The simulation MUST start with the same year as the CyclicBegin year.
651  if ( [ ! X${config_UserChoices_CyclicBegin} = X ] && [ ! X${config_UserChoices_CyclicEnd} = X ] ) ; then
652    CycleNb=$(( ${config_UserChoices_CyclicEnd} - ${config_UserChoices_CyclicBegin} + 1 ))
653    CyclicYear=$(( ( ( ${year} - ${config_UserChoices_CyclicBegin} ) % ${CycleNb} ) + ${config_UserChoices_CyclicBegin} ))
654    IGCM_debug_Print 1 "CyclicYear   = ${CyclicYear} current year=$year"
655  else
656    CyclicYear="ERROR_CyclicYear_Variable_Not_Defined"
657    IGCM_debug_Print 1 "CyclicYear not possible to use without adding CyclicBegin and CyclicEnd in config.card"
658  fi
659
660  # END: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
661
662  #===================================================================#
663  # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
664  #             But available to any son functions                    #
665  #===================================================================#
666
667  # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !)
668  (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 ))
669
670  # Debug Print :
671  echo
672  IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution"
673  IGCM_debug_Print 1 "Year of simulation      : ${year}"
674  IGCM_debug_Print 1 "Month of simulation     : ${month}"
675  IGCM_debug_Print 1 "PeriodLengthInDays      : ${PeriodLengthInDays}"
676  IGCM_debug_Print 1 "PeriodDateBegin         : ${PeriodDateBegin}"
677  IGCM_debug_Print 1 "PeriodDateEnd           : ${PeriodDateEnd}"
678  IGCM_debug_Print 1 "SimulationLengthInDays  : ${SimulationLengthInDays}"
679  IGCM_debug_Print 1 "ExperienceLengthInDays  : ${ExperienceLengthInDays}"
680
681  #================================================================#
682  #         Prepare variables available for comp_finalyze          #
683  #================================================================#
684
685  # Period for save files
686  eval DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd} > /dev/null 2>&1
687
688  # Prefix for save files of this period
689  eval PREFIX=${config_UserChoices_JobName}_${DatesPeriod}  > /dev/null 2>&1
690
691  # List of files that will be deleted in RUN_DIR after run
692  [ -f stack ] && FileToBeDeleted[0]="stack"
693
694  # Test if the same run as already been saved :
695  if [ X${JobType} = XRUN ] ; then
696    if [ ${DRYRUN} -le 0 ] ; then
697      if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then
698        IGCM_debug_Exit "IGCM_config_PeriodStart" "You are currently RErunning an old job."
699        IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files"
700        IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or "
701        IGCM_debug_Print 1 " the whole ${R_SAVE} tree. See clean_month.job in ${libIGCM} directory."
702        IGCM_debug_Print 1 " This exit has been initiated because at least ${R_BUF_KSH}/${PREFIX}_${Exe_Output} exists."
703        IGCM_debug_Verif_Exit
704      fi
705    fi
706  else
707    if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then
708      IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. Allowed in DEBUG or DEV mode."
709    fi
710  fi
711
712  typeset ExeNameIn ExeNameFirst CompNameFirst
713  typeset comp i
714  typeset tempvar tempvarMPI tempvarNOD NbElts j NbExec
715
716  (( PROCESSUS_NUMBER = 0 ))
717  (( i=0 ))
718  (( NbExec=0 ))
719
720  OK_PARA_MPI=false
721  OK_PARA_OMP=false
722  OK_PARA_NOD=false
723  OK_PARA_MPMD=false
724
725  for comp in ${config_ListOfComponents[*]} ; do
726
727    IGCM_debug_Print 1 ${comp}
728
729    eval ExeNameIn=\${config_Executable_${comp}[0]}
730
731    # NO order in config.card for parallelized values !
732    # just use suffix : MPI , OMP and NOD (for number of NODes.)
733
734    # NOD is the number of NODes allocated
735    eval ${comp}_PROC_NOD=0
736
737    # MPI is the number of MPI processus per nodes
738    eval ${comp}_PROC_MPI=0
739
740    # OMP is the number of OpenMP threads per MPI processus
741    eval ${comp}_PROC_OMP=0
742
743    # Only if we really have an executable for the component :
744###    if [ X${ExeNameIn} != X\"\" ] ; then
745    if ( [ "X${ExeNameIn}" != X\"\" ] && [ "X${ExeNameIn}" != "Xinca.dat" ] ) ; then
746
747      # Keep the first executable found and the first CompName
748      ExeNameFirst=${ExeNameIn}
749      CompNameFirst=${comp}
750
751      # Are we a second executable?
752      (( NbExec = NbExec + 1 ))
753
754      # set 1 MPI task, 1 OpenMP thread and 1 node as default
755      eval ${comp}_PROC_MPI=1
756      eval ${comp}_PROC_OMP=1
757      eval ${comp}_PROC_NOD=1
758
759      eval NbElts=\${#config_Executable_${comp}[@]}
760
761      if [ ${NbElts} -ge 2 ] ; then
762        (( j = 2 ))
763
764        while [ $j -lt ${NbElts} ] ; do
765          eval tempvar=\${config_Executable_${comp}[${j}]}
766
767          if [ X${tempvar} = X ] ; then
768            echo "Error reading MPI/OMP parameters !!!"
769            echo "Check your config.card."
770            exit 1
771          fi
772
773          eval IGCM_debug_Print 2 ${tempvar}
774
775          case ${tempvar} in
776          *[mM][pP][iI]*)
777               # Read MPI parameter for composante
778            eval ${comp}_PROC_MPI=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/MPI//" )
779            OK_PARA_MPI=true;;
780          *[oO][mM][pP]*)
781               # Read OMP parameter for composante
782            eval ${comp}_PROC_OMP=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/OMP//" )
783            OK_PARA_OMP=true;;
784          *[nN][oO][dD]*)
785               # Read NOD (NumBer of Nodes) parameter for composante
786            eval ${comp}_PROC_NOD=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/NOD//" )
787            OK_PARA_NOD=true
788            OK_PARA_MPI=true;;
789          esac
790
791          (( j = j + 1 ))
792        done
793
794      fi
795
796      eval tempvarMPI=\${${comp}_PROC_MPI}
797      eval tempvarNOD=\${${comp}_PROC_NOD}
798      eval tempvarOMP=\${${comp}_PROC_OMP}
799
800      (( PROCESSUS_NUMBER = PROCESSUS_NUMBER + tempvarMPI * tempvarNOD * tempvarOMP ))
801
802    fi
803
804    (( i=i+1 ))
805  done
806
807  # set MPMD mode if more than 2 executable names.
808  [ ${NbExec} -ge 2 ] && OK_PARA_MPMD=true
809
810  # Verification of BATCH_NUM_PROC_TOT total number of processors set in job header.
811  if [ X${BATCH_NUM_PROC_TOT} != X ] ; then
812    # BATCH_NUM_PROC_TOT is set
813    if ( ${OK_PARA_MPI} ) ; then
814      IGCM_debug_Print 1 "MPI/OMP/NOD found into config.card and BATCH_NUM_PROC_TOT = ${BATCH_NUM_PROC_TOT} "
815    else
816      # with previous method.
817      if [ ${BATCH_NUM_PROC_TOT} -gt 1 ] ; then
818        # with more than 1 proc
819        if ( ${OK_PARA_MPMD} ) ; then
820          # with MPMD ie CPL/oasis method
821          echo "We will use default number of MPI tasks for this machine : "
822          echo "${DEFAULT_NUM_PROC_OCE} for OCE; "
823          echo "${DEFAULT_NUM_PROC_CPL} for CPL; "
824          echo "${DEFAULT_NUM_PROC_ATM} for ATM; "
825          echo "${DEFAULT_NUM_PROC_TOTAL} for the total number of processors; "
826          OK_PARA_MPI=true
827          CPL_PROC_MPI=${DEFAULT_NUM_PROC_CPL}
828          OCE_PROC_MPI=${DEFAULT_NUM_PROC_OCE}
829          ATM_PROC_MPI=${DEFAULT_NUM_PROC_ATM}
830          PROCESSUS_NUMBER=${DEFAULT_NUM_PROC_TOTAL}
831        else
832          # with have only one executable
833          echo "We will use ${BATCH_NUM_PROC_TOT} MPI tasks for ${CompNameFirst} : ${ExeNameFirst} "
834          OK_PARA_MPI=true
835          eval ${CompNameFirst}_PROC_MPI=${BATCH_NUM_PROC_TOT}
836          PROCESSUS_NUMBER=${BATCH_NUM_PROC_TOT}
837        fi
838      else
839        PROCESSUS_NUMBER=1
840      fi
841    fi
842    # Verification with PBS parameter
843    if [ ${BATCH_NUM_PROC_TOT} -ne ${PROCESSUS_NUMBER} ] ; then
844      echo "Warning with parallelization parameters !"
845      echo "Job header variable BATCH_NUM_PROC_TOT = ${BATCH_NUM_PROC_TOT} "
846      echo "is the total number of _processors_ reserved."
847      echo "It is not equal to the sum of _processus_  = ${PROCESSUS_NUMBER}."
848      echo "We stop now."
849      exit 1
850    fi
851    NUM_PROC_CPL=${CPL_PROC_MPI} # for backward compatibility
852    NUM_PROC_OCE=${OCE_PROC_MPI} # for backward compatibility
853    NUM_PROC_ATM=${ATM_PROC_MPI} # for backward compatibility
854  else # BATCH_NUM_PROC_TOT=""
855    if ( ${OK_PARA_MPI} ) ; then
856      echo "You have not given a value of ${BATCH_NUM_PROC_TOT} processors,"
857      echo "but you have filled the parallel parameter in config->Executable->list."
858      echo "Please add BATCH_NUM_PROC_TOT variable in job header."
859      echo "We stop now."
860      exit 1
861    else
862      # sequential case !
863      if [ ${PROCESSUS_NUMBER} -eq 0 ] ; then
864        (( PROCESSUS_NUMBER = 1 ))
865        echo "PROCESSUS_NUMBER is all 0 (sequential use of old definition in config->Executable->list)."
866        echo "We set it to 1."
867      fi
868    fi
869  fi
870
871  IGCM_debug_Print 1 "MPI/OMP treatment PROCESSUS_NUMBER = ${PROCESSUS_NUMBER}"
872
873  IGCM_sys_build_execution_scripts
874
875  ExecutionFail=false
876
877  IGCM_debug_PopStack "IGCM_config_PeriodStart"
878}
879
880#===================================
881function IGCM_config_SaveSourceModifications
882{
883  IGCM_debug_PushStack "IGCM_config_SaveSourceModifications"
884
885  typeset ExeOutDateMax listVarEnv
886  ExeOutDateMax=$1
887
888  listVarEnv="ExeOutDateMax,R_OUT_EXE,PREFIX,SUBMIT_DIR"
889  IGCM_sys_RshMaster "\
890    . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh; \
891    export ExeOutDateMax=${ExeOutDateMax};\
892    export R_OUT_EXE=${R_OUT_EXE};\
893    export PREFIX=${PREFIX};\
894    export SUBMIT_DIR=${SUBMIT_DIR};\
895    export listVarEnv=${listVarEnv};\
896    Script_Output=out_SaveSourceModifications;\
897    IGCM_sys_Qsub ${libIGCM}/SaveSourceModifications.job ${ExeOutDateMax} ${R_OUT_EXE} ${PREFIX} ${SUBMIT_DIR}"
898
899  IGCM_debug_PopStack "IGCM_config_SaveSourceModifications"
900}
901
902#===================================
903function IGCM_config_PeriodEnd
904{
905  IGCM_debug_PushStack "IGCM_config_PeriodEnd"
906
907  echo
908  IGCM_debug_Print 1 "IGCM_config_PeriodEnd"
909  echo
910
911  #==================================#
912  #         Save Job output          #
913  #==================================#
914  if [ X${Pack} = Xtrue ] ; then
915    IGCM_sys_PutBuffer_Out ${Exe_Output} ${R_BUF_KSH}/${PREFIX}_${Exe_Output}
916  else
917    IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output}
918  fi
919  eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}"
920
921  IGCM_card_CheckConflict run.card
922  if [ X${Pack} = Xtrue ] ; then
923    IGCM_sys_PutBuffer_Out ${SUBMIT_DIR}/run.card ${R_BUF_KSH}/run.card rw
924  else
925    IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/run.card rw
926  fi
927
928  if [ ${DRYRUN} -le 1 ] ; then
929
930    IGCM_debug_Print 1 "Check components binary : size and creation date"
931
932    typeset LS_comp LS_bin ExeDate ExeCpuLog NextExeSize LastCompExeSize
933    typeset comp i
934    typeset ExeNameIn ExeNameOut UpdateExe ExeSecDateMax
935
936    #==================================#
937    #        Get last Exe Size         #
938    #==================================#
939
940    (( i=0 ))
941    if ( ${FirstInitialize} ) ; then
942      run_Log_LastExeSize=""
943      for comp in ${config_ListOfComponents[*]} ; do
944        run_Log_LastExeSize[$i]=0
945        (( i=i+1 ))
946      done
947    else
948      IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize
949    fi
950    #==================================#
951    #         And Build ExeDate        #
952    #==================================#
953
954    # 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
955    # 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")
956    # 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
957    ExeDate=""
958    NextExeSize="( "
959    (( i=0 ))
960    UpdateExe=false
961    (( ExeSecDateMax = 0 ))
962    for comp in ${config_ListOfComponents[*]} ; do
963
964      IGCM_debug_Print 3 ${comp}
965
966      eval ExeNameIn=\${config_Executable_${comp}[0]}
967      eval ExeNameOut=\${config_Executable_${comp}[1]}
968      # Only if we really have an executable for the component :
969      if [ X${ExeNameIn} = X\"\" ] ; then
970        # If there is no exe file for this component
971        (( ExeSize=0 ))
972      else
973        eval LS_bin=${R_EXE}/${ExeNameIn}
974        IGCM_sys_FileSize ${LS_bin} ExeSize
975
976        set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} )
977        if [ X${ExeDate} = X ] ; then
978          # First component exe date
979          ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]}
980        else
981          ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]}
982        fi
983        ExeDate=${ExeDate}_${LS_comp[7]}
984      fi
985
986      if [ ${i} -eq 0 ] ; then
987        # First component
988        NextExeSize="( "${ExeSize}
989      else
990        NextExeSize=${NextExeSize}", "${ExeSize}
991      fi
992      eval LastCompExeSize=${run_Log_LastExeSize[$i]}
993      (( i=i+1 ))
994
995      if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then
996        if ( ${FirstInitialize} ) ; then
997          IGCM_debug_Print 1 "Save first ${ExeNameIn} in ${R_OUT_EXE} !"
998        else
999          IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !"
1000          IGCM_debug_Print 1 "Save latest ${ExeNameIn} in ${R_OUT_EXE} !"
1001          eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut}
1002        fi
1003        eval IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw
1004        UpdateExe=true
1005
1006        # SD : switch off for now
1007        #IGCM_sys_GetDate_FichWork ${LS_bin} ExeSecDate
1008        #if [ $ExeSecDateMax -lt $ExeSecDate ] ; then
1009        #  ExeSecDateMax=$ExeSecDate
1010        #fi
1011      fi
1012    done
1013
1014    # SD : switch off for now
1015    #if ( ${UpdateExe} ) ; then
1016    #  echo "Launch SaveSourceModifications."
1017    #  IGCM_config_SaveSourceModifications ${ExeSecDateMax}
1018    #fi
1019
1020    NextExeSize=${NextExeSize}" )"
1021    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}"
1022
1023    if [ ${DRYRUN} -le 1 ] ; then
1024      tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt
1025      ExeCpuLog=$( gawk -f ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt )
1026      RET=$?
1027      if [ $RET -eq 0 ] ; then
1028        # ExeCpuLog variable contents 5 fields
1029        echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" |   \
1030          gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \
1031            $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card
1032      fi
1033      eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}_tail.txt"
1034    fi
1035
1036  fi
1037
1038  # All was right ? no ? then we stop.
1039  IGCM_debug_Verif_Exit
1040
1041  # If all was OK, we can delete all files not necessary for next Job
1042  echo
1043  IGCM_debug_Print 1 "Files that will be deleted before next period-run : "
1044
1045  if [ ${DRYRUN} -le 2 ] ; then
1046    for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done
1047  else
1048    echo ${FileToBeDeleted[@]}
1049  fi
1050
1051  #=================================================#
1052  #         Modification of libIGCM behaviour       #
1053  #=================================================#
1054
1055  # To use this function, one must copy libIGCM.card from ${libIGCM} directory
1056  # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card,
1057  # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop.
1058  if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then
1059    echo
1060    echo "########################################################################"
1061    echo "!!!                 Modification of libIGCM behaviour                !!!"
1062    echo
1063
1064    IGCM_debug_Print 1 "DefineArrayFromOption  : libIGCM_UserChanges in libIGCM.card"
1065    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges
1066    IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]}
1067
1068    # Special treatments for libIGCM internals
1069    for option in ${libIGCM_UserChanges[*]} ; do
1070      IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option}
1071
1072      echo "We will change : ${option}."
1073      eval echo "Previous value : " \${${option}}
1074      eval echo "Change to : " \${libIGCM_UserChanges_${option}}
1075
1076      eval ${option}=\${libIGCM_UserChanges_${option}}
1077
1078      case ${option} in
1079      config_UserChoices_DateEnd)
1080        IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd
1081        DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
1082
1083        # Period Length In Days between DateBegin and DateEnd
1084        (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
1085        if [ ${ExperienceLengthInDays} -lt 0 ] ; then
1086          IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that."
1087          IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates."
1088          IGCM_debug_Verif_Exit
1089        fi
1090        ;;
1091      config_UserChoices_PeriodLength)
1092        IGCM_debug_Print 1  "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}"
1093        ;;
1094      PeriodNb)
1095        IGCM_debug_Print 1  "Loop in main Job with ${PeriodNb} period(s)"
1096        ;;
1097      config_Post_RebuildFrequency)
1098        IGCM_debug_Print 1  "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure"
1099        IGCM_post_Configure
1100        ;;
1101      config_Post_TimeSeriesFrequency)
1102        IGCM_debug_Print 1  "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Configure"
1103        IGCM_post_Configure
1104        ;;
1105      config_Post_SeasonalFrequency)
1106        IGCM_debug_Print 1  "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Configure"
1107        IGCM_post_Configure
1108        ;;
1109      esac
1110    done
1111
1112    echo
1113    echo "########################################################################"
1114    echo
1115  fi
1116
1117  #=================================================#
1118  #         Determine next computed period          #
1119  #=================================================#
1120
1121  PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 )
1122  IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
1123  year_m1=$(( year - 1 ))
1124  year_p1=$(( year + 1 ))
1125  IGCM_config_Analyse_PeriodLength
1126  PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) )
1127
1128  # Debug Print :
1129  echo
1130  IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution"
1131  IGCM_debug_Print 1 "PeriodDateBegin       : ${PeriodDateBegin}"
1132  IGCM_debug_Print 1 "PeriodDateEnd         : ${PeriodDateEnd}"
1133  IGCM_debug_Print 1 "PeriodLengthInDays    : ${PeriodLengthInDays}"
1134
1135  PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} )
1136  PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} )
1137
1138  (( CumulPeriod = CumulPeriod + 1 ))
1139
1140  # Debug Print :
1141  echo
1142  IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}"
1143  IGCM_debug_Print 3 "PeriodDateEnd Human   : ${PeriodDateEnd}"
1144  IGCM_debug_Print 3 "CumulPeriod           : ${CumulPeriod}"
1145
1146  #=================================================#
1147  #             Write updated run.card              #
1148  #=================================================#
1149
1150  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix}
1151  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
1152  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
1153  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
1154
1155  if ( ${FirstInitialize} ) ; then
1156    # It's no more the first time
1157    FirstInitialize=false
1158  fi
1159
1160  IGCM_debug_PopStack "IGCM_config_PeriodEnd"
1161}
1162
1163#===================================
1164function IGCM_config_Finalize
1165{
1166  IGCM_debug_PushStack "IGCM_config_Finalize"
1167
1168  echo
1169  IGCM_debug_Print 1 "IGCM_config_Finalize"
1170  echo
1171
1172  if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then
1173    #==========================#
1174    # End of entire simulation #
1175    #==========================#
1176
1177    # Mail notification
1178    IGCM_sys_SendMail
1179
1180    #
1181    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed"
1182    IGCM_debug_Print 1 "Normal End of computation."
1183    if ( $DEBUG_debug ) ; then
1184      echo
1185      IGCM_debug_Print 1 "Your files on ${R_SAVE} :"
1186      IGCM_sys_Tree ${R_SAVE}
1187
1188      IGCM_debug_Print 1 "Your files on ${R_BUFR} :"
1189      IGCM_sys_Tree ${R_BUFR}
1190    fi
1191  else
1192    #=================#
1193    # Submit next job #
1194    #=================#
1195
1196    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
1197
1198    # Name of next Ksh Script output :
1199    eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )"
1200
1201    IGCM_debug_Print 1 "Submit next job"
1202    # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR
1203    IGCM_sys_Cd ${SUBMIT_DIR}
1204    # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName}
1205    ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l )
1206    [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) )
1207    # Submit next job and come back
1208    IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}
1209    IGCM_sys_Cd -
1210  fi
1211
1212  # Supress Non Deleted Boundary files
1213  #if [ ${DRYRUN} -le 2 ] ; then
1214  #  IGCM_comp_DelFixeBoundaryFiles
1215  #  ls -la
1216  #fi
1217
1218  # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_JobName}.${$}
1219  # Only for production run (No clean up in DEV or DEB mode)
1220  # and command sent from .. directory.
1221  IGCM_sys_Cd ..
1222  [ X${JobType} = XRUN ] && IGCM_sys_Rm -rf ${RUN_DIR}
1223
1224  IGCM_debug_PopStack "IGCM_config_Finalize"
1225}
1226
1227#===================================
Note: See TracBrowser for help on using the repository browser.