source: tags/libIGCM_v1_12/libIGCM_config/libIGCM_config.ksh @ 1435

Last change on this file since 1435 was 576, checked in by mafoipsl, 12 years ago

jgipsl : to allow ListOfComponents? known by driver.

  • 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 Revision Author Date
File size: 34.3 KB
RevLine 
[2]1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
[373]5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
[2]9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#===================================
15function IGCM_config_Initialize
16{
17    IGCM_debug_PushStack "IGCM_config_Initialize"
18
19    # Debug Print :
20    echo
[457]21    IGCM_debug_Print 1 "IGCM_config_Initialize"
[2]22
[443]23    if [ ! -r ${SUBMIT_DIR}/run.card ]; then 
24        #================================================#
25        #         The file run.card doesn't exist        #
26        #================================================#
27        FirstInitialize=true
28        #copy initial run.card
29        IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${SUBMIT_DIR}/run.card
[466]30        IGCM_debug_Print 2 "run.card copied from run.card.init"
[443]31    else
32        FirstInitialize=false
[466]33        IGCM_debug_Print 2 "run.card exists"
[443]34    fi
35
[2]36    # Test modipsl tree existence.
37    IGCM_sys_TestDir ${MODIPSL}
[466]38    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
[2]39    IGCM_sys_TestDir ${libIGCM}
[466]40    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
[2]41    IGCM_sys_TestDir ${R_EXE}
[466]42    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
[2]43    IGCM_sys_TestDir ${SUBMIT_DIR}
[466]44    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
[2]45
[144]46    if ( $DEBUG_debug ) ; then
47        echo "Keep trace of inital SUBMIT_DIR : "
48        ls -lta ${SUBMIT_DIR}
49    fi
50
[2]51    #==================================
52
53    typeset option auxprint CompatibilityTag
54    # Read libIGCM compatibility version in config.card
55    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Compatibility libIGCM
56    eval CompatibilityTag=${config_Compatibility_libIGCM} > /dev/null 2>&1     
57
58    if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then
59        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 ."
60    fi
61
62    #==================================
63    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices
64
65    for option in ${config_UserChoices[*]} ; do
66        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option}
67    done
[457]68    echo
[2]69    IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
[341]70    # Name Space of this experience
71    if [ X${config_UserChoices_SpaceName} != X ] ; then
72        IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName
73    fi
74    # Expericence class of the run
75    if [ X${config_UserChoices_ExperimentName} != X ] ; then
76        IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName
77    fi
[2]78    IGCM_debug_PrintVariables 3 config_UserChoices_JobName
[144]79    if [ 3 -le ${Verbosity} ] ; then
80        echo "--------------Debug3-->" "config_UserChoices_LongName="
81        echo "--------------Debug3-->" \"${config_UserChoices_LongName}\"
82    fi
[2]83    IGCM_debug_PrintVariables 3 config_UserChoices_TagName
84    IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
85    IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
86    IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
87    IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
88
89    #==================================
90
91    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents
[576]92    for comp in ${config_ListOfComponents[*]} ; do
93        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
94    done
[2]95
96    echo
97    IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
98    IGCM_debug_Print 3 ${config_ListOfComponents[*]}
99
100    NbComponents=${#config_ListOfComponents[*]}
101
102    #==================================
103    # Define principal executable
104
105    IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable
106    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Executable Name
107   
108    #==================================
109    # Define Outputs Name
[457]110    IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output"
[2]111    eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'}
112    IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}"
113    eval Exe_Output=out_${config_Executable_Name}
114    IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}"
115
116    #==================================
117
118    #===================================================================#
119    # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
120    #             But available to any son functions                    #
121    #===================================================================#
122
123    # Convert yyyy-mm-dd date to gregorian yyyymmdd
124    DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
125    DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
126
127    # Period Length In Days between DateBegin and DateEnd
128    (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
129    if [ ${ExperienceLengthInDays} -lt 0 ] ; then
130        IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that."
131        IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates."
132        IGCM_debug_Verif_Exit
133    fi
134
135    # Day and Year of Initial State (Given in julian format)
[146]136    InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 ))
137    InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 ))
[2]138
139    #==================================
140    # Restarts : Gerneral rule or local for each component ?
141    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts
142
143    echo
144    IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts"
145
146    for option in ${config_Restarts[*]} ; do
147        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option}
148        eval auxprint=\${config_Restarts_${option}}
149        IGCM_debug_Print 3 "${option} : ${auxprint}"
150    done
151
152    #================================================================#
153    #                  Test and Prepare directories                  #
154    #================================================================#
155
156    # ==> 4 kinds of input files :
157    #     1) R_INIT  : Initial State Files   (Etat0, carteveg)
158    #     2) R_BC    : Boundary Conditions   (Forcages, lai)
159    #     3) Parameters files (allready define through ${SUBMIT_DIR})
160    #     4) Restarts files   (allready define in IGCM_config_Initialize)
161
162    # Here we offer the possibility to redefine R_INIT, R_BC
163    # and PeriodNb through config.card
164    R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT}
[457]165    IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb"
[2]166    IGCM_debug_Print 3 "R_INIT=${R_INIT}"
167    R_BC=${config_UserChoices_R_BC:=${R_IN}/BC}
168    IGCM_debug_Print 3  "R_BC=${R_BC}"
169    PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}}
170    IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)"
171
172    # Test Archive input/output.
173    IGCM_sys_TestDirArchive ${ARCHIVE}
[67]174    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
[297]175    IGCM_sys_TestDirArchive ${R_IN}
[67]176    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
[2]177
178    #====================================================
179    #R_SAVE : Job output directory
[263]180    if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
181        FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
182        R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
183        R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
184    else
185        R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
186        R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName}
187    fi
[2]188
[444]189    if ( ${FirstInitialize} ) ; then
[2]190        IGCM_sys_MkdirArchive ${R_SAVE}
191    else
[457]192        IGCM_sys_TestDirArchive ${R_SAVE}
193        [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
[2]194        #Test state of run in run.card
195        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
[457]196       
[2]197        if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
198            echo
[457]199            IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
200            IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this"
201            IGCM_debug_Exit
[2]202            IGCM_debug_Verif_Exit
203        fi
204    fi
205
[146]206    #==================================
207    # Post :
208    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post
209
210    echo
211    IGCM_debug_Print 1 "DefineArrayFromOption : config_Post"
212
213    for option in ${config_Post[*]} ; do
214        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option}
215        eval auxprint=\${config_Post_${option}}
216        IGCM_debug_Print 3 "${option} : ${auxprint}"
217    done
218
[166]219    #====================================================
[146]220    # Define REBUILD_DIR : where we store files needing rebuild process
221    if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then
222        REBUILD_DIR=${R_SAVE}/TMP
223        IGCM_sys_MkdirArchive ${REBUILD_DIR}
224    else
[157]225        REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
226        IGCM_sys_MkdirWork ${REBUILD_DIR}
[146]227    fi
228
[2]229    #====================================================
[128]230    # Experience type : DEB(ug), DEV(elopment), RUN
231    if [ X${JobType} != XRUN ] ; then
232        echo
233        echo "===================================================="
234        echo "libIGCM JOB is NOT in RUN type mode."
235        echo "!! OUTPUT files will NOT be PROTECTED !!"
236        echo "Be carefull : you can ERASE the result of this job !"
237
238        case ${JobType} in
239            DEB)
[166]240                echo "DEBUG mode : activation of 'set -vx' mode."
241                echo "DEBUG mode : no protection for output files."
[196]242                echo "DEBUG mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
[166]243                ;;
[128]244            DEV)
245                echo "DEVelopment mode : no protection for output files."
[196]246                echo "DEVelopment mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
[128]247                ;;
[166]248        esac
249
[427]250        if ( [ X${config_Post_RebuildFrequency} != XNONE ] && [ ${DRYRUN} -eq 0 ] ) ; then
[183]251            if [ X${config_Post_RebuildFrequency} != X${config_UserChoices_PeriodLength} ] ; then
252                echo "------------"
253                echo "WARNING : Job is NOT in RUN mode then we will force REBUILD Frequency"
254                echo "          to PeriodLength : ${config_UserChoices_PeriodLength}"
255                echo "------------"
256                config_Post_RebuildFrequency=${config_UserChoices_PeriodLength}
257            fi
[166]258        fi
[128]259        echo "===================================================="
260        echo
261    fi
262
[166]263    #====================================================
264    #R_OUT_KSH : Storage place for job output
265    #R_OUT_EXE : Storage place for binary used during simulation
266    R_OUT_KSH=${R_SAVE}/Out
267    R_OUT_EXE=${R_SAVE}/Exe
268
[2]269    IGCM_debug_PopStack "IGCM_config_Initialize"
270}
271
272#===================================
[118]273function IGCM_config_Analyse_PeriodLength
274{
275    IGCM_debug_PushStack "IGCM_config_Analyse_PeriodLength"
276
[124]277    typeset i
278
[118]279    # Determine number of day(s) in PeriodLength :
280    case ${config_UserChoices_PeriodLength} in
281        *Y|*y)
[128]282            PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' ) 
[457]283            IGCM_debug_Print 2 "Number of years for PeriodLength : ${PeriodLengthInYears}"
[118]284            PeriodLengthInDays=0
285            i=0
286            until [ $i -ge $PeriodLengthInYears ] ; do 
287                (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) )) 
288                (( i=i+1 )) 
289            done 
290            ;;
291        *M|*m)
[128]292            PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' ) 
[457]293            IGCM_debug_Print 2 "Number of months for PeriodLength : ${PeriodLengthInMonths}"
[118]294            PeriodLengthInDays=0
295            i=0
296            until [ $i -ge $PeriodLengthInMonths ] ; do
297                if [ $(( month + i )) -lt 13 ] ; then 
298                    (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 
299                else 
300                    (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 
301                fi 
302                (( i=i+1 )) 
303            done 
304            ;;
305        *D|*d) 
[128]306            PeriodLengthInMonths=0
307            PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' );;
[118]308        *) 
309            IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D."
310            IGCM_debug_Verif_Exit ;;
311    esac
312
313    IGCM_debug_PopStack "IGCM_config_Analyse_PeriodLength"
[380]314}
[118]315
[380]316#===================================
317function IGCM_config_Check
318{
319    IGCM_debug_PushStack "IGCM_config_Check"
320
321    # If one of the following modulo is not zero :
322    # we will issue an error then explain and exit in
323    # AA_job IGCM_debug_Verif_Exit call before binary submission
324
325    echo
[457]326    IGCM_debug_Print 1 "IGCM_config_Check"
[380]327    echo
328
[387]329    typeset i
330
[380]331    if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
332        AsynchronousRebuild=true
333        IGCM_debug_Print 1 "Asynchronous rebuild has been activated."
334        echo
335        # modulo (RebuildFrequency and PeriodLength/TimeSeriesFrequency/SeasonalFrequency) must be zero
[457]336        IGCM_debug_Print 1 "Check coherence between RebuildFrequency and PeriodLength"
[380]337        IGCM_post_CheckModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength
[457]338        IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and RebuildFrequency"
[380]339        IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_RebuildFrequency
[457]340        IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and RebuildFrequency"
[380]341        IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_RebuildFrequency
342    else
343        AsynchronousRebuild=false
344        IGCM_debug_Print 1 "Asynchronous rebuild has not been activated"
345        IGCM_debug_Print 1 "Proceed with standard post-treatment pathway"
346        echo
347        #modulo (TimeSeriesFrequency/SeasonalFrequency and PeriodLenght) must be zero
[457]348        IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PeriodLength"
[380]349        IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_UserChoices_PeriodLength
[457]350        IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PeriodLength"
[380]351        IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency   config_UserChoices_PeriodLength
352    fi
353
[387]354    #modulo (TimeSeriesFrequency and all Chunck2D) must be zero
355    NbJob=${#CHUNCK2D_SIZE[@]}
356    i=0
357    until [ $i -ge $NbJob ]; do
[393]358        value=${CHUNCK2D_SIZE[${i}]}
[457]359        IGCM_debug_Print 1 "Check coherence between All Chunck2D frequency and TimeSeriesFrequency"
[394]360        IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
[439]361        case ${value} in 
362            *Y|*y) ;;
[457]363            *)  IGCM_debug_Print 1 "All ChunckJob2D frequency must be expressed in year *Y|*y in comp.card"
[439]364                IGCM_debug_Exit "This will stop the job" ;;
365        esac
[387]366        (( i=i+1 ))
367    done
368
369    #modulo (TimeSeriesFrequency and all Chunck3D) must be zero
370    NbJob=${#CHUNCK3D_SIZE[@]}
371    i=0
372    until [ $i -ge $NbJob ]; do
[393]373        value=${CHUNCK3D_SIZE[${i}]}
[457]374        IGCM_debug_Print 1 "Check coherence between All Chunck3D frequency and TimeSeriesFrequency"
[394]375        IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
[439]376        case ${value} in 
377            *Y|*y) ;;
[457]378            *)  IGCM_debug_Print 1 "All ChunckJob3D frequency must be expressed in year *Y|*y in comp.card"
[439]379                IGCM_debug_Exit "This will stop the job" ;;
380        esac
[387]381        (( i=i+1 ))
382    done
383
[380]384    IGCM_debug_PopStack "IGCM_config_Check"
[118]385}
386
387#===================================
[2]388function IGCM_config_PeriodStart
389{
390    IGCM_debug_PushStack "IGCM_config_PeriodStart"
391
392    echo
[457]393    IGCM_debug_Print 1 "IGCM_config_PeriodStart"
[2]394    echo
395
[443]396    if ( ${FirstInitialize} ) ; then
[2]397        #================================================#
[443]398        #         Initialize date/period information     #
[2]399        #================================================#
400
[522]401        IGCM_date_GetYearMonthDay $DateBegin year month day
[124]402        IGCM_config_Analyse_PeriodLength
[2]403
404        eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1
[146]405        PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) )
[2]406        eval CumulPeriod=1 > /dev/null 2>&1
407
408        #=================================================#
[443]409        #              Write updated run.card             #
[2]410        #=================================================#
411
412        #Correct run.card Configuration for this period
413        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
414        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
415        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
[473]416        if [ X$( grep "SubmitPath" ${SUBMIT_DIR}/run.card ) != X ] ; then
417            IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration SubmitPath ${SUBMIT_DIR}
418        fi
[427]419
[2]420        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
421 
422    else
423        #================================================#
424        #         The file run.card allready exist       #
425        #================================================#
426
427        #Test state of run in run.card
428        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
429        if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
430            echo
[457]431            IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
432            IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this"
433            echo
434            IGCM_debug_Exit
[2]435            IGCM_debug_Verif_Exit
436        fi
437
438        #===================================#
439        #        Read updated run.card      #
440        #===================================#
441
442        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix
443        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
444        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
445        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
446
447        PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
448        PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
449        eval CumulPeriod="${run_Configuration_CumulPeriod}" > /dev/null 2>&1
450
[471]451        LastPeriodDateEnd=$( echo ${run_Configuration_OldPrefix} | sed -e "s/${config_UserChoices_JobName}_//" )
452
453        typeset LastDate
454        set +A LastDate -- $( echo ${LastPeriodDateEnd} | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1 \2 \3/" )
455        LastYearDateEnd=${LastDate[0]}
456        LastMonthDateEnd=${LastDate[1]}
457        LastDayDateEnd=${LastDate[2]}
458
[2]459        if [ ${Period} = 1 ]; then
460           # save last Job output
[224]461            typeset LastPeriod iLastPeriod Last_Script_Output_Name
[2]462            (( LastPeriod=CumulPeriod-PeriodNb ))
[224]463            iLastPeriod=$( printf "%06d" ${LastPeriod} )
464            Last_Script_Output_Name="${Script_Output_Prefix}_${config_UserChoices_JobName}.${iLastPeriod}"
465            Last_run_card="run.card.${iLastPeriod}"
[2]466            #eval ls -l ${SUBMIT_DIR}/${Last_Script_Output_Name}
467            #eval IGCM_sys_Put_Out ${SUBMIT_DIR}/${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name} > /dev/null 2>&1
[457]468            IGCM_debug_Print 2 "Try to save previous ksh job output"
[2]469            IGCM_sys_Cd ${SUBMIT_DIR}/
[227]470            IGCM_sys_Put_Out ${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name}.$$ rw
[471]471
472            IGCM_card_CheckConflict run.card
[227]473            IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/${Last_run_card}.$$ rw
[471]474
[2]475            IGCM_sys_Cd ${RUN_DIR}
476        else
477            unset FileToBeDeleted
478        fi
479
[522]480        IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
[124]481        IGCM_config_Analyse_PeriodLength
[2]482
483        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
484
485    fi   
486    OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd}
[522]487
488    # BEGIN: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
489    # Compute year_m1 and year_p1 (year minus 1Y and year plus 1Y)
490    year_m1=$(( year - 1 ))
491    year_p1=$(( year + 1 ))     
492    # Compute month_m1 (month minus 1M)
493    # Compute yyyymm_m1 (yyyymm minus 1M)
494    month_m1=$(( month - 1 ))
495    if [ ${month_m1} = 0 ]; then
496        month_m1=12
497        yyyymm_m1=${year_m1}12
498    elif [ ${month_m1} -le 9 ]; then
499        month_m1=0${month_m1}
500        yyyymm_m1=${year}${month_m1}
501    else
502        yyyymm_m1=${year}${month_m1}
503    fi
504    # Compute month_p1 (month plus 1M)
505    # Compute yyyymm_p1 (yyyymm plus 1M)
506    month_p1=$(( month + 1 ))
507    if [ ${month_p1} = 13 ]; then
508        month_p1=01
509        yyyymm_p1=${year_p1}01
510    elif [ ${month_p1} -le 9 ]; then
511        month_p1=0${month_p1}
512        yyyymm_p1=${year}${month_p1}
513    else
514        yyyymm_p1=${year}${month_p1}
515    fi
516    #IGCM_debug_Print 1 "jg 1 month_m1 = ${month_m1} month_p1 = ${month_p1} "
517    #IGCM_debug_Print 1 "jg 1 calculate yyyymm_m1 = ${yyyymm_m1} "
518    #IGCM_debug_Print 1 "jg 1 calculate yyyymm_p1 = ${yyyymm_p1} "
519
520    # END: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
521
[2]522    #===================================================================#
523    # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
524    #             But available to any son functions                    #
525    #===================================================================#
526
527    # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !)
528    (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 ))
529
530    # Debug Print :
531    IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution"
[457]532    IGCM_debug_Print 1 "Year of simulation      : ${year}"
533    IGCM_debug_Print 1 "Month of simulation     : ${month}"
534    IGCM_debug_Print 1 "PeriodLengthInDays      : ${PeriodLengthInDays}"
535    IGCM_debug_Print 1 "PeriodDateBegin         : ${PeriodDateBegin}"
536    IGCM_debug_Print 1 "PeriodDateEnd           : ${PeriodDateEnd}"
537    IGCM_debug_Print 1 "SimulationLengthInDays  : ${SimulationLengthInDays}"
538    IGCM_debug_Print 1 "ExperienceLengthInDays  : ${ExperienceLengthInDays}"
[2]539
540    #================================================================#
541    #         Prepare variables available for comp_finalyze          #
542    #================================================================#
543
544    # Period for save files
545    eval DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd} > /dev/null 2>&1
546
547    # Prefix for save files of this period
548    eval PREFIX=${config_UserChoices_JobName}_${DatesPeriod}  > /dev/null 2>&1
549
550    # List of files that will be deleted in RUN_DIR after run
[52]551    [ -f stack ] && FileToBeDeleted[0]="stack"
[2]552
553    # Test if the same run as already been saved :
[128]554    if [ X${JobType} = XRUN ] ; then
555        if [ ${DRYRUN} -le 0 ] ; then
556            if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then
[380]557                IGCM_debug_Exit "IGCM_config_PeriodStart" "You are currently RErunning an old job."
[128]558                IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files"
559                IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or "
[380]560                IGCM_debug_Print 1 " the whole ${R_SAVE} tree. See clean_month.job in ${libIGCM} directory."
561                IGCM_debug_Print 1 " This exit has been initiated because at least ${R_OUT_KSH}/${PREFIX}_${Exe_Output} exists."
[128]562                IGCM_debug_Verif_Exit
563            fi
564        fi
565    else
[2]566        if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then
[457]567            IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. Allowed in DEBUG or DEV mode."
[2]568        fi
569    fi
[128]570
[473]571    ExecutionFail=false
572
[2]573    IGCM_debug_PopStack "IGCM_config_PeriodStart"
574}
575
576#===================================
577function IGCM_config_PeriodEnd
578{
579    IGCM_debug_PushStack "IGCM_config_PeriodEnd"
580
581    echo
[457]582    IGCM_debug_Print 1 "IGCM_config_PeriodEnd"
[2]583    echo
584
585    #==================================#
586    #         Save Job output          #
587    #==================================#
588    IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output}
589    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}"
[471]590
591    IGCM_card_CheckConflict run.card
[457]592    IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/run.card rw
[2]593
[457]594    IGCM_debug_Print 1 "Check components binary : size and creation date"
595
596    typeset LS_comp LS_bin ExeDate ExeCpuLog NextExeSize LastCompExeSize
[2]597    typeset comp i   
[528]598    typeset ExeNameIn ExeNameOut
[2]599
600    #==================================#
601    #        Get last Exe Size         #
602    #==================================#
603
[457]604    (( i=0 ))
605    if ( ${FirstInitialize} ) ; then
606        run_Log_LastExeSize=""
607        for comp in ${config_ListOfComponents[*]} ; do
608            run_Log_LastExeSize[$i]=0
609            (( i=i+1 ))
610        done
611    else
612        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize
[2]613    fi
614    #==================================#
615    #         And Build ExeDate        #
616    #==================================#
617
618    # 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
[57]619    # 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")
620    # 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
[2]621    ExeDate=""
622    NextExeSize="( "
623    (( i=0 ))
[528]624
[2]625    for comp in ${config_ListOfComponents[*]} ; do
626
[457]627        IGCM_debug_Print 3 ${comp}
[2]628
629        eval ExeNameIn=\${config_Executable_${comp}[0]}
630        eval ExeNameOut=\${config_Executable_${comp}[1]}
[124]631        # Only if we really have an executable for the component :
[2]632        if [ X${ExeNameIn} = X\"\" ] ; then
633            # If there is no exe file for this component
634            (( ExeSize=0 ))
635        else
636            eval LS_bin=${R_EXE}/${ExeNameIn}
637            IGCM_sys_FileSize ${LS_bin} ExeSize
638
[57]639            set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} )
[2]640            if [ X${ExeDate} = X ] ; then 
641                # First component exe date
642                ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]}
643            else
644                ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]}
645            fi
646            ExeDate=${ExeDate}_${LS_comp[7]}
647        fi
648
649        if [ ${i} -eq 0 ] ; then
650            # First component
651            NextExeSize="( "${ExeSize}
652        else
653            NextExeSize=${NextExeSize}", "${ExeSize}
654        fi
655        eval LastCompExeSize=${run_Log_LastExeSize[$i]}
656        (( i=i+1 ))
657
[457]658        if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then
659            if ( ${FirstInitialize} ) ; then
660                IGCM_debug_Print 1 "Save first ${ExeNameIn} in ${R_OUT_EXE} !"
661            else
662                IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !"
663                IGCM_debug_Print 1 "Save latest ${ExeNameIn} in ${R_OUT_EXE} !"
664                eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut}
[2]665            fi
[457]666            eval IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw
[2]667        fi
668    done
669
[457]670    NextExeSize=${NextExeSize}" )"
671    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}"
672
[2]673    if [ ${DRYRUN} -le 1 ] ; then
674        tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt
[164]675        ExeCpuLog=$( gawk -f ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt )
[2]676        RET=$?
[57]677        if [ $RET -eq 0 ] ; then
678            # ExeCpuLog variable contents 5 fields
[92]679            echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" |   \
[109]680             gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \
[57]681                              $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card
[2]682        fi
683        eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}_tail.txt"
684    fi
685
686    # All was right ? no ? then we stop.
687    IGCM_debug_Verif_Exit
688
689    # If all was OK, we can delete all files not necessary for next Job
[457]690    echo
[92]691    IGCM_debug_Print 1 "Files that will be deleted before next period-run : "
[2]692
693    if [ ${DRYRUN} -le 2 ] ; then
[139]694        for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done
[2]695    else
696        echo ${FileToBeDeleted[@]}
697    fi
698
699    #=================================================#
[119]700    #         Modification of libIGCM behaviour       #
701    #=================================================#
702
[146]703    # To use this function, one must copy libIGCM.card from ${libIGCM} directory
[457]704    # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card,
[146]705    # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop.
[119]706    if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then
707        echo
708        echo "########################################################################"
709        echo "!!!                 Modification of libIGCM behaviour                !!!"
710        echo
711
712        IGCM_debug_Print 1 "DefineArrayFromOption  : libIGCM_UserChanges in libIGCM.card"
713        IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges
714        IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]}
715
716        # Special treatments for libIGCM internals
717        for option in ${libIGCM_UserChanges[*]} ; do
718            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option}
719
720            echo "We will change : ${option}."
721            eval echo "Previous value : " \${${option}}
722            eval echo "Change to : " \${libIGCM_UserChanges_${option}}
723           
724            eval ${option}=\${libIGCM_UserChanges_${option}}
725
726            case ${option} in
727                config_UserChoices_DateEnd)
[457]728                    IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd
[119]729                    DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
730
731                    # Period Length In Days between DateBegin and DateEnd
732                    (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
733                    if [ ${ExperienceLengthInDays} -lt 0 ] ; then
734                        IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that."
735                        IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates."
736                        IGCM_debug_Verif_Exit
737                    fi
738                    ;;
739                config_UserChoices_PeriodLength)
[457]740                    IGCM_debug_Print 1  "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}"
[119]741                    ;;
742                PeriodNb)
[457]743                    IGCM_debug_Print 1  "Loop in main Job with ${PeriodNb} period(s)"
[119]744                    ;;
745                config_Post_RebuildFrequency)
[457]746                    IGCM_debug_Print 1  "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure"
[119]747                    IGCM_post_Configure
748                    ;;
749                config_Post_TimeSeriesFrequency)
[457]750                    IGCM_debug_Print 1  "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Initialize"
[121]751                    IGCM_post_Configure
[119]752                    ;;
753                config_Post_SeasonalFrequency)
[457]754                    IGCM_debug_Print 1  "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Initialize"
[121]755                    IGCM_post_Configure
[119]756                    ;;
757            esac
758        done
759
760        echo
761        echo "########################################################################"
762        echo
763    fi
764
765    #=================================================#
[2]766    #         Determine next computed period          #
767    #=================================================#
768
769    PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 )
[522]770    IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
[230]771    year_m1=$(( year - 1 ))
772    year_p1=$(( year + 1 ))
[124]773    IGCM_config_Analyse_PeriodLength
[146]774    PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) )
[2]775
776    # Debug Print :
777    echo
778    IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution"
[457]779    IGCM_debug_Print 1 "PeriodDateBegin       : ${PeriodDateBegin}"
780    IGCM_debug_Print 1 "PeriodDateEnd         : ${PeriodDateEnd}"
781    IGCM_debug_Print 1 "PeriodLengthInDays    : ${PeriodLengthInDays}"
[2]782
783    PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} )
784    PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} )
785
786    (( CumulPeriod = CumulPeriod + 1 ))
787
788    # Debug Print :
789    echo
790    IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}"
791    IGCM_debug_Print 3 "PeriodDateEnd Human   : ${PeriodDateEnd}"
792    IGCM_debug_Print 3 "CumulPeriod           : ${CumulPeriod}"
793
794    #=================================================#
795    #             Write updated run.card              #
796    #=================================================#
797
798    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix}
799    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
800    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
801    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
802
[446]803    if ( ${FirstInitialize} ) ; then
804        # It's no more the first time
805        FirstInitialize=false
806    fi
807
[2]808    IGCM_debug_PopStack "IGCM_config_PeriodEnd"
809}
810
811#===================================
812function IGCM_config_Finalize
813{
814    IGCM_debug_PushStack "IGCM_config_Finalize"
815
816    echo
[457]817    IGCM_debug_Print 1 "IGCM_config_Finalize"
[2]818    echo
819
820    if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then
821        #==========================#
822        # End of entire simulation #
823        #==========================#
824
[154]825        # Mail notification
826        IGCM_sys_SendMail
[2]827
[154]828        #
[2]829        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed"
830        IGCM_debug_Print 1 "Normal End of computation."
831        if ( $DEBUG_debug ) ; then
832            echo
833            IGCM_debug_Print 1 "Your files on ${R_OUT} :"
834            IGCM_sys_Tree ${R_SAVE}
835        fi
836    else
837        #=================#
838        # Submit next job #
839        #=================#
840
841        IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
842
843        # Name of next Ksh Script output :
[57]844        eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )"
[2]845
846        IGCM_debug_Print 1 "Submit next job"
[274]847        # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR
[2]848        IGCM_sys_Cd ${SUBMIT_DIR}
[380]849        # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName}
[398]850        ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l )
[380]851        [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) )
852        # Submit next job and come back
[2]853        IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}
[274]854        IGCM_sys_Cd -
[2]855    fi
856
[154]857    # Supress Non Deleted Boundary files
858    if [ ${DRYRUN} -le 2 ] ; then
859        IGCM_comp_DelFixeBoundaryFiles
860        ls -la
861    fi
[274]862   
[154]863    # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
864    # Only for production run (No clean up in DEV or DEB mode)
[274]865    # and command sent from .. directory.
866    IGCM_sys_Cd ..
[187]867    [ X${JobType} = XRUN ] && IGCM_sys_Rm -rf ${RUN_DIR}
[154]868
[2]869    IGCM_debug_PopStack "IGCM_config_Finalize"
870}
871
872#===================================
Note: See TracBrowser for help on using the repository browser.