source: tags/ORCHIDEE_1_9_6/ORCHIDEE_OL/ENSEMBLE/Job_ENSEMBLE @ 3663

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

Correct ENSEMBLE scripts and fluxnet.ksh (remove unused parts of the script + correction).

  • Property svn:executable set to *
File size: 14.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 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=::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
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    if [ ! -f ${SUBMIT_DIR}/PARAM/run.def ] ; then
247        echo "#ENSEMBLE add :" > ${New_SUBMIT_DIR}/PARAM/run.def
248    else
249        IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/run.def ${New_SUBMIT_DIR}/PARAM/run.def
250        echo "#ENSEMBLE add :" >> ${New_SUBMIT_DIR}/PARAM/run.def
251    fi
252    echo "" >> ${New_SUBMIT_DIR}/PARAM/run.def
253
254    eval first_option=${ensemble_SubJobParams[0]} > /dev/null 2>&1
255    if [ X${first_option} != X"Error:" ] ; then
256        IGCM_card_DefineArrayFromSection ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams
257        eval first_option=${spinup_SubJobParams[0]} > /dev/null 2>&1
258
259        typeset option option_
260        for option in ${ensemble_SubJobParams[*]} ; do
261            echo "For parameter file run.def"
262            eval echo "${option}="\${ensemble_SubJobParams_${option}}
263            eval ORCHIDEE_grep ${option}
264            if [ ${SearchParam} == "undefined" ] ; then
265                echo "ERROR : parameter ${option} doesn't exist in run parameter file !"
266                echo "You must correct subjobparam option in ensemble.card file or add new parameter in run.def file"
267                echo "We must STOP here."
268                exit 1
269            fi
270            eval ORCHIDEE_def ${option} \${ensemble_SubJobParams_${option}}
271           
272            if [ X${first_option} != X"Error:" ] ; then
273                for option in ${spinup_SubJobParams[*]} ; do
274                    if [ X${option} == X${option_} ] ; then
275                        eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams ${option} \${ensemble_SubJobParams_${option}}
276                    fi
277                done
278            fi
279        done
280    fi
281
282    (( iphys = 0 ))
283    (( indext = index + 4 ))
284    while [ $iphys -lt ${ensemble_CONFIG_NbSitesParam} ] ; do
285       
286        # Detect if physical parameter has
287        #  array description or line per PFT description in the parameter file
288        SearchParam=""
289        ORCHIDEE_grep ${ensemble_CONFIG_NameSitesParam[${iphys}]}
290
291        case ${SearchParam} in
292            undefined)
293                echo "ERROR : parameter ${ensemble_CONFIG_NameSitesParam[${iphys}]} does not exist in run.def parameter file !"
294                echo "You must correct NameSiteParam option in ensemble.card file or add new parameter in run.def file"
295                echo "We must STOP here."
296                exit 1
297                ;;
298            value)
299                ORCHIDEE_def ${ensemble_CONFIG_NameSitesParam[${iphys}]} ${ensemble_CONFIG_Sites[$(( indext )) ]}
300                (( indext = indext + 1 ))
301                ;;
302            line)
303                ipft=1
304                while [ $ipft -le ${NbPFTs} ] ; do
305                    if [ $ipft -lt 10 ] ; then
306                        numpft=0${ipft}
307                    else
308                        numpft=${ipft}
309                    fi
310           
311                    ORCHIDEE_def ${ensemble_CONFIG_NameSitesParam[${iphys}]}__${numpft} ${ensemble_CONFIG_Sites[$(( indext )) ]}
312                    (( indext = indext + 1 ))
313                    (( ipft = ipft + 1 ))
314                done
315                ;;
316            vector)
317                unset ValueSiteParams
318                ipft=0
319                while [ $ipft -lt ${NbPFTs} ] ; do
320                    ValueSiteParams[${ipft}]=${ensemble_CONFIG_Sites[$(( indext )) ]}
321                    (( indext = indext + 1 ))
322                    (( ipft = ipft + 1 ))
323                done
324                ORCHIDEE_def ${ensemble_CONFIG_NameSitesParam[${iphys}]} "${ValueSiteParams[*]}"
325                ;;
326        esac
327
328        (( iphys = iphys + 1 ))
329    done
330
331    IGCM_debug_Verif_Exit
332
333# Lauch the SPINUP Job :
334
335    echo "#!/bin/ksh" > ${RUN_DIR_PATH}/SubJob${site}.ksh
336    echo "MODIPSL=${MODIPSL}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
337    echo "libIGCM=${libIGCM}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
338    echo "cd ${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
339    echo "export SUBMIT_DIR=${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
340    echo ". ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
341    echo ". ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
342    echo "export Script_Output=Script_Output_${SubJobName}.000001" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
343    echo "export config_UserChoices_JobName=${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
344    echo "export CumulPeriod=1" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
345#    echo "nohup Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
346    echo "IGCM_sys_Qsub Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
347
348    if [ ${DRYRUN} -le 1 ] ; then
349        chmod u+x ${RUN_DIR_PATH}/SubJob${site}.ksh
350        nohup ${RUN_DIR_PATH}/SubJob${site}.ksh
351    fi
352
353    IGCM_debug_Verif_Exit
354
355    (( isite=isite+1 ))
356    (( index=index+NumInfosBySite ))
357done
358
359IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
Note: See TracBrowser for help on using the repository browser.