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

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