source: tags/libIGCM_v2.2/libIGCM_config/libIGCM_config.ksh

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

Tag libIGCM_v2.2 is mainly a release dedicated to IPSLCM6 transition

  • netcdf4 support on Curie
  • can activate BigBrother?, will also be use to transport metric results
  • bug fixes
  • code cleanup

Tickets solved:
https://forge.ipsl.jussieu.fr/libigcm/query?status=closed&group=resolution&milestone=libIGCM_v2.2+metrics

Full changelog:
https://forge.ipsl.jussieu.fr/libigcm/log/trunk/libIGCM?action=stop_on_copy&mode=stop_on_copy&rev=997&stop_rev=951&limit=100&verbose=on

Next release will continue to focus on metrics. Tickets can be inspected there : http://forge.ipsl.jussieu.fr/libigcm/query?milestone=libIGCM_v2.3+metrics&group=status&order=priority

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