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

Last change on this file since 760 was 760, checked in by labetoulle, 11 years ago

RunChecker? :

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