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

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