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

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

SD : - 2 options for asynchronous rebuild

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