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

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