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

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