source: tags/ORCHIDEE_1_9_6/ORCHIDEE_OL/SPINUP/COMP/spinup.driver @ 3847

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

Modified FLUXNET and ENSEMBLE configurations for the externalization. Delete obselete files in OOL_SEC and OOL_SEC_STO. Update SPINUP config.

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