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

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