source: tags/libIGCM_v2.0_beta2/libIGCM_config/libIGCM_config.ksh @ 1456

Last change on this file since 1456 was 662, checked in by acosce, 12 years ago

BugFix? for inca config

1- management of two executable with only one launch (inca individual case)
2- refine restart list and will find restart with different extension (.nc, .txt etc...)

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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