source: branches/ORCHIDEE_EXT/ORCHIDEE_OL/ENSEMBLE/Job_ENSEMBLE @ 262

Last change on this file since 262 was 262, checked in by didier.solyga, 13 years ago

Add ENSEMBLE from the trunk version in ORCHIDEE_OL (the previous ENSEMBLE was FLUXNET)

  • Property svn:executable set to *
File size: 15.0 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 ENSEMBLE 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=/work/cont003/p86manci/TEST_LIB_trunk_04-03-11
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
90R_BC=${R_IN}/BC
91
92IGCM_sys_MkdirWork ${RUN_DIR_PATH}
93
94. ${SUBMIT_DIR}/ensemble.ksh
95
96ENSEMBLE_initialize
97
98function correct_duree
99{
100    # Ths function compute the nearest multiple of dyear near duree
101    typeset duree dyear
102    duree=$1
103    dyear=$2
104    if [ $(( duree % dyear )) -gt 0 ] ; then
105        echo $(( ( duree / dyear + 1 ) * dyear ))
106    else
107        echo ${duree}
108    fi
109}
110
111# Path for all skeleton SubJob scripts to SPINUP directory
112Skeleton_Path=$( cd ../; pwd )
113
114isite=1
115index=0
116echo ${isite} ${NumSites}
117while [ ${isite} -le ${NumSites} ] ; do
118   
119    site=${ensemble_CONFIG_Sites[$index]}
120    echo "   ------------------------"
121    echo "   SPINUP for Site : ${site}"
122
123    DATE0_YEAR=${ensemble_CONFIG_Sites[ $(( index + ColumnYear )) ]}
124    TIME_YEAR=${ensemble_CONFIG_Sites[ $(( index + ColumnLength )) ]}
125
126#######################################################
127# Script internal settings
128# nothing to be modified below this line
129######################################################ä
130
131# Copy the SPINUP directory
132    SubJobName=${site}${config_UserChoices_JobName}
133    New_SUBMIT_DIR=${SUBMIT_DIR}/${SubJobName}
134    IGCM_sys_Cp -Rp ../SPINUP ${New_SUBMIT_DIR}
135#     ls -la ${New_SUBMIT_DIR}
136#     cat ${New_SUBMIT_DIR}/config.card
137#     echo "---"
138
139    # Install this directory
140    # modifications on config.card
141    MyJobName=${config_UserChoices_JobName}
142    IGCM_card_DefineVariableFromOption ${New_SUBMIT_DIR}/config.card UserChoices JobName
143    OldJobName=${config_UserChoices_JobName}
144    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobName ${SubJobName}
145    config_UserChoices_JobName=${MyJobName}
146    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices TagName
147    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices TagName ${config_UserChoices_TagName}
148    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices CalendarType ${config_UserChoices_CalendarType}
149
150    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobClass ${config_UserChoices_JobClass}
151    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobNumProcTot ${config_UserChoices_JobNumProcTot}
152    sed -e "s/^JobRunOptions=.*/JobRunOptions=\'${config_UserChoices_JobRunOptions}\'/" ${New_SUBMIT_DIR}/config.card > temp.card
153    IGCM_sys_Mv temp.card ${New_SUBMIT_DIR}/config.card
154
155    # Give path for all skeleton SubJob scripts to SPINUP directory
156    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices SubJobPath ${Skeleton_Path}
157
158    # All SubJobs in SPINUP in one or more years (must be used with libIGCM branches/AllPostFred).
159    # It is the length of the forcing file.
160    if [ X"${config_UserChoices_CalendarType}" = X"360d" ] ; then
161        This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1230
162        This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-30
163    else
164        This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1231
165        This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-31
166    fi
167
168    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateBegin ${DATE0_YEAR}-01-01
169    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodLength ${TIME_YEAR}Y
170
171    # DateEnd is defined by SpinUp job itself (it will be modified in config.card).
172    # but to get all SpinUp Job loops, we have to add at least a number of years greater
173    # than those that will be modified in config.card. Default is 150.00.00 years more for SpinUp.
174    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateEnd $(( DATE0_YEAR + 150 ))-01-01
175
176    # Infinit SPINUP Job :
177    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodNb 99999
178
179    # SRF section : first restart and post-treatments
180    typeset option
181    for option in ${config_SRF[*]} ; do
182        eval value=\${config_SRF_${option}}
183        eval echo ${option} ${value}
184        if [ X${value} != X ] ; then
185            eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF ${option} \${config_SRF_${option}}
186        fi
187    done
188    if [ X"${ensemble_UserChoices_ok_stomate}" = "Xy" ] ; then
189        for option in ${config_SBG[*]} ; do
190            eval value=\${config_SBG_${option}}
191            eval echo ${option} ${value}
192            if [ X${value} != X ] ; then
193                eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG ${option} \${config_SBG_${option}}
194            fi
195        done
196    fi
197
198    # modifications on spinup.card
199    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobForcingFile List "(${ensemble_CONFIG_ForcingPath}/${ensemble_CONFIG_Sites[$(( index + ColumnFilename ))]}, forcing_file.nc)"
200
201    typeset option
202    for option in ${ensemble_UserChoices[*]} ; do
203        eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices ${option} \${ensemble_UserChoices_${option}}
204    done
205
206    # Max levels for ENSEMBLE
207    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices sechiba_LEVEL 10
208    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices stomate_LEVEL 10
209
210    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices DRIVER_NORESTART y
211    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices DRIVER_TIMELENGTH n
212
213    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_nostomate $( correct_duree ${ensemble_SPINUP_duree_nostomate} ${TIME_YEAR} )
214    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_inistomate $( correct_duree ${ensemble_SPINUP_duree_inistomate} ${TIME_YEAR} )
215    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_offlineini $( correct_duree ${ensemble_SPINUP_duree_offlineini} ${TIME_YEAR} )
216    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices n_iter ${ensemble_SPINUP_n_iter}
217    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_sechiba $( correct_duree ${ensemble_SPINUP_duree_sechiba} ${TIME_YEAR} )
218    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_stomate $( correct_duree ${ensemble_SPINUP_duree_stomate} ${TIME_YEAR} )
219    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_carbonsol $( correct_duree ${ensemble_SPINUP_duree_carbonsol} ${TIME_YEAR} )
220    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_final $( correct_duree ${ensemble_SPINUP_duree_final} ${TIME_YEAR} )
221
222    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices BoundaryFilesListNonDel y
223
224    # TimeSeries : ALMAOUTPUT for SECHIBA
225    typeset option
226    for option in ${config_SubJobPost[*]} ; do
227        eval value=\${config_SubJobPost_${option}}
228        eval echo ${option} ${value}
229        if [ X${value} != X ] ; then
230            eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SubJobPost ${option} \${config_SubJobPost_${option}}
231        fi
232    done
233
234    # modifications on Job script
235    rm ${New_SUBMIT_DIR}/Job_${OldJobName}
236    IGCM_sys_Cp ${SUBMIT_DIR}/Job_${MyJobName} ${New_SUBMIT_DIR}/Job_${SubJobName}
237
238    sed -e "s/ ${MyJobName}/ ${SubJobName}/" \
239        -e "s/Script_Output_${MyJobName}/Script_Output_${SubJobName}/" \
240        ${New_SUBMIT_DIR}/Job_${SubJobName} > ${New_SUBMIT_DIR}/Job_${SubJobName}_
241    IGCM_sys_Mv ${New_SUBMIT_DIR}/Job_${SubJobName}_ ${New_SUBMIT_DIR}/Job_${SubJobName}
242    chmod u+x ${New_SUBMIT_DIR}/Job_${SubJobName}
243
244
245    # modification on parameter files
246    IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/sechiba.def ${New_SUBMIT_DIR}/PARAM/sechiba.def
247    IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/stomate.def ${New_SUBMIT_DIR}/PARAM/stomate.def
248    IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/driver.def ${New_SUBMIT_DIR}/PARAM/driver.def
249
250    eval first_option=${ensemble_SubJobParams[0]} > /dev/null 2>&1
251    if [ X${first_option} != X"Error:" ] ; then
252        IGCM_card_DefineArrayFromSection ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams
253        eval first_option=${spinup_SubJobParams[0]} > /dev/null 2>&1
254           
255        typeset option option_ PARAM_FILE
256        for option in ${ensemble_SubJobParams[*]} ; do
257            PARAM_FILE=$( echo ${option} | awk -F_ '{print $1}' )
258            echo "For parameter file ${PARAM_FILE}.def"
259            option_=$( echo ${option} | sed -e "s/${PARAM_FILE}_//" )
260            eval echo "${option_}="\${ensemble_SubJobParams_${option}}
261            case ${PARAM_FILE} in
262                sechiba)
263                    eval SECHIBA_sed ${option_} \${ensemble_SubJobParams_${option}}
264                    ;;
265                stomate)
266                    eval STOMATE_sed ${option_} \${ensemble_SubJobParams_${option}}
267                    ;;
268                driver)
269                    eval DRIVER_sed ${option_} \${ensemble_SubJobParams_${option}}
270                    ;;
271            esac
272
273            if [ X${first_option} != X"Error:" ] ; then
274                for option_ in ${spinup_SubJobParams[*]} ; do
275                    if [ X${option} == X${option_} ] ; then
276                        eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams ${option} \${ensemble_SubJobParams_${option}}
277                    fi
278                done
279            fi
280        done
281    fi
282
283    (( iphys = 0 ))
284    (( indext = index + 4 ))
285    while [ $iphys -lt ${ensemble_CONFIG_NbSitesParam} ] ; do
286       
287        # Detect if physical parameter has
288        #  array description or line per PFT description in the parameter file
289        SearchParam=""
290        ${ensemble_CONFIG_CompSitesParam[${iphys}]}_grep ${ensemble_CONFIG_NameSitesParam[${iphys}]}
291
292        case ${SearchParam} in
293            undefined)
294                echo "ERROR : parameter ${ensemble_CONFIG_NameSitesParam[${iphys}]} doen't exist in ${ensemble_CONFIG_CompSitesParam[${iphys}]} parameter file !"
295                echo "You must correct NameSiteParam option in ensemble.card file or add new parameter in component.def file"
296                echo "We must STOP here."
297                exit 1
298                ;;
299            value)
300                ${ensemble_CONFIG_CompSitesParam[${iphys}]}_sed ${ensemble_CONFIG_NameSitesParam[${iphys}]} ${ensemble_CONFIG_Sites[$(( indext )) ]}
301                (( indext = indext + 1 ))
302                ;;
303            line)
304                ipft=1
305                while [ $ipft -le ${NbPFTs} ] ; do
306                    if [ $ipft -lt 10 ] ; then
307                        numpft=0${ipft}
308                    else
309                        numpft=${ipft}
310                    fi
311           
312                    ${ensemble_CONFIG_CompSitesParam[${iphys}]}_sed ${ensemble_CONFIG_NameSitesParam[${iphys}]}__${numpft} ${ensemble_CONFIG_Sites[$(( indext )) ]}
313                    (( indext = indext + 1 ))
314                    (( ipft = ipft + 1 ))
315                done
316                ;;
317            vector)
318                unset ValueSiteParams
319                ipft=0
320                while [ $ipft -lt ${NbPFTs} ] ; do
321                    ValueSiteParams[${ipft}]=${ensemble_CONFIG_Sites[$(( indext )) ]}
322                    (( indext = indext + 1 ))
323                    (( ipft = ipft + 1 ))
324                done
325                ${ensemble_CONFIG_CompSitesParam[${iphys}]}_sed ${ensemble_CONFIG_NameSitesParam[${iphys}]} "${ValueSiteParams[*]}"
326                ;;
327        esac
328
329        (( iphys = iphys + 1 ))
330    done
331
332    IGCM_debug_Verif_Exit
333
334# Lauch the SPINUP Job :
335
336    echo "#!/bin/ksh" > ${RUN_DIR_PATH}/SubJob${site}.ksh
337    echo "MODIPSL=${MODIPSL}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
338    echo "libIGCM=${libIGCM}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
339    echo "cd ${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
340    echo "export SUBMIT_DIR=${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
341    echo ". ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
342    echo ". ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
343    echo "export Script_Output=Script_Output_${SubJobName}.000001" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
344    echo "export config_UserChoices_JobName=${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
345    echo "export CumulPeriod=1" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
346#    echo "nohup Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
347    echo "IGCM_sys_Qsub Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
348
349    if [ ${DRYRUN} -le 1 ] ; then
350        chmod u+x ${RUN_DIR_PATH}/SubJob${site}.ksh
351        nohup ${RUN_DIR_PATH}/SubJob${site}.ksh
352    fi
353
354    IGCM_debug_Verif_Exit
355
356    (( isite=isite+1 ))
357    (( index=index+NumInfosBySite ))
358done
359
360IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
Note: See TracBrowser for help on using the repository browser.