source: tags/libIGCM_v2.0_rc3/libIGCM_config/libIGCM_config.ksh @ 1435

Last change on this file since 1435 was 799, checked in by sdipsl, 11 years ago

For Josefine, add CyclicYear? variable to be used by comp.card to periodically loop over a forcing.

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