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

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