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

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

To keep compatibility with existing config.card we don't read predefined option.
Thanks to NEMO team for testing.

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