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

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