source: branches/ORCHIDEE_2_2/ORCHIDEE_OL/ENSEMBLE/Job_ENSEMBLE @ 7074

Last change on this file since 7074 was 5633, checked in by josefine.ghattas, 6 years ago

Update ENSEMBLE configuration as done in branche ORCHIDEE_CN_CONFIG changeset [5615], [5616]
N Vuichard

  • Property svn:executable set to *
File size: 17.3 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 Sonke Zaehle "site_new.def" job
18#                       #################################################
19
20export BRIDGE_MSUB_PROJECT=gen6328
21
22if [ $# -lt 1 ] ; then
23   echo ""
24   echo "ERROR: Bad usage. You must give the name of the card as argument."
25   echo ""
26   echo "Do as follow for fluxnet simulation with fluxnet.card:"
27   echo "   ./Job_ENSEMBLE fluxnet  > out_Job_ENSEMBLE"
28   echo "Do as follow for ensemble simulation with ensemble.card:"
29   echo "   ./Job_ENSEMBLE ensemble > out_Job_ENSMEBLE"
30   echo ""
31   exit
32fi
33
34SUBMIT_DIR=$( pwd )
35MODIPSL=$(cd ${SUBMIT_DIR}'/../../..';pwd;)
36libIGCM=${MODIPSL}/libIGCM
37
38
39# All SubJobs in SPINUP in ONE OR MORE YEARS run (must be used with libIGCM branches/AllPostFred).
40
41#D--------------------------------------------------------------------==
42#D-                   -1. User modification place
43#D--------------------------------------------------------------------==
44
45#D- Increased verbosity (1, 2, 3)
46#Verbosity=3
47
48#D-
49# --------------------------------------------------------------------
50#D- ! Optionnal features /!\ Use with care !
51# --------------------------------------------------------------------
52
53#D- Low level debug : to bypass lib test checks and stack construction
54#D- Default=true
55DEBUG_debug=false
56
57#D- Set DEBUG_sys to false to disable output calls of function
58#D- Default=true
59#DEBUG_sys=false
60
61#D- Turn in dry run mode ? (0,1,2,3)
62#D- Default=0
63#DRYRUN=3
64# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
65# -------------------------------------------------------------------------------------
66# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
67# |          |  Cp/Exe param files |            |  Chmod  |                           |
68# |          |      Qsub           |            |         |                           |
69# -------------------------------------------------------------------------------------
70# |    0     |       yes           |    yes     |  yes    |      yes                  |
71# -------------------------------------------------------------------------------------
72# |    1     |       yes           |    yes     |  yes    |      no                   |
73# -------------------------------------------------------------------------------------
74# |    2     |       yes           |    yes     |  no     |      no                   |
75# -------------------------------------------------------------------------------------
76# |    3     |       yes           |    no      |  no     |      no                   |
77# -------------------------------------------------------------------------------------
78
79
80#D-
81#D--------------------------------------------------------------------==
82#D-                   0. System Environment
83#D-                      - Define variables for Number of processors
84#D-                      - Define MPI variables
85#D-                      - Define batch scheduler variables
86#D-                      - Source IGCM Library
87#D-                      - Get RESOLution in .resol file (temporary)
88#D--------------------------------------------------------------------==
89
90#D--------------------------------------------------------------------==
91#TaskType=post-processing
92
93. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
94. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
95. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
96#-------
97. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
98. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
99. ${libIGCM}/libIGCM_comp/libIGCM_comp.ksh
100. ${libIGCM}/libIGCM_post/libIGCM_post.ksh
101#-------
102( ${DEBUG_debug} ) && IGCM_debug_Check
103( ${DEBUG_debug} ) && IGCM_card_Check
104( ${DEBUG_debug} ) && IGCM_date_Check
105
106#D--------------------------------------------------------------------==
107#D- 0.1 COMMON ENVIRONMENT
108#D-     - Read libIGCM compatibility version in config.card
109#D-     - Read UserChoices section
110#D-     - Read Ensemble section
111#D-     - Read Post section
112#D-     - Define all netcdf output directories
113#D--------------------------------------------------------------------==
114IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card
115
116
117
118#D--------------------------------------------------------------------==
119#D- 1. INITIALIZE CONFIGURATION
120#D-    - Simulation configuration
121#D-    - Simulation parameters
122#D-    - Execution parameter
123#D-    - Define input files directory
124#D-    - Read or initialize CumulPeriod
125#D-    - run.card
126#D---------------------------------------------------------------------==
127IGCM_config_Initialize
128
129
130
131IGCM_sys_Cp -p ensemble.card ref.card
132IGCM_sys_Cp -p $1.card ensemble.card
133
134
135#set -vx
136R_BC=${R_IN}/BC
137
138IGCM_sys_MkdirWork ${RUN_DIR_PATH}
139
140. ${SUBMIT_DIR}/ensemble.ksh
141
142ENSEMBLE_initialize
143
144
145IGCM_sys_MkdirWork ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_UserChoices_JobName}
146
147
148function correct_duree
149{
150    # Ths function compute the nearest multiple of dyear near duree
151    typeset duree dyear
152    duree=$1
153    dyear=$2
154    if [ $(( duree % dyear )) -gt 0 ] ; then
155        echo $(( ( duree / dyear + 1 ) * dyear ))
156    else
157        echo ${duree}
158    fi
159}
160
161# Path for all skeleton SubJob scripts to SPINUP directory
162Skeleton_Path=$( cd ../SPINUP/SUBJOB/; pwd )
163
164
165for group in  ${ensemble_CONFIG_Groups[*]} ; do
166   isite=1
167   index=0
168
169   eval temp=\${ensemble_CONFIG_${group}[*]}
170   set -A group_site -- $temp
171
172   # Number of sites :
173   NumSites=$(( ${#group_site[*]} / NumInfosBySite ))
174   NumAllSites=$(( NumAllSites + NumSites ))
175
176   while [ ${isite} -le ${NumSites} ] ; do
177   
178    site=${group_site[$index]}
179
180    echo "   ------------------------"
181    echo "   SPINUP for Site : ${site}"
182
183    DATE0_YEAR=${group_site[ $(( index + ColumnYear )) ]}
184    TIME_YEAR=${group_site[ $(( index + ColumnLength )) ]}
185
186#######################################################
187# Script internal settings
188# nothing to be modified below this line
189######################################################?
190
191# Copy the SPINUP directory
192    SubJobName=${site}${config_UserChoices_JobName}
193    New_SUBMIT_DIR=${SUBMIT_DIR}/${SubJobName}
194    IGCM_sys_Cp -Rp ../SPINUP ${New_SUBMIT_DIR}
195#     ls -la ${New_SUBMIT_DIR}
196#     cat ${New_SUBMIT_DIR}/config.card
197#     echo "---"
198
199    # Install this directory
200    # modifications on config.card
201    MyJobName=${config_UserChoices_JobName}
202    IGCM_card_DefineVariableFromOption ${New_SUBMIT_DIR}/config.card UserChoices JobName
203    OldJobName=${config_UserChoices_JobName}
204    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobName ${SubJobName}
205    config_UserChoices_JobName=${MyJobName}
206    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices TagName
207    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices TagName ${config_UserChoices_TagName}
208    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices CalendarType ${config_UserChoices_CalendarType}
209
210    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobNumProcTot ${config_UserChoices_JobNumProcTot}
211
212    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobNumProcTot ${config_UserChoices_JobNumProcTot}
213
214    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices SpaceName ${config_UserChoices_SpaceName}
215
216    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices ExperimentName ${config_UserChoices_ExperimentName}
217
218    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices ARCHIVE ${config_UserChoices_ARCHIVE}
219
220    # Give path for all skeleton SubJob scripts to SPINUP directory
221    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices SubJobPath ${Skeleton_Path}
222
223    # All SubJobs in SPINUP in one or more years (must be used with libIGCM branches/AllPostFred).
224    # It is the length of the forcing file.
225    if [ X"${config_UserChoices_CalendarType}" = X"360d" ] ; then
226        This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1230
227        This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-30
228    else
229        This_Job_DateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))1231
230        This_Job_HumanDateEnd=$(( DATE0_YEAR + TIME_YEAR - 1 ))-12-31
231    fi
232
233    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateBegin ${DATE0_YEAR}-01-01
234    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodLength ${TIME_YEAR}Y
235
236    # DateEnd is defined by SpinUp job itself (it will be modified in config.card).
237    # but to get all SpinUp Job loops, we have to add at least a number of years greater
238    # than those that will be modified in config.card. Default is 150.00.00 years more for SpinUp.
239    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateEnd $(( DATE0_YEAR + 150 ))-01-01
240
241    # Infinit SPINUP Job :
242    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodNb 99999
243
244    # SRF section : first restart and post-treatments
245    typeset option
246    for option in ${config_SRF[*]} ; do
247        eval value=\${config_SRF_${option}}
248        eval echo ${option} ${value}
249        if [ X${value} != X ] ; then
250            eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF ${option} \${config_SRF_${option}}
251        fi
252    done
253    if [ X"${ensemble_UserChoices_ok_stomate}" = "Xy" ] ; then
254        for option in ${config_SBG[*]} ; do
255            eval value=\${config_SBG_${option}}
256            eval echo ${option} ${value}
257            if [ X${value} != X ] ; then
258                eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG ${option} \${config_SBG_${option}}
259            fi
260        done
261    fi
262
263    # modifications on spinup.card
264    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobForcingFile List "(${ensemble_CONFIG_ForcingPath}/${group_site[$(( index + ColumnFilename ))]}, forcing_file.nc)"
265
266    typeset option
267    for option in ${ensemble_UserChoices[*]} ; do
268        eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices ${option} \${ensemble_UserChoices_${option}}
269    done
270
271
272    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices DRIVER_NORESTART y
273    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices DRIVER_TIMELENGTH n
274
275    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_nostomate $( correct_duree ${ensemble_SPINUP_duree_nostomate} ${TIME_YEAR} )
276    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_inistomate $( correct_duree ${ensemble_SPINUP_duree_inistomate} ${TIME_YEAR} )
277    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_offlineini $( correct_duree ${ensemble_SPINUP_duree_offlineini} ${TIME_YEAR} )
278    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices n_iter ${ensemble_SPINUP_n_iter}
279    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_sechiba $( correct_duree ${ensemble_SPINUP_duree_sechiba} ${TIME_YEAR} )
280    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_stomate $( correct_duree ${ensemble_SPINUP_duree_stomate} ${TIME_YEAR} )
281    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_carbonsol $( correct_duree ${ensemble_SPINUP_duree_carbonsol} ${TIME_YEAR} )
282    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices duree_final $( correct_duree ${ensemble_SPINUP_duree_final} ${TIME_YEAR} )
283
284    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card UserChoices BoundaryFilesListNonDel y
285
286    # TimeSeries : ALMAOUTPUT for SECHIBA
287    typeset option
288    for option in ${config_SubJobPost[*]} ; do
289        eval value=\${config_SubJobPost_${option}}
290        eval echo ${option} ${value}
291        if [ X${value} != X ] ; then
292            eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SubJobPost ${option} \${config_SubJobPost_${option}}
293        fi
294    done
295
296    # modifications on Job script
297    rm ${New_SUBMIT_DIR}/Job_${OldJobName}
298    IGCM_sys_Cp ${SUBMIT_DIR}/Job_${MyJobName} ${New_SUBMIT_DIR}/Job_${SubJobName}
299
300    sed -e "s/ ${MyJobName}/ ${SubJobName}/" \
301        -e "s/Script_Output_${MyJobName}/Script_Output_${SubJobName}/" \
302        -e "s/\(IGCM_config_Finalize\)/\1\nif\ [\ \${config_UserChoices_JobName}\ =\ \"${SubJobName}\"\ ]\nthen\nIGCM_sys_Mv\ \${R_OUT}\/\${config_UserChoices_TagName}\/\${config_UserChoices_SpaceName}\/\${config_UserChoices_ExperimentName}\/\${config_UserChoices_JobName}\ \${R_OUT}\/\${config_UserChoices_TagName}\/\${config_UserChoices_SpaceName}\/\${config_UserChoices_ExperimentName}\/${config_UserChoices_JobName}\/\nIGCM_sys_Mv\ \${R_OUT}\/\${config_UserChoices_TagName}\/\${config_UserChoices_SpaceName}\/\${config_UserChoices_ExperimentName}\/\${config_UserChoices_JobName}HIST\ \${R_OUT}\/\${config_UserChoices_TagName}\/\${config_UserChoices_SpaceName}\/\${config_UserChoices_ExperimentName}\/${config_UserChoices_JobName}\/\nfi/" \
303        ${New_SUBMIT_DIR}/Job_${SubJobName} > ${New_SUBMIT_DIR}/Job_${SubJobName}_
304    IGCM_sys_Mv ${New_SUBMIT_DIR}/Job_${SubJobName}_ ${New_SUBMIT_DIR}/Job_${SubJobName}
305    chmod u+x ${New_SUBMIT_DIR}/Job_${SubJobName}
306
307
308    # modification on parameter files
309    if [ ! -f ${SUBMIT_DIR}/PARAM/run.def ] ; then
310        echo "#ENSEMBLE add :" > ${New_SUBMIT_DIR}/PARAM/run.def
311    else
312        IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/run.def ${New_SUBMIT_DIR}/PARAM/run.def
313        echo "#ENSEMBLE add :" >> ${New_SUBMIT_DIR}/PARAM/run.def
314    fi
315    echo "" >> ${New_SUBMIT_DIR}/PARAM/run.def
316
317    eval first_option=${ensemble_SubJobParams[0]} > /dev/null 2>&1
318    if [ X${first_option} != X"Error:" ] ; then
319        IGCM_card_DefineArrayFromSection ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams
320        eval first_option=${spinup_SubJobParams[0]} > /dev/null 2>&1
321
322        typeset option option_
323        for option in ${ensemble_SubJobParams[*]} ; do
324            echo "For parameter file run.def"
325            eval echo "${option}="\${ensemble_SubJobParams_${option}}
326            eval ORCHIDEE_grep ${option}
327            if [ ${SearchParam} == "undefined" ] ; then
328                echo "ERROR : parameter ${option} doesn't exist in run parameter file !"
329                echo "You must correct subjobparam option in your card file or add new parameter in run.def file"
330                echo "We must STOP here."
331                exit 1
332            fi
333            eval param=\${ensemble_SubJobParams_${option}}
334            eval ORCHIDEE_def ${option} $param
335           
336            if [ X${first_option} != X"Error:" ] ; then
337                for option_ in ${spinup_SubJobParams[*]} ; do
338                    echo "option=" ${option} " option_=" ${option_}
339                    if [ X${option} == X${option_} ] ; then
340                        eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/spinup.card SubJobParams ${option} $param
341                    fi
342                done
343            fi
344        done
345    fi
346
347    (( iphys = 0 ))
348    (( indext = index + 4 ))
349    while [ $iphys -lt ${ensemble_CONFIG_NbSitesParam} ] ; do
350       
351        # Detect if physical parameter has
352        #  array description or line per PFT description in the parameter file
353        SearchParam=""
354        ORCHIDEE_grep ${ensemble_CONFIG_NameSitesParam[${iphys}]}
355
356        case ${SearchParam} in
357            undefined)
358                echo "ERROR : parameter ${ensemble_CONFIG_NameSitesParam[${iphys}]} doesn't exist in run.def parameter file !"
359                echo "You must correct NameSiteParam option in your card file or add new parameter in run.def file"
360                echo "We must STOP here."
361                exit 1
362                ;;
363            value)
364                ORCHIDEE_def ${ensemble_CONFIG_NameSitesParam[${iphys}]} ${group_site[$(( indext )) ]}
365                (( indext = indext + 1 ))
366                ;;
367            line)
368                ipft=1
369                while [ $ipft -le ${NbPFTs} ] ; do
370                    if [ $ipft -lt 10 ] ; then
371                        numpft=0${ipft}
372                    else
373                        numpft=${ipft}
374                    fi
375           
376                    ORCHIDEE_def ${ensemble_CONFIG_NameSitesParam[${iphys}]}__${numpft} ${group_site[$(( indext )) ]}
377                    (( indext = indext + 1 ))
378                    (( ipft = ipft + 1 ))
379                done
380                ;;
381            vector)
382                unset ValueSiteParams
383                ipft=0
384                while [ $ipft -lt ${NbPFTs} ] ; do
385                    ValueSiteParams[${ipft}]=${group_site[$(( indext )) ]}
386                    (( indext = indext + 1 ))
387                    (( ipft = ipft + 1 ))
388                done
389                ORCHIDEE_def ${ensemble_CONFIG_NameSitesParam[${iphys}]} "${ValueSiteParams[*]}"
390                ;;
391        esac
392
393        (( iphys = iphys + 1 ))
394    done
395
396    IGCM_debug_Verif_Exit
397
398# Lauch the SPINUP Job :
399
400    echo "#!/bin/ksh" > ${RUN_DIR_PATH}/SubJob${site}.ksh
401    echo "MODIPSL=${MODIPSL}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
402    echo "libIGCM=${libIGCM}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
403    echo "cd ${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
404    echo "export SUBMIT_DIR=${New_SUBMIT_DIR}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
405    echo ". ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
406    echo ". ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
407    echo "export Script_Output=out_qsub_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
408    echo "export config_UserChoices_JobName=${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
409    echo "export CumulPeriod=1" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
410#    echo "nohup Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
411    echo "IGCM_sys_Qsub Job_${SubJobName}" >> ${RUN_DIR_PATH}/SubJob${site}.ksh
412
413    if [ ${DRYRUN} -le 1 ] ; then
414        chmod u+x ${RUN_DIR_PATH}/SubJob${site}.ksh
415        nohup ${RUN_DIR_PATH}/SubJob${site}.ksh
416    fi
417
418    IGCM_debug_Verif_Exit
419
420    (( isite=isite+1 ))
421    (( index=index+NumInfosBySite ))
422done
423done
424
425IGCM_sys_Mv ref.card ensemble.card
426IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
Note: See TracBrowser for help on using the repository browser.