source: tags/libIGCM_v2.0_beta4/libIGCM_config/libIGCM_config.ksh @ 1170

Last change on this file since 1170 was 691, checked in by sdipsl, 12 years ago
  • IGCM_sys_GetDate_FichWork is causing trouble on SX9 (ls --full-time option not avaible on SX9)
  • This is related to IGCM_config_SaveSourceModifications
  • IGCM_config_SaveSourceModifications will be reintroduced (at least on some machine) during beta4
  • 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
146  #==================================
147  # Define Outputs Name
148  IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output"
149  eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'}
150  IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}"
151  eval Exe_Output=out_execution
152  IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}"
153
154  #===================================================================#
155  # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
156  #             But available to any son functions                    #
157  #===================================================================#
158
159  # Convert yyyy-mm-dd date to gregorian yyyymmdd
160  DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
161  DateEnd=$(   IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd}   )
162
163  # Period Length In Days between DateBegin and DateEnd
164  (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
165  if [ ${ExperienceLengthInDays} -lt 0 ] ; then
166    IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that."
167    IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates."
168    IGCM_debug_Verif_Exit
169  fi
170
171  # Day and Year of Initial State (Given in julian format)
172  InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 ))
173  InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 ))
174
175  #==================================
176  # Restarts : Gerneral rule or local for each component ?
177  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts
178
179  echo
180  IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts"
181
182  for option in ${config_Restarts[*]} ; do
183    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option}
184    eval auxprint=\${config_Restarts_${option}}
185    IGCM_debug_Print 3 "${option} : ${auxprint}"
186  done
187
188  #================================================================#
189  #                  Test and Prepare directories                  #
190  #================================================================#
191
192  # ==> 4 kinds of input files :
193  #     1) R_INIT  : Initial State Files   (Etat0, carteveg)
194  #     2) R_BC    : Boundary Conditions   (Forcages, lai)
195  #     3) Parameters files (allready define through ${SUBMIT_DIR})
196  #     4) Restarts files   (allready define in IGCM_config_Initialize)
197
198  # Here we offer the possibility to redefine R_INIT, R_BC
199  # and PeriodNb through config.card
200  R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT}
201  IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb"
202  IGCM_debug_Print 3 "R_INIT=${R_INIT}"
203  R_BC=${config_UserChoices_R_BC:=${R_IN}/BC}
204  IGCM_debug_Print 3  "R_BC=${R_BC}"
205  PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}}
206  IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)"
207
208  # Test Archive input/output.
209  IGCM_sys_TestDirArchive ${ARCHIVE}
210  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
211  IGCM_sys_TestDirArchive ${R_IN}
212  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
213
214  #====================================================
215  #R_SAVE : Job output directory
216  if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
217    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
218    if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
219      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
220      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
221      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
222      R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
223    else
224      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
225      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
226      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
227      R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
228    fi
229  else
230    if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
231      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
232      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
233      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
234      R_DODS=${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
235    else
236      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
237      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
238      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
239      R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName}
240    fi
241  fi
242
243  if ( ${FirstInitialize} ) ; then
244    IGCM_sys_MkdirArchive ${R_SAVE}
245    IGCM_sys_Mkdir        ${R_BUFR}
246  else
247    IGCM_sys_TestDirArchive ${R_SAVE}
248    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive ${R_SAVE}"
249
250    IGCM_sys_TestDir        ${R_BUFR}
251    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir ${R_BUFR}"
252
253    #Test state of run in run.card
254    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
255
256    if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
257      echo
258      IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
259      IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this"
260      IGCM_debug_Exit
261      IGCM_debug_Verif_Exit
262    fi
263  fi
264
265  #====================================================
266  # Define REBUILD_DIR : where we store files needing rebuild process
267  if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
268    REBUILD_DIR=${R_SAVE}/TMP
269    IGCM_sys_MkdirArchive ${REBUILD_DIR}
270  else
271    REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
272    IGCM_sys_MkdirWork ${REBUILD_DIR}
273  fi
274
275  #====================================================
276  # Experience type : DEB(ug), DEV(elopment), RUN
277  if [ X${JobType} != XRUN ] ; then
278    echo
279    echo "===================================================="
280    echo "libIGCM JOB is NOT in RUN type mode."
281    echo "!! OUTPUT files will NOT be PROTECTED !!"
282    echo "Be carefull : you can ERASE the result of this job !"
283
284    case ${JobType} in
285    DEB)
286      echo "DEBUG mode : activation of 'set -vx' mode."
287      echo "DEBUG mode : no protection for output files."
288      echo "DEBUG mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
289      ;;
290    DEV)
291      echo "DEVelopment mode : no protection for output files."
292      echo "DEVelopment mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
293      ;;
294    esac
295
296    if ( [ X${config_Post_RebuildFrequency} != XNONE ] && [ ${DRYRUN} -eq 0 ] ) ; then
297      if [ X${config_Post_RebuildFrequency} != X${config_UserChoices_PeriodLength} ] ; then
298        echo "------------"
299        echo "WARNING : Job is NOT in RUN mode then we will force REBUILD Frequency"
300        echo "          to PeriodLength : ${config_UserChoices_PeriodLength}"
301        echo "------------"
302        config_Post_RebuildFrequency=${config_UserChoices_PeriodLength}
303      fi
304    fi
305    echo "===================================================="
306    echo
307  fi
308
309  #====================================================
310  #R_OUT_KSH : Storage place for job output
311  #R_OUT_EXE : Storage place for binary used during simulation
312  R_OUT_KSH=${R_SAVE}/Out
313  R_OUT_EXE=${R_SAVE}/Exe
314
315  #====================================================
316  #R_BUF_KSH : Buffer place for job output
317  #R_BUF_EXE : Buffer place for binary used during simulation
318  R_BUF_KSH=${R_BUFR}/Out
319  R_BUF_EXE=${R_BUFR}/Exe
320
321  IGCM_debug_PopStack "IGCM_config_Initialize"
322}
323
324#===================================
325function IGCM_config_Analyse_PeriodLength
326{
327  IGCM_debug_PushStack "IGCM_config_Analyse_PeriodLength"
328
329  typeset i
330
331  # Determine number of day(s) in PeriodLength :
332  case ${config_UserChoices_PeriodLength} in
333  *Y|*y)
334    PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' )
335    IGCM_debug_Print 2 "Number of years for PeriodLength : ${PeriodLengthInYears}"
336    PeriodLengthInDays=0
337    i=0
338    until [ $i -ge $PeriodLengthInYears ] ; do
339      (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) ))
340      (( i=i+1 ))
341    done
342    ;;
343  *M|*m)
344    PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' )
345    IGCM_debug_Print 2 "Number of months for PeriodLength : ${PeriodLengthInMonths}"
346    PeriodLengthInDays=0
347    i=0
348    until [ $i -ge $PeriodLengthInMonths ] ; do
349      if [ $(( month + i )) -lt 13 ] ; then
350        (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i )) ) ))
351      else
352        (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) ))
353      fi
354      (( i=i+1 ))
355    done
356    ;;
357  *D|*d)
358    PeriodLengthInMonths=0
359    PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' );;
360  *)
361    IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D."
362    IGCM_debug_Verif_Exit ;;
363  esac
364
365  IGCM_debug_PopStack "IGCM_config_Analyse_PeriodLength"
366}
367
368#===================================
369function IGCM_config_Check
370{
371  IGCM_debug_PushStack "IGCM_config_Check"
372
373  # If one of the following modulo is not zero :
374  # we will issue an error then explain and exit in
375  # AA_job IGCM_debug_Verif_Exit call before binary submission
376
377  echo
378  IGCM_debug_Print 1 "IGCM_config_Check"
379  echo
380
381  typeset i
382
383  # Check RebuildFrequency against key frequencies : PeriodLength ; PackFrequency ; TimeSeriesFrequency ; SeasonalFrequency
384  if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
385    AsynchronousRebuild=true
386    IGCM_debug_Print 1 "Asynchronous rebuild has been activated."
387    echo
388    # modulo (RebuildFrequency and PeriodLength/TimeSeriesFrequency/SeasonalFrequency) must be zero
389    IGCM_debug_Print 1 "Check coherence between RebuildFrequency and PeriodLength"
390    IGCM_post_CheckModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength
391    IGCM_debug_Print 1 "Check coherence between PackFrequency and RebuildFrequency"
392    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_Post_RebuildFrequency
393    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and RebuildFrequency"
394    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_RebuildFrequency
395    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and RebuildFrequency"
396    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_RebuildFrequency
397  else
398    AsynchronousRebuild=false
399    IGCM_debug_Print 1 "Asynchronous rebuild has not been activated"
400    IGCM_debug_Print 1 "Proceed with standard post-treatment pathway"
401    echo
402    #modulo (PeriodLength and TimeSeriesFrequency/SeasonalFrequency) must be zero
403    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PeriodLength"
404    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_UserChoices_PeriodLength
405    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PeriodLength"
406    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency   config_UserChoices_PeriodLength
407  fi
408
409  # Check PackFrequency against other key frequencies
410  # Modulo (PackFrequency and TimeSeriesFrequency/SeasonalFrequency and PeriodLenght) must be zero
411  if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
412    Pack=true
413    #
414    IGCM_debug_Print 1 "Check coherence between PackFrequency and PeriodLength"
415    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_UserChoices_PeriodLength
416    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PackFrequency"
417    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_PackFrequency
418    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PackFrequency"
419    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_PackFrequency
420  else
421    Pack=false
422  fi
423
424  #modulo (TimeSeriesFrequency and all Chunck2D) must be zero
425  NbJob=${#CHUNCK2D_SIZE[@]}
426  i=0
427  until [ $i -ge $NbJob ]; do
428    value=${CHUNCK2D_SIZE[${i}]}
429    IGCM_debug_Print 1 "Check coherence between All Chunck2D frequency and TimeSeriesFrequency"
430    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
431    case ${value} in
432    *Y|*y) ;;
433    *)  IGCM_debug_Print 1 "All ChunckJob2D frequency must be expressed in year *Y|*y in comp.card"
434      IGCM_debug_Exit "This will stop the job" ;;
435    esac
436    (( i=i+1 ))
437  done
438
439  #modulo (TimeSeriesFrequency and all Chunck3D) must be zero
440  NbJob=${#CHUNCK3D_SIZE[@]}
441  i=0
442  until [ $i -ge $NbJob ]; do
443    value=${CHUNCK3D_SIZE[${i}]}
444    IGCM_debug_Print 1 "Check coherence between All Chunck3D frequency and TimeSeriesFrequency"
445    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
446    case ${value} in
447    *Y|*y) ;;
448    *)  IGCM_debug_Print 1 "All ChunckJob3D frequency must be expressed in year *Y|*y in comp.card"
449      IGCM_debug_Exit "This will stop the job" ;;
450    esac
451    (( i=i+1 ))
452  done
453
454  #check to be sure there is enough space on temporary filesystems to run
455  IGCM_debug_Print 1 "Check if there is enough space on temporary filesystem"
456  IGCM_sys_check_quota
457
458  IGCM_debug_PopStack "IGCM_config_Check"
459}
460
461#===================================
462function IGCM_config_PeriodStart
463{
464  IGCM_debug_PushStack "IGCM_config_PeriodStart"
465
466  echo
467  IGCM_debug_Print 1 "IGCM_config_PeriodStart"
468  echo
469
470  if ( ${FirstInitialize} ) ; then
471    #================================================#
472    #         Initialize date/period information     #
473    #================================================#
474
475    IGCM_date_GetYearMonthDay $DateBegin year month day
476    IGCM_config_Analyse_PeriodLength
477
478    eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1
479    PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) )
480    eval CumulPeriod=1 > /dev/null 2>&1
481
482    #=================================================#
483    #              Write updated run.card             #
484    #=================================================#
485
486    #Correct run.card Configuration for this period
487    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
488    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
489    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
490    if [ X$( grep "SubmitPath" ${SUBMIT_DIR}/run.card ) != X ] ; then
491      IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration SubmitPath ${SUBMIT_DIR}
492    fi
493
494    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
495
496  else
497    #================================================#
498    #         The file run.card allready exist       #
499    #================================================#
500
501    #Test state of run in run.card
502    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
503    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
504      echo
505      IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
506      IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this"
507      echo
508      IGCM_debug_Exit
509      IGCM_debug_Verif_Exit
510    fi
511
512    #===================================#
513    #        Read updated run.card      #
514    #===================================#
515
516    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
517    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
518    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
519    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
520
521    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
522    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
523    eval CumulPeriod="${run_Configuration_CumulPeriod}" > /dev/null 2>&1
524
525    LastPeriodDateEnd=$( echo ${run_Configuration_OldPrefix} | sed -e "s/${config_UserChoices_JobName}_//" )
526
527    typeset LastDate
528    set +A LastDate -- $( echo ${LastPeriodDateEnd} | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1 \2 \3/" )
529    LastYearDateEnd=${LastDate[0]}
530    LastMonthDateEnd=${LastDate[1]}
531    LastDayDateEnd=${LastDate[2]}
532
533    if [ ${Period} = 1 ]; then
534      # save last Job output
535      typeset LastPeriod iLastPeriod Last_Script_Output_Name
536      (( LastPeriod=CumulPeriod-PeriodNb ))
537      iLastPeriod=$( printf "%06d" ${LastPeriod} )
538      Last_Script_Output_Name="${Script_Output_Prefix}_${config_UserChoices_JobName}.${iLastPeriod}"
539      Last_run_card="run.card.${iLastPeriod}"
540      #eval ls -l ${SUBMIT_DIR}/${Last_Script_Output_Name}
541      #eval IGCM_sys_Put_Out ${SUBMIT_DIR}/${Last_Script_Output_Name} ${R_BUF_KSH}/${Last_Script_Output_Name} > /dev/null 2>&1
542      IGCM_debug_Print 2 "Try to save previous ksh job output"
543      IGCM_sys_Cd ${SUBMIT_DIR}/
544      if [ X${Pack} = Xtrue ] ; then
545        IGCM_sys_PutBuffer_Out ${Last_Script_Output_Name} ${R_BUF_KSH}/${Last_Script_Output_Name}.$$ rw
546      else
547        IGCM_sys_Put_Out ${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name}.$$ rw
548      fi
549
550      IGCM_card_CheckConflict run.card
551      if [ X${Pack} = Xtrue ] ; then
552        IGCM_sys_PutBuffer_Out ${SUBMIT_DIR}/run.card ${R_BUF_KSH}/${Last_run_card}.$$ rw
553      else
554        IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/${Last_run_card}.$$ rw
555      fi
556      IGCM_sys_Cd ${RUN_DIR}
557    else
558      unset FileToBeDeleted
559    fi
560
561    IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
562    IGCM_config_Analyse_PeriodLength
563
564    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
565
566  fi
567  OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd}
568
569  # BEGIN: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
570  # Compute year_m1 and year_p1 (year minus 1Y and year plus 1Y)
571  year_m1=$(( year - 1 ))
572  year_p1=$(( year + 1 ))
573  # Compute month_m1 (month minus 1M)
574  # Compute yyyymm_m1 (yyyymm minus 1M)
575  month_m1=$(( month - 1 ))
576  if [ ${month_m1} = 0 ]; then
577    month_m1=12
578    yyyymm_m1=${year_m1}12
579  elif [ ${month_m1} -le 9 ]; then
580    month_m1=0${month_m1}
581    yyyymm_m1=${year}${month_m1}
582  else
583    yyyymm_m1=${year}${month_m1}
584  fi
585  # Compute month_p1 (month plus 1M)
586  # Compute yyyymm_p1 (yyyymm plus 1M)
587  month_p1=$(( month + 1 ))
588  if [ ${month_p1} = 13 ]; then
589    month_p1=01
590    yyyymm_p1=${year_p1}01
591  elif [ ${month_p1} -le 9 ]; then
592    month_p1=0${month_p1}
593    yyyymm_p1=${year}${month_p1}
594  else
595    yyyymm_p1=${year}${month_p1}
596  fi
597  #IGCM_debug_Print 1 "jg 1 month_m1 = ${month_m1} month_p1 = ${month_p1} "
598  #IGCM_debug_Print 1 "jg 1 calculate yyyymm_m1 = ${yyyymm_m1} "
599  #IGCM_debug_Print 1 "jg 1 calculate yyyymm_p1 = ${yyyymm_p1} "
600
601  # END: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
602
603  #===================================================================#
604  # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
605  #             But available to any son functions                    #
606  #===================================================================#
607
608  # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !)
609  (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 ))
610
611  # Debug Print :
612  IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution"
613  IGCM_debug_Print 1 "Year of simulation      : ${year}"
614  IGCM_debug_Print 1 "Month of simulation     : ${month}"
615  IGCM_debug_Print 1 "PeriodLengthInDays      : ${PeriodLengthInDays}"
616  IGCM_debug_Print 1 "PeriodDateBegin         : ${PeriodDateBegin}"
617  IGCM_debug_Print 1 "PeriodDateEnd           : ${PeriodDateEnd}"
618  IGCM_debug_Print 1 "SimulationLengthInDays  : ${SimulationLengthInDays}"
619  IGCM_debug_Print 1 "ExperienceLengthInDays  : ${ExperienceLengthInDays}"
620
621  #================================================================#
622  #         Prepare variables available for comp_finalyze          #
623  #================================================================#
624
625  # Period for save files
626  eval DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd} > /dev/null 2>&1
627
628  # Prefix for save files of this period
629  eval PREFIX=${config_UserChoices_JobName}_${DatesPeriod}  > /dev/null 2>&1
630
631  # List of files that will be deleted in RUN_DIR after run
632  [ -f stack ] && FileToBeDeleted[0]="stack"
633
634  # Test if the same run as already been saved :
635  if [ X${JobType} = XRUN ] ; then
636    if [ ${DRYRUN} -le 0 ] ; then
637      if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then
638        IGCM_debug_Exit "IGCM_config_PeriodStart" "You are currently RErunning an old job."
639        IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files"
640        IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or "
641        IGCM_debug_Print 1 " the whole ${R_SAVE} tree. See clean_month.job in ${libIGCM} directory."
642        IGCM_debug_Print 1 " This exit has been initiated because at least ${R_BUF_KSH}/${PREFIX}_${Exe_Output} exists."
643        IGCM_debug_Verif_Exit
644      fi
645    fi
646  else
647    if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then
648      IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. Allowed in DEBUG or DEV mode."
649    fi
650  fi
651
652  typeset ExeNameIn ExeNameFirst CompNameFirst
653  typeset comp i
654  typeset tempvar tempvarMPI tempvarNOD NbElts j NbExec
655
656  (( PROCESSUS_NUMBER = 0 ))
657  (( i=0 ))
658  (( NbExec=0 ))
659
660  OK_PARA_MPI=false
661  OK_PARA_OMP=false
662  OK_PARA_NOD=false
663  OK_PARA_MPMD=false
664
665  for comp in ${config_ListOfComponents[*]} ; do
666
667    IGCM_debug_Print 1 ${comp}
668
669    eval ExeNameIn=\${config_Executable_${comp}[0]}
670
671    # NO order in config.card for parallelized values !
672    # just use suffix : MPI , OMP and NOD (for number of NODes.)
673
674    # NOD is the number of NODes allocated
675    eval ${comp}_PROC_NOD=0
676
677    # MPI is the number of MPI processus per nodes
678    eval ${comp}_PROC_MPI=0
679
680    # OMP is the number of OpenMP threads per MPI processus
681    eval ${comp}_PROC_OMP=0
682
683    # Only if we really have an executable for the component :
684###    if [ X${ExeNameIn} != X\"\" ] ; then
685    if ( [ "X${ExeNameIn}" != X\"\" ] && [ "X${ExeNameIn}" != "Xinca.dat" ] ) ; 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} : ${ExeNameFirst} "
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        # SD : switch off for now
947        #IGCM_sys_GetDate_FichWork ${LS_bin} ExeSecDate
948        #if [ $ExeSecDateMax -lt $ExeSecDate ] ; then
949        #  ExeSecDateMax=$ExeSecDate
950        #fi
951      fi
952    done
953
954    # SD : switch off for now
955    #if ( ${UpdateExe} ) ; then
956    #  echo "Launch SaveSourceModifications."
957    #  IGCM_config_SaveSourceModifications ${ExeSecDateMax}
958    #fi
959
960    NextExeSize=${NextExeSize}" )"
961    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}"
962
963    if [ ${DRYRUN} -le 1 ] ; then
964      tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt
965      ExeCpuLog=$( gawk -f ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt )
966      RET=$?
967      if [ $RET -eq 0 ] ; then
968        # ExeCpuLog variable contents 5 fields
969        echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" |   \
970          gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \
971            $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card
972      fi
973      eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}_tail.txt"
974    fi
975
976  fi
977
978  # All was right ? no ? then we stop.
979  IGCM_debug_Verif_Exit
980
981  # If all was OK, we can delete all files not necessary for next Job
982  echo
983  IGCM_debug_Print 1 "Files that will be deleted before next period-run : "
984
985  if [ ${DRYRUN} -le 2 ] ; then
986    for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done
987  else
988    echo ${FileToBeDeleted[@]}
989  fi
990
991  #=================================================#
992  #         Modification of libIGCM behaviour       #
993  #=================================================#
994
995  # To use this function, one must copy libIGCM.card from ${libIGCM} directory
996  # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card,
997  # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop.
998  if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then
999    echo
1000    echo "########################################################################"
1001    echo "!!!                 Modification of libIGCM behaviour                !!!"
1002    echo
1003
1004    IGCM_debug_Print 1 "DefineArrayFromOption  : libIGCM_UserChanges in libIGCM.card"
1005    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges
1006    IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]}
1007
1008    # Special treatments for libIGCM internals
1009    for option in ${libIGCM_UserChanges[*]} ; do
1010      IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option}
1011
1012      echo "We will change : ${option}."
1013      eval echo "Previous value : " \${${option}}
1014      eval echo "Change to : " \${libIGCM_UserChanges_${option}}
1015
1016      eval ${option}=\${libIGCM_UserChanges_${option}}
1017
1018      case ${option} in
1019      config_UserChoices_DateEnd)
1020        IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd
1021        DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
1022
1023        # Period Length In Days between DateBegin and DateEnd
1024        (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
1025        if [ ${ExperienceLengthInDays} -lt 0 ] ; then
1026          IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that."
1027          IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates."
1028          IGCM_debug_Verif_Exit
1029        fi
1030        ;;
1031      config_UserChoices_PeriodLength)
1032        IGCM_debug_Print 1  "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}"
1033        ;;
1034      PeriodNb)
1035        IGCM_debug_Print 1  "Loop in main Job with ${PeriodNb} period(s)"
1036        ;;
1037      config_Post_RebuildFrequency)
1038        IGCM_debug_Print 1  "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure"
1039        IGCM_post_Configure
1040        ;;
1041      config_Post_TimeSeriesFrequency)
1042        IGCM_debug_Print 1  "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Configure"
1043        IGCM_post_Configure
1044        ;;
1045      config_Post_SeasonalFrequency)
1046        IGCM_debug_Print 1  "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Configure"
1047        IGCM_post_Configure
1048        ;;
1049      esac
1050    done
1051
1052    echo
1053    echo "########################################################################"
1054    echo
1055  fi
1056
1057  #=================================================#
1058  #         Determine next computed period          #
1059  #=================================================#
1060
1061  PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 )
1062  IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
1063  year_m1=$(( year - 1 ))
1064  year_p1=$(( year + 1 ))
1065  IGCM_config_Analyse_PeriodLength
1066  PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) )
1067
1068  # Debug Print :
1069  echo
1070  IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution"
1071  IGCM_debug_Print 1 "PeriodDateBegin       : ${PeriodDateBegin}"
1072  IGCM_debug_Print 1 "PeriodDateEnd         : ${PeriodDateEnd}"
1073  IGCM_debug_Print 1 "PeriodLengthInDays    : ${PeriodLengthInDays}"
1074
1075  PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} )
1076  PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} )
1077
1078  (( CumulPeriod = CumulPeriod + 1 ))
1079
1080  # Debug Print :
1081  echo
1082  IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}"
1083  IGCM_debug_Print 3 "PeriodDateEnd Human   : ${PeriodDateEnd}"
1084  IGCM_debug_Print 3 "CumulPeriod           : ${CumulPeriod}"
1085
1086  #=================================================#
1087  #             Write updated run.card              #
1088  #=================================================#
1089
1090  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix}
1091  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
1092  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
1093  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
1094
1095  if ( ${FirstInitialize} ) ; then
1096    # It's no more the first time
1097    FirstInitialize=false
1098  fi
1099
1100  IGCM_debug_PopStack "IGCM_config_PeriodEnd"
1101}
1102
1103#===================================
1104function IGCM_config_Finalize
1105{
1106  IGCM_debug_PushStack "IGCM_config_Finalize"
1107
1108  echo
1109  IGCM_debug_Print 1 "IGCM_config_Finalize"
1110  echo
1111
1112  if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then
1113    #==========================#
1114    # End of entire simulation #
1115    #==========================#
1116
1117    # Mail notification
1118    IGCM_sys_SendMail
1119
1120    #
1121    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed"
1122    IGCM_debug_Print 1 "Normal End of computation."
1123    if ( $DEBUG_debug ) ; then
1124      echo
1125      IGCM_debug_Print 1 "Your files on ${R_SAVE} :"
1126      IGCM_sys_Tree ${R_SAVE}
1127
1128      IGCM_debug_Print 1 "Your files on ${R_BUFR} :"
1129      IGCM_sys_Tree ${R_BUFR}
1130    fi
1131  else
1132    #=================#
1133    # Submit next job #
1134    #=================#
1135
1136    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
1137
1138    # Name of next Ksh Script output :
1139    eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )"
1140
1141    IGCM_debug_Print 1 "Submit next job"
1142    # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR
1143    IGCM_sys_Cd ${SUBMIT_DIR}
1144    # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName}
1145    ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l )
1146    [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) )
1147    # Submit next job and come back
1148    IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}
1149    IGCM_sys_Cd -
1150  fi
1151
1152  # Supress Non Deleted Boundary files
1153  if [ ${DRYRUN} -le 2 ] ; then
1154    IGCM_comp_DelFixeBoundaryFiles
1155    ls -la
1156  fi
1157
1158  # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
1159  # Only for production run (No clean up in DEV or DEB mode)
1160  # and command sent from .. directory.
1161  IGCM_sys_Cd ..
1162  [ X${JobType} = XRUN ] && IGCM_sys_Rm -rf ${RUN_DIR}
1163
1164  IGCM_debug_PopStack "IGCM_config_Finalize"
1165}
1166
1167#===================================
Note: See TracBrowser for help on using the repository browser.