#!/bin/ksh #************************************************************** # Author: Sebastien Denvil, Martial Mancip # Contact: Sebastien.Denvil__at__ipsl.jussieu.fr Martial.Mancip__at__ipsl.jussieu.fr # $Revision:: $ Revision of last commit # $Author:: $ Author of last commit # $Date:: $ Date of last commit # IPSL (2006) # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC # #************************************************************** #=================================== function IGCM_config_Initialize { IGCM_debug_PushStack "IGCM_config_Initialize" # Debug Print : echo IGCM_debug_Print 1 "IGCM_config_Initialize" if [ ! -r ${SUBMIT_DIR}/run.card ]; then #================================================# # The file run.card doesn't exist # #================================================# FirstInitialize=true #copy initial run.card IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${SUBMIT_DIR}/run.card else FirstInitialize=false fi # Test modipsl tree existence. IGCM_sys_TestDir ${MODIPSL} [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" IGCM_sys_TestDir ${libIGCM} [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" IGCM_sys_TestDir ${R_EXE} [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" IGCM_sys_TestDir ${SUBMIT_DIR} [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" if ( $DEBUG_debug ) ; then echo "Keep trace of inital SUBMIT_DIR : " ls -lta ${SUBMIT_DIR} fi #================================== typeset option auxprint CompatibilityTag # Read libIGCM compatibility version in config.card IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Compatibility libIGCM eval CompatibilityTag=${config_Compatibility_libIGCM} > /dev/null 2>&1 if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then 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 ." fi #================================== IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices for option in ${config_UserChoices[*]} ; do IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option} done echo IGCM_debug_Print 1 "DefineArrayFromOption : config_UserChoices" # Name Space of this experience if [ X${config_UserChoices_SpaceName} != X ] ; then IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName fi # Expericence class of the run if [ X${config_UserChoices_ExperimentName} != X ] ; then IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName fi IGCM_debug_PrintVariables 3 config_UserChoices_JobName if [ 3 -le ${Verbosity} ] ; then echo "--------------Debug3-->" "config_UserChoices_LongName=" echo "--------------Debug3-->" \"${config_UserChoices_LongName}\" fi IGCM_debug_PrintVariables 3 config_UserChoices_TagName IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength #================================== IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents echo IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents" IGCM_debug_Print 3 ${config_ListOfComponents[*]} NbComponents=${#config_ListOfComponents[*]} #================================== # Define principal executable IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Executable IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Executable Name #================================== # Define Outputs Name IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output" eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'} IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}" eval Exe_Output=out_${config_Executable_Name} IGCM_debug_Print 3 "Exe_Output = ${Exe_Output}" #================================== #===================================================================# # Prepare variables available for ${COMP}.card and ${COMP}.driver # # But available to any son functions # #===================================================================# # Convert yyyy-mm-dd date to gregorian yyyymmdd DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} ) DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} ) # Period Length In Days between DateBegin and DateEnd (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} ) + 1 )) if [ ${ExperienceLengthInDays} -lt 0 ] ; then IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that." IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates." IGCM_debug_Verif_Exit fi # Day and Year of Initial State (Given in julian format) InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 )) InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 )) #================================== # Restarts : Gerneral rule or local for each component ? IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts echo IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts" for option in ${config_Restarts[*]} ; do IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option} eval auxprint=\${config_Restarts_${option}} IGCM_debug_Print 3 "${option} : ${auxprint}" done #================================================================# # Test and Prepare directories # #================================================================# # ==> 4 kinds of input files : # 1) R_INIT : Initial State Files (Etat0, carteveg) # 2) R_BC : Boundary Conditions (Forcages, lai) # 3) Parameters files (allready define through ${SUBMIT_DIR}) # 4) Restarts files (allready define in IGCM_config_Initialize) # Here we offer the possibility to redefine R_INIT, R_BC # and PeriodNb through config.card R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT} IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb" IGCM_debug_Print 3 "R_INIT=${R_INIT}" R_BC=${config_UserChoices_R_BC:=${R_IN}/BC} IGCM_debug_Print 3 "R_BC=${R_BC}" PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}} IGCM_debug_Print 3 "Loop in main Job with ${PeriodNb} period(s)" # Test Archive input/output. IGCM_sys_TestDirArchive ${ARCHIVE} [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" IGCM_sys_TestDirArchive ${R_IN} [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" #==================================================== #R_SAVE : Job output directory if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' ) R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} else R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName} R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName} fi if ( ${FirstInitialize} ) ; then IGCM_sys_MkdirArchive ${R_SAVE} else IGCM_sys_TestDirArchive ${R_SAVE} [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" #Test state of run in run.card IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then echo IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!" IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this" IGCM_debug_Exit IGCM_debug_Verif_Exit fi fi #================================== # Post : IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post echo IGCM_debug_Print 1 "DefineArrayFromOption : config_Post" for option in ${config_Post[*]} ; do IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option} eval auxprint=\${config_Post_${option}} IGCM_debug_Print 3 "${option} : ${auxprint}" done #==================================================== # Define REBUILD_DIR : where we store files needing rebuild process if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then REBUILD_DIR=${R_SAVE}/TMP IGCM_sys_MkdirArchive ${REBUILD_DIR} else REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName} IGCM_sys_MkdirWork ${REBUILD_DIR} fi #==================================================== # Experience type : DEB(ug), DEV(elopment), RUN if [ X${JobType} != XRUN ] ; then echo echo "====================================================" echo "libIGCM JOB is NOT in RUN type mode." echo "!! OUTPUT files will NOT be PROTECTED !!" echo "Be carefull : you can ERASE the result of this job !" case ${JobType} in DEB) echo "DEBUG mode : activation of 'set -vx' mode." echo "DEBUG mode : no protection for output files." echo "DEBUG mode : if active force asynchronous rebuild frequency to PeriodLength frequency." ;; DEV) echo "DEVelopment mode : no protection for output files." echo "DEVelopment mode : if active force asynchronous rebuild frequency to PeriodLength frequency." ;; esac if ( [ X${config_Post_RebuildFrequency} != XNONE ] && [ ${DRYRUN} -eq 0 ] ) ; then if [ X${config_Post_RebuildFrequency} != X${config_UserChoices_PeriodLength} ] ; then echo "------------" echo "WARNING : Job is NOT in RUN mode then we will force REBUILD Frequency" echo " to PeriodLength : ${config_UserChoices_PeriodLength}" echo "------------" config_Post_RebuildFrequency=${config_UserChoices_PeriodLength} fi fi echo "====================================================" echo fi #==================================================== #R_OUT_KSH : Storage place for job output #R_OUT_EXE : Storage place for binary used during simulation R_OUT_KSH=${R_SAVE}/Out R_OUT_EXE=${R_SAVE}/Exe IGCM_debug_PopStack "IGCM_config_Initialize" } #=================================== function IGCM_config_Analyse_PeriodLength { IGCM_debug_PushStack "IGCM_config_Analyse_PeriodLength" typeset i # Determine number of day(s) in PeriodLength : case ${config_UserChoices_PeriodLength} in *Y|*y) PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' ) IGCM_debug_Print 2 "Number of years for PeriodLength : ${PeriodLengthInYears}" PeriodLengthInDays=0 i=0 until [ $i -ge $PeriodLengthInYears ] ; do (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) )) (( i=i+1 )) done ;; *M|*m) PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' ) IGCM_debug_Print 2 "Number of months for PeriodLength : ${PeriodLengthInMonths}" PeriodLengthInDays=0 i=0 until [ $i -ge $PeriodLengthInMonths ] ; do if [ $(( month + i )) -lt 13 ] ; then (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) else (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) fi (( i=i+1 )) done ;; *D|*d) PeriodLengthInMonths=0 PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' );; *) IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D." IGCM_debug_Verif_Exit ;; esac IGCM_debug_PopStack "IGCM_config_Analyse_PeriodLength" } #=================================== function IGCM_config_Check { IGCM_debug_PushStack "IGCM_config_Check" # If one of the following modulo is not zero : # we will issue an error then explain and exit in # AA_job IGCM_debug_Verif_Exit call before binary submission echo IGCM_debug_Print 1 "IGCM_config_Check" echo typeset i if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then AsynchronousRebuild=true IGCM_debug_Print 1 "Asynchronous rebuild has been activated." echo # modulo (RebuildFrequency and PeriodLength/TimeSeriesFrequency/SeasonalFrequency) must be zero IGCM_debug_Print 1 "Check coherence between RebuildFrequency and PeriodLength" IGCM_post_CheckModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and RebuildFrequency" IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_RebuildFrequency IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and RebuildFrequency" IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_RebuildFrequency else AsynchronousRebuild=false IGCM_debug_Print 1 "Asynchronous rebuild has not been activated" IGCM_debug_Print 1 "Proceed with standard post-treatment pathway" echo #modulo (TimeSeriesFrequency/SeasonalFrequency and PeriodLenght) must be zero IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PeriodLength" IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_UserChoices_PeriodLength IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PeriodLength" IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_UserChoices_PeriodLength fi #modulo (TimeSeriesFrequency and all Chunck2D) must be zero NbJob=${#CHUNCK2D_SIZE[@]} i=0 until [ $i -ge $NbJob ]; do value=${CHUNCK2D_SIZE[${i}]} IGCM_debug_Print 1 "Check coherence between All Chunck2D frequency and TimeSeriesFrequency" IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency case ${value} in *Y|*y) ;; *) IGCM_debug_Print 1 "All ChunckJob2D frequency must be expressed in year *Y|*y in comp.card" IGCM_debug_Exit "This will stop the job" ;; esac (( i=i+1 )) done #modulo (TimeSeriesFrequency and all Chunck3D) must be zero NbJob=${#CHUNCK3D_SIZE[@]} i=0 until [ $i -ge $NbJob ]; do value=${CHUNCK3D_SIZE[${i}]} IGCM_debug_Print 1 "Check coherence between All Chunck3D frequency and TimeSeriesFrequency" IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency case ${value} in *Y|*y) ;; *) IGCM_debug_Print 1 "All ChunckJob3D frequency must be expressed in year *Y|*y in comp.card" IGCM_debug_Exit "This will stop the job" ;; esac (( i=i+1 )) done IGCM_debug_PopStack "IGCM_config_Check" } #=================================== function IGCM_config_PeriodStart { IGCM_debug_PushStack "IGCM_config_PeriodStart" echo IGCM_debug_Print 1 "IGCM_config_PeriodStart" echo if ( ${FirstInitialize} ) ; then #================================================# # Initialize date/period information # #================================================# IGCM_date_GetYearMonth $DateBegin year month year_m1=$(( year - 1 )) year_p1=$(( year + 1 )) IGCM_config_Analyse_PeriodLength eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1 PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) ) eval CumulPeriod=1 > /dev/null 2>&1 #=================================================# # Write updated run.card # #=================================================# #Correct run.card Configuration for this period IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration SubmitPath ${SUBMIT_DIR} IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" else #================================================# # The file run.card allready exist # #================================================# #Test state of run in run.card IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then echo IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!" IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this" echo IGCM_debug_Exit IGCM_debug_Verif_Exit fi #===================================# # Read updated run.card # #===================================# IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} ) PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} ) eval CumulPeriod="${run_Configuration_CumulPeriod}" > /dev/null 2>&1 if [ ${Period} = 1 ]; then # save last Job output typeset LastPeriod iLastPeriod Last_Script_Output_Name (( LastPeriod=CumulPeriod-PeriodNb )) iLastPeriod=$( printf "%06d" ${LastPeriod} ) Last_Script_Output_Name="${Script_Output_Prefix}_${config_UserChoices_JobName}.${iLastPeriod}" Last_run_card="run.card.${iLastPeriod}" #eval ls -l ${SUBMIT_DIR}/${Last_Script_Output_Name} #eval IGCM_sys_Put_Out ${SUBMIT_DIR}/${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name} > /dev/null 2>&1 IGCM_debug_Print 2 "Try to save previous ksh job output" IGCM_sys_Cd ${SUBMIT_DIR}/ IGCM_sys_Put_Out ${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name}.$$ rw IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/${Last_run_card}.$$ rw IGCM_sys_Cd ${RUN_DIR} else unset FileToBeDeleted fi IGCM_date_GetYearMonth $PeriodDateBegin year month year_m1=$(( year - 1 )) year_p1=$(( year + 1 )) IGCM_config_Analyse_PeriodLength IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" fi OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd} #===================================================================# # Prepare variables available for ${COMP}.card and ${COMP}.driver # # But available to any son functions # #===================================================================# # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !) (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 )) # Debug Print : IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution" IGCM_debug_Print 1 "Year of simulation : ${year}" IGCM_debug_Print 1 "Month of simulation : ${month}" IGCM_debug_Print 1 "PeriodLengthInDays : ${PeriodLengthInDays}" IGCM_debug_Print 1 "PeriodDateBegin : ${PeriodDateBegin}" IGCM_debug_Print 1 "PeriodDateEnd : ${PeriodDateEnd}" IGCM_debug_Print 1 "SimulationLengthInDays : ${SimulationLengthInDays}" IGCM_debug_Print 1 "ExperienceLengthInDays : ${ExperienceLengthInDays}" #================================================================# # Prepare variables available for comp_finalyze # #================================================================# # Period for save files eval DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd} > /dev/null 2>&1 # Prefix for save files of this period eval PREFIX=${config_UserChoices_JobName}_${DatesPeriod} > /dev/null 2>&1 # List of files that will be deleted in RUN_DIR after run [ -f stack ] && FileToBeDeleted[0]="stack" # Test if the same run as already been saved : if [ X${JobType} = XRUN ] ; then if [ ${DRYRUN} -le 0 ] ; then if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then IGCM_debug_Exit "IGCM_config_PeriodStart" "You are currently RErunning an old job." IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files" IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or " IGCM_debug_Print 1 " the whole ${R_SAVE} tree. See clean_month.job in ${libIGCM} directory." IGCM_debug_Print 1 " This exit has been initiated because at least ${R_OUT_KSH}/${PREFIX}_${Exe_Output} exists." IGCM_debug_Verif_Exit fi fi else if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. Allowed in DEBUG or DEV mode." fi fi IGCM_debug_PopStack "IGCM_config_PeriodStart" } #=================================== function IGCM_config_PeriodEnd { IGCM_debug_PushStack "IGCM_config_PeriodEnd" echo IGCM_debug_Print 1 "IGCM_config_PeriodEnd" echo #==================================# # Save Job output # #==================================# IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output} eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}" IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/run.card rw IGCM_debug_Print 1 "Check components binary : size and creation date" typeset LS_comp LS_bin ExeDate ExeCpuLog NextExeSize LastCompExeSize typeset comp i typeset ExeNameIn ExeNameOut #==================================# # Get last Exe Size # #==================================# (( i=0 )) if ( ${FirstInitialize} ) ; then run_Log_LastExeSize="" for comp in ${config_ListOfComponents[*]} ; do run_Log_LastExeSize[$i]=0 (( i=i+1 )) done else IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize fi #==================================# # And Build ExeDate # #==================================# # 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 # 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") # 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 ExeDate="" NextExeSize="( " (( i=0 )) for comp in ${config_ListOfComponents[*]} ; do IGCM_debug_Print 3 ${comp} eval ExeNameIn=\${config_Executable_${comp}[0]} eval ExeNameOut=\${config_Executable_${comp}[1]} # Only if we really have an executable for the component : if [ X${ExeNameIn} = X\"\" ] ; then # If there is no exe file for this component (( ExeSize=0 )) else eval LS_bin=${R_EXE}/${ExeNameIn} IGCM_sys_FileSize ${LS_bin} ExeSize set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} ) if [ X${ExeDate} = X ] ; then # First component exe date ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]} else ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]} fi ExeDate=${ExeDate}_${LS_comp[7]} fi if [ ${i} -eq 0 ] ; then # First component NextExeSize="( "${ExeSize} else NextExeSize=${NextExeSize}", "${ExeSize} fi eval LastCompExeSize=${run_Log_LastExeSize[$i]} (( i=i+1 )) if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then if ( ${FirstInitialize} ) ; then IGCM_debug_Print 1 "Save first ${ExeNameIn} in ${R_OUT_EXE} !" else IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !" IGCM_debug_Print 1 "Save latest ${ExeNameIn} in ${R_OUT_EXE} !" eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut} fi eval IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw fi done NextExeSize=${NextExeSize}" )" IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}" if [ ${DRYRUN} -le 1 ] ; then tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt ExeCpuLog=$( gawk -f ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt ) RET=$? if [ $RET -eq 0 ] ; then # ExeCpuLog variable contents 5 fields echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" | \ gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \ $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card fi eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}_tail.txt" fi # All was right ? no ? then we stop. IGCM_debug_Verif_Exit # If all was OK, we can delete all files not necessary for next Job echo IGCM_debug_Print 1 "Files that will be deleted before next period-run : " if [ ${DRYRUN} -le 2 ] ; then for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done else echo ${FileToBeDeleted[@]} fi #=================================================# # Modification of libIGCM behaviour # #=================================================# # To use this function, one must copy libIGCM.card from ${libIGCM} directory # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card, # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop. if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then echo echo "########################################################################" echo "!!! Modification of libIGCM behaviour !!!" echo IGCM_debug_Print 1 "DefineArrayFromOption : libIGCM_UserChanges in libIGCM.card" IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]} # Special treatments for libIGCM internals for option in ${libIGCM_UserChanges[*]} ; do IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option} echo "We will change : ${option}." eval echo "Previous value : " \${${option}} eval echo "Change to : " \${libIGCM_UserChanges_${option}} eval ${option}=\${libIGCM_UserChanges_${option}} case ${option} in config_UserChoices_DateEnd) IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} ) # Period Length In Days between DateBegin and DateEnd (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} ) + 1 )) if [ ${ExperienceLengthInDays} -lt 0 ] ; then IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that." IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates." IGCM_debug_Verif_Exit fi ;; config_UserChoices_PeriodLength) IGCM_debug_Print 1 "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}" ;; PeriodNb) IGCM_debug_Print 1 "Loop in main Job with ${PeriodNb} period(s)" ;; config_Post_RebuildFrequency) IGCM_debug_Print 1 "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure" IGCM_post_Configure ;; config_Post_TimeSeriesFrequency) IGCM_debug_Print 1 "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Initialize" IGCM_post_Configure ;; config_Post_SeasonalFrequency) IGCM_debug_Print 1 "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Initialize" IGCM_post_Configure ;; esac done echo echo "########################################################################" echo fi #=================================================# # Determine next computed period # #=================================================# PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 ) IGCM_date_GetYearMonth $PeriodDateBegin year month year_m1=$(( year - 1 )) year_p1=$(( year + 1 )) IGCM_config_Analyse_PeriodLength PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) ) # Debug Print : echo IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution" IGCM_debug_Print 1 "PeriodDateBegin : ${PeriodDateBegin}" IGCM_debug_Print 1 "PeriodDateEnd : ${PeriodDateEnd}" IGCM_debug_Print 1 "PeriodLengthInDays : ${PeriodLengthInDays}" PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} ) PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} ) (( CumulPeriod = CumulPeriod + 1 )) # Debug Print : echo IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}" IGCM_debug_Print 3 "PeriodDateEnd Human : ${PeriodDateEnd}" IGCM_debug_Print 3 "CumulPeriod : ${CumulPeriod}" #=================================================# # Write updated run.card # #=================================================# IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix} IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} if ( ${FirstInitialize} ) ; then # It's no more the first time FirstInitialize=false fi IGCM_debug_PopStack "IGCM_config_PeriodEnd" } #=================================== function IGCM_config_Finalize { IGCM_debug_PushStack "IGCM_config_Finalize" echo IGCM_debug_Print 1 "IGCM_config_Finalize" echo if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then #==========================# # End of entire simulation # #==========================# # Mail notification IGCM_sys_SendMail # IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed" IGCM_debug_Print 1 "Normal End of computation." if ( $DEBUG_debug ) ; then echo IGCM_debug_Print 1 "Your files on ${R_OUT} :" IGCM_sys_Tree ${R_SAVE} fi else #=================# # Submit next job # #=================# IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue" # Name of next Ksh Script output : eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )" IGCM_debug_Print 1 "Submit next job" # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR IGCM_sys_Cd ${SUBMIT_DIR} # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName} ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l ) [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) ) # Submit next job and come back IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} IGCM_sys_Cd - fi # Supress Non Deleted Boundary files if [ ${DRYRUN} -le 2 ] ; then IGCM_comp_DelFixeBoundaryFiles ls -la fi # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_TagName}/${config_UserChoices_JobName} # Only for production run (No clean up in DEV or DEB mode) # and command sent from .. directory. IGCM_sys_Cd .. [ X${JobType} = XRUN ] && IGCM_sys_Rm -rf ${RUN_DIR} IGCM_debug_PopStack "IGCM_config_Finalize" } #===================================