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

Last change on this file since 121 was 121, checked in by mmaipsl, 15 years ago

Add "uname -a" to know where we have run.
Never use IGCM_post_Initialize now, always IGCM_post_Configure.

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