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

Last change on this file since 108 was 108, checked in by sdipsl, 15 years ago

May be last touch before tag 1.3

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