#!/bin/ksh # $Date: 2010/06/25 19:03:52 $ # $Author: ssipsl $ # $Revision: 1.13 $ # IPSL (2006) # This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC #D--------------------------------------------------------------------== #D--------------------------------------------------------------------== #D- #D- Job to launch FLUXNET spinup simulations #D- #D--------------------------------------------------------------------== #D--------------------------------------------------------------------== #D- # Job inspired from Sönke Zaehle "site_new.def" job # ################################################# MODIPSL=::modipsl:: libIGCM=${MODIPSL}/libIGCM # All SubJobs in SPINUP in ONE OR MORE YEARS run (must be used with libIGCM branches/AllPostFred). #D--------------------------------------------------------------------== #D- -1. User modification place #D--------------------------------------------------------------------== #D- Increased verbosity (1, 2, 3) #Verbosity=3 #D- # -------------------------------------------------------------------- #D- ! Optionnal features /!\ Use with care ! # -------------------------------------------------------------------- #D- Low level debug : to bypass lib test checks and stack construction #D- Default=true DEBUG_debug=false #D- Set DEBUG_sys to false to disable output calls of function #D- Default=true #DEBUG_sys=false #D- Turn in dry run mode ? (0,1,2,3) #D- Default=0 #DRYRUN=3 # YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE ! # ------------------------------------------------------------------------------------- # | DRYRUN= | Date computations, | sys_Get | Exe | sys_Put_Out; sys_Put_Rest | # | | Cp/Exe param files | | Chmod | | # | | Qsub | | | | # ------------------------------------------------------------------------------------- # | 0 | yes | yes | yes | yes | # ------------------------------------------------------------------------------------- # | 1 | yes | yes | yes | no | # ------------------------------------------------------------------------------------- # | 2 | yes | yes | no | no | # ------------------------------------------------------------------------------------- # | 3 | yes | no | no | no | # ------------------------------------------------------------------------------------- #D- #D--------------------------------------------------------------------== #D- 0. System Environment #D- - Define variables for Number of processors #D- - Define MPI variables #D- - Define batch scheduler variables #D- - Source IGCM Library #D- - Get RESOLution in .resol file (temporary) #D--------------------------------------------------------------------== #D--------------------------------------------------------------------== . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh ( ${DEBUG_debug} ) && IGCM_debug_Check . ${libIGCM}/libIGCM_card/libIGCM_card.ksh ( ${DEBUG_debug} ) && IGCM_card_Check . ${libIGCM}/libIGCM_date/libIGCM_date.ksh ( ${DEBUG_debug} ) && IGCM_date_Check #------- . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh #set -vx R_BC=${R_IN}/BC IGCM_sys_MkdirWork ${RUN_DIR_PATH} . ${SUBMIT_DIR}/fluxnet.ksh FLUXNET_initialize function correct_duree { # Ths function compute the nearest multiple of dyear near duree typeset duree dyear duree=$1 dyear=$2 if [ $(( duree % dyear )) -gt 0 ] ; then echo $(( ( duree / dyear + 1 ) * dyear )) else echo ${duree} fi } # Path for all skeleton SubJob scripts to SPINUP directory Skeleton_Path=$( cd ../; pwd ) isite=1 index=0 echo ${isite} ${NumSites} while [ ${isite} -le ${NumSites} ] ; do site=${fluxnet_FLUXNET_Sites[$index]} echo " ------------------------" echo " SPINUP for Site : ${site}" DATE0_YEAR=${fluxnet_FLUXNET_Sites[ $(( index + ColumnYear )) ]} TIME_YEAR=${fluxnet_FLUXNET_Sites[ $(( index + ColumnLength )) ]} ####################################################### # Script internal settings # nothing to be modified below this line ######################################################ä # Copy the SPINUP directory SubJobName=${site}${config_UserChoices_JobName} New_SUBMIT_DIR=${SUBMIT_DIR}/${SubJobName} IGCM_sys_Cp -Rp ../SPINUP ${New_SUBMIT_DIR} # ls -la ${New_SUBMIT_DIR} # cat ${New_SUBMIT_DIR}/config.card # echo "---" # Install this directory # modifications on config.card MyJobName=${config_UserChoices_JobName} IGCM_card_DefineVariableFromOption ${New_SUBMIT_DIR}/config.card UserChoices JobName OldJobName=${config_UserChoices_JobName} IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobName ${SubJobName} config_UserChoices_JobName=${MyJobName} IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices TagName IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices TagName ${config_UserChoices_TagName} IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices CalendarType ${config_UserChoices_CalendarType} IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobClass ${config_UserChoices_JobClass} IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobNumProcTot ${config_UserChoices_JobNumProcTot} sed -e "s/^JobRunOptions=.*/JobRunOptions=\'${config_UserChoices_JobRunOptions}\'/" ${New_SUBMIT_DIR}/config.card > temp.card IGCM_sys_Mv temp.card ${New_SUBMIT_DIR}/config.card # Give path for all skeleton SubJob scripts to SPINUP directory IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices SubJobPath ${Skeleton_Path} # All SubJobs in SPINUP in one or more years (must be used with libIGCM branches/AllPostFred). # It is the length of the forcing file. if [ X"${config_UserChoices_CalendarType}" = X"360d" ] ; then This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1230 This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-30 else This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1231 This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-31 fi IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateBegin ${DATE0_YEAR}-01-01 IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodLength ${TIME_YEAR}Y # DateEnd is defined by SpinUp job itself (it will be modified in config.card). # but to get all SpinUp Job loops, we have to add at least a number of years greater # than those that will be modified in config.card. Default is 150.00.00 years more for SpinUp. IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateEnd $(( DATE0_YEAR + 150 ))-01-01 # Infinit SPINUP Job : IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodNb 99999 # SRF section : first restart and post-treatments typeset option for option in ${config_SRF[*]} ; do eval value=\${config_SRF_${option}} eval echo ${option} ${value} if [ X${value} != X ] ; then eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF ${option} \${config_SRF_${option}} fi done if [ X"${fluxnet_UserChoices_ok_stomate}" = "Xy" ] ; then for option in ${config_SBG[*]} ; do eval value=\${config_SBG_${option}} eval echo ${option} ${value} if [ X${value} != X ] ; then eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG ${option} \${config_SBG_${option}} fi done fi # modifications on spinup.card IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobForcingFile List "(${fluxnet_FLUXNET_FluxnetPath}/${fluxnet_FLUXNET_Sites[$(( index + ColumnFilename ))]}, forcing_file.nc)" typeset option for option in ${fluxnet_UserChoices[*]} ; do eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices ${option} \${fluxnet_UserChoices_${option}} done # No routing for FLUXNET IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices ok_routing n # Max levels for FLUXNET IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices sechiba_LEVEL 10 IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices stomate_LEVEL 10 IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices DRIVER_NORESTART y eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_nostomate $( correct_duree ${fluxnet_SPINUP_duree_nostomate} ${TIME_YEAR} ) eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_inistomate $( correct_duree ${fluxnet_SPINUP_duree_inistomate} ${TIME_YEAR} ) eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_offlineini $( correct_duree ${fluxnet_SPINUP_duree_offlineini} ${TIME_YEAR} ) eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices n_iter ${fluxnet_SPINUP_n_iter} eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_sechiba $( correct_duree ${fluxnet_SPINUP_duree_sechiba} ${TIME_YEAR} ) eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_stomate $( correct_duree ${fluxnet_SPINUP_duree_stomate} ${TIME_YEAR} ) eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_carbonsol $( correct_duree ${fluxnet_SPINUP_duree_carbonsol} ${TIME_YEAR} ) eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_final $( correct_duree ${fluxnet_SPINUP_duree_final} ${TIME_YEAR} ) IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices BoundaryFilesListNonDel y # TimeSeries : ALMAOUTPUT for SECHIBA typeset option for option in ${config_SubJobPost[*]} ; do eval value=\${config_SubJobPost_${option}} eval echo ${option} ${value} if [ X${value} != X ] ; then eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SubJobPost ${option} \${config_SubJobPost_${option}} fi done # eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF TimeSeriesFrequency ${TIME_YEAR}Y # eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF TimeSeriesFrequency NONE set -A sechiba_TimeSeriesVars2D -- nobiofrac SWnet LWnet Qh Qle Qg Qf DelSurfHeat DelColdCont Snowf Rainf Evap \ Qs Qsb Qsm DelSoilMoist DelSWE DelIntercept AvgSurfT RadT Albedo SWE SoilMoist SoilWet SoilTemp PotEvap \ ECanop TVeg ESoil RootMoist SubSnow ACond SnowFrac SAlbedo SnowDepth dis IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobPost sechiba_TimeSeriesVars2D "("$( echo ${sechiba_TimeSeriesVars2D[@]} | sed -e "s/ /,/g" )")" set -A sechiba_TimeSeriesVars3D -- vegetfrac maxvegetfrac GPP IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobPost sechiba_TimeSeriesVars3D "("$( echo ${sechiba_TimeSeriesVars3D[@]} | sed -e "s/ /,/g" )")" # modifications on Job script rm ${New_SUBMIT_DIR}/Job_${OldJobName} IGCM_sys_Cp ${SUBMIT_DIR}/Job_${MyJobName} ${New_SUBMIT_DIR}/Job_${SubJobName} sed -e "s/ ${MyJobName}/ ${SubJobName}/" \ -e "s/Script_Output_${MyJobName}/Script_Output_${SubJobName}/" \ ${New_SUBMIT_DIR}/Job_${SubJobName} > ${New_SUBMIT_DIR}/Job_${SubJobName}_ IGCM_sys_Mv ${New_SUBMIT_DIR}/Job_${SubJobName}_ ${New_SUBMIT_DIR}/Job_${SubJobName} chmod u+x ${New_SUBMIT_DIR}/Job_${SubJobName} # modification on parameter files IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/sechiba.def ${New_SUBMIT_DIR}/PARAM/sechiba.def IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/stomate.def ${New_SUBMIT_DIR}/PARAM/stomate.def IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/driver.def ${New_SUBMIT_DIR}/PARAM/driver.def eval first_option=${fluxnet_SubJobParams[0]} > /dev/null 2>&1 if [ X${first_option} != X"Error:" ] ; then IGCM_card_DefineArrayFromSection ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams eval first_option=${spinup_SubJobParams[0]} > /dev/null 2>&1 typeset option option_ PARAM_FILE for option in ${fluxnet_SubJobParams[*]} ; do PARAM_FILE=$( echo ${option} | awk -F_ '{print $1}' ) echo "For parameter file ${PARAM_FILE}.def" option_=$( echo ${option} | sed -e "s/${PARAM_FILE}_//" ) eval echo "${option_}="\${fluxnet_SubJobParams_${option}} case ${PARAM_FILE} in sechiba) eval SECHIBA_sed ${option_} \${fluxnet_SubJobParams_${option}} ;; stomate) eval STOMATE_sed ${option_} \${fluxnet_SubJobParams_${option}} ;; driver) eval DRIVER_sed ${option_} \${fluxnet_SubJobParams_${option}} ;; esac if [ X${first_option} != X"Error:" ] ; then for option_ in ${spinup_SubJobParams[*]} ; do if [ X${option} == X${option_} ] ; then eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams ${option} \${fluxnet_SubJobParams_${option}} fi done fi done fi # Replace vegetation IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices impose_veg y (( iphys = 0 )) while [ $iphys -lt ${fluxnet_FLUXNET_NbSitesParam} ] ; do # Detect if physical parameter has # array description or line per PFT description in the parameter file SearchParam="" ${fluxnet_FLUXNET_CompSitesParam[${iphys}]}_grep ${fluxnet_FLUXNET_NameSitesParam[${iphys}]} case ${SearchParam} in undefined) echo "ERROR : parameter ${fluxnet_FLUXNET_NameSitesParam[${iphys}]} doen't exist in ${fluxnet_FLUXNET_CompSitesParam[${iphys}]} parameter file !" echo "You must correct NameSiteParam option in fluxnet.card file or add new parameter in component.def file" echo "We must STOP here." exit 1 ;; line) ipft=1 while [ $ipft -le ${NbPFTs} ] ; do if [ $ipft -lt 10 ] ; then numpft=0${ipft} else numpft=${ipft} fi ${fluxnet_FLUXNET_CompSitesParam[${iphys}]}_sed ${fluxnet_FLUXNET_NameSitesParam[${iphys}]}__${numpft} ${fluxnet_FLUXNET_Sites[$(( index + 4 + ( iphys * NbPFTs ) + ipft - 1 )) ]} (( ipft = ipft + 1 )) done ;; vector) unset ValueSiteParams ipft=0 while [ $ipft -lt ${NbPFTs} ] ; do ValueSiteParams[${ipft}]=${fluxnet_FLUXNET_Sites[$(( index + 4 + ( iphys * NbPFTs ) + ipft - 1 )) ]} (( ipft = ipft + 1 )) done ${fluxnet_FLUXNET_CompSitesParam[${iphys}]}_sed ${fluxnet_FLUXNET_NameSitesParam[${iphys}]} "${ValueSiteParams[*]}" ;; esac (( iphys = iphys + 1 )) done IGCM_debug_Verif_Exit # Lauch the SPINUP Job : echo "#!/bin/ksh" > ${RUN_DIR_PATH}/SubJob${site}.ksh echo "MODIPSL=${MODIPSL}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh echo "libIGCM=${libIGCM}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh echo "cd ${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh echo "export SUBMIT_DIR=${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh echo ". ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh echo ". ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh echo "export Script_Output=out_qsub_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh echo "export config_UserChoices_JobName=${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh echo "export CumulPeriod=1" >> ${RUN_DIR_PATH}/SubJob${site}.ksh # echo "nohup Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh echo "IGCM_sys_Qsub Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh if [ ${DRYRUN} -le 1 ] ; then chmod u+x ${RUN_DIR_PATH}/SubJob${site}.ksh nohup ${RUN_DIR_PATH}/SubJob${site}.ksh fi IGCM_debug_Verif_Exit (( isite=isite+1 )) (( index=index+NumInfosBySite )) done IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}