source: branches/ORCHIDEE_2_2/ORCHIDEE_OL/SPINUP/COMP/spinup.driver @ 7759

Last change on this file since 7759 was 7073, checked in by nicolas.vuichard, 4 years ago

update SPINUP config to handle historical transient simulation with CO2 varying in ENSEMBLE (fluxnet) configuration

File size: 51.0 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
256    if [ X${spinup_UserChoices_BoundaryFilesListNonDel} = Xy ] ; then
257        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card BoundaryFiles ListNonDel "()"
258    fi
259
260    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card UserChoices NORESTART ${spinup_UserChoices_DRIVER_NORESTART}
261    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card UserChoices TIMELENGTH ${spinup_UserChoices_DRIVER_TIMELENGTH}
262
263    spinup_SubJobForcingFile_List0=${spinup_SubJobForcingFile_List[0]} > /dev/null 2>&1
264    if [ X${spinup_SubJobForcingFile_List0} != X${NULL_STR} ] ; then
265        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card BoundaryFiles List "("$( echo ${spinup_SubJobForcingFile_List[@]} | sed -e "s/ /,/g" )")"
266    else
267        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card BoundaryFiles List "()"
268    fi
269
270    spinup_SubJobForcingFile_ListNonDel0=${spinup_SubJobForcingFile_ListNonDel[0]} > /dev/null 2>&1
271    if [ X${spinup_SubJobForcingFile_ListNonDel0} != X${NULL_STR} ] ; then
272        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card BoundaryFiles ListNonDel "("$( echo ${spinup_SubJobForcingFile_ListNonDel[@]} | sed -e "s/ /,/g" )")"
273    else
274        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/orchidee_ol.card BoundaryFiles ListNonDel "()"
275    fi
276
277    IGCM_debug_PopStack "SPIN_prepare"
278}
279
280#-----------------------------------------------------------------
281function SPIN_OptionsSechiba
282{
283    IGCM_debug_PushStack "SPIN_OptionsSechiba"
284
285
286    spinup_SubJobPost_sechiba_TimeSeriesVars0=${spinup_SubJobPost_sechiba_TimeSeriesVars2D[0]}
287    if [ X${spinup_SubJobPost_sechiba_TimeSeriesVars0} != X${NULL_STR} ] ; then
288        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card Post_1M_sechiba_history TimeSeriesVars2D "("$( echo ${spinup_SubJobPost_sechiba_TimeSeriesVars2D[@]} | sed -e "s/ /,/g" )")"
289    else
290        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card Post_1M_sechiba_history TimeSeriesVars2D "()"
291    fi
292    spinup_SubJobPost_sechiba_TimeSeriesVars0=${spinup_SubJobPost_sechiba_TimeSeriesVars3D[0]}
293    if [ X${spinup_SubJobPost_sechiba_TimeSeriesVars0} != X${NULL_STR} ] ; then
294        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card Post_1M_sechiba_history TimeSeriesVars3D "("$( echo ${spinup_SubJobPost_sechiba_TimeSeriesVars3D[@]} | sed -e "s/ /,/g" )")"
295    else
296        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card Post_1M_sechiba_history TimeSeriesVars3D "()"
297    fi
298
299    IGCM_debug_PopStack "SPIN_OptionsSechiba"
300}
301
302#-----------------------------------------------------------------
303function SPIN_OptionsStomate
304{
305    IGCM_debug_PushStack "SPIN_OptionsStomate"
306
307
308    IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card UserChoices SPINUP_ANALYTIC ${spinup_UserChoices_SPINUP_ANALYTIC}
309
310    spinup_SubJobPost_stomate_TimeSeriesVars0=${spinup_SubJobPost_stomate_TimeSeriesVars2D[0]} > /dev/null 2>&1
311    if [ X${spinup_SubJobPost_stomate_TimeSeriesVars0} != X${NULL_STR} ] ; then
312        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card Post_1M_stomate_history TimeSeriesVars2D "("$( echo ${spinup_SubJobPost_stomate_TimeSeriesVars2D[@]} | sed -e "s/ /,/g" )")"
313    else
314        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card Post_1M_stomate_history TimeSeriesVars3D "()"
315    fi
316    spinup_SubJobPost_stomate_TimeSeriesVars0=${spinup_SubJobPost_stomate_TimeSeriesVars3D[0]} > /dev/null 2>&1
317    if [ X${spinup_SubJobPost_stomate_TimeSeriesVars0} != X${NULL_STR} ] ; then
318        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card Post_1M_stomate_history TimeSeriesVars3D "("$( echo ${spinup_SubJobPost_stomate_TimeSeriesVars3D[@]} | sed -e "s/ /,/g" )")"
319    else
320        IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/stomate.card Post_1M_stomate_history TimeSeriesVars3D "()"
321    fi
322
323    # Nb years for forcing FORCESOIL
324    ORCHIDEE_def FORCESOIL_STEP_PER_YEAR 365
325    # Force creation of stomate_forcing.nc and stomate_Cforcing files
326    ORCHIDEE_def STOMATE_FORCING_NAME stomate_forcing.nc
327    ORCHIDEE_def STOMATE_CFORCING_NAME stomate_Cforcing.nc
328
329    IGCM_debug_PopStack "SPIN_OptionsStomate"
330}
331
332#-----------------------------------------------------------------
333function SPIN_PeriodStart
334{
335    IGCM_debug_PushStack "SPIN_PeriodStart"
336    echo "" > stack
337    IGCM_debug_PopStack "SPIN_PeriodStart"
338}
339
340#-----------------------------------------------------------------
341Update_SPIN_iter=false
342function SPIN_Update
343{
344    IGCM_debug_PushStack "SPIN_Update"
345
346    Update_SPIN_iter=false
347
348    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/output.card Global
349    SpinUpPath=${output_Global_Path}
350
351    # StageName is the internal name for the interation for spinup
352    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card Stage StageName
353    StageName=${output_Stage_StageName}
354
355    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card PreviousStage LastStageName
356    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card PreviousStage LastExtName
357    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card PreviousStage LastRestartDate
358
359    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card Global Iteration
360    iter=${output_Global_Iteration}
361
362    config_SubJob_PeriodLength="${config_UserChoices_PeriodLength}"
363
364    # ExtName is the short JobName of this stage
365
366    if ( [ X${StageName} = X"start" ] ) ; then 
367        # We are in first step.
368        if ( ${FirstInitialize} ) ; then
369            # What is the first step ?
370
371            # First phase : Is there restarts (we would initialize ORCHIDEE) or not ?
372            IGCM_card_WriteOption ${SUBMIT_DIR}/output.card PreviousStage LastStageName "start"
373            output_PreviousStage_LastStageName="start"
374            if ( [ X"${config_SRF_Restart}" = "Xn" ] && [ X"${config_SBG_Restart}" = "Xn" ] ) ; then
375                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
376                    if [ ${spinup_UserChoices_duree_inistomate} -gt 0 ] ; then
377                        # Perhaps we want to by-pass first SECHIBA-ONLY Stage and do a SECSTO Job first ?
378                        StageName=SECSTOINI
379                        ExtName=STOI
380                    else
381                        echo "SPINUP no restart : !!!! Error !!!! "
382                        echo         "ok_stomate = " ${spinup_UserChoices_ok_stomate}
383                        echo         "duree_inistomate = " ${spinup_UserChoices_duree_inistomate}
384                        echo "NO SPINUP possible !!"
385                        exit 1
386                    fi
387                elif [ ${spinup_UserChoices_duree_nostomate} -gt 0 ] ; then
388                        StageName=SECINI
389                        ExtName=SECI
390                else
391                    echo "SPINUP : NO RESTART and NO INITIALIZATION !"
392                    echo "     We will launch the iteration loop directly."
393                    if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
394                        StageName=SECSTO
395                        iter=1
396                        ExtName=ORC-${iter}
397                        Update_SPIN_iter=true
398                    else
399                        echo "SPINUP : !!!! Error !!!! "
400                        echo         "duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
401                        echo "NO SPINUP possible !!"
402                        exit 1
403                    fi
404                fi
405            else
406                echo "SPINUP : "
407                echo "     We will to launch the iteration loop WITH RESTARTS."
408                echo "     Global Restart path = " ${config_Restarts_RestartPath}
409                if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
410                    StageName=SECSTO
411                    iter=1
412                    ExtName=ORC-${iter}
413                    Update_SPIN_iter=true
414                else
415                    echo "SPINUP : !!!! Error !!!! "
416                    echo "        duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
417                    echo "NO SPINUP possible !!"
418                    exit 1
419                fi
420            fi
421            echo "(" start "," ${ExtName} ") \\" >> ${SUBMIT_DIR}/output.card
422
423        else
424            echo "SPINUP : !!!! Error with output !!!! "
425            echo "        duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
426            echo "NO SPINUP possible !!"
427            exit 1
428        fi
429
430    else
431        # We are not in first step.
432
433        # WHAT IS THE NEXT STEP ?
434        case ${output_PreviousStage_LastStageName} in
435            "SECINI")
436                echo "     We begin the iteration loop !!"
437                if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
438                    StageName=SECSTO
439                    iter=1
440                    ExtName=ORC-${iter}
441                    Update_SPIN_iter=true
442                else
443                    echo "SPINUP : !!!! Error !!!! "
444                    echo         "duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
445                    echo "NO SPINUP possible !!"
446                    exit 1
447                fi
448                ;;
449            "SECSTOINI")
450                if [ ${spinup_UserChoices_duree_offlineini} -gt 0 ] ; then
451                    StageName=TSTOINI
452                    ExtName=TSTOI
453                else
454                    echo "     We begin the iteration loop !!"
455                    if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
456                        StageName=SECSTO
457                        iter=1
458                        ExtName=ORC-${iter}
459                        Update_SPIN_iter=true
460                    else
461                        echo "SPINUP : !!!! Error !!!! "
462                        echo         "duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
463                        echo "NO SPINUP possible !!"
464                        exit 1
465                    fi
466                fi
467                ;;
468            "TSTOINI")
469                echo "     We begin the iteration loop !!"
470                if [ ${spinup_UserChoices_duree_sechiba} -gt 0 ] ; then
471                    echo "     We begin the iteration loop !!"
472                    StageName=SECSTO
473                    iter=1
474                    ExtName=ORC-${iter}
475                    Update_SPIN_iter=true
476                else
477                    echo "SPINUP : !!!! Error !!!! "
478                    echo         "duree_sechiba = " ${spinup_UserChoices_duree_sechiba}
479                    echo "NO SPINUP possible !!"
480                    exit 1
481                fi
482                ;;
483            "SECSTO")
484               
485                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
486                    echo "We will print he value of the previous SPINUP_DONE :"
487                    TestSpinUpDone=""
488                    TestSpinUpDone=$(IGCM_card_PrintOption ${SUBMIT_DIR}/${output_PreviousStage_LastExtName}/COMP/stomate.card UserChoices SPINUP_DONE)
489                    echo "Value of test_spinup : ${TestSpinUpDone} "
490                fi
491
492                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
493                    if [ ${spinup_UserChoices_duree_stomate} -gt 0 ] ; then
494                        StageName=TSTO
495                        ExtName=TST-${iter}
496                    elif [ ${spinup_UserChoices_duree_carbonsol} -gt 0 ] ; then
497                        StageName=FORC
498                        ExtName=FOR-${iter}
499                    elif ( [ ${iter} -eq ${spinup_UserChoices_n_iter} ] || [ X"${TestSpinUpDone}" = "Xy" ] ) ; then
500                        echo "Ending loop Job"
501                        StageName=SECSTOF
502                        ExtName=FIN
503                        IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration END
504                    else
505                        StageName=SECSTO
506                        (( iter=iter+1 ))
507                        ExtName=ORC-${iter}
508                        Update_SPIN_iter=true
509                    fi
510                elif [ ${iter} -eq ${spinup_UserChoices_n_iter} ] ; then
511                    echo "Ending loop Job"
512                    StageName=SECSTOF
513                    ExtName=FIN
514                    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration END
515                else
516                    StageName=SECSTO
517                    (( iter=iter+1 ))
518                    ExtName=ORC-${iter}
519                    Update_SPIN_iter=true
520                fi
521                ;;
522            "TSTO") 
523                if [ ${spinup_UserChoices_duree_carbonsol} -gt 0 ] ; then
524                    StageName=FORC
525                    ExtName=FOR-${iter}
526                elif [ ${iter} -eq ${spinup_UserChoices_n_iter} ] ; then
527                    echo "Ending loop Job"
528                    StageName=SECSTOF
529                    ExtName=FIN
530                    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration END
531                else
532                    StageName=SECSTO
533                    (( iter=iter+1 ))
534                    ExtName=ORC-${iter}
535                    Update_SPIN_iter=true
536                fi
537                ;;
538            "FORC") 
539                if [ ${iter} -eq ${spinup_UserChoices_n_iter} ] || [ X${iter} = XEND ] ; then
540                    echo "Ending loop Job"
541                    StageName=SECSTOF
542                    ExtName=FIN
543                    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration END
544                else
545                    StageName=SECSTO
546                    (( iter=iter+1 ))
547                    ExtName=ORC-${iter}
548                    Update_SPIN_iter=true
549                fi
550                ;;
551            "SECSTOF") 
552                echo "Begin Historical Job"
553                StageName=HISTO
554                ExtName=HIST
555                IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration HIST
556                ;;
557
558            "HISTO")
559                echo "SPINUP : We have done the SPINUP !! "
560                echo "The job will be closed."
561                ;;
562        esac
563    fi
564
565    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Stage StageName ${StageName}
566    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Stage ExtName ${ExtName}
567
568    # BEGIN THE NEW STEP :
569    LastJobName=${config_UserChoices_JobName}${output_PreviousStage_LastExtName}
570
571    # Copy and modifications of the standard card set
572    case $StageName in
573        "SECINI")
574
575            # SECHIBA only initialisation step
576            This_Job_Length_In_Years=${spinup_UserChoices_duree_nostomate}
577
578            # Copy the standard card set
579            # !!! must not have been modified !!!
580            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC ${ExtName}
581
582            Level_Hist=${spinup_UserChoices_level_hist_init}
583            if [ X${Level_Hist} != X ] ; then
584                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
585                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
586            fi
587
588            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart n
589   
590            SPIN_prepare
591
592            SPIN_OptionsSechiba
593
594            ;;
595        "SECSTOINI")
596
597            # SECHIBA+STOMATE initialisation step
598            This_Job_Length_In_Years=${spinup_UserChoices_duree_inistomate}
599
600            # Copy the standard card set
601            # !!! must not have been modified !!!
602            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC_STO ${ExtName}
603
604            Level_Hist=${spinup_UserChoices_level_hist_init}
605            if [ X${Level_Hist} != X ] ; then
606                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
607                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
608            fi
609
610            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart n
611            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
612                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart n
613            fi
614   
615            SPIN_prepare
616
617            SPIN_OptionsSechiba
618            SPIN_OptionsStomate
619
620            ;;
621
622        "TSTOINI")
623
624            # TESTSTOMATE initialisation step
625            This_Job_Length_In_Years=${spinup_UserChoices_duree_offlineini}
626           
627            # TESTSTOMATE will run in one execution only
628            config_SubJob_PeriodLength="${This_Job_Length_In_Years}Y"
629
630            # Copy the standard card set
631            # !!! must not have been modified !!!
632            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/TESTSTOMATE ${ExtName}
633
634            Level_Hist=${spinup_UserChoices_level_hist_init}
635            if [ X${Level_Hist} != X ] ; then
636                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
637                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
638            fi
639
640            # Always restart for teststomate
641            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Restarts OverRule n
642            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
643            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
644            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
645            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
646
647            # Define restart simulation name
648            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
649            config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
650            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
651           
652            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
653            config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
654            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
655           
656            IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/output.card PreviousStage LastRestartDate
657
658            # We Get the forcing file from the previous run of ORCHIDEE
659            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
660            IGCM_sys_Mv sechiba.card.tmp ${New_SUBMIT_DIR}/COMP/sechiba.card
661
662            IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices IMPOSE_VEG ${spinup_UserChoices_impose_veg}
663            IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices LAND_USE ${spinup_UserChoices_land_use}
664
665            typeset option
666            for option in ${config_SubJobPost[*]} ; do
667                eval value=\${config_SubJobPost_${option}}
668                eval echo ${option} ${value}
669                if [ X${value} != X ] ; then
670                    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Post ${option} \${config_SubJobPost_${option}}
671                fi
672            done
673
674            SPIN_OptionsStomate
675
676            ;;
677        "SECSTO")
678
679            # loop step
680
681            This_Job_Length_In_Years=${spinup_UserChoices_duree_sechiba}
682
683            # Copy the standard card set
684            # !!! must not have been modified !!!
685            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
686                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC_STO ${ExtName}
687            else
688                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC ${ExtName}
689            fi
690
691            Level_Hist=${spinup_UserChoices_level_hist_init}
692            if [ X${Level_Hist} != X ] ; then
693                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
694                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
695            fi
696
697            SPIN_prepare
698
699            if [ X${output_PreviousStage_LastStageName} != X"start" ] ; then
700                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
701                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
702                # Define restart simulation name
703                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
704                config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
705                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
706
707                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
708                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
709                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
710                    # Define restart simulation name
711                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
712                    config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
713                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
714                fi
715            else
716                # If we begin directly with the loop.
717                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF Restart
718                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF RestartDate
719                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF RestartJobName
720                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF RestartPath
721                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF OldName
722                echo "Run in iteration loop with restarts : "
723                echo ${config_SRF_Restart}, ${config_SRF_RestartDate}, ${config_SRF_RestartJobName}, ${config_SRF_RestartPath}, ${config_SRF_OldName}
724
725                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart ${config_SRF_Restart}
726                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${config_SRF_RestartDate}
727                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${config_SRF_RestartJobName}
728                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
729                if [ X${config_SRF_OldName} != X"" ] ; then
730                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF OldName ${config_SRF_OldName}
731                fi
732                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
733                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG Restart
734                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG RestartDate
735                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG RestartJobName
736                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG RestartPath
737                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG OldName
738                        echo "Run in iteration loop with STOMATE restarts : "
739                        echo ${config_SBG_Restart}, ${config_SBG_RestartDate}, ${config_SBG_RestartJobName}, ${config_SBG_RestartPath}, ${config_SBG_OldName}
740
741                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart ${config_SBG_Restart}
742                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${config_SBG_RestartDate}
743                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${config_SBG_RestartJobName}
744                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
745                        if [ X${config_SBG_OldName} != X"" ] ; then
746                            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG OldName ${config_SBG_OldName}
747                        fi
748                fi
749            fi
750
751            SPIN_OptionsSechiba
752            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
753                SPIN_OptionsStomate
754            fi
755
756            ;;
757        "TSTO") 
758
759            # TESTSTOMATE loop step
760            This_Job_Length_In_Years=${spinup_UserChoices_duree_stomate}
761           
762            # One execution only
763            config_SubJob_PeriodLength="${This_Job_Length_In_Years}Y"
764
765            # Copy the standard card set
766            # !!! must not have been modified !!!
767            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/TESTSTOMATE ${ExtName}
768
769            Level_Hist=${spinup_UserChoices_level_hist_init}
770            if [ X${Level_Hist} != X ] ; then
771                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
772                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
773            fi
774
775            # Always restart for teststomate
776            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Restarts OverRule n
777            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
778            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
779            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
780            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
781
782            # Define restart simulation name
783            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
784            config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
785            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
786
787            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
788            config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
789            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
790
791            # We Get the forcing file from the previous run of ORCHIDEE
792            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
793            IGCM_sys_Mv sechiba.card.tmp ${New_SUBMIT_DIR}/COMP/sechiba.card
794
795            IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices IMPOSE_VEG ${spinup_UserChoices_impose_veg}
796            IGCM_card_WriteOption ${New_SUBMIT_DIR}/COMP/sechiba.card UserChoices LAND_USE ${spinup_UserChoices_land_use}
797
798            typeset option
799            for option in ${config_SubJobPost[*]} ; do
800                eval value=\${config_SubJobPost_${option}}
801                eval echo ${option} ${value}
802                if [ X${value} != X ] ; then
803                    eval IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card Post ${option} \${config_SubJobPost_${option}}
804                fi
805            done
806
807            SPIN_OptionsStomate
808
809            ;;
810        "FORC") 
811            # FORCESOIL loop step
812            This_Job_Length_In_Years=${spinup_UserChoices_duree_carbonsol}
813           
814            # Copy the standard card set
815            # !!! must not have been modified !!!
816            SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC_STO ${ExtName}
817
818            Level_Hist=${spinup_UserChoices_level_hist_init}
819            if [ X${Level_Hist} != X ] ; then
820                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
821                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
822            fi
823
824            ORCHIDEE_def SPINUP_ANALYTIC "y"
825
826            SPIN_prepare
827
828            if [ X${output_PreviousStage_LastStageName} != X"start" ] ; then
829                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
830                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
831                # Define restart simulation name
832                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
833                config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
834                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
835
836                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
837                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
838                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
839                    # Define restart simulation name
840                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
841                    config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
842                    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
843                fi
844            else
845                # If we begin directly with the loop.
846                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF Restart
847                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF RestartDate
848                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF RestartJobName
849                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF RestartPath
850                IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SRF OldName
851                echo "Run in iteration loop with restarts : "
852                echo ${config_SRF_Restart}, ${config_SRF_RestartDate}, ${config_SRF_RestartJobName}, ${config_SRF_RestartPath}, ${config_SRF_OldName}
853 
854                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart ${config_SRF_Restart}
855                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${config_SRF_RestartDate}
856                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${config_SRF_RestartJobName}
857                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
858                if [ X${config_SRF_OldName} != X"" ] ; then
859                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF OldName ${config_SRF_OldName}
860                fi
861                if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
862                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG Restart
863                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG RestartDate
864                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG RestartJobName
865                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG RestartPath
866                        IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card SBG OldName
867                        echo "Run in iteration loop with STOMATE restarts : "
868                        echo ${config_SBG_Restart}, ${config_SBG_RestartDate}, ${config_SBG_RestartJobName}, ${config_SBG_RestartPath}, ${config_SBG_OldName}
869
870                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart ${config_SBG_Restart}
871                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${config_SBG_RestartDate}
872                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${config_SBG_RestartJobName}
873                        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
874                        if [ X${config_SBG_OldName} != X"" ] ; then
875                            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG OldName ${config_SBG_OldName}
876                        fi
877                fi
878            fi
879
880            SPIN_OptionsSechiba
881            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
882                SPIN_OptionsStomate
883            fi
884
885
886
887
888            ;;
889        "SECSTOF") 
890
891            # END step
892
893            This_Job_Length_In_Years=${spinup_UserChoices_duree_final}
894
895            # Copy the standard card set
896            # !!! must not have been modified !!!
897            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
898                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC_STO ${ExtName}
899            else
900                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC ${ExtName}
901            fi
902
903            Level_Hist=${spinup_UserChoices_level_hist_trans}
904            if [ X${Level_Hist} != X ] ; then
905                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
906                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
907            fi
908
909            SPIN_prepare
910
911            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
912            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
913            # Define restart simulation name
914            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
915            config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
916            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
917            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
918                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
919                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
920                # Define restart simulation name
921                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
922                config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
923                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
924            fi
925
926            SPIN_OptionsSechiba
927            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
928                SPIN_OptionsStomate
929            fi
930
931            ;;
932
933        "HISTO") 
934
935            # Historical step
936
937            case ${config_SubJob_PeriodLength} in
938                *Y|*y)
939                    This_Job_Length_In_Years=$( echo ${1} | awk -F '[yY]' "{print ${config_SubJob_PeriodLength}}" )
940                    ;;
941                *M|*m)
942                    This_Job_Length_In_Years=1
943                    ;;
944                *)
945                    echo "SPINUP : Impossible"
946                    echo "     We have a PeriodLength less than 1M : " ${config_SubJob_PeriodLength}
947                    echo "     We can't do the spinup with such a frequency !"
948                    exit 1
949                    ;;
950            esac
951
952            # Copy the standard card set
953            # !!! must not have been modified !!!
954            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
955                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC_STO ${ExtName}
956            else
957                SPIN_Cp_Job ${spinup_UserChoices_SubJobPath}/OOL_SEC ${ExtName}
958            fi
959
960            Level_Hist=${spinup_UserChoices_level_hist_final}
961            if [ X${Level_Hist} != X ] ; then
962                ORCHIDEE_def SECHIBA_HISTLEVEL ${Level_Hist}
963                ORCHIDEE_def STOMATE_HISTLEVEL ${Level_Hist}
964            fi
965
966            SPIN_prepare
967
968            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF Restart y
969            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartDate ${output_PreviousStage_LastRestartDate}
970            # Define restart simulation name
971            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartJobName ${LastJobName}
972            config_SRF_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
973            IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF RestartPath ${config_SRF_RestartPath}
974            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
975                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG Restart y
976                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartDate ${output_PreviousStage_LastRestartDate}
977                # Define restart simulation name
978                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartJobName ${LastJobName}
979                config_SBG_RestartPath=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}
980                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG RestartPath ${config_SBG_RestartPath}
981            fi
982
983            SPIN_OptionsSechiba
984            if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
985                SPIN_OptionsStomate
986            fi
987
988            ;;
989        *)
990            echo "Erreur !! StageName not found."
991            exit 1
992    esac
993
994
995    # For all Subjobs 
996    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Stage StageName ${StageName}
997    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Stage ExtName ${ExtName}
998    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices CalendarType ${config_UserChoices_CalendarType}
999
1000
1001    myDateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
1002    IGCM_date_GetYearMonth ${myDateBegin} UserChoices_year UserChoices_month
1003    if [ ${StageName} = "HISTO" ]  ; then
1004       This_Job_year=${UserChoices_year}
1005    elif [ ${StageName} = "SECSTOF" ]  ; then
1006       This_Job_year=$(( UserChoices_year - spinup_UserChoices_duree_final))
1007    else
1008       This_Job_year=$(( UserChoices_year - spinup_UserChoices_duree_final -1 ))       
1009    fi
1010
1011    if ( [ ${StageName} != "SECSTOF" ] &&  [ ${StageName} != "HISTO" ] ) ; then
1012
1013        eval CO2_Init=${spinup_UserChoices_co2_init}
1014        if [ X${CO2_Init} != X ] ; then
1015            if [ X${CO2_Init}=X"auto" ]; then
1016                eval CO2_Init=`grep Annee_${This_Job_year} /ccc/work/cont003/igcmg/igcmg/IGCM/SRF/CO2/CO2_1860_2016_TRENDYv2017.txt | awk -F= '{print $2}'`
1017            fi
1018            ORCHIDEE_def ATM_CO2 ${CO2_Init}
1019        fi
1020    fi
1021   
1022
1023    This_Job_DateBegin=$( IGCM_date_YearDigit $This_Job_year )-01-01   
1024    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateBegin ${This_Job_DateBegin}
1025
1026    # Compute DateEnd for SECHIBA initialisation step
1027    IGCM_date_GetYearMonth ${DateBegin} year month
1028    if [ X"${config_UserChoices_CalendarType}" = X"360d" ] ; then
1029        This_Job_DateEnd=$( IGCM_date_YearDigit $(( This_Job_year + This_Job_Length_In_Years - 1 )) )1230
1030        This_Job_HumanDateEnd=$( IGCM_date_YearDigit $(( This_Job_year + This_Job_Length_In_Years - 1 )) )-12-30
1031    else
1032        This_Job_DateEnd=$( IGCM_date_YearDigit $(( This_Job_year + This_Job_Length_In_Years - 1 )) )1231
1033        This_Job_HumanDateEnd=$( IGCM_date_YearDigit $(( This_Job_year + This_Job_Length_In_Years - 1 )) )-12-31
1034    fi
1035    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices DateEnd ${This_Job_HumanDateEnd}
1036
1037
1038    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodLength ${config_SubJob_PeriodLength}
1039    # Compute Subjob number of Periods
1040    case ${config_SubJob_PeriodLength} in
1041    *Y|*y)
1042        PeriodNbSubJob=$(( This_Job_Length_In_Years / $( echo ${1} | awk -F '[yY]' "{print ${config_SubJob_PeriodLength}}" ) ))
1043        ;;
1044    *M|*m)
1045        PeriodNbSubJob=$(( 12 * This_Job_Length_In_Years / $( echo ${1} | awk -F '[mM]' "{print ${config_SubJob_PeriodLength}}" ) ))
1046        ;;
1047    *)
1048        echo "SPINUP : Impossible"
1049        echo "     We have a PeriodLength less than 1M : " ${config_SubJob_PeriodLength}
1050        echo "     We can't do the spinup with such a frequency !"
1051        exit 1
1052        ;;
1053    esac
1054    IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card UserChoices PeriodNb ${PeriodNbSubJob}
1055
1056    echo "SECHIBA WriteFrequency : " ${config_SRF_WriteFrequency}
1057    if ( [ X${StageName} != X"TSTOINI" ] && [ X${StageName} != X"TSTO" ] && [ X${StageName} != X"FORC" ] ) ; then
1058        IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "${config_SRF_WriteFrequency}"
1059    fi
1060    if [ X"${spinup_UserChoices_ok_stomate}" = "Xy" ] ; then
1061        echo "STOMATE WriteFrequency : " ${config_SBG_WriteFrequency}
1062        case $StageName in
1063            "TSTOINI"|"TSTO")
1064                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1Y"
1065                ;;
1066            *)
1067                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "${config_SBG_WriteFrequency}"
1068        esac
1069    fi
1070
1071
1072    if ( [ ${StageName} = "HISTO" ] ) ; then
1073        case ${spinup_UserChoices_freq_hist_final} in
1074            "low")
1075                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "1Y"
1076                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1Y"
1077                ;;
1078            "med")
1079                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "1M"
1080                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1M"
1081                ;;
1082            "high")
1083                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "1800s"
1084                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1d"
1085                ;;
1086        esac
1087    elif ( [ ${StageName} = "SECSTOF" ] ) ; then
1088        case ${spinup_UserChoices_freq_hist_trans} in
1089            "low")
1090                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "1Y"
1091                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1Y"
1092                ;;
1093            "med")
1094                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "1M"
1095                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1M"
1096                ;;
1097            "high")
1098                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "1800s"
1099                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1d"
1100                ;;
1101        esac
1102    else
1103        case ${spinup_UserChoices_freq_hist_init} in
1104            "low")
1105                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "1Y"
1106                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1Y"
1107                ;;
1108            "med")
1109                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "1M"
1110                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1M"
1111                ;;
1112            "high")
1113                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SRF WriteFrequency "1800s"
1114                IGCM_card_WriteOption ${New_SUBMIT_DIR}/config.card SBG WriteFrequency "1d"
1115                ;;
1116        esac
1117    fi
1118
1119
1120    # Remove the script created by the system (curie or obelix) by IGCM_sys_build_execution_scripts
1121    \rm ${RUN_DIR}/script_SPIN.ksh 
1122
1123    # (Re)-Create the script
1124    echo "#!/bin/ksh" > ${RUN_DIR}/script_SPIN.ksh
1125    echo "cd ${New_SUBMIT_DIR}" >> ${RUN_DIR}/script_SPIN.ksh
1126    echo "export SUBMIT_DIR=${New_SUBMIT_DIR}" >> ${RUN_DIR}/script_SPIN.ksh
1127    echo "${New_SUBMIT_DIR}/Job_${SubJobName} > ${New_SUBMIT_DIR}/Script_Output_${SubJobName}.000001 </dev/null 2>&1" >> ${RUN_DIR}/script_SPIN.ksh
1128    echo "echo 'End of Subjob : ' \$( date )" >> ${RUN_DIR}/script_SPIN.ksh
1129    echo "echo 'finish.'" >> ${RUN_DIR}/script_SPIN.ksh
1130
1131    # Give Execution right to the script
1132    chmod u+x ${RUN_DIR}/script_SPIN.ksh
1133
1134    cp -rp ${RUN_DIR}/script_SPIN.ksh ${RUN_DIR}/SPIN
1135
1136    # force run with nohup
1137    BATCH_NUM_PROC_TOT=1
1138    MPIRUN_COMMAND="time nohup"
1139
1140    # Compatibility with libIGCM version < 2.0
1141    config_Executable_Name=script_SPIN.ksh
1142
1143    IGCM_debug_PopStack "SPIN_Update"
1144}
1145
1146#-----------------------------------------------------------------
1147function SPIN_Finalize
1148{
1149    IGCM_debug_PushStack "SPIN_Finalize"
1150
1151    \rm ${RUN_DIR}/script_SPIN.ksh
1152
1153    echo "Return to Master SPINUP job : " $( date )
1154
1155    # Does the SubJob began ?
1156    if [ -f ${New_SUBMIT_DIR}/run.card ] ; then
1157        IGCM_card_DefineVariableFromOption ${New_SUBMIT_DIR}/run.card Configuration PeriodState
1158    else
1159        run_Configuration_PeriodState="Fatal"
1160    fi
1161
1162# ATTENTION : avec ce test "!= Completed", on impose que chaque sous-job est contenu dans une seule itération PBS
1163# On pourrait améliorer ce point pour tenir compte d'un sous-job long...
1164# Mais il faudrait faire ce test au début de la fonction update
1165# pour déterminer si on doit reprendre un job non terminer ou démarrer le suivant.
1166    # Did it finish ?
1167    if [ X${run_Configuration_PeriodState} != X"Completed" ] ; then
1168        IGCM_debug_Exit "SPIN_update Error Run SubJob : " ${SubJobName} ${run_Configuration_PeriodState}
1169    fi
1170    IGCM_debug_Verif_Exit
1171   
1172    # Save the Stage in output.card
1173    if ( ${Update_SPIN_iter} ) ; then
1174        IGCM_card_WriteOption ${SUBMIT_DIR}/output.card Global Iteration ${iter}
1175    fi
1176
1177    echo "(" ${StageName} "," ${ExtName} ") \\" >> ${SUBMIT_DIR}/output.card
1178    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card PreviousStage LastStageName ${StageName}
1179    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card PreviousStage LastExtName ${ExtName}
1180    IGCM_card_WriteOption ${SUBMIT_DIR}/output.card PreviousStage LastRestartDate ${This_Job_DateEnd}
1181
1182
1183    # For forcesoil, we have to copy the sechiba restart of last Stage
1184    if [ X${StageName} = X"FORC" ] ; then
1185        # This must be done on the ARCHIVE HOST.
1186        IGCM_sys_MkdirArchive ${config_SBG_RestartPath}/${SubJobName}/SRF/Restart
1187        IGCM_sys_RshArchive \
1188            "cp -fp ${config_SBG_RestartPath}/${LastJobName}/SRF/Restart/${LastJobName}_${output_PreviousStage_LastRestartDate}_sechiba_rest.nc"\
1189                  " ${config_SBG_RestartPath}/${SubJobName}/SRF/Restart/${SubJobName}_${This_Job_DateEnd}_sechiba_rest.nc"
1190    fi
1191
1192    # For SPINUP, we don't need a restart ! Then we save the output.card
1193    IGCM_sys_Cp ${SUBMIT_DIR}/output.card output_out.card
1194    FileToBeDeleted[${#FileToBeDeleted[@]}]=output_out.card
1195
1196
1197# If NOT DEBUG mode :
1198# we can move Previous Job in SPINUP save DIR.
1199    if ( [ X${spinup_UserChoices_DEBUG_SPIN} = Xn ] && [ X${output_PreviousStage_LastStageName} != Xstart ] ) ; then
1200        if ( [ X${spinup_UserChoices_CONSERVE} = Xn ] \
1201          && [ X${output_PreviousStage_LastStageName} != XSECINI ] \
1202          && [ X${output_PreviousStage_LastStageName} != XSECSTOINI ] ) ; then
1203            IGCM_sys_RshArchive "rm -Rf ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_UserChoices_JobName}${output_PreviousStage_LastExtName}/*/Analyse/*"
1204            IGCM_sys_RshArchive "rm -Rf ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_UserChoices_JobName}${output_PreviousStage_LastExtName}/*/Output/*"
1205        fi
1206
1207        IGCM_sys_RshArchive "mv -f ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_UserChoices_JobName}${output_PreviousStage_LastExtName}"\
1208                                 " ${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_UserChoices_JobName}/SPIN/Output/"
1209    fi
1210
1211#   Test the end of the SPINUP !
1212    if [ X${StageName} = X"HISTO" ] ; then
1213        DateEnd=${PeriodDateEnd}
1214        (( SimulationLengthInDays=ExperienceLengthInDays + 1 ))
1215        echo "SPINUP : END Job !!!"
1216    fi
1217
1218    IGCM_debug_PopStack "SPIN_Finalize"
1219}
Note: See TracBrowser for help on using the repository browser.