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

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