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

Last change on this file since 1488 was 1488, checked in by acosce, 5 years ago

Add possibility to define the chemistry configuration in config.card in order to use it in executable name for new way of compilation (v6.2)

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