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

Last change on this file since 365 was 365, checked in by mmaipsl, 14 years ago

make some i variables local to there subroutines.

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