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

Last change on this file since 478 was 473, checked in by mmaipsl, 13 years ago

Backward compatibility :

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