source: branches/libIGCM_MPI_OpenMP/libIGCM_config/libIGCM_config.ksh @ 571

Last change on this file since 571 was 571, checked in by mafoipsl, 12 years ago

First try to merge libIGCM_MPI_OpenMP branch with libIGCM trunk revision 569. Tested on vargas with PackFrequency?=NONE included into config.card.

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