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

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