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

Last change on this file since 1220 was 1220, checked in by sdipsl, 9 years ago
  • Any post-procesing errors will stop the computing jobs when SpaceName?=PROD. See #260
  • Feature was removed some years ago because postprocessing errors were legions. More robust now.
  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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