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

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