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

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

Cosmetics :

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