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

Last change on this file since 630 was 630, checked in by mafoipsl, 12 years ago

Add PackDefault? treatment.

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