source: tags/libIGCM_v2.5/libIGCM_config/libIGCM_config.ksh @ 1456

Last change on this file since 1456 was 1150, checked in by sdipsl, 9 years ago

adressing #242
message 2000 and 3000 (pushstack and popstack) has been turned off for the moment to ease downstream processing

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