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

Last change on this file since 28 was 28, checked in by sdipsl, 16 years ago

SD,MM : - Merging partly branch AllPostFred? with trunk.

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