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

Last change on this file since 145 was 144, checked in by mmaipsl, 15 years ago

Add a ls of SUBMIT_DIR on the beginning of the job if DEBUG_debug is true.
Correct the bug of the print of config_UserChoices_LongName.

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