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

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

Take care of backward compatibility on NEC.

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