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

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

Add default number of processors in libIGCM_sys library. Adapted and tested on vargas and SX9.

  • 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.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
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                     PROCESSUS_NUMBER=${DEFAULT_NUM_PROC_TOTAL}
662                else
663                     # with have only one executable
664                     echo "We will use ${BATCH_NUM_PROC_TOT} MPI tasks for ${CompNameFirst} : ${config_Executable_Name} "
665                     OK_PARA_MPI=true
666                     eval ${CompNameFirst}_PROC_MPI=${BATCH_NUM_PROC_TOT}
667                     PROCESSUS_NUMBER=${BATCH_NUM_PROC_TOT}
668                fi
669            else
670                PROCESSUS_NUMBER=1
671            fi
672        fi
673        # Verification with PBS parameter
674        if [ ${BATCH_NUM_PROC_TOT} -ne ${PROCESSUS_NUMBER} ] ; then
675            echo "Warning with parallelization parameters !"
676            echo "Job header variable BATCH_NUM_PROC_TOT = ${BATCH_NUM_PROC_TOT} "
677            echo "is the total number of _processors_ reserved."
678            echo "It is not equal to the sum of _processus_  = ${PROCESSUS_NUMBER}."
679            echo "We stop now."
680            exit 1
681        fi
682
683    else # BATCH_NUM_PROC_TOT=""
684        if ( ${OK_PARA_MPI} ) ; then
685            echo "You have not given a value of ${BATCH_NUM_PROC_TOT} processors,"
686            echo "but you have filled the parallel parameter in config->Executable->list."
687            echo "Please add BATCH_NUM_PROC_TOT variable in job header."
688            echo "We stop now."
689            exit 1
690        else
691        # sequential case !
692            if [ ${PROCESSUS_NUMBER} -eq 0 ] ; then
693               (( PROCESSUS_NUMBER = 1 ))
694               echo "PROCESSUS_NUMBER is all 0 (sequential use of old definition in config->Executable->list)."
695               echo "We set it to 1."
696            fi
697        fi
698    fi
699
700    IGCM_debug_Print 1 "MPI/OMP treatment PROCESSUS_NUMBER = ${PROCESSUS_NUMBER}"
701
702#     if ( ${OK_PARA_MPI} || ${OK_PARA_OMP} || ${OK_PARA_NOD} ) ; then
703    IGCM_sys_build_execution_scripts
704#     fi
705
706    ExecutionFail=false
707
708    IGCM_debug_PopStack "IGCM_config_PeriodStart"
709}
710
711#===================================
712function IGCM_config_PeriodEnd
713{
714    IGCM_debug_PushStack "IGCM_config_PeriodEnd"
715
716    echo
717    IGCM_debug_Print 1 "IGCM_config_PeriodEnd"
718    echo
719
720    #==================================#
721    #         Save Job output          #
722    #==================================#
723    IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output}
724    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}"
725
726    IGCM_card_CheckConflict run.card
727    IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/run.card rw
728
729    IGCM_debug_Print 1 "Check components binary : size and creation date"
730
731    typeset LS_comp LS_bin ExeDate ExeCpuLog NextExeSize LastCompExeSize
732    typeset comp i   
733    typeset ExeNameIn ExeNameOut
734
735    #==================================#
736    #        Get last Exe Size         #
737    #==================================#
738
739    (( i=0 ))
740    if ( ${FirstInitialize} ) ; then
741        run_Log_LastExeSize=""
742        for comp in ${config_ListOfComponents[*]} ; do
743            run_Log_LastExeSize[$i]=0
744            (( i=i+1 ))
745        done
746    else
747        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize
748    fi
749    #==================================#
750    #         And Build ExeDate        #
751    #==================================#
752
753    # 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
754    # 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")
755    # 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
756    ExeDate=""
757    NextExeSize="( "
758    (( i=0 ))
759
760    for comp in ${config_ListOfComponents[*]} ; do
761
762        IGCM_debug_Print 3 ${comp}
763
764        eval ExeNameIn=\${config_Executable_${comp}[0]}
765        eval ExeNameOut=\${config_Executable_${comp}[1]}
766        # Only if we really have an executable for the component :
767        if [ X${ExeNameIn} = X\"\" ] ; then
768            # If there is no exe file for this component
769            (( ExeSize=0 ))
770        else
771            eval LS_bin=${R_EXE}/${ExeNameIn}
772            IGCM_sys_FileSize ${LS_bin} ExeSize
773
774            set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} )
775            if [ X${ExeDate} = X ] ; then 
776                # First component exe date
777                ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]}
778            else
779                ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]}
780            fi
781            ExeDate=${ExeDate}_${LS_comp[7]}
782        fi
783
784        if [ ${i} -eq 0 ] ; then
785            # First component
786            NextExeSize="( "${ExeSize}
787        else
788            NextExeSize=${NextExeSize}", "${ExeSize}
789        fi
790        eval LastCompExeSize=${run_Log_LastExeSize[$i]}
791        (( i=i+1 ))
792
793        if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then
794            if ( ${FirstInitialize} ) ; then
795                IGCM_debug_Print 1 "Save first ${ExeNameIn} in ${R_OUT_EXE} !"
796            else
797                IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !"
798                IGCM_debug_Print 1 "Save latest ${ExeNameIn} in ${R_OUT_EXE} !"
799                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut}
800            fi
801            eval IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw
802        fi
803    done
804
805    NextExeSize=${NextExeSize}" )"
806    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}"
807
808    if [ ${DRYRUN} -le 1 ] ; then
809        tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt
810        ExeCpuLog=$( gawk -f ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt )
811        RET=$?
812        if [ $RET -eq 0 ] ; then
813            # ExeCpuLog variable contents 5 fields
814            echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" |   \
815             gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \
816                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card
817        fi
818        eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}_tail.txt"
819    fi
820
821    # All was right ? no ? then we stop.
822    IGCM_debug_Verif_Exit
823
824    # If all was OK, we can delete all files not necessary for next Job
825    echo
826    IGCM_debug_Print 1 "Files that will be deleted before next period-run : "
827
828    if [ ${DRYRUN} -le 2 ] ; then
829        for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done
830    else
831        echo ${FileToBeDeleted[@]}
832    fi
833
834    #=================================================#
835    #         Modification of libIGCM behaviour       #
836    #=================================================#
837
838    # To use this function, one must copy libIGCM.card from ${libIGCM} directory
839    # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card,
840    # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop.
841    if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then
842        echo
843        echo "########################################################################"
844        echo "!!!                 Modification of libIGCM behaviour                !!!"
845        echo
846
847        IGCM_debug_Print 1 "DefineArrayFromOption  : libIGCM_UserChanges in libIGCM.card"
848        IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges
849        IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]}
850
851        # Special treatments for libIGCM internals
852        for option in ${libIGCM_UserChanges[*]} ; do
853            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option}
854
855            echo "We will change : ${option}."
856            eval echo "Previous value : " \${${option}}
857            eval echo "Change to : " \${libIGCM_UserChanges_${option}}
858           
859            eval ${option}=\${libIGCM_UserChanges_${option}}
860
861            case ${option} in
862                config_UserChoices_DateEnd)
863                    IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd
864                    DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
865
866                    # Period Length In Days between DateBegin and DateEnd
867                    (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
868                    if [ ${ExperienceLengthInDays} -lt 0 ] ; then
869                        IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that."
870                        IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates."
871                        IGCM_debug_Verif_Exit
872                    fi
873                    ;;
874                config_UserChoices_PeriodLength)
875                    IGCM_debug_Print 1  "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}"
876                    ;;
877                PeriodNb)
878                    IGCM_debug_Print 1  "Loop in main Job with ${PeriodNb} period(s)"
879                    ;;
880                config_Post_RebuildFrequency)
881                    IGCM_debug_Print 1  "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure"
882                    IGCM_post_Configure
883                    ;;
884                config_Post_TimeSeriesFrequency)
885                    IGCM_debug_Print 1  "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Initialize"
886                    IGCM_post_Configure
887                    ;;
888                config_Post_SeasonalFrequency)
889                    IGCM_debug_Print 1  "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Initialize"
890                    IGCM_post_Configure
891                    ;;
892            esac
893        done
894
895        echo
896        echo "########################################################################"
897        echo
898    fi
899
900    #=================================================#
901    #         Determine next computed period          #
902    #=================================================#
903
904    PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 )
905    IGCM_date_GetYearMonth $PeriodDateBegin year month
906    year_m1=$(( year - 1 ))
907    year_p1=$(( year + 1 ))
908    IGCM_config_Analyse_PeriodLength
909    PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) )
910
911    # Debug Print :
912    echo
913    IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution"
914    IGCM_debug_Print 1 "PeriodDateBegin       : ${PeriodDateBegin}"
915    IGCM_debug_Print 1 "PeriodDateEnd         : ${PeriodDateEnd}"
916    IGCM_debug_Print 1 "PeriodLengthInDays    : ${PeriodLengthInDays}"
917
918    PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} )
919    PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} )
920
921    (( CumulPeriod = CumulPeriod + 1 ))
922
923    # Debug Print :
924    echo
925    IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}"
926    IGCM_debug_Print 3 "PeriodDateEnd Human   : ${PeriodDateEnd}"
927    IGCM_debug_Print 3 "CumulPeriod           : ${CumulPeriod}"
928
929    #=================================================#
930    #             Write updated run.card              #
931    #=================================================#
932
933    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix}
934    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
935    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
936    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
937
938    if ( ${FirstInitialize} ) ; then
939        # It's no more the first time
940        FirstInitialize=false
941    fi
942
943    IGCM_debug_PopStack "IGCM_config_PeriodEnd"
944}
945
946#===================================
947function IGCM_config_Finalize
948{
949    IGCM_debug_PushStack "IGCM_config_Finalize"
950
951    echo
952    IGCM_debug_Print 1 "IGCM_config_Finalize"
953    echo
954
955    if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then
956        #==========================#
957        # End of entire simulation #
958        #==========================#
959
960        # Mail notification
961        IGCM_sys_SendMail
962
963        #
964        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed"
965        IGCM_debug_Print 1 "Normal End of computation."
966        if ( $DEBUG_debug ) ; then
967            echo
968            IGCM_debug_Print 1 "Your files on ${R_OUT} :"
969            IGCM_sys_Tree ${R_SAVE}
970        fi
971    else
972        #=================#
973        # Submit next job #
974        #=================#
975
976        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
977
978        # Name of next Ksh Script output :
979        eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )"
980
981        IGCM_debug_Print 1 "Submit next job"
982        # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR
983        IGCM_sys_Cd ${SUBMIT_DIR}
984        # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName}
985        ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l )
986        [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) )
987        # Submit next job and come back
988        IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}
989        IGCM_sys_Cd -
990    fi
991
992    # Supress Non Deleted Boundary files
993    if [ ${DRYRUN} -le 2 ] ; then
994        IGCM_comp_DelFixeBoundaryFiles
995        ls -la
996    fi
997   
998    # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
999    # Only for production run (No clean up in DEV or DEB mode)
1000    # and command sent from .. directory.
1001    IGCM_sys_Cd ..
1002    [ X${JobType} = XRUN ] && IGCM_sys_Rm -rf ${RUN_DIR}
1003
1004    IGCM_debug_PopStack "IGCM_config_Finalize"
1005}
1006
1007#===================================
Note: See TracBrowser for help on using the repository browser.