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

Last change on this file since 658 was 658, checked in by labetoulle, 12 years ago

Add Ensemble functionality to libIGCM - First step :
modify output directories according to an option in section [Ensemble]
in config.card (modification of config.card yet to be done).

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