source: CONFIG_DEVT/ORCHIDEE_OL_TP/FORCESOIL/COMP/stomate.driver @ 5868

Last change on this file since 5868 was 5570, checked in by aclsce, 3 years ago

Created ORCHIDEE_OL_TP configuration : temporary configuration to be used during prectical session.

  • Property svn:executable set to *
File size: 5.9 KB
Line 
1#!/bin/ksh
2
3#D- Driver du script pour STOMATE
4
5#-----------------------------------------------------------------
6function SBG_Initialize
7{
8    IGCM_debug_PushStack "SBG_Initialize"
9
10    RESOL_SBG=ALL
11
12    typeset frequency
13    for frequency in ${config_SBG_WriteFrequency} ; do
14        case ${frequency} in
15            HF|hf) SBG_ok_hf=y ;;
16        esac
17    done
18   
19    IGCM_debug_PopStack "SBG_Initialize"
20}
21
22#-----------------------------------------------------------------
23function SBG_PeriodStart
24{
25    IGCM_debug_PushStack "SBG_PeriodStart"
26
27    IGCM_debug_PopStack "SBG_PeriodStart"
28}
29
30#-----------------------------------------------------------------
31function SBG_Update
32{
33    IGCM_debug_PushStack "SBG_Update"
34
35    typeset STOMATE_WRITE_STEP
36
37    # Set default values for stomate output files
38    # These variables are used only to modify file_def_orchidee.xml if XIOS=y
39    stomate_enabled=.FALSE.
40    stomate_freq=0s
41
42    case ${config_SBG_WriteFrequency} in
43        *Y|*y) 
44            WriteInYears=$( echo ${config_SBG_WriteFrequency} | awk -F '[yY]' '{print $1}' )
45            PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | awk -F '[yY]' '{print $1}' )
46            (( STOMATE_WRITE_STEP = PeriodLengthInDays * WriteInYears / PeriodLengthInYears )) 
47
48            stomate_enabled=.TRUE.
49            stomate_freq=${WriteInYears}y
50        ;;
51        1M|1m) 
52            stomate_enabled=.TRUE.
53            stomate_freq=1mo
54            case ${config_UserChoices_PeriodLength} in
55            *Y|*y)
56                STOMATE_WRITE_STEP=-1.
57                ;;
58            *M|*m)
59                STOMATE_WRITE_STEP=-1.
60                ;;
61            *)
62                (( STOMATE_WRITE_STEP = $( IGCM_date_DaysInMonth $year $month ) )) ;;
63            esac
64            ;;
65        *M|*m) 
66            WriteInMonths=$( echo ${config_SBG_WriteFrequency} | awk -F '[mM]' '{print $1}' )
67            stomate_enabled=.TRUE.
68            stomate_freq=${WriteInMonths}mo
69            case ${config_UserChoices_PeriodLength} in
70            *Y|*y)
71                PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | awk -F '[yY]' '{print $1}' )
72                (( STOMATE_WRITE_STEP = 30 )) ;;
73            *M|*m)
74                PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | awk -F '[mM]' '{print $1}' )
75                (( STOMATE_WRITE_STEP = PeriodLengthInDays * WriteInMonths / PeriodLengthInMonths )) ;;
76            *)
77                (( STOMATE_WRITE_STEP = $( IGCM_date_DaysInMonth $year $month ) )) ;;
78            esac
79            ;;
80        5D|5d)
81            stomate_enabled=.TRUE.
82            stomate_freq=5d
83            (( STOMATE_WRITE_STEP = 5 )) ;;
84        1D|1d)
85            stomate_enabled=.TRUE.
86            stomate_freq=1d
87            (( STOMATE_WRITE_STEP = 1 )) ;;
88        *s)
89            WriteInSeconds=$( echo ${config_SBG_WriteFrequency} | awk -F '[s]' '{print $1}' )
90            stomate_enabled=.TRUE.
91            stomate_freq=${WriteInSeconds}s
92            (( STOMATE_WRITE_STEP = 1 )) ;;
93        *) 
94            IGCM_debug_Exit "SBG_Update " ${config_SBG_WriteFrequency} " invalid WriteFrequency : choose in 1Y, 1M, 5D, 1D." 
95            IGCM_debug_Verif_Exit ;;
96    esac
97
98    # Modify file_def_orchidee.def if XIOS is activated
99    if [ X${orchidee_ol_UserChoices_XIOS} = Xy ] ; then
100        # Modify file_def_orchidee.xml
101        IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 enabled ${stomate_enabled}
102        IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate1 output_freq ${stomate_freq}
103        IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 enabled ${stomate_enabled}
104        IGCM_comp_modifyXmlFile nonblocker file_def_orchidee.xml stomate2 output_freq ${stomate_freq}
105
106        # Deactivate stomate IOIPSL output
107        (( STOMATE_WRITE_STEP = 0 ))
108    fi
109
110    ORCHIDEE_def STOMATE_OK_STOMATE y
111
112    if [ X${stomate_UserChoices_SPINUP_ANALYTIC} = Xy ] ; then
113       ORCHIDEE_def SPINUP_ANALYTIC y
114     
115       # Test if CyclicBegin and CyclicEnd is set in config.card
116       if ( [ X${config_UserChoices_CyclicBegin} = X ] || [ X${config_UserChoices_CyclicEnd} = X ] ) ; then
117           IGCM_debug_Exit "CyclicBegin and CyclicEnd must be set in config.card to run option spinup_analytic."
118       fi
119       # Calculate and set number of years of forcing data
120       CycleNb=$(( ${config_UserChoices_CyclicEnd} - ${config_UserChoices_CyclicBegin} + 1 ))
121       ORCHIDEE_def SPINUP_PERIOD ${CycleNb}
122
123    fi
124
125    ORCHIDEE_def STOMATE_HIST_DT ${STOMATE_WRITE_STEP}
126    ORCHIDEE_def STOMATE_HISTLEVEL ${stomate_UserChoices_stomate_LEVEL}
127    if ( [ ${CumulPeriod} -eq 1 ] && [ "${config_SBG_Restart}" = "n" ] ) ; then
128        echo "STOMATE : without restart"
129    else
130        ORCHIDEE_def STOMATE_RESTART_FILEIN stomate_rest_in.nc
131    fi
132
133    if [ X${SBG_ok_hf} = Xy ] ; then
134        ORCHIDEE_def STOMATE_IPCC_HIST_DT 1D
135    else
136        ORCHIDEE_def STOMATE_IPCC_HIST_DT ${STOMATE_WRITE_STEP}
137    fi
138
139
140    if [ -f CO2.txt ] ; then
141        # If this file exist, then read CO2 value and set ATM_CO2 in run.def
142        IPCC_CO2=`grep Annee_${year} CO2.txt | awk -F= '{print $2}'`
143        ORCHIDEE_def ATM_CO2 ${IPCC_CO2}
144    fi
145
146
147    # Special case using forcesoil executable
148    if [ -f forcesoil ] ; then
149        # Set STOMATE_CFORCING_NAME
150        ORCHIDEE_def STOMATE_CFORCING_NAME stomate_Cforcing.nc
151
152        # Check if restart file is missing
153        if ( [ ${CumulPeriod} -eq 1 ] && [ "${config_SBG_Restart}" = "n" ] ) ; then
154            IGCM_debug_Exit "YOU MUST USE OLD STOMATE RESTART FILE WITH THE JOB FORCESOIL."
155            IGCM_debug_Verif_Exit
156        fi
157    fi
158
159    IGCM_debug_PopStack "SBG_Update"
160}
161
162#-----------------------------------------------------------------
163function SBG_Finalize
164{
165    IGCM_debug_PushStack "SBG_Finalize"
166
167#   Check if equilibrium is reached for spinup analytic
168#   and if true stop the simulation in the end of this period.
169    if [ X${stomate_UserChoices_SPINUP_ANALYTIC} = Xy ] ; then
170      CondSpinup=$(grep -a  "Equilibrium for carbon pools is reached"  out_*)
171      if [ X"${CondSpinup}" != X ] ; then
172        echo "SPINUP ANALYTIC :  your spinup is successful :"
173        echo ${CondSpinup}
174        echo "We stop the simulation now. PeriodDateEnd is set to DateEnd."
175        PeriodDateEnd=${DateEnd}
176      fi
177    fi
178
179    IGCM_debug_PopStack "SBG_Finalize"
180}
Note: See TracBrowser for help on using the repository browser.