source: branches/AllPostFred/libIGCM_config/libIGCM_config.ksh @ 10

Last change on this file since 10 was 10, checked in by mmaipsl, 16 years ago

MM: All frequencies in post-treatement.

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