source: branches/ORCHIDEE_Quest/ORCHIDEE_OL/SPINUP/COMP/spinup.driver @ 8765

Last change on this file since 8765 was 5083, checked in by nicolas.vuichard, 7 years ago

update ENSEMBLE config for current ORCHIDEE and libIGCM versions

File size: 45.9 KB
Line 
1#!/bin/ksh
2
3#D- Driver du script pour SPINUP (off-line)
4
5
6function ORCHIDEE_def
7{
8    IGCM_debug_PushStack "ORCHIDEE_def"
9   
10    typeset ORCHIDEE_def_KEY ORCHIDEE_default_KEY
11
12    ORCHIDEE_def_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/run.def | gawk -- 'BEGIN {FS="="} {print $2}')
13    if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then
14        ORCHIDEE_default_KEY=$( grep -e "^${1}\ *=" ${New_SUBMIT_DIR}/PARAM/orchidee.default | gawk -- 'BEGIN {FS="="} {print $2}')
15    fi
16
17    if [ X"${ORCHIDEE_def_KEY}" != X ] ; then
18        IGCM_debug_Print 2 "ORCHIDEE : ${1} has already been set in def file."
19        if [ -f ${New_SUBMIT_DIR}/PARAM/orchidee.default ] ; then
20            IGCM_debug_Print 2 " default value : ${ORCHIDEE_default_KEY}"
21        fi
22        IGCM_debug_Print 2 " script value : ${2}"
23        IGCM_debug_Print 2 " USER value : ${ORCHIDEE_def_KEY}"
24        IGCM_debug_Print 2 " We will NOT set in again !"
25    else
26        echo "${1}= ${2}" >> ${New_SUBMIT_DIR}/PARAM/run.def
27        echo "" >> ${New_SUBMIT_DIR}/PARAM/run.def
28        echo "ORCHIDEE_def : ${1} ${2}"
29    fi
30
31    IGCM_debug_PopStack "ORCHIDEE_def"
32    return $RET
33}
34
35#-----------------------------------------------------------------
36function SPIN_Initialize
37{
38    IGCM_debug_PushStack "SPIN_Initialize"
39
40    # No parallelization for spinup job !
41    BATCH_NUM_PROC_TOT=""
42
43    RESOL=${spinup_UserChoices_RESOL}
44
45    # Copy initial output card for spinup job :
46    if [ ! -f ${SUBMIT_DIR}/output.card ] ; then
47        IGCM_sys_Cp ${SUBMIT_DIR}/output.card_init ${SUBMIT_DIR}/output.card
48        iter=0
49    else
50        IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/output.card Global
51        iter=${output_Global_Iteration}
52        IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/output.card PreviousStage
53        LastStageName=${output_Stage_LastStageName}
54        IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/output.card Stage
55        StageName=${output_Stage_StageName}
56    fi
57    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Path "${SUBMIT_DIR}"
58
59    # Compute DateEnd for ALL SPINUP
60    if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
61        ok_stom=1
62    else
63        ok_stom=0
64    fi
65
66# Compute Spinup dates
67    case ${config_UserChoices_PeriodLength} in
68    *Y|*y)
69        PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | awk -F '[yY]' "{print ${config_UserChoices_PeriodLength}}" )
70        ;;
71    *) 
72        PeriodLengthInYears=1
73    esac
74
75# function SPIN_DateEnd ()
76# {
77#     IGCM_debug_PushStack "SPIN_DateEnd"
78
79# We must count only one PeriodLength (=${PeriodLengthInYears}) for each teststomate or forcesoil step.
80    This_SpinUp_Length_In_Years=$(( \
81           ( ${spinup_UserChoices_duree_nostomate} * ( 1 - ${ok_stom} ) ) \
82        + ( ${spinup_UserChoices_duree_inistomate} + ${PeriodLengthInYears} ) * ${ok_stom} \
83        + ${spinup_UserChoices_n_iter} * ${spinup_UserChoices_duree_sechiba} \
84        + ${spinup_UserChoices_n_iter} * ${ok_stom} * ( ${PeriodLengthInYears} + ${PeriodLengthInYears} ) \
85        + ${spinup_UserChoices_duree_final} ))
86
87    IGCM_date_GetYearMonth ${DateBegin} year month   
88    if [ X"${config_UserChoices_CalendarType}" = X"360d" ] ; then
89        This_SpinUp_DateEnd=$(( year + This_SpinUp_Length_In_Years - 1 ))1230
90        This_SpinUp_HumanDateEnd=$(( year + This_SpinUp_Length_In_Years - 1 ))-12-30
91    else
92        This_SpinUp_DateEnd=$(( year + This_SpinUp_Length_In_Years - 1 ))1231
93        This_SpinUp_HumanDateEnd=$(( year + This_SpinUp_Length_In_Years - 1 ))-12-31
94    fi
95    IGCM_card_WriteOption ${SUBMIT_DIR}/config.card UserChoices DateEnd ${This_SpinUp_HumanDateEnd}
96    echo "SPINUP NEW Job DateEnd : " ${This_SpinUp_HumanDateEnd}
97    (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${This_SpinUp_DateEnd} ${DateBegin} )  + 1 ))
98
99#    IGCM_debug_PopStack "SPIN_DateEnd"
100#}
101#   SPIN_DateEnd
102   
103    # Subjobs configuration :
104    # -----------------------
105
106    # 1) SRF section of config.card
107# This section gives first restart file path and WriteFrequency.
108    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card SRF
109    set +A config_SRF -- ${config_SRF[*]} > /dev/null 2>&1
110    typeset option
111    for option in ${config_SRF[*]} ; do
112        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF ${option}
113    done
114
115    if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
116        IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card SBG
117        set +A config_SBG -- ${config_SBG[*]} > /dev/null 2>&1
118        typeset option
119        for option in ${config_SBG[*]} ; do
120            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG ${option}
121        done
122    fi
123
124
125    # 2) Subjob parametrization : SubJobParams in spinup.card
126# This section give flags to put in run.def of Subjobs.
127    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/COMP/spinup.card SubJobParams
128    set +A spinup_SubJobParams -- ${spinup_SubJobParams[*]} > /dev/null 2>&1
129
130    eval first_option=${spinup_SubJobParams[0]} > /dev/null 2>&1
131    if [ X${first_option} != X"Error:" ] ; then
132        typeset option
133        for option in ${spinup_SubJobParams[*]} ; do
134            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/spinup.card SubJobParams ${option}
135        done
136    fi
137
138    # 3) Post-treatment
139    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card SubJobPost
140    typeset option
141    for option in ${config_SubJobPost[*]} ; do
142        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SubJobPost ${option}
143    done
144
145    # 4) Get the forcing file name (structure with variables inside) for this Spinup
146    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/spinup.card SubJobForcingFile List
147    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/spinup.card SubJobForcingFile ListNonDel
148
149    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/spinup.card SubJobPost sechiba_TimeSeriesVars2D
150    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/spinup.card SubJobPost sechiba_TimeSeriesVars3D
151    if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
152        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/spinup.card SubJobPost stomate_TimeSeriesVars2D
153        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/spinup.card SubJobPost stomate_TimeSeriesVars3D
154    fi
155    IGCM_debug_PopStack "SPIN_Initialize"
156}
157
158#-----------------------------------------------------------------
159function SPIN_Cp_Job
160{
161    IGCM_debug_PushStack "SPIN_Cp_Job"
162
163    typeset Path_Job_Ini New_Name
164
165    # Where to find the standard cards/drivers for this job
166    Path_Job_Ini=$1
167
168    # New Name for the Job :
169    New_Name=$2
170    # New Path for the job
171    New_SUBMIT_DIR=${SUBMIT_DIR}/${New_Name}
172
173    # Copy the standard sub-job in the ${SUBMIT_DIR} with the New_Name
174    IGCM_sys_Cp -Rp ${Path_Job_Ini} ${New_SUBMIT_DIR}
175
176    # Install this directory
177    # modifications on config.card
178    MyJobName=${config_UserChoices_JobName}
179    IGCM_card_DefineVariableFromOption ${New_SUBMIT_DIR}/config.card UserChoices JobName
180    OldJobName=${config_UserChoices_JobName}
181
182    SubJobName=${MyJobName}${New_Name}
183    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobName ${SubJobName}
184    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices TagName ${config_UserChoices_TagName}
185    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices SpaceName ${config_UserChoices_SpaceName}
186    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices ExperimentName ${config_UserChoices_ExperimentName}
187    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices ARCHIVE ${config_UserChoices_ARCHIVE}
188    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices JobNumProcTot ${config_UserChoices_JobNumProcTot}
189    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Post PackFrequency ${config_Post_PackFrequency}
190
191    # keep the spinup JobName
192    config_UserChoices_JobName=${MyJobName}
193
194    # modifications on Job
195    \rm ${New_SUBMIT_DIR}/Job_${OldJobName} 
196
197    sed -e "s/ ${MyJobName} / ${New_Name} /" \
198        -e "s/Script_Output_${MyJobName}.000001 /Script_Output_${New_Name}.000001 /" \
199        ${SUBMIT_DIR}/Job_${MyJobName} > ${New_SUBMIT_DIR}/Job_${SubJobName}
200    chmod u+x ${New_SUBMIT_DIR}/Job_${SubJobName}
201
202    # modification on parameter files
203    if [ ! -f ${SUBMIT_DIR}/PARAM/run.def ] ; then
204        echo "#spinup add :" > ${New_SUBMIT_DIR}/PARAM/run.def
205    else
206        IGCM_sys_Cp ${SUBMIT_DIR}/PARAM/run.def ${New_SUBMIT_DIR}/PARAM/run.def
207        echo "#spinup add :" >> ${New_SUBMIT_DIR}/PARAM/run.def
208    fi
209    echo "" >> ${New_SUBMIT_DIR}/PARAM/run.def
210
211    eval first_option=${spinup_SubJobParams[0]} > /dev/null 2>&1
212    if [ X${first_option} != X"Error:" ] ; then
213        typeset option
214        for option in ${spinup_SubJobParams[*]} ; do
215            echo "For parameter file run.def"
216            eval echo "${option}="\${spinup_SubJobParams_${option}}
217            eval ORCHIDEE_def ${option} \${spinup_SubJobParams_${option}}
218        done
219    fi
220
221    if ( [ X${config_UserChoices_JobNumProcTot} != X ] && [ "${config_UserChoices_JobNumProcTot}" -gt 1 ] ) ; then
222        gawk -- "{if (! match(\$0,/^# .Date.*/) ) { print \$0 } else { printf(\"BATCH_NUM_PROC_TOT=%d \\n\\n\",${config_UserChoices_JobNumProcTot}) ; print \$0 } }" \
223            ${New_SUBMIT_DIR}/Job_${SubJobName} > ${New_SUBMIT_DIR}/Job_${SubJobName}_
224        IGCM_sys_Mv ${New_SUBMIT_DIR}/Job_${SubJobName}_ ${New_SUBMIT_DIR}/Job_${SubJobName}
225        chmod u+x ${New_SUBMIT_DIR}/Job_${SubJobName}
226    fi
227
228    IGCM_debug_PopStack "SPIN_Cp_Job"
229}
230
231function SPIN_prepare
232{
233    IGCM_debug_PushStack "SPIN_prepare"
234
235    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Restarts OverRule n
236    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card OOL Restart n
237
238    typeset option
239    for option in ${config_SubJobPost[*]} ; do
240        eval value=\${config_SubJobPost_${option}}
241        eval echo ${option} ${value}
242        if [ X${value} != X ] ; then
243            eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Post ${option} \${config_SubJobPost_${option}}
244        fi
245    done
246
247    # For Subjob special flags
248    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices ROUTING ${spinup_UserChoices_ok_routing}
249    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices NEWHYDROL ${spinup_UserChoices_ok_newhydrol}
250    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices LAIMAP ${spinup_UserChoices_lai_map}
251    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices IMPOSE_VEG ${spinup_UserChoices_impose_veg}
252    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices LAND_USE ${spinup_UserChoices_land_use}
253    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices OKCO2 ${spinup_UserChoices_ok_co2}
254
255    if [ X${spinup_UserChoices_BoundaryFilesListNonDel} = Xy ] ; then
256        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card BoundaryFiles ListNonDel "()"
257    fi
258
259    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card UserChoices NORESTART ${spinup_UserChoices_DRIVER_NORESTART}
260    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card UserChoices TIMELENGTH ${spinup_UserChoices_DRIVER_TIMELENGTH}
261
262    spinup_SubJobForcingFile_List0=${spinup_SubJobForcingFile_List[0]} > /dev/null 2>&1
263    if [ X${spinup_SubJobForcingFile_List0} != X${NULL_STR} ] ; then
264        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card BoundaryFiles List "("$( echo ${spinup_SubJobForcingFile_List[@]} | sed -e "s/ /,/g" )")"
265    else
266        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card BoundaryFiles List "()"
267    fi
268
269    spinup_SubJobForcingFile_ListNonDel0=${spinup_SubJobForcingFile_ListNonDel[0]} > /dev/null 2>&1
270    if [ X${spinup_SubJobForcingFile_ListNonDel0} != X${NULL_STR} ] ; then
271        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card BoundaryFiles ListNonDel "("$( echo ${spinup_SubJobForcingFile_ListNonDel[@]} | sed -e "s/ /,/g" )")"
272    else
273        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card BoundaryFiles ListNonDel "()"
274    fi
275
276    IGCM_debug_PopStack "SPIN_prepare"
277}
278
279#-----------------------------------------------------------------
280function SPIN_OptionsSechiba
281{
282    IGCM_debug_PushStack "SPIN_OptionsSechiba"
283
284
285    spinup_SubJobPost_sechiba_TimeSeriesVars0=${spinup_SubJobPost_sechiba_TimeSeriesVars2D[0]}
286    if [ X${spinup_SubJobPost_sechiba_TimeSeriesVars0} != X${NULL_STR} ] ; then
287        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card Post_1M_sechiba_history TimeSeriesVars2D "("$( echo ${spinup_SubJobPost_sechiba_TimeSeriesVars2D[@]} | sed -e "s/ /,/g" )")"
288    else
289        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card Post_1M_sechiba_history TimeSeriesVars2D "()"
290    fi
291    spinup_SubJobPost_sechiba_TimeSeriesVars0=${spinup_SubJobPost_sechiba_TimeSeriesVars3D[0]}
292    if [ X${spinup_SubJobPost_sechiba_TimeSeriesVars0} != X${NULL_STR} ] ; then
293        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card Post_1M_sechiba_history TimeSeriesVars3D "("$( echo ${spinup_SubJobPost_sechiba_TimeSeriesVars3D[@]} | sed -e "s/ /,/g" )")"
294    else
295        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card Post_1M_sechiba_history TimeSeriesVars3D "()"
296    fi
297
298    IGCM_debug_PopStack "SPIN_OptionsSechiba"
299}
300
301#-----------------------------------------------------------------
302function SPIN_OptionsStomate
303{
304    IGCM_debug_PushStack "SPIN_OptionsStomate"
305
306
307    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card UserChoices SPINUP_ANALYTIC ${spinup_UserChoices_SPINUP_ANALYTIC}
308
309    spinup_SubJobPost_stomate_TimeSeriesVars0=${spinup_SubJobPost_stomate_TimeSeriesVars2D[0]} > /dev/null 2>&1
310    if [ X${spinup_SubJobPost_stomate_TimeSeriesVars0} != X${NULL_STR} ] ; then
311        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card Post_1M_stomate_history TimeSeriesVars2D "("$( echo ${spinup_SubJobPost_stomate_TimeSeriesVars2D[@]} | sed -e "s/ /,/g" )")"
312    else
313        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card Post_1M_stomate_history TimeSeriesVars3D "()"
314    fi
315    spinup_SubJobPost_stomate_TimeSeriesVars0=${spinup_SubJobPost_stomate_TimeSeriesVars3D[0]} > /dev/null 2>&1
316    if [ X${spinup_SubJobPost_stomate_TimeSeriesVars0} != X${NULL_STR} ] ; then
317        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card Post_1M_stomate_history TimeSeriesVars3D "("$( echo ${spinup_SubJobPost_stomate_TimeSeriesVars3D[@]} | sed -e "s/ /,/g" )")"
318    else
319        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card Post_1M_stomate_history TimeSeriesVars3D "()"
320    fi
321
322    # Nb years for forcing FORCESOIL
323    ORCHIDEE_def FORCESOIL_STEP_PER_YEAR 365
324    # Force creation of stomate_forcing.nc and stomate_Cforcing files
325    ORCHIDEE_def STOMATE_FORCING_NAME stomate_forcing.nc
326    ORCHIDEE_def STOMATE_CFORCING_NAME stomate_Cforcing.nc
327
328    IGCM_debug_PopStack "SPIN_OptionsStomate"
329}
330
331#-----------------------------------------------------------------
332function SPIN_PeriodStart
333{
334    IGCM_debug_PushStack "SPIN_PeriodStart"
335    echo "" > stack
336    IGCM_debug_PopStack "SPIN_PeriodStart"
337}
338
339#-----------------------------------------------------------------
340Update_SPIN_iter=false
341function SPIN_Update
342{
343    IGCM_debug_PushStack "SPIN_Update"
344
345    Update_SPIN_iter=false
346
347    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/output.card Global
348    SpinUpPath=${output_Global_Path}
349
350    # StageName is the internal name for the interation for spinup
351    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card Stage StageName
352    StageName=${output_Stage_StageName}
353
354    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card PreviousStage LastStageName
355    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card PreviousStage LastExtName
356    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card PreviousStage LastRestartDate
357
358    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card Global Iteration
359    iter=${output_Global_Iteration}
360
361    config_SubJob_PeriodLength="${config_UserChoices_PeriodLength}"
362
363    # ExtName is the short JobName of this stage
364
365    if ( [ X${StageName} = X"start" ] ) ; then 
366        # We are in first step.
367        if ( ${FirstInitialize} ) ; then
368            # What is the first step ?
369
370            # First phase : Is there restarts (we would initialize ORCHIDEE) or not ?
371            IGCM_card_WriteOption ${SUBMIT_DIR}/output.card PreviousStage LastStageName "start"
372            output_PreviousStage_LastStageName="start"
373            if ( [ X"${config_SRF_Restart}" = "Xn" ] && [ X"${config_SBG_Restart}" = "Xn" ] ) ; then
374                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
375                    if [ ${spinup_UserChoices_duree_inistomate} -gt 0 ] ; then
376                        # Perhaps we want to by-pass first SECHIBA-ONLY Stage and do a SECSTO Job first ?
377                        StageName=SECSTOINI
378                        ExtName=STOI
379                    else
380                        echo "SPINUP no restart : !!!! Error !!!! "
381                        echo         "ok_stomate = " ${spinup_UserChoices_ok_stomate}
382                        echo         "duree_inistomate = " ${spinup_UserChoices_duree_inistomate}
383                        echo "NO SPINUP possible !!"
384                        exit 1
385                    fi
386                elif [ ${spinup_UserChoices_duree_nostomate} -gt 0 ] ; then
387                        StageName=SECINI
388                        ExtName=SECI
389                else
390                    echo "SPINUP : NO RESTART and NO INITIALIZATION !"
391                    echo "     We will launch the iteration loop directly."
392                    if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
393                        StageName=SECSTO
394                        iter=1
395                        ExtName=ORC-${iter}
396                        Update_SPIN_iter=true
397                    else
398                        echo "SPINUP : !!!! Error !!!! "
399                        echo         "duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
400                        echo "NO SPINUP possible !!"
401                        exit 1
402                    fi
403                fi
404            else
405                echo "SPINUP : "
406                echo "     We will to launch the iteration loop WITH RESTARTS."
407                echo "     Global Restart path = " ${config_Restarts_RestartPath}
408                if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
409                    StageName=SECSTO
410                    iter=1
411                    ExtName=ORC-${iter}
412                    Update_SPIN_iter=true
413                else
414                    echo "SPINUP : !!!! Error !!!! "
415                    echo "        duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
416                    echo "NO SPINUP possible !!"
417                    exit 1
418                fi
419            fi
420            echo "(" start "," ${ExtName} ") \\" >> ${SUBMIT_DIR}/output.card
421
422        else
423            echo "SPINUP : !!!! Error with output !!!! "
424            echo "        duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
425            echo "NO SPINUP possible !!"
426            exit 1
427        fi
428
429    else
430        # We are not in first step.
431
432        # WHAT IS THE NEXT STEP ?
433        case ${output_PreviousStage_LastStageName} in
434            "SECINI")
435                echo "     We begin the iteration loop !!"
436                if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
437                    StageName=SECSTO
438                    iter=1
439                    ExtName=ORC-${iter}
440                    Update_SPIN_iter=true
441                else
442                    echo "SPINUP : !!!! Error !!!! "
443                    echo         "duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
444                    echo "NO SPINUP possible !!"
445                    exit 1
446                fi
447                ;;
448            "SECSTOINI")
449                if [ ${spinup_UserChoices_duree_offlineini} -gt 0 ] ; then
450                    StageName=TSTOINI
451                    ExtName=TSTOI
452                else
453                    echo "     We begin the iteration loop !!"
454                    if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
455                        StageName=SECSTO
456                        iter=1
457                        ExtName=ORC-${iter}
458                        Update_SPIN_iter=true
459                    else
460                        echo "SPINUP : !!!! Error !!!! "
461                        echo         "duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
462                        echo "NO SPINUP possible !!"
463                        exit 1
464                    fi
465                fi
466                ;;
467            "TSTOINI")
468                echo "     We begin the iteration loop !!"
469                if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
470                    echo "     We begin the iteration loop !!"
471                    StageName=SECSTO
472                    iter=1
473                    ExtName=ORC-${iter}
474                    Update_SPIN_iter=true
475                else
476                    echo "SPINUP : !!!! Error !!!! "
477                    echo         "duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
478                    echo "NO SPINUP possible !!"
479                    exit 1
480                fi
481                ;;
482            "SECSTO")
483               
484                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
485                    echo "We will print he value of the previous SPINUP_DONE :"
486                    TestSpinUpDone=""
487                    TestSpinUpDone=$(IGCM_card_PrintOption ${SUBMIT_DIR}/${output_PreviousStage_LastExtName}/COMP/stomate.card UserChoices SPINUP_DONE)
488                    echo "Value of test_spinup : ${TestSpinUpDone} "
489                fi
490
491                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
492                    if [ ${spinup_UserChoices_duree_stomate} -gt 0 ] ; then
493                        StageName=TSTO
494                        ExtName=TST-${iter}
495                    elif [ ${spinup_UserChoices_duree_carbonsol} -gt 0 ] ; then
496                        StageName=FORC
497                        ExtName=FOR-${iter}
498                    elif ( [ ${iter} -eq ${spinup_UserChoices_n_iter} ] || [ X"${TestSpinUpDone}" = "Xy" ] ) ; then
499                        echo "Ending loop Job"
500                        StageName=SECSTOF
501                        ExtName=FIN
502                        IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration END
503                    else
504                        StageName=SECSTO
505                        (( iter=iter+1 ))
506                        ExtName=ORC-${iter}
507                        Update_SPIN_iter=true
508                    fi
509                elif [ ${iter} -eq ${spinup_UserChoices_n_iter} ] ; then
510                    echo "Ending loop Job"
511                    StageName=SECSTOF
512                    ExtName=FIN
513                    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration END
514                else
515                    StageName=SECSTO
516                    (( iter=iter+1 ))
517                    ExtName=ORC-${iter}
518                    Update_SPIN_iter=true
519                fi
520                ;;
521            "TSTO") 
522                if [ ${spinup_UserChoices_duree_carbonsol} -gt 0 ] ; then
523                    StageName=FORC
524                    ExtName=FOR-${iter}
525                elif [ ${iter} -eq ${spinup_UserChoices_n_iter} ] ; then
526                    echo "Ending loop Job"
527                    StageName=SECSTOF
528                    ExtName=FIN
529                    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration END
530                else
531                    StageName=SECSTO
532                    (( iter=iter+1 ))
533                    ExtName=ORC-${iter}
534                    Update_SPIN_iter=true
535                fi
536                ;;
537            "FORC") 
538                if [ ${iter} -eq ${spinup_UserChoices_n_iter} ] || [ X${iter} = XEND ] ; then
539                    echo "Ending loop Job"
540                    StageName=SECSTOF
541                    ExtName=FIN
542                    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration END
543                else
544                    StageName=SECSTO
545                    (( iter=iter+1 ))
546                    ExtName=ORC-${iter}
547                    Update_SPIN_iter=true
548                fi
549                ;;
550            "SECSTOF") 
551                echo "Begin Historical Job"
552                StageName=HISTO
553                ExtName=HIST
554                IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration HIST
555                ;;
556
557            "HISTO")
558                echo "SPINUP : We have done the SPINUP !! "
559                echo "The job will be closed."
560                ;;
561        esac
562    fi
563
564    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Stage StageName ${StageName}
565    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Stage ExtName ${ExtName}
566
567    # BEGIN THE NEW STEP :
568    LastJobName=${config_UserChoices_JobName}${output_PreviousStage_LastExtName}
569
570    # Copy and modifications of the standard card set
571    case $StageName in
572        "SECINI")
573
574            # SECHIBA only initialisation step
575            This_Job_Length_In_Years=${spinup_UserChoices_duree_nostomate}
576
577            # Copy the standard card set
578            # !!! must not have been modified !!!
579            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC ${ExtName}
580
581            Level_Hist=${spinup_UserChoices_level_hist}
582            if [ X${Level_Hist} != X ] ; then
583                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
584                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
585            fi
586
587            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart n
588   
589            SPIN_prepare
590
591            SPIN_OptionsSechiba
592
593            ;;
594        "SECSTOINI")
595
596            # SECHIBA+STOMATE initialisation step
597            This_Job_Length_In_Years=${spinup_UserChoices_duree_inistomate}
598
599            # Copy the standard card set
600            # !!! must not have been modified !!!
601            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC_STO ${ExtName}
602
603            Level_Hist=${spinup_UserChoices_level_hist}
604            if [ X${Level_Hist} != X ] ; then
605                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
606                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
607            fi
608
609            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart n
610            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
611                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart n
612            fi
613   
614            SPIN_prepare
615
616            SPIN_OptionsSechiba
617            SPIN_OptionsStomate
618
619            ;;
620
621        "TSTOINI")
622
623            # TESTSTOMATE initialisation step
624            This_Job_Length_In_Years=${spinup_UserChoices_duree_offlineini}
625           
626            # TESTSTOMATE will run in one execution only
627            config_SubJob_PeriodLength="${This_Job_Length_In_Years}Y"
628
629            # Copy the standard card set
630            # !!! must not have been modified !!!
631            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/TESTSTOMATE ${ExtName}
632
633            Level_Hist=${spinup_UserChoices_level_hist}
634            if [ X${Level_Hist} != X ] ; then
635                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
636                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
637            fi
638
639            # Always restart for teststomate
640            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Restarts OverRule n
641            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
642            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
643            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
644            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
645
646            # Define restart simulation name
647            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
648            config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
649            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
650           
651            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
652            config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
653            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
654           
655            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card PreviousStage LastRestartDate
656
657            # We Get the forcing file from the previous run of ORCHIDEE
658            sed -e "s&(\${config_SBG_RestartPath}/\${config_SBG_RestartJobName}/SBG/Restart/\${config_SBG_RestartJobName}_\${Date_Restarts}_stomate_forcing.nc, stomate_forcing.nc)&(${config_SBG_RestartPath}/${LastJobName}/SBG/Restart/${LastJobName}_${output_PreviousStage_LastRestartDate}_stomate_forcing.nc, stomate_forcing.nc)&" ${New_SUBMIT_DIR}/COMP/sechiba.card > sechiba.card.tmp
659            IGCM_sys_Mv sechiba.card.tmp ${New_SUBMIT_DIR}/COMP/sechiba.card
660
661            IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices IMPOSE_VEG ${spinup_UserChoices_impose_veg}
662            IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices LAND_USE ${spinup_UserChoices_land_use}
663
664            typeset option
665            for option in ${config_SubJobPost[*]} ; do
666                eval value=\${config_SubJobPost_${option}}
667                eval echo ${option} ${value}
668                if [ X${value} != X ] ; then
669                    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Post ${option} \${config_SubJobPost_${option}}
670                fi
671            done
672
673            SPIN_OptionsStomate
674
675            ;;
676        "SECSTO")
677
678            # loop step
679
680            This_Job_Length_In_Years=${spinup_UserChoices_duree_sechiba}
681
682            # Copy the standard card set
683            # !!! must not have been modified !!!
684            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
685                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC_STO ${ExtName}
686            else
687                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC ${ExtName}
688            fi
689
690            Level_Hist=${spinup_UserChoices_level_hist}
691            if [ X${Level_Hist} != X ] ; then
692                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
693                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
694            fi
695
696            SPIN_prepare
697
698            if [ X${output_PreviousStage_LastStageName} != X"start" ] ; then
699                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
700                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
701                # Define restart simulation name
702                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
703                config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
704                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
705
706                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
707                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
708                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
709                    # Define restart simulation name
710                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
711                    config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
712                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
713                fi
714            else
715                # If we begin directly with the loop.
716                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF Restart
717                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF RestartDate
718                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF RestartJobName
719                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF RestartPath
720                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF OldName
721                echo "Run in iteration loop with restarts : "
722                echo ${config_SRF_Restart}, ${config_SRF_RestartDate}, ${config_SRF_RestartJobName}, ${config_SRF_RestartPath}, ${config_SRF_OldName}
723
724                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart ${config_SRF_Restart}
725                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${config_SRF_RestartDate}
726                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${config_SRF_RestartJobName}
727                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
728                if [ X${config_SRF_OldName} != X"" ] ; then
729                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF OldName ${config_SRF_OldName}
730                fi
731                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
732                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG Restart
733                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG RestartDate
734                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG RestartJobName
735                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG RestartPath
736                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG OldName
737                        echo "Run in iteration loop with STOMATE restarts : "
738                        echo ${config_SBG_Restart}, ${config_SBG_RestartDate}, ${config_SBG_RestartJobName}, ${config_SBG_RestartPath}, ${config_SBG_OldName}
739
740                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart ${config_SBG_Restart}
741                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${config_SBG_RestartDate}
742                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${config_SBG_RestartJobName}
743                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
744                        if [ X${config_SBG_OldName} != X"" ] ; then
745                            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG OldName ${config_SBG_OldName}
746                        fi
747                fi
748            fi
749
750            SPIN_OptionsSechiba
751            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
752                SPIN_OptionsStomate
753            fi
754
755            ;;
756        "TSTO") 
757
758            # TESTSTOMATE loop step
759            This_Job_Length_In_Years=${spinup_UserChoices_duree_stomate}
760           
761            # One execution only
762            config_SubJob_PeriodLength="${This_Job_Length_In_Years}Y"
763
764            # Copy the standard card set
765            # !!! must not have been modified !!!
766            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/TESTSTOMATE ${ExtName}
767
768            Level_Hist=${spinup_UserChoices_level_hist}
769            if [ X${Level_Hist} != X ] ; then
770                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
771                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
772            fi
773
774            # Always restart for teststomate
775            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Restarts OverRule n
776            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
777            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
778            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
779            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
780
781            # Define restart simulation name
782            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
783            config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
784            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
785
786            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
787            config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
788            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
789
790            # We Get the forcing file from the previous run of ORCHIDEE
791            sed -e "s&(\${config_SBG_RestartPath}/\${config_SBG_RestartJobName}/SBG/Restart/\${config_SBG_RestartJobName}_\${Date_Restarts}_stomate_forcing.nc, stomate_forcing.nc)&(${config_SBG_RestartPath}/${LastJobName}/SBG/Restart/${LastJobName}_${output_PreviousStage_LastRestartDate}_stomate_forcing.nc, stomate_forcing.nc)&" ${New_SUBMIT_DIR}/COMP/sechiba.card > sechiba.card.tmp
792            IGCM_sys_Mv sechiba.card.tmp ${New_SUBMIT_DIR}/COMP/sechiba.card
793
794            IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices IMPOSE_VEG ${spinup_UserChoices_impose_veg}
795            IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices LAND_USE ${spinup_UserChoices_land_use}
796
797            typeset option
798            for option in ${config_SubJobPost[*]} ; do
799                eval value=\${config_SubJobPost_${option}}
800                eval echo ${option} ${value}
801                if [ X${value} != X ] ; then
802                    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Post ${option} \${config_SubJobPost_${option}}
803                fi
804            done
805
806            SPIN_OptionsStomate
807
808            ;;
809        "FORC") 
810            # FORCESOIL loop step
811            This_Job_Length_In_Years=${spinup_UserChoices_duree_carbonsol}
812           
813            # One execution only
814            config_SubJob_PeriodLength="${This_Job_Length_In_Years}Y"
815
816            # Copy the standard card set
817            # !!! must not have been modified !!!
818            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/FORCESOIL ${ExtName}
819
820            Level_Hist=${spinup_UserChoices_level_hist}
821            if [ X${Level_Hist} != X ] ; then
822                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
823                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
824            fi
825
826            # Always restart for forcesoil
827            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Restarts OverRule n
828            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
829            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
830
831            # Define restart simulation name
832            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
833            config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
834            config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
835            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
836
837            # We Get the forcing file from the previous run of ORCHIDEE
838            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card PreviousStage LastRestartDate
839
840            IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card BoundaryFiles ListNonDel \
841                    "(${config_SBG_RestartPath}/${LastJobName}/SBG/Restart/${LastJobName}_${output_PreviousStage_LastRestartDate}_stomate_Cforcing.nc, stomate_Cforcing.nc), \\"
842
843            # Nb years for forcing FORCESOIL
844            ORCHIDEE_def FORCESOIL_STEP_PER_YEAR 365
845
846            ;;
847        "SECSTOF") 
848
849            # END step
850
851            This_Job_Length_In_Years=${spinup_UserChoices_duree_final}
852
853            # Copy the standard card set
854            # !!! must not have been modified !!!
855            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
856                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC_STO ${ExtName}
857            else
858                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC ${ExtName}
859            fi
860
861            Level_Hist=${spinup_UserChoices_level_hist}
862            if [ X${Level_Hist} != X ] ; then
863                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
864                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
865            fi
866
867            SPIN_prepare
868
869            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
870            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
871            # Define restart simulation name
872            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
873            config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
874            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
875            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
876                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
877                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
878                # Define restart simulation name
879                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
880                config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
881                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
882            fi
883
884            SPIN_OptionsSechiba
885            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
886                SPIN_OptionsStomate
887            fi
888
889            ;;
890
891        "HISTO") 
892
893            # Historical step
894
895            case ${config_SubJob_PeriodLength} in
896                *Y|*y)
897                    This_Job_Length_In_Years=$( echo ${1} | awk -F '[yY]' "{print ${config_SubJob_PeriodLength}}" )
898                    ;;
899                *M|*m)
900                    This_Job_Length_In_Years=1
901                    ;;
902                *)
903                    echo "SPINUP : Impossible"
904                    echo "     We have a PeriodLength less than 1M : " ${config_SubJob_PeriodLength}
905                    echo "     We can't do the spinup with such a frequency !"
906                    exit 1
907                    ;;
908            esac
909
910            # Copy the standard card set
911            # !!! must not have been modified !!!
912            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
913                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC_STO ${ExtName}
914            else
915                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC ${ExtName}
916            fi
917
918            Level_Hist=${spinup_UserChoices_level_hist_final}
919            if [ X${Level_Hist} != X ] ; then
920                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
921                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
922            fi
923
924            SPIN_prepare
925
926            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
927            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
928            # Define restart simulation name
929            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
930            config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
931            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
932            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
933                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
934                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
935                # Define restart simulation name
936                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
937                config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
938                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
939            fi
940
941            SPIN_OptionsSechiba
942            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
943                SPIN_OptionsStomate
944            fi
945
946            ;;
947        *)
948            echo "Erreur !! StageName not found."
949            exit 1
950    esac
951
952
953    # For all Subjobs 
954    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Stage StageName ${StageName}
955    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Stage ExtName ${ExtName}
956    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices CalendarType ${config_UserChoices_CalendarType}
957    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateBegin ${config_UserChoices_DateBegin}
958
959    # Compute DateEnd for SECHIBA initialisation step
960    IGCM_date_GetYearMonth ${DateBegin} year month
961    if [ X"${config_UserChoices_CalendarType}" = X"360d" ] ; then
962        This_Job_DateEnd=$( IGCM_date_YearDigit $(( year + This_Job_Length_In_Years - 1 )) )1230
963        This_Job_HumanDateEnd=$( IGCM_date_YearDigit $(( year + This_Job_Length_In_Years - 1 )) )-12-30
964    else
965        This_Job_DateEnd=$( IGCM_date_YearDigit $(( year + This_Job_Length_In_Years - 1 )) )1231
966        This_Job_HumanDateEnd=$( IGCM_date_YearDigit $(( year + This_Job_Length_In_Years - 1 )) )-12-31
967    fi
968    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateEnd ${This_Job_HumanDateEnd}
969
970
971    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodLength ${config_SubJob_PeriodLength}
972    # Compute Subjob number of Periods
973    case ${config_SubJob_PeriodLength} in
974    *Y|*y)
975        PeriodNbSubJob=$(( This_Job_Length_In_Years / $( echo ${1} | awk -F '[yY]' "{print ${config_SubJob_PeriodLength}}" ) ))
976        ;;
977    *M|*m)
978        PeriodNbSubJob=$(( 12 * This_Job_Length_In_Years / $( echo ${1} | awk -F '[mM]' "{print ${config_SubJob_PeriodLength}}" ) ))
979        ;;
980    *)
981        echo "SPINUP : Impossible"
982        echo "     We have a PeriodLength less than 1M : " ${config_SubJob_PeriodLength}
983        echo "     We can't do the spinup with such a frequency !"
984        exit 1
985        ;;
986    esac
987    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodNb ${PeriodNbSubJob}
988
989    echo "SECHIBA WriteFrequency : " ${config_SRF_WriteFrequency}
990    if ( [ X${StageName} != X"TSTOINI" ] && [ X${StageName} != X"TSTO" ] && [ X${StageName} != X"FORC" ] ) ; then
991        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "${config_SRF_WriteFrequency}"
992    fi
993    if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
994        echo "STOMATE WriteFrequency : " ${config_SBG_WriteFrequency}
995        case $StageName in
996            "TSTOINI"|"TSTO")
997                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1Y"
998                ;;
999            *)
1000                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "${config_SBG_WriteFrequency}"
1001        esac
1002    fi
1003
1004    # Remove the script created by the system (curie or obelix) by IGCM_sys_build_execution_scripts
1005    \rm ${RUN_DIR}/script_SPIN.ksh 
1006
1007    # (Re)-Create the script
1008    echo "#!/bin/ksh" > ${RUN_DIR}/script_SPIN.ksh
1009    echo "cd ${New_SUBMIT_DIR}" >> ${RUN_DIR}/script_SPIN.ksh
1010    echo "export SUBMIT_DIR=${New_SUBMIT_DIR}" >> ${RUN_DIR}/script_SPIN.ksh
1011    echo "${New_SUBMIT_DIR}/Job_${SubJobName} > ${New_SUBMIT_DIR}/Script_Output_${SubJobName}.000001 </dev/null 2>&1" >> ${RUN_DIR}/script_SPIN.ksh
1012    echo "echo 'End of Subjob : ' \$( date )" >> ${RUN_DIR}/script_SPIN.ksh
1013    echo "echo 'finish.'" >> ${RUN_DIR}/script_SPIN.ksh
1014
1015    # Give Execution right to the script
1016    chmod u+x ${RUN_DIR}/script_SPIN.ksh
1017
1018    cp -rp ${RUN_DIR}/script_SPIN.ksh ${RUN_DIR}/SPIN
1019
1020    # force run with nohup
1021    BATCH_NUM_PROC_TOT=1
1022    MPIRUN_COMMAND="time nohup"
1023
1024    # Compatibility with libIGCM version < 2.0
1025    config_Executable_Name=script_SPIN.ksh
1026
1027    IGCM_debug_PopStack "SPIN_Update"
1028}
1029
1030#-----------------------------------------------------------------
1031function SPIN_Finalize
1032{
1033    IGCM_debug_PushStack "SPIN_Finalize"
1034
1035    \rm ${RUN_DIR}/script_SPIN.ksh
1036
1037    echo "Return to Master SPINUP job : " $( date )
1038
1039    # Does the SubJob began ?
1040    if [ -f ${New_SUBMIT_DIR}/run.card ] ; then
1041        IGCM_card_DefineVariableFromOption ${New_SUBMIT_DIR}/run.card Configuration PeriodState
1042    else
1043        run_Configuration_PeriodState="Fatal"
1044    fi
1045
1046# ATTENTION : avec ce test "!= Completed", on impose que chaque sous-job est contenu dans une seule itération PBS
1047# On pourrait améliorer ce point pour tenir compte d'un sous-job long...
1048# Mais il faudrait faire ce test au début de la fonction update
1049# pour déterminer si on doit reprendre un job non terminer ou démarrer le suivant.
1050    # Did it finish ?
1051    if [ X${run_Configuration_PeriodState} != X"Completed" ] ; then
1052        IGCM_debug_Exit "SPIN_update Error Run SubJob : " ${SubJobName} ${run_Configuration_PeriodState}
1053    fi
1054    IGCM_debug_Verif_Exit
1055   
1056    # Save the Stage in output.card
1057    if ( ${Update_SPIN_iter} ) ; then
1058        IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration ${iter}
1059    fi
1060
1061    echo "(" ${StageName} "," ${ExtName} ") \\" >> ${SUBMIT_DIR}/output.card
1062    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card PreviousStage LastStageName ${StageName}
1063    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card PreviousStage LastExtName ${ExtName}
1064    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card PreviousStage LastRestartDate ${This_Job_DateEnd}
1065
1066
1067    # For forcesoil, we have to copy the sechiba restart of last Stage
1068    if [ X${StageName} = X"FORC" ] ; then
1069        # This must be done on the ARCHIVE HOST.
1070        IGCM_sys_MkdirArchive ${config_SBG_RestartPath}/${SubJobName}/SRF/Restart
1071        IGCM_sys_RshArchive \
1072            "cp -fp ${config_SBG_RestartPath}/${LastJobName}/SRF/Restart/${LastJobName}_${output_PreviousStage_LastRestartDate}_sechiba_rest.nc"\
1073                  " ${config_SBG_RestartPath}/${SubJobName}/SRF/Restart/${SubJobName}_${This_Job_DateEnd}_sechiba_rest.nc"
1074    fi
1075
1076    # For SPINUP, we don't need a restart ! Then we save the output.card
1077    IGCM_sys_Cp ${SUBMIT_DIR}/output.card output_out.card
1078    FileToBeDeleted[${#FileToBeDeleted[@]}]=output_out.card
1079
1080
1081# If NOT DEBUG mode :
1082# we can move Previous Job in SPINUP save DIR.
1083    if ( [ X${spinup_UserChoices_DEBUG_SPIN} = Xn ] && [ X${output_PreviousStage_LastStageName} != Xstart ] ) ; then
1084        if ( [ X${spinup_UserChoices_CONSERVE} = Xn ] \
1085          && [ X${output_PreviousStage_LastStageName} != XSECINI ] \
1086          && [ X${output_PreviousStage_LastStageName} != XSECSTOINI ] ) ; then
1087            IGCM_sys_RshArchive "rm -Rf ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_UserChoices_JobName}${output_PreviousStage_LastExtName}/*/Analyse/*"
1088            IGCM_sys_RshArchive "rm -Rf ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_UserChoices_JobName}${output_PreviousStage_LastExtName}/*/Output/*"
1089        fi
1090
1091        IGCM_sys_RshArchive "mv -f ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_UserChoices_JobName}${output_PreviousStage_LastExtName}"\
1092                                 " ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_UserChoices_JobName}/SPIN/Output/"
1093    fi
1094
1095#   Test the end of the SPINUP !
1096    if [ X${StageName} = X"HISTO" ] ; then
1097        DateEnd=${PeriodDateEnd}
1098        (( SimulationLengthInDays=ExperienceLengthInDays + 1 ))
1099        echo "SPINUP : END Job !!!"
1100    fi
1101
1102    IGCM_debug_PopStack "SPIN_Finalize"
1103}
Note: See TracBrowser for help on using the repository browser.