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

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

Test only $R_IN for existence - and no more R_INIT and R_BC - because it is defined in sys library.

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