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

Last change on this file since 1048 was 1048, checked in by sdipsl, 10 years ago

timestamp precision is now millisecond. Add a uuid to each message. see #207 and #214

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