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

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