source: tags/libIGCM_v1_3/libIGCM_config/libIGCM_config.ksh @ 803

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

Bypass a little bug filling ${FileToBeDeleted?}. Parameter files may be recorded twice. No big deal.

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