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

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