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

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