source: tags/ORCHIDEE_1_9_5_1/ORCHIDEE_OL/FLUXNET/Job_FLUXNET_validation @ 8626

Last change on this file since 8626 was 118, checked in by martial.mancip, 13 years ago

Update driver scripts on tag ORCHIDEE_1_9_5_1.

File size: 15.8 KB
Line 
1#!/bin/ksh
2
3# $Date: 2010/06/25 19:03:52 $
4# $Author: ssipsl $
5# $Revision: 1.13 $
6# IPSL (2006)
7#  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
8
9#D--------------------------------------------------------------------==
10#D--------------------------------------------------------------------==
11#D-
12#D-                      Job to launch FLUXNET spinup simulations
13#D-
14#D--------------------------------------------------------------------==
15#D--------------------------------------------------------------------==
16#D-
17#                       Job inspired from Sönke Zaehle "site_new.def" job
18#                       #################################################
19
20
21
22MODIPSL=::modipsl::
23libIGCM=${MODIPSL}/libIGCM
24
25# All SubJobs in SPINUP in ONE OR MORE YEARS run (must be used with libIGCM branches/AllPostFred).
26
27
28
29#D--------------------------------------------------------------------==
30#D-                   -1. User modification place
31#D--------------------------------------------------------------------==
32
33#D- Increased verbosity (1, 2, 3)
34#Verbosity=3
35
36#D-
37# --------------------------------------------------------------------
38#D- ! Optionnal features /!\ Use with care !
39# --------------------------------------------------------------------
40
41#D- Low level debug : to bypass lib test checks and stack construction
42#D- Default=true
43DEBUG_debug=false
44
45#D- Set DEBUG_sys to false to disable output calls of function
46#D- Default=true
47#DEBUG_sys=false
48
49#D- Turn in dry run mode ? (0,1,2,3)
50#D- Default=0
51#DRYRUN=3
52# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
53# -------------------------------------------------------------------------------------
54# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
55# |          |  Cp/Exe param files |            |  Chmod  |                           |
56# |          |      Qsub           |            |         |                           |
57# -------------------------------------------------------------------------------------
58# |    0     |       yes           |    yes     |  yes    |      yes                  |
59# -------------------------------------------------------------------------------------
60# |    1     |       yes           |    yes     |  yes    |      no                   |
61# -------------------------------------------------------------------------------------
62# |    2     |       yes           |    yes     |  no     |      no                   |
63# -------------------------------------------------------------------------------------
64# |    3     |       yes           |    no      |  no     |      no                   |
65# -------------------------------------------------------------------------------------
66
67
68#D-
69#D--------------------------------------------------------------------==
70#D-                   0. System Environment
71#D-                      - Define variables for Number of processors
72#D-                      - Define MPI variables
73#D-                      - Define batch scheduler variables
74#D-                      - Source IGCM Library
75#D-                      - Get RESOLution in .resol file (temporary)
76#D--------------------------------------------------------------------==
77
78#D--------------------------------------------------------------------==
79
80. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
81        ( ${DEBUG_debug} ) && IGCM_debug_Check
82. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
83       ( ${DEBUG_debug} ) && IGCM_card_Check
84. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
85       ( ${DEBUG_debug} ) && IGCM_date_Check
86#-------
87. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
88
89
90#set -vx
91R_BC=${R_IN}/BC
92
93IGCM_sys_MkdirWork ${RUN_DIR_PATH}
94
95. ${SUBMIT_DIR}/fluxnet.ksh
96
97FLUXNET_initialize
98
99function correct_duree
100{
101    # Ths function compute the nearest multiple of dyear near duree
102    typeset duree dyear
103    duree=$1
104    dyear=$2
105    if [ $(( duree % dyear )) -gt 0 ] ; then
106        echo $(( ( duree / dyear + 1 ) * dyear ))
107    else
108        echo ${duree}
109    fi
110}
111
112# Path for all skeleton SubJob scripts to SPINUP directory
113Skeleton_Path=$( cd ../; pwd )
114
115isite=1
116index=0
117echo ${isite} ${NumSites}
118while [ ${isite} -le ${NumSites} ] ; do
119   
120    site=${fluxnet_FLUXNET_Sites[$index]}
121    echo "   ------------------------"
122    echo "   SPINUP for Site : ${site}"
123
124    DATE0_YEAR=${fluxnet_FLUXNET_Sites[ $(( index + ColumnYear )) ]}
125    TIME_YEAR=${fluxnet_FLUXNET_Sites[ $(( index + ColumnLength )) ]}
126
127#######################################################
128# Script internal settings
129# nothing to be modified below this line
130######################################################ä
131
132# Copy the SPINUP directory
133    SubJobName=${site}${config_UserChoices_JobName}
134    New_SUBMIT_DIR=${SUBMIT_DIR}/${SubJobName}
135    IGCM_sys_Cp -Rp ../SPINUP ${New_SUBMIT_DIR}
136#     ls -la ${New_SUBMIT_DIR}
137#     cat ${New_SUBMIT_DIR}/config.card
138#     echo "---"
139
140    # Install this directory
141    # modifications on config.card
142    MyJobName=${config_UserChoices_JobName}
143    IGCM_card_DefineVariableFromOption ${New_SUBMIT_DIR}/config.card UserChoices JobName
144    OldJobName=${config_UserChoices_JobName}
145    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobName ${SubJobName}
146    config_UserChoices_JobName=${MyJobName}
147    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices TagName
148    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices TagName ${config_UserChoices_TagName}
149    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices CalendarType ${config_UserChoices_CalendarType}
150
151    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobClass ${config_UserChoices_JobClass}
152    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobNumProcTot ${config_UserChoices_JobNumProcTot}
153    sed -e "s/^JobRunOptions=.*/JobRunOptions=\'${config_UserChoices_JobRunOptions}\'/" ${New_SUBMIT_DIR}/config.card > temp.card
154    IGCM_sys_Mv temp.card ${New_SUBMIT_DIR}/config.card
155
156    # Give path for all skeleton SubJob scripts to SPINUP directory
157    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices SubJobPath ${Skeleton_Path}
158
159    # All SubJobs in SPINUP in one or more years (must be used with libIGCM branches/AllPostFred).
160    # It is the length of the forcing file.
161    if [ X"${config_UserChoices_CalendarType}" = X"360d" ] ; then
162        This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1230
163        This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-30
164    else
165        This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1231
166        This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-31
167    fi
168
169    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateBegin ${DATE0_YEAR}-01-01
170    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodLength ${TIME_YEAR}Y
171
172    # DateEnd is defined by SpinUp job itself (it will be modified in config.card).
173    # but to get all SpinUp Job loops, we have to add at least a number of years greater
174    # than those that will be modified in config.card. Default is 150.00.00 years more for SpinUp.
175    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateEnd $(( DATE0_YEAR + 150 ))-01-01
176
177    # Infinit SPINUP Job :
178    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodNb 99999
179
180    # SRF section : first restart and post-treatments
181    typeset option
182    for option in ${config_SRF[*]} ; do
183        eval value=\${config_SRF_${option}}
184        eval echo ${option} ${value}
185        if [ X${value} != X ] ; then
186            eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF ${option} \${config_SRF_${option}}
187        fi
188    done
189    if [ X"${fluxnet_UserChoices_ok_stomate}" = "Xy" ] ; then
190        for option in ${config_SBG[*]} ; do
191            eval value=\${config_SBG_${option}}
192            eval echo ${option} ${value}
193            if [ X${value} != X ] ; then
194                eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG ${option} \${config_SBG_${option}}
195            fi
196        done
197    fi
198
199    # modifications on spinup.card
200    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobForcingFile List "(${fluxnet_FLUXNET_FluxnetPath}/${fluxnet_FLUXNET_Sites[$(( index + ColumnFilename ))]}, forcing_file.nc)"
201
202    typeset option
203    for option in ${fluxnet_UserChoices[*]} ; do
204        eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices ${option} \${fluxnet_UserChoices_${option}}
205    done
206    # No routing for FLUXNET
207    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices ok_routing n
208
209    # Max levels for FLUXNET
210    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices sechiba_LEVEL 10
211    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices stomate_LEVEL 10
212
213    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices DRIVER_NORESTART y
214
215    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_nostomate $( correct_duree ${fluxnet_SPINUP_duree_nostomate} ${TIME_YEAR} )
216    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_inistomate $( correct_duree ${fluxnet_SPINUP_duree_inistomate} ${TIME_YEAR} )
217    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_offlineini $( correct_duree ${fluxnet_SPINUP_duree_offlineini} ${TIME_YEAR} )
218    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices n_iter ${fluxnet_SPINUP_n_iter}
219    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_sechiba $( correct_duree ${fluxnet_SPINUP_duree_sechiba} ${TIME_YEAR} )
220    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_stomate $( correct_duree ${fluxnet_SPINUP_duree_stomate} ${TIME_YEAR} )
221    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_carbonsol $( correct_duree ${fluxnet_SPINUP_duree_carbonsol} ${TIME_YEAR} )
222    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_final $( correct_duree ${fluxnet_SPINUP_duree_final} ${TIME_YEAR} )
223
224    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices BoundaryFilesListNonDel y
225
226    # TimeSeries : ALMAOUTPUT for SECHIBA
227    typeset option
228    for option in ${config_SubJobPost[*]} ; do
229        eval value=\${config_SubJobPost_${option}}
230        eval echo ${option} ${value}
231        if [ X${value} != X ] ; then
232            eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SubJobPost ${option} \${config_SubJobPost_${option}}
233        fi
234    done
235#    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF TimeSeriesFrequency ${TIME_YEAR}Y
236#    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF TimeSeriesFrequency NONE
237    set -A sechiba_TimeSeriesVars2D -- nobiofrac SWnet LWnet Qh Qle Qg Qf DelSurfHeat DelColdCont Snowf Rainf Evap \
238                                     Qs Qsb Qsm DelSoilMoist DelSWE DelIntercept AvgSurfT RadT Albedo SWE SoilMoist SoilWet SoilTemp PotEvap \
239                                     ECanop TVeg ESoil RootMoist SubSnow ACond SnowFrac SAlbedo SnowDepth dis
240    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobPost sechiba_TimeSeriesVars2D "("$( echo ${sechiba_TimeSeriesVars2D[@]} | sed -e "s/ /,/g" )")"
241    set -A sechiba_TimeSeriesVars3D -- vegetfrac maxvegetfrac GPP
242    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobPost sechiba_TimeSeriesVars3D "("$( echo ${sechiba_TimeSeriesVars3D[@]} | sed -e "s/ /,/g" )")"
243
244    # modifications on Job script
245    rm ${New_SUBMIT_DIR}/Job_${OldJobName}
246    IGCM_sys_Cp ${SUBMIT_DIR}/Job_${MyJobName} ${New_SUBMIT_DIR}/Job_${SubJobName}
247
248    sed -e "s/ ${MyJobName}/ ${SubJobName}/" \
249        -e "s/Script_Output_${MyJobName}/Script_Output_${SubJobName}/" \
250        ${New_SUBMIT_DIR}/Job_${SubJobName} > ${New_SUBMIT_DIR}/Job_${SubJobName}_
251    IGCM_sys_Mv ${New_SUBMIT_DIR}/Job_${SubJobName}_ ${New_SUBMIT_DIR}/Job_${SubJobName}
252    chmod u+x ${New_SUBMIT_DIR}/Job_${SubJobName}
253
254
255    # modification on parameter files
256    IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/sechiba.def ${New_SUBMIT_DIR}/PARAM/sechiba.def
257    IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/stomate.def ${New_SUBMIT_DIR}/PARAM/stomate.def
258    IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/driver.def ${New_SUBMIT_DIR}/PARAM/driver.def
259
260    eval first_option=${fluxnet_SubJobParams[0]} > /dev/null 2>&1
261    if [ X${first_option} != X"Error:" ] ; then
262        IGCM_card_DefineArrayFromSection ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams
263        eval first_option=${spinup_SubJobParams[0]} > /dev/null 2>&1
264           
265        typeset option option_ PARAM_FILE
266        for option in ${fluxnet_SubJobParams[*]} ; do
267            PARAM_FILE=$( echo ${option} | awk -F_ '{print $1}' )
268            echo "For parameter file ${PARAM_FILE}.def"
269            option_=$( echo ${option} | sed -e "s/${PARAM_FILE}_//" )
270            eval echo "${option_}="\${fluxnet_SubJobParams_${option}}
271            case ${PARAM_FILE} in
272                sechiba)
273                    eval SECHIBA_sed ${option_} \${fluxnet_SubJobParams_${option}}
274                    ;;
275                stomate)
276                    eval STOMATE_sed ${option_} \${fluxnet_SubJobParams_${option}}
277                    ;;
278                driver)
279                    eval DRIVER_sed ${option_} \${fluxnet_SubJobParams_${option}}
280                    ;;
281            esac
282
283            if [ X${first_option} != X"Error:" ] ; then
284                for option_ in ${spinup_SubJobParams[*]} ; do
285                    if [ X${option} == X${option_} ] ; then
286                        eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams ${option} \${fluxnet_SubJobParams_${option}}
287                    fi
288                done
289            fi
290        done
291    fi
292
293    # Replace vegetation
294    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices impose_veg y
295
296    (( iphys = 0 ))
297    while [ $iphys -lt ${fluxnet_FLUXNET_NbSitesParam} ] ; do
298       
299        # Detect if physical parameter has
300        #  array description or line per PFT description in the parameter file
301        SearchParam=""
302        ${fluxnet_FLUXNET_CompSitesParam[${iphys}]}_grep ${fluxnet_FLUXNET_NameSitesParam[${iphys}]}
303
304        case ${SearchParam} in
305            undefined)
306                echo "ERROR : parameter ${fluxnet_FLUXNET_NameSitesParam[${iphys}]} doen't exist in ${fluxnet_FLUXNET_CompSitesParam[${iphys}]} parameter file !"
307                echo "You must correct NameSiteParam option in fluxnet.card file or add new parameter in component.def file"
308                echo "We must STOP here."
309                exit 1
310                ;;
311            line)
312                ipft=1
313                while [ $ipft -le ${NbPFTs} ] ; do
314                    if [ $ipft -lt 10 ] ; then
315                        numpft=0${ipft}
316                    else
317                        numpft=${ipft}
318                    fi
319           
320                    ${fluxnet_FLUXNET_CompSitesParam[${iphys}]}_sed ${fluxnet_FLUXNET_NameSitesParam[${iphys}]}__${numpft} ${fluxnet_FLUXNET_Sites[$(( index + 4 + ( iphys * NbPFTs ) + ipft - 1 )) ]}
321                    (( ipft = ipft + 1 ))
322                done
323                ;;
324            vector)
325                unset ValueSiteParams
326                ipft=0
327                while [ $ipft -lt ${NbPFTs} ] ; do
328                    ValueSiteParams[${ipft}]=${fluxnet_FLUXNET_Sites[$(( index + 4 + ( iphys * NbPFTs ) + ipft - 1 )) ]}
329                    (( ipft = ipft + 1 ))
330                done
331                ${fluxnet_FLUXNET_CompSitesParam[${iphys}]}_sed ${fluxnet_FLUXNET_NameSitesParam[${iphys}]} "${ValueSiteParams[*]}"
332                ;;
333        esac
334
335        (( iphys = iphys + 1 ))
336    done
337
338    IGCM_debug_Verif_Exit
339
340# Lauch the SPINUP Job :
341
342    echo "#!/bin/ksh" > ${RUN_DIR_PATH}/SubJob${site}.ksh
343    echo "MODIPSL=${MODIPSL}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
344    echo "libIGCM=${libIGCM}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
345    echo "cd ${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
346    echo "export SUBMIT_DIR=${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
347    echo ". ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
348    echo ". ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
349    echo "export Script_Output=out_qsub_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
350    echo "export config_UserChoices_JobName=${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
351    echo "export CumulPeriod=1" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
352#    echo "nohup Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
353    echo "IGCM_sys_Qsub Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
354
355    if [ ${DRYRUN} -le 1 ] ; then
356        chmod u+x ${RUN_DIR_PATH}/SubJob${site}.ksh
357        nohup ${RUN_DIR_PATH}/SubJob${site}.ksh
358    fi
359
360    IGCM_debug_Verif_Exit
361
362    (( isite=isite+1 ))
363    (( index=index+NumInfosBySite ))
364done
365
366IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
Note: See TracBrowser for help on using the repository browser.