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

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