source: tags/ORCHIDEE_1_9_6/ORCHIDEE_OL/FLUXNET/Job_FLUXNET_validation @ 4234

Last change on this file since 4234 was 876, checked in by didier.solyga, 12 years ago

Modified FLUXNET and ENSEMBLE configurations for the externalization. Delete obselete files in OOL_SEC and OOL_SEC_STO. Update SPINUP config.

File size: 16.4 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=
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
99
100IGCM_sys_MkdirWork ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
101
102
103function correct_duree
104{
105    # Ths function compute the nearest multiple of dyear near duree
106    typeset duree dyear
107    duree=$1
108    dyear=$2
109    if [ $(( duree % dyear )) -gt 0 ] ; then
110        echo $(( ( duree / dyear + 1 ) * dyear ))
111    else
112        echo ${duree}
113    fi
114}
115
116# Path for all skeleton SubJob scripts to SPINUP directory
117Skeleton_Path=$( cd ../; pwd )
118
119
120for group in  ${fluxnet_FLUXNET_Groups[*]} ; do
121   isite=1
122   index=0
123
124   eval temp=\${fluxnet_FLUXNET_${group}[*]}
125   set -A group_site -- $temp
126
127   # Number of sites :
128   NumSites=$(( ${#group_site[*]} / NumInfosBySite ))
129   NumAllSites=$(( NumAllSites + NumSites ))
130
131   while [ ${isite} -le ${NumSites} ] ; do
132   
133    site=${group_site[$index]}
134
135    echo "   ------------------------"
136    echo "   SPINUP for Site : ${site}"
137
138    DATE0_YEAR=${group_site[ $(( index + ColumnYear )) ]}
139    TIME_YEAR=${group_site[ $(( index + ColumnLength )) ]}
140
141#######################################################
142# Script internal settings
143# nothing to be modified below this line
144######################################################ä
145
146# Copy the SPINUP directory
147    SubJobName=${site}${config_UserChoices_JobName}
148    New_SUBMIT_DIR=${SUBMIT_DIR}/${SubJobName}
149    IGCM_sys_Cp -Rp ../SPINUP ${New_SUBMIT_DIR}
150#     ls -la ${New_SUBMIT_DIR}
151#     cat ${New_SUBMIT_DIR}/config.card
152#     echo "---"
153
154    # Install this directory
155    # modifications on config.card
156    MyJobName=${config_UserChoices_JobName}
157    IGCM_card_DefineVariableFromOption ${New_SUBMIT_DIR}/config.card UserChoices JobName
158    OldJobName=${config_UserChoices_JobName}
159    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobName ${SubJobName}
160    config_UserChoices_JobName=${MyJobName}
161    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices TagName
162    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices TagName ${config_UserChoices_TagName}
163    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices CalendarType ${config_UserChoices_CalendarType}
164
165    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobClass ${config_UserChoices_JobClass}
166    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobNumProcTot ${config_UserChoices_JobNumProcTot}
167    sed -e "s/^JobRunOptions=.*/JobRunOptions=\'${config_UserChoices_JobRunOptions}\'/" ${New_SUBMIT_DIR}/config.card > temp.card
168    IGCM_sys_Mv temp.card ${New_SUBMIT_DIR}/config.card
169
170    # Give path for all skeleton SubJob scripts to SPINUP directory
171    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices SubJobPath ${Skeleton_Path}
172
173    # All SubJobs in SPINUP in one or more years (must be used with libIGCM branches/AllPostFred).
174    # It is the length of the forcing file.
175    if [ X"${config_UserChoices_CalendarType}" = X"360d" ] ; then
176        This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1230
177        This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-30
178    else
179        This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1231
180        This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-31
181    fi
182
183    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateBegin ${DATE0_YEAR}-01-01
184    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodLength ${TIME_YEAR}Y
185
186    # DateEnd is defined by SpinUp job itself (it will be modified in config.card).
187    # but to get all SpinUp Job loops, we have to add at least a number of years greater
188    # than those that will be modified in config.card. Default is 150.00.00 years more for SpinUp.
189    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateEnd $(( DATE0_YEAR + 150 ))-01-01
190
191    # Infinit SPINUP Job :
192    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodNb 99999
193
194    # SRF section : first restart and post-treatments
195    typeset option
196    for option in ${config_SRF[*]} ; do
197        eval value=\${config_SRF_${option}}
198        eval echo ${option} ${value}
199        if [ X${value} != X ] ; then
200            eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF ${option} \${config_SRF_${option}}
201        fi
202    done
203    if [ X"${fluxnet_UserChoices_ok_stomate}" = "Xy" ] ; then
204        for option in ${config_SBG[*]} ; do
205            eval value=\${config_SBG_${option}}
206            eval echo ${option} ${value}
207            if [ X${value} != X ] ; then
208                eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG ${option} \${config_SBG_${option}}
209            fi
210        done
211    fi
212
213    # modifications on spinup.card
214    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobForcingFile List "(${fluxnet_FLUXNET_FluxnetPath}/${group_site[$(( index + ColumnFilename ))]}, forcing_file.nc)"
215
216    typeset option
217    for option in ${fluxnet_UserChoices[*]} ; do
218        eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices ${option} \${fluxnet_UserChoices_${option}}
219    done
220    # No routing for FLUXNET
221    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices ok_routing n
222
223    # Max levels for FLUXNET
224    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices sechiba_LEVEL 10
225    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices stomate_LEVEL 10
226
227    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices DRIVER_NORESTART y
228    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices DRIVER_TIMELENGTH n
229
230    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_nostomate $( correct_duree ${fluxnet_SPINUP_duree_nostomate} ${TIME_YEAR} )
231    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_inistomate $( correct_duree ${fluxnet_SPINUP_duree_inistomate} ${TIME_YEAR} )
232    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_offlineini $( correct_duree ${fluxnet_SPINUP_duree_offlineini} ${TIME_YEAR} )
233    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices n_iter ${fluxnet_SPINUP_n_iter}
234    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_sechiba $( correct_duree ${fluxnet_SPINUP_duree_sechiba} ${TIME_YEAR} )
235    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_stomate $( correct_duree ${fluxnet_SPINUP_duree_stomate} ${TIME_YEAR} )
236    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_carbonsol $( correct_duree ${fluxnet_SPINUP_duree_carbonsol} ${TIME_YEAR} )
237    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_final $( correct_duree ${fluxnet_SPINUP_duree_final} ${TIME_YEAR} )
238
239    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices BoundaryFilesListNonDel y
240
241    # TimeSeries : ALMAOUTPUT for SECHIBA
242    typeset option
243    for option in ${config_SubJobPost[*]} ; do
244        eval value=\${config_SubJobPost_${option}}
245        eval echo ${option} ${value}
246        if [ X${value} != X ] ; then
247            eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SubJobPost ${option} \${config_SubJobPost_${option}}
248        fi
249    done
250#    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF TimeSeriesFrequency ${TIME_YEAR}Y
251#    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF TimeSeriesFrequency NONE
252    set -A sechiba_TimeSeriesVars2D -- nobiofrac SWnet LWnet Qh Qle Qg Qf DelSurfHeat DelColdCont Snowf Rainf Evap \
253                                     Qs Qsb Qsm DelSoilMoist DelSWE DelIntercept AvgSurfT RadT Albedo SWE SoilMoist SoilWet SoilTemp PotEvap \
254                                     ECanop TVeg ESoil RootMoist SubSnow ACond SnowFrac SAlbedo SnowDepth dis
255    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobPost sechiba_TimeSeriesVars2D "("$( echo ${sechiba_TimeSeriesVars2D[@]} | sed -e "s/ /,/g" )")"
256    set -A sechiba_TimeSeriesVars3D -- vegetfrac maxvegetfrac GPP
257    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobPost sechiba_TimeSeriesVars3D "("$( echo ${sechiba_TimeSeriesVars3D[@]} | sed -e "s/ /,/g" )")"
258
259    # modifications on Job script
260    rm ${New_SUBMIT_DIR}/Job_${OldJobName}
261    IGCM_sys_Cp ${SUBMIT_DIR}/Job_${MyJobName} ${New_SUBMIT_DIR}/Job_${SubJobName}
262
263    sed -e "s/ ${MyJobName}/ ${SubJobName}/" \
264        -e "s/Script_Output_${MyJobName}/Script_Output_${SubJobName}/" \
265        -e "s/\(IGCM_config_Finalize\)/\1\nif\ [\ \${config_UserChoices_JobName}\ =\ \"${SubJobName}\"\ ]\nthen\nIGCM_sys_Mv\ \${R_OUT}\/\${config_UserChoices_TagName}\/\${config_UserChoices_JobName}\ \${R_OUT}\/\${config_UserChoices_TagName}\/${config_UserChoices_JobName}\/\nIGCM_sys_Mv\ \${R_OUT}\/\${config_UserChoices_TagName}\/\${config_UserChoices_JobName}HIST\ \${R_OUT}\/\${config_UserChoices_TagName}\/${config_UserChoices_JobName}\/\nfi/" \
266        ${New_SUBMIT_DIR}/Job_${SubJobName} > ${New_SUBMIT_DIR}/Job_${SubJobName}_
267    IGCM_sys_Mv ${New_SUBMIT_DIR}/Job_${SubJobName}_ ${New_SUBMIT_DIR}/Job_${SubJobName}
268    chmod u+x ${New_SUBMIT_DIR}/Job_${SubJobName}
269
270
271    # modification on parameter files
272    if [ ! -f ${SUBMIT_DIR}/PARAM/run.def ] ; then
273        echo "#FLUXNET add :" > ${New_SUBMIT_DIR}/PARAM/run.def
274    else
275        IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/run.def ${New_SUBMIT_DIR}/PARAM/run.def
276        echo "#FLUXNET add :" >> ${New_SUBMIT_DIR}/PARAM/run.def
277    fi
278    echo "" >> ${New_SUBMIT_DIR}/PARAM/run.def
279
280    eval first_option=${fluxnet_SubJobParams[0]} > /dev/null 2>&1
281    if [ X${first_option} != X"Error:" ] ; then
282        IGCM_card_DefineArrayFromSection ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams
283        eval first_option=${spinup_SubJobParams[0]} > /dev/null 2>&1
284
285        typeset option option_
286        for option in ${fluxnet_SubJobParams[*]} ; do
287            echo "For parameter file run.def"
288            eval echo "${option}="\${fluxnet_SubJobParams_${option}}
289            eval ORCHIDEE_grep ${option}
290            if [ ${SearchParam} == "undefined" ] ; then
291                echo "ERROR : parameter ${option} doesn't exist in run parameter file !"
292                echo "You must correct subjobparam option in fluxnet.card file or add new parameter in run.def file"
293                echo "We must STOP here."
294                exit 1
295            fi
296            eval ORCHIDEE_def ${option} \${fluxnet_SubJobParams_${option}}
297           
298            if [ X${first_option} != X"Error:" ] ; then
299                for option in ${spinup_SubJobParams[*]} ; do
300                    if [ X${option} == X${option_} ] ; then
301                        eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams ${option} \${fluxnet_SubJobParams_${option}}
302                    fi
303                done
304            fi
305        done
306    fi
307
308    # Replace vegetation
309    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices impose_veg y
310
311    (( iphys = 0 ))
312    while [ $iphys -lt ${fluxnet_FLUXNET_NbSitesParam} ] ; do
313       
314        # Detect if physical parameter has
315        #  array description or line per PFT description in the parameter file
316        SearchParam=""
317        ORCHIDEE_grep ${fluxnet_FLUXNET_NameSitesParam[${iphys}]}
318
319        case ${SearchParam} in
320            undefined)
321                echo "ERROR : parameter ${fluxnet_FLUXNET_NameSitesParam[${iphys}]} doesn't exist in run.def parameter file !"
322                echo "You must correct NameSiteParam option in fluxnet.card file or add new parameter in run.def file"
323                echo "We must STOP here."
324                exit 1
325                ;;
326            line)
327                ipft=1
328                while [ $ipft -le ${NbPFTs} ] ; do
329                    if [ $ipft -lt 10 ] ; then
330                        numpft=0${ipft}
331                    else
332                        numpft=${ipft}
333                    fi
334           
335                    ORCHIDEE_def ${fluxnet_FLUXNET_NameSitesParam[${iphys}]}__${numpft} ${group_site[$(( index + 4 + ( iphys * NbPFTs ) + ipft - 1 )) ]}
336                    (( ipft = ipft + 1 ))
337                done
338                ;;
339            vector)
340                unset ValueSiteParams
341                ipft=1
342                while [ $ipft -le ${NbPFTs} ] ; do
343                    ValueSiteParams[${ipft}]=${group_site[$(( index + 4 + ( iphys * NbPFTs ) + ipft - 1 )) ]}
344                    (( ipft = ipft + 1 ))
345                done
346                ORCHIDEE_def ${fluxnet_FLUXNET_NameSitesParam[${iphys}]} "${ValueSiteParams[*]}"
347                ;;
348        esac
349
350        (( iphys = iphys + 1 ))
351    done
352
353    IGCM_debug_Verif_Exit
354
355# Lauch the SPINUP Job :
356
357    echo "#!/bin/ksh" > ${RUN_DIR_PATH}/SubJob${site}.ksh
358    echo "MODIPSL=${MODIPSL}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
359    echo "libIGCM=${libIGCM}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
360    echo "cd ${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
361    echo "export SUBMIT_DIR=${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
362    echo ". ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
363    echo ". ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
364    echo "export Script_Output=out_qsub_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
365    echo "export config_UserChoices_JobName=${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
366    echo "export CumulPeriod=1" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
367#    echo "nohup Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
368    echo "IGCM_sys_Qsub Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
369
370    if [ ${DRYRUN} -le 1 ] ; then
371        chmod u+x ${RUN_DIR_PATH}/SubJob${site}.ksh
372        nohup ${RUN_DIR_PATH}/SubJob${site}.ksh
373    fi
374
375    IGCM_debug_Verif_Exit
376
377    (( isite=isite+1 ))
378    (( index=index+NumInfosBySite ))
379done
380done
381
382IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
Note: See TracBrowser for help on using the repository browser.