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

Last change on this file since 457 was 457, checked in by sdipsl, 13 years ago
  • Bugfix on titane. Exe files has never been saved and ExeFileSize? in the run.card has always been false. Due to ExeSize? variable scope, decalare local to a function but assigned in another function. It works by chance on some machine, because ExeSize? is not initialized...
  • Bugfix of the revision [433]. out_orchidee was always save in SUBMIT_DIR.
  • Now if a job fail : all concatenated debug files (OutputTextFiles?) will be place in SUBMIT_DIR/Debug for convenience.
  • Continuation of [431], concatenate text files following numerical instead of alphabetical order. MAF.
  • Cosmetic and verbosty has been revisited.
  • 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: 32.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    else
31        FirstInitialize=false
32    fi
33
34    # Test modipsl tree existence.
35    IGCM_sys_TestDir ${MODIPSL}
36    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
37    IGCM_sys_TestDir ${libIGCM}
38    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
39    IGCM_sys_TestDir ${R_EXE}
40    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
41    IGCM_sys_TestDir ${SUBMIT_DIR}
42    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
43
44    if ( $DEBUG_debug ) ; then
45        echo "Keep trace of inital SUBMIT_DIR : "
46        ls -lta ${SUBMIT_DIR}
47    fi
48
49    #==================================
50
51    typeset option auxprint CompatibilityTag
52    # Read libIGCM compatibility version in config.card
53    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Compatibility libIGCM
54    eval CompatibilityTag=${config_Compatibility_libIGCM} > /dev/null 2>&1     
55
56    if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then
57        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 ."
58    fi
59
60    #==================================
61    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices
62
63    for option in ${config_UserChoices[*]} ; do
64        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option}
65    done
66    echo
67    IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
68    # Name Space of this experience
69    if [ X${config_UserChoices_SpaceName} != X ] ; then
70        IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName
71    fi
72    # Expericence class of the run
73    if [ X${config_UserChoices_ExperimentName} != X ] ; then
74        IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName
75    fi
76    IGCM_debug_PrintVariables 3 config_UserChoices_JobName
77    if [ 3 -le ${Verbosity} ] ; then
78        echo "--------------Debug3-->" "config_UserChoices_LongName="
79        echo "--------------Debug3-->" \"${config_UserChoices_LongName}\"
80    fi
81    IGCM_debug_PrintVariables 3 config_UserChoices_TagName
82    IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
83    IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
84    IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
85    IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
86
87    #==================================
88
89    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents
90
91    echo
92    IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
93    IGCM_debug_Print 3 ${config_ListOfComponents[*]}
94
95    NbComponents=${#config_ListOfComponents[*]}
96
97    #==================================
98    # Define principal executable
99
100    IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable
101    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Executable Name
102   
103    #==================================
104    # Define Outputs Name
105    IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output"
106    eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'}
107    IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}"
108    eval Exe_Output=out_${config_Executable_Name}
109    IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}"
110
111    #==================================
112
113    #===================================================================#
114    # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
115    #             But available to any son functions                    #
116    #===================================================================#
117
118    # Convert yyyy-mm-dd date to gregorian yyyymmdd
119    DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
120    DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
121
122    # Period Length In Days between DateBegin and DateEnd
123    (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
124    if [ ${ExperienceLengthInDays} -lt 0 ] ; then
125        IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that."
126        IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates."
127        IGCM_debug_Verif_Exit
128    fi
129
130    # Day and Year of Initial State (Given in julian format)
131    InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 ))
132    InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 ))
133
134    #==================================
135    # Restarts : Gerneral rule or local for each component ?
136    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts
137
138    echo
139    IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts"
140
141    for option in ${config_Restarts[*]} ; do
142        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option}
143        eval auxprint=\${config_Restarts_${option}}
144        IGCM_debug_Print 3 "${option} : ${auxprint}"
145    done
146
147    #================================================================#
148    #                  Test and Prepare directories                  #
149    #================================================================#
150
151    # ==> 4 kinds of input files :
152    #     1) R_INIT  : Initial State Files   (Etat0, carteveg)
153    #     2) R_BC    : Boundary Conditions   (Forcages, lai)
154    #     3) Parameters files (allready define through ${SUBMIT_DIR})
155    #     4) Restarts files   (allready define in IGCM_config_Initialize)
156
157    # Here we offer the possibility to redefine R_INIT, R_BC
158    # and PeriodNb through config.card
159    R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT}
160    IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb"
161    IGCM_debug_Print 3 "R_INIT=${R_INIT}"
162    R_BC=${config_UserChoices_R_BC:=${R_IN}/BC}
163    IGCM_debug_Print 3  "R_BC=${R_BC}"
164    PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}}
165    IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)"
166
167    # Test Archive input/output.
168    IGCM_sys_TestDirArchive ${ARCHIVE}
169    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
170    IGCM_sys_TestDirArchive ${R_IN}
171    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
172
173    #====================================================
174    #R_SAVE : Job output directory
175    if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
176        FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
177        R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
178        R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
179    else
180        R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
181        R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName}
182    fi
183
184    if ( ${FirstInitialize} ) ; then
185        IGCM_sys_MkdirArchive ${R_SAVE}
186    else
187        IGCM_sys_TestDirArchive ${R_SAVE}
188        [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
189        #Test state of run in run.card
190        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
191       
192        if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
193            echo
194            IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
195            IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this"
196            IGCM_debug_Exit
197            IGCM_debug_Verif_Exit
198        fi
199    fi
200
201    #==================================
202    # Post :
203    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post
204
205    echo
206    IGCM_debug_Print 1 "DefineArrayFromOption : config_Post"
207
208    for option in ${config_Post[*]} ; do
209        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option}
210        eval auxprint=\${config_Post_${option}}
211        IGCM_debug_Print 3 "${option} : ${auxprint}"
212    done
213
214    #====================================================
215    # Define REBUILD_DIR : where we store files needing rebuild process
216    if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
217        REBUILD_DIR=${R_SAVE}/TMP
218        IGCM_sys_MkdirArchive ${REBUILD_DIR}
219    else
220        REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
221        IGCM_sys_MkdirWork ${REBUILD_DIR}
222    fi
223
224    #====================================================
225    # Experience type : DEB(ug), DEV(elopment), RUN
226    if [ X${JobType} != XRUN ] ; then
227        echo
228        echo "===================================================="
229        echo "libIGCM JOB is NOT in RUN type mode."
230        echo "!! OUTPUT files will NOT be PROTECTED !!"
231        echo "Be carefull : you can ERASE the result of this job !"
232
233        case ${JobType} in
234            DEB)
235                echo "DEBUG mode : activation of 'set -vx' mode."
236                echo "DEBUG mode : no protection for output files."
237                echo "DEBUG mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
238                ;;
239            DEV)
240                echo "DEVelopment mode : no protection for output files."
241                echo "DEVelopment mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
242                ;;
243        esac
244
245        if ( [ X${config_Post_RebuildFrequency} != XNONE ] && [ ${DRYRUN} -eq 0 ] ) ; then
246            if [ X${config_Post_RebuildFrequency} != X${config_UserChoices_PeriodLength} ] ; then
247                echo "------------"
248                echo "WARNING : Job is NOT in RUN mode then we will force REBUILD Frequency"
249                echo "          to PeriodLength : ${config_UserChoices_PeriodLength}"
250                echo "------------"
251                config_Post_RebuildFrequency=${config_UserChoices_PeriodLength}
252            fi
253        fi
254        echo "===================================================="
255        echo
256    fi
257
258    #====================================================
259    #R_OUT_KSH : Storage place for job output
260    #R_OUT_EXE : Storage place for binary used during simulation
261    R_OUT_KSH=${R_SAVE}/Out
262    R_OUT_EXE=${R_SAVE}/Exe
263
264    IGCM_debug_PopStack "IGCM_config_Initialize"
265}
266
267#===================================
268function IGCM_config_Analyse_PeriodLength
269{
270    IGCM_debug_PushStack "IGCM_config_Analyse_PeriodLength"
271
272    typeset i
273
274    # Determine number of day(s) in PeriodLength :
275    case ${config_UserChoices_PeriodLength} in
276        *Y|*y)
277            PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' ) 
278            IGCM_debug_Print 2 "Number of years for PeriodLength : ${PeriodLengthInYears}"
279            PeriodLengthInDays=0
280            i=0
281            until [ $i -ge $PeriodLengthInYears ] ; do 
282                (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) )) 
283                (( i=i+1 )) 
284            done 
285            ;;
286        *M|*m)
287            PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' ) 
288            IGCM_debug_Print 2 "Number of months for PeriodLength : ${PeriodLengthInMonths}"
289            PeriodLengthInDays=0
290            i=0
291            until [ $i -ge $PeriodLengthInMonths ] ; do
292                if [ $(( month + i )) -lt 13 ] ; then 
293                    (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 
294                else 
295                    (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 
296                fi 
297                (( i=i+1 )) 
298            done 
299            ;;
300        *D|*d) 
301            PeriodLengthInMonths=0
302            PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' );;
303        *) 
304            IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D."
305            IGCM_debug_Verif_Exit ;;
306    esac
307
308    IGCM_debug_PopStack "IGCM_config_Analyse_PeriodLength"
309}
310
311#===================================
312function IGCM_config_Check
313{
314    IGCM_debug_PushStack "IGCM_config_Check"
315
316    # If one of the following modulo is not zero :
317    # we will issue an error then explain and exit in
318    # AA_job IGCM_debug_Verif_Exit call before binary submission
319
320    echo
321    IGCM_debug_Print 1 "IGCM_config_Check"
322    echo
323
324    typeset i
325
326    if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
327        AsynchronousRebuild=true
328        IGCM_debug_Print 1 "Asynchronous rebuild has been activated."
329        echo
330        # modulo (RebuildFrequency and PeriodLength/TimeSeriesFrequency/SeasonalFrequency) must be zero
331        IGCM_debug_Print 1 "Check coherence between RebuildFrequency and PeriodLength"
332        IGCM_post_CheckModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength
333        IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and RebuildFrequency"
334        IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_RebuildFrequency
335        IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and RebuildFrequency"
336        IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_RebuildFrequency
337    else
338        AsynchronousRebuild=false
339        IGCM_debug_Print 1 "Asynchronous rebuild has not been activated"
340        IGCM_debug_Print 1 "Proceed with standard post-treatment pathway"
341        echo
342        #modulo (TimeSeriesFrequency/SeasonalFrequency and PeriodLenght) must be zero
343        IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PeriodLength"
344        IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_UserChoices_PeriodLength
345        IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PeriodLength"
346        IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency   config_UserChoices_PeriodLength
347    fi
348
349    #modulo (TimeSeriesFrequency and all Chunck2D) must be zero
350    NbJob=${#CHUNCK2D_SIZE[@]}
351    i=0
352    until [ $i -ge $NbJob ]; do
353        value=${CHUNCK2D_SIZE[${i}]}
354        IGCM_debug_Print 1 "Check coherence between All Chunck2D frequency and TimeSeriesFrequency"
355        IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
356        case ${value} in 
357            *Y|*y) ;;
358            *)  IGCM_debug_Print 1 "All ChunckJob2D frequency must be expressed in year *Y|*y in comp.card"
359                IGCM_debug_Exit "This will stop the job" ;;
360        esac
361        (( i=i+1 ))
362    done
363
364    #modulo (TimeSeriesFrequency and all Chunck3D) must be zero
365    NbJob=${#CHUNCK3D_SIZE[@]}
366    i=0
367    until [ $i -ge $NbJob ]; do
368        value=${CHUNCK3D_SIZE[${i}]}
369        IGCM_debug_Print 1 "Check coherence between All Chunck3D frequency and TimeSeriesFrequency"
370        IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
371        case ${value} in 
372            *Y|*y) ;;
373            *)  IGCM_debug_Print 1 "All ChunckJob3D frequency must be expressed in year *Y|*y in comp.card"
374                IGCM_debug_Exit "This will stop the job" ;;
375        esac
376        (( i=i+1 ))
377    done
378
379    IGCM_debug_PopStack "IGCM_config_Check"
380}
381
382#===================================
383function IGCM_config_PeriodStart
384{
385    IGCM_debug_PushStack "IGCM_config_PeriodStart"
386
387    echo
388    IGCM_debug_Print 1 "IGCM_config_PeriodStart"
389    echo
390
391    if ( ${FirstInitialize} ) ; then
392        #================================================#
393        #         Initialize date/period information     #
394        #================================================#
395
396        IGCM_date_GetYearMonth $DateBegin year month
397        year_m1=$(( year - 1 ))
398        year_p1=$(( year + 1 )) 
399        IGCM_config_Analyse_PeriodLength
400
401        eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1
402        PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) )
403        eval CumulPeriod=1 > /dev/null 2>&1
404
405        #=================================================#
406        #              Write updated run.card             #
407        #=================================================#
408
409        #Correct run.card Configuration for this period
410        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
411        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
412        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
413        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration SubmitPath ${SUBMIT_DIR}
414
415        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
416 
417    else
418        #================================================#
419        #         The file run.card allready exist       #
420        #================================================#
421
422        #Test state of run in run.card
423        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
424        if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
425            echo
426            IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
427            IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this"
428            echo
429            IGCM_debug_Exit
430            IGCM_debug_Verif_Exit
431        fi
432
433        #===================================#
434        #        Read updated run.card      #
435        #===================================#
436
437        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
438        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
439        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
440        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
441
442        PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
443        PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
444        eval CumulPeriod="${run_Configuration_CumulPeriod}" > /dev/null 2>&1
445
446        if [ ${Period} = 1 ]; then
447           # save last Job output
448            typeset LastPeriod iLastPeriod Last_Script_Output_Name
449            (( LastPeriod=CumulPeriod-PeriodNb ))
450            iLastPeriod=$( printf "%06d" ${LastPeriod} )
451            Last_Script_Output_Name="${Script_Output_Prefix}_${config_UserChoices_JobName}.${iLastPeriod}"
452            Last_run_card="run.card.${iLastPeriod}"
453            #eval ls -l ${SUBMIT_DIR}/${Last_Script_Output_Name}
454            #eval IGCM_sys_Put_Out ${SUBMIT_DIR}/${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name} > /dev/null 2>&1
455            IGCM_debug_Print 2 "Try to save previous ksh job output"
456            IGCM_sys_Cd ${SUBMIT_DIR}/
457            IGCM_sys_Put_Out ${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name}.$$ rw
458            IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/${Last_run_card}.$$ rw
459            IGCM_sys_Cd ${RUN_DIR}
460        else
461            unset FileToBeDeleted
462        fi
463
464        IGCM_date_GetYearMonth $PeriodDateBegin year month
465        year_m1=$(( year - 1 ))
466        year_p1=$(( year + 1 )) 
467        IGCM_config_Analyse_PeriodLength
468
469        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
470
471    fi   
472    OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd}
473 
474    #===================================================================#
475    # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
476    #             But available to any son functions                    #
477    #===================================================================#
478
479    # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !)
480    (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 ))
481
482    # Debug Print :
483    IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution"
484    IGCM_debug_Print 1 "Year of simulation      : ${year}"
485    IGCM_debug_Print 1 "Month of simulation     : ${month}"
486    IGCM_debug_Print 1 "PeriodLengthInDays      : ${PeriodLengthInDays}"
487    IGCM_debug_Print 1 "PeriodDateBegin         : ${PeriodDateBegin}"
488    IGCM_debug_Print 1 "PeriodDateEnd           : ${PeriodDateEnd}"
489    IGCM_debug_Print 1 "SimulationLengthInDays  : ${SimulationLengthInDays}"
490    IGCM_debug_Print 1 "ExperienceLengthInDays  : ${ExperienceLengthInDays}"
491
492    #================================================================#
493    #         Prepare variables available for comp_finalyze          #
494    #================================================================#
495
496    # Period for save files
497    eval DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd} > /dev/null 2>&1
498
499    # Prefix for save files of this period
500    eval PREFIX=${config_UserChoices_JobName}_${DatesPeriod}  > /dev/null 2>&1
501
502    # List of files that will be deleted in RUN_DIR after run
503    [ -f stack ] && FileToBeDeleted[0]="stack"
504
505    # Test if the same run as already been saved :
506    if [ X${JobType} = XRUN ] ; then
507        if [ ${DRYRUN} -le 0 ] ; then
508            if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then
509                IGCM_debug_Exit "IGCM_config_PeriodStart" "You are currently RErunning an old job."
510                IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files"
511                IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or "
512                IGCM_debug_Print 1 " the whole ${R_SAVE} tree. See clean_month.job in ${libIGCM} directory."
513                IGCM_debug_Print 1 " This exit has been initiated because at least ${R_OUT_KSH}/${PREFIX}_${Exe_Output} exists."
514                IGCM_debug_Verif_Exit
515            fi
516        fi
517    else
518        if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then
519            IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. Allowed in DEBUG or DEV mode."
520        fi
521    fi
522
523    IGCM_debug_PopStack "IGCM_config_PeriodStart"
524}
525
526#===================================
527function IGCM_config_PeriodEnd
528{
529    IGCM_debug_PushStack "IGCM_config_PeriodEnd"
530
531    echo
532    IGCM_debug_Print 1 "IGCM_config_PeriodEnd"
533    echo
534
535    #==================================#
536    #         Save Job output          #
537    #==================================#
538    IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output}
539    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}"
540    IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/run.card rw
541
542    IGCM_debug_Print 1 "Check components binary : size and creation date"
543
544    typeset LS_comp LS_bin ExeDate ExeCpuLog NextExeSize LastCompExeSize
545    typeset comp i   
546    typeset ExeNameIn ExeNameOut
547
548    #==================================#
549    #        Get last Exe Size         #
550    #==================================#
551
552    (( i=0 ))
553    if ( ${FirstInitialize} ) ; then
554        run_Log_LastExeSize=""
555        for comp in ${config_ListOfComponents[*]} ; do
556            run_Log_LastExeSize[$i]=0
557            (( i=i+1 ))
558        done
559    else
560        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize
561    fi
562    #==================================#
563    #         And Build ExeDate        #
564    #==================================#
565
566    # 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
567    # 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")
568    # 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
569    ExeDate=""
570    NextExeSize="( "
571    (( i=0 ))
572
573    for comp in ${config_ListOfComponents[*]} ; do
574
575        IGCM_debug_Print 3 ${comp}
576
577        eval ExeNameIn=\${config_Executable_${comp}[0]}
578        eval ExeNameOut=\${config_Executable_${comp}[1]}
579        # Only if we really have an executable for the component :
580        if [ X${ExeNameIn} = X\"\" ] ; then
581            # If there is no exe file for this component
582            (( ExeSize=0 ))
583        else
584            eval LS_bin=${R_EXE}/${ExeNameIn}
585            IGCM_sys_FileSize ${LS_bin} ExeSize
586
587            set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} )
588            if [ X${ExeDate} = X ] ; then 
589                # First component exe date
590                ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]}
591            else
592                ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]}
593            fi
594            ExeDate=${ExeDate}_${LS_comp[7]}
595        fi
596
597        if [ ${i} -eq 0 ] ; then
598            # First component
599            NextExeSize="( "${ExeSize}
600        else
601            NextExeSize=${NextExeSize}", "${ExeSize}
602        fi
603        eval LastCompExeSize=${run_Log_LastExeSize[$i]}
604        (( i=i+1 ))
605
606        if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then
607            if ( ${FirstInitialize} ) ; then
608                IGCM_debug_Print 1 "Save first ${ExeNameIn} in ${R_OUT_EXE} !"
609            else
610                IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !"
611                IGCM_debug_Print 1 "Save latest ${ExeNameIn} in ${R_OUT_EXE} !"
612                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut}
613            fi
614            eval IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw
615        fi
616    done
617
618    NextExeSize=${NextExeSize}" )"
619    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}"
620
621    if [ ${DRYRUN} -le 1 ] ; then
622        tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt
623        ExeCpuLog=$( gawk -f ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt )
624        RET=$?
625        if [ $RET -eq 0 ] ; then
626            # ExeCpuLog variable contents 5 fields
627            echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" |   \
628             gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \
629                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card
630        fi
631        eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}_tail.txt"
632    fi
633
634    # All was right ? no ? then we stop.
635    IGCM_debug_Verif_Exit
636
637    # If all was OK, we can delete all files not necessary for next Job
638    echo
639    IGCM_debug_Print 1 "Files that will be deleted before next period-run : "
640
641    if [ ${DRYRUN} -le 2 ] ; then
642        for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done
643    else
644        echo ${FileToBeDeleted[@]}
645    fi
646
647    #=================================================#
648    #         Modification of libIGCM behaviour       #
649    #=================================================#
650
651    # To use this function, one must copy libIGCM.card from ${libIGCM} directory
652    # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card,
653    # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop.
654    if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then
655        echo
656        echo "########################################################################"
657        echo "!!!                 Modification of libIGCM behaviour                !!!"
658        echo
659
660        IGCM_debug_Print 1 "DefineArrayFromOption  : libIGCM_UserChanges in libIGCM.card"
661        IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges
662        IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]}
663
664        # Special treatments for libIGCM internals
665        for option in ${libIGCM_UserChanges[*]} ; do
666            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option}
667
668            echo "We will change : ${option}."
669            eval echo "Previous value : " \${${option}}
670            eval echo "Change to : " \${libIGCM_UserChanges_${option}}
671           
672            eval ${option}=\${libIGCM_UserChanges_${option}}
673
674            case ${option} in
675                config_UserChoices_DateEnd)
676                    IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd
677                    DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
678
679                    # Period Length In Days between DateBegin and DateEnd
680                    (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
681                    if [ ${ExperienceLengthInDays} -lt 0 ] ; then
682                        IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that."
683                        IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates."
684                        IGCM_debug_Verif_Exit
685                    fi
686                    ;;
687                config_UserChoices_PeriodLength)
688                    IGCM_debug_Print 1  "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}"
689                    ;;
690                PeriodNb)
691                    IGCM_debug_Print 1  "Loop in main Job with ${PeriodNb} period(s)"
692                    ;;
693                config_Post_RebuildFrequency)
694                    IGCM_debug_Print 1  "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure"
695                    IGCM_post_Configure
696                    ;;
697                config_Post_TimeSeriesFrequency)
698                    IGCM_debug_Print 1  "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Initialize"
699                    IGCM_post_Configure
700                    ;;
701                config_Post_SeasonalFrequency)
702                    IGCM_debug_Print 1  "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Initialize"
703                    IGCM_post_Configure
704                    ;;
705            esac
706        done
707
708        echo
709        echo "########################################################################"
710        echo
711    fi
712
713    #=================================================#
714    #         Determine next computed period          #
715    #=================================================#
716
717    PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 )
718    IGCM_date_GetYearMonth $PeriodDateBegin year month
719    year_m1=$(( year - 1 ))
720    year_p1=$(( year + 1 ))
721    IGCM_config_Analyse_PeriodLength
722    PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) )
723
724    # Debug Print :
725    echo
726    IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution"
727    IGCM_debug_Print 1 "PeriodDateBegin       : ${PeriodDateBegin}"
728    IGCM_debug_Print 1 "PeriodDateEnd         : ${PeriodDateEnd}"
729    IGCM_debug_Print 1 "PeriodLengthInDays    : ${PeriodLengthInDays}"
730
731    PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} )
732    PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} )
733
734    (( CumulPeriod = CumulPeriod + 1 ))
735
736    # Debug Print :
737    echo
738    IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}"
739    IGCM_debug_Print 3 "PeriodDateEnd Human   : ${PeriodDateEnd}"
740    IGCM_debug_Print 3 "CumulPeriod           : ${CumulPeriod}"
741
742    #=================================================#
743    #             Write updated run.card              #
744    #=================================================#
745
746    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix}
747    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
748    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
749    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
750
751    if ( ${FirstInitialize} ) ; then
752        # It's no more the first time
753        FirstInitialize=false
754    fi
755
756    IGCM_debug_PopStack "IGCM_config_PeriodEnd"
757}
758
759#===================================
760function IGCM_config_Finalize
761{
762    IGCM_debug_PushStack "IGCM_config_Finalize"
763
764    echo
765    IGCM_debug_Print 1 "IGCM_config_Finalize"
766    echo
767
768    if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then
769        #==========================#
770        # End of entire simulation #
771        #==========================#
772
773        # Mail notification
774        IGCM_sys_SendMail
775
776        #
777        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed"
778        IGCM_debug_Print 1 "Normal End of computation."
779        if ( $DEBUG_debug ) ; then
780            echo
781            IGCM_debug_Print 1 "Your files on ${R_OUT} :"
782            IGCM_sys_Tree ${R_SAVE}
783        fi
784    else
785        #=================#
786        # Submit next job #
787        #=================#
788
789        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
790
791        # Name of next Ksh Script output :
792        eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )"
793
794        IGCM_debug_Print 1 "Submit next job"
795        # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR
796        IGCM_sys_Cd ${SUBMIT_DIR}
797        # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName}
798        ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l )
799        [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) )
800        # Submit next job and come back
801        IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}
802        IGCM_sys_Cd -
803    fi
804
805    # Supress Non Deleted Boundary files
806    if [ ${DRYRUN} -le 2 ] ; then
807        IGCM_comp_DelFixeBoundaryFiles
808        ls -la
809    fi
810   
811    # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
812    # Only for production run (No clean up in DEV or DEB mode)
813    # and command sent from .. directory.
814    IGCM_sys_Cd ..
815    [ X${JobType} = XRUN ] && IGCM_sys_Rm -rf ${RUN_DIR}
816
817    IGCM_debug_PopStack "IGCM_config_Finalize"
818}
819
820#===================================
Note: See TracBrowser for help on using the repository browser.