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

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

Correct a bug in last definition of year minus and plus one, sorry.

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