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

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

libIGCM is ready for ulam except concerning the monitoring

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