1 | #!/bin/ksh |
---|
2 | |
---|
3 | #----------------------------------- |
---|
4 | function MBG_Initialize |
---|
5 | { |
---|
6 | IGCM_debug_PushStack "MBG_Initialize" |
---|
7 | |
---|
8 | # Local function to find namelists parameters |
---|
9 | supergrep () { |
---|
10 | grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" |
---|
11 | } |
---|
12 | |
---|
13 | if [ X"${pisces_UserChoices_Offline_Mode}" = X"y" ] ; then |
---|
14 | |
---|
15 | if [ X$ResolOce != X ]; then |
---|
16 | #ResolOce is set in config.card |
---|
17 | RESOL_OCE=${ResolOce} |
---|
18 | else |
---|
19 | RESOL_OCE=${config_UserChoices_ExpType%%_*} |
---|
20 | fi |
---|
21 | ORCAGRID=${opa9_UserChoices_ORCA_version%%.*} |
---|
22 | exptype=${config_UserChoices_ExpType##*/} |
---|
23 | |
---|
24 | IGCM_debug_Print 1 " " |
---|
25 | IGCM_debug_Print 1 "RESOL_OCE : ${RESOL_OCE}" |
---|
26 | IGCM_debug_Print 1 "ORCAGRID : ${ORCAGRID}" |
---|
27 | IGCM_debug_Print 1 "EXPERIMENT TYPE : ${exptype}" |
---|
28 | |
---|
29 | |
---|
30 | OPA_RDT=$( supergrep rn_Dt ${SUBMIT_DIR}/PARAM/NAMELIST/${RESOL_OCE}/namelist_offline_${exptype}_cfg | sed 's/ *rn_Dt *=//' | sed 's/\. *,//' ) |
---|
31 | # Period Length In Days between DateBegin and first day of calendar 0001 01 01 |
---|
32 | # /!\ Needed by OPA namelist to compute file names /!\ |
---|
33 | (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 )) |
---|
34 | |
---|
35 | (( OPA_NPDT_DAY = 86400 / OPA_RDT )) |
---|
36 | (( OPA_NPDT_YEAR = OPA_NPDT_DAY * 365 )) |
---|
37 | |
---|
38 | |
---|
39 | IGCM_debug_Print 1 " " |
---|
40 | IGCM_debug_Print 1 "OPA_RDT ${OPA_RDT}" |
---|
41 | IGCM_debug_Print 1 "OPA_NPDT_DAY ${OPA_NPDT_DAY}" |
---|
42 | IGCM_debug_Print 1 "OPA_NPDT_YEAR ${OPA_NPDT_YEAR}" |
---|
43 | fi |
---|
44 | |
---|
45 | IGCM_debug_PopStack "MBG_Initialize" |
---|
46 | } |
---|
47 | |
---|
48 | #----------------------------------- |
---|
49 | function MBG_Update |
---|
50 | { |
---|
51 | IGCM_debug_PushStack "MBG_Update" |
---|
52 | |
---|
53 | |
---|
54 | ##--Write Frequency for iomput |
---|
55 | ## Differents frequencies are allowed for MBG files |
---|
56 | |
---|
57 | VT1D_ENABLE=".FALSE." |
---|
58 | VT5D_ENABLE=".FALSE." |
---|
59 | VT1M_ENABLE=".FALSE." |
---|
60 | VT1Y_ENABLE=".FALSE." |
---|
61 | |
---|
62 | for frequency in ${config_MBG_WriteFrequency} ; do |
---|
63 | case ${frequency} in |
---|
64 | ( 1D|1d ) VT1D_ENABLE=".TRUE." ;; |
---|
65 | ( 5D|5d ) VT5D_ENABLE=".TRUE." ;; |
---|
66 | ( 1M|1m ) VT1M_ENABLE=".TRUE." ;; |
---|
67 | ( *[yY] ) VT1Y_ENABLE=".TRUE." ;; |
---|
68 | esac |
---|
69 | done |
---|
70 | |
---|
71 | |
---|
72 | if [ X"${pisces_UserChoices_Offline_Mode}" = X"y" ] ; then |
---|
73 | |
---|
74 | # Period Length In Days between DateBegin and first day of calendar 0001 01 01 |
---|
75 | # Needed by OPA namelist to compute correct file names |
---|
76 | (( PeriodDaysSinceJC = $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1 )) |
---|
77 | |
---|
78 | ## Count of number of time steps from begin of OPA job |
---|
79 | (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NPDT_DAY + 1 )) |
---|
80 | (( OPA_NDT = PeriodLengthInDays * OPA_NPDT_DAY )) |
---|
81 | (( OPA_NITEND = OPA_NIT000 + OPA_NDT - 1)) |
---|
82 | |
---|
83 | ## Forcing to write one restart file at the end of period |
---|
84 | OPA_NSTOCK="${OPA_NITEND}" |
---|
85 | |
---|
86 | # nleapy configuration |
---|
87 | case ${config_UserChoices_CalendarType} in |
---|
88 | leap) |
---|
89 | OPA_NLEAPY=1;; |
---|
90 | noleap) |
---|
91 | OPA_NLEAPY=0;; |
---|
92 | 360d) |
---|
93 | OPA_NLEAPY=30;; |
---|
94 | esac |
---|
95 | |
---|
96 | typeset -r PRECIS=8 |
---|
97 | NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) |
---|
98 | |
---|
99 | |
---|
100 | DYN_SSH_INI=.TRUE. |
---|
101 | if [ "${exptype}" = "ia" ] ; then |
---|
102 | NbDynFile=${#pisces_UserChoices_DynFiles[*]} |
---|
103 | (( LengthForcing=${pisces_UserChoices_DynYearEnd} - ${pisces_UserChoices_DynYearStart} + 1 )) |
---|
104 | (( DiffForcing=abs( ${pisces_UserChoices_DynYearEnd} - ${year} ) )) |
---|
105 | (( ModuloForcing=${DiffForcing} % ${LengthForcing} )) |
---|
106 | if [ ${ModuloForcing} -eq 0 ] ; then |
---|
107 | (( year_forcing=${pisces_UserChoices_DynYearEnd} )) |
---|
108 | else |
---|
109 | if [ ${year} -ge ${pisces_UserChoices_DynYearStart} ] && [ ${year} -le ${pisces_UserChoices_DynYearEnd} ] ; then |
---|
110 | year_forcing=${year} |
---|
111 | elif [ ${year} -lt ${pisces_UserChoices_DynYearStart} ] ; then |
---|
112 | (( year_forcing=${pisces_UserChoices_DynYearEnd} - ${ModuloForcing} )) |
---|
113 | else |
---|
114 | (( year_forcing=${pisces_UserChoices_DynYearStart} + ${ModuloForcing} - 1 )) |
---|
115 | fi |
---|
116 | fi |
---|
117 | (( year_forcing_m1 = ${year_forcing} - 1)) |
---|
118 | (( year_forcing_p1 = ${year_forcing} + 1)) |
---|
119 | eval CurrDateFor=${year_forcing}0101_${year_forcing}1231 |
---|
120 | eval PrevDateFor=${year_forcing_m1}0101_${year_forcing_m1}1231 |
---|
121 | eval NextDateFor=${year_forcing_p1}0101_${year_forcing_p1}1231 |
---|
122 | (( i = 0 )) |
---|
123 | while [ $i -lt ${NbDynFile} ] ; do |
---|
124 | eval Suffix=${pisces_UserChoices_DynFiles[$i]} |
---|
125 | eval RunFileName=${pisces_UserChoices_DynRunName}_${Suffix} |
---|
126 | eval PrevDynFileName=${pisces_UserChoices_DynName}_${PrevDateFor}_${pisces_UserChoices_DynFreq}_${Suffix} |
---|
127 | eval CurrDynFileName=${pisces_UserChoices_DynName}_${CurrDateFor}_${pisces_UserChoices_DynFreq}_${Suffix} |
---|
128 | eval NextDynFileName=${pisces_UserChoices_DynName}_${NextDateFor}_${pisces_UserChoices_DynFreq}_${Suffix} |
---|
129 | IGCM_sys_Get ${pisces_UserChoices_R_DYN}/${PrevDynFileName}.nc ${RunFileName}_y${year_m1}.nc |
---|
130 | IGCM_sys_Get ${pisces_UserChoices_R_DYN}/${CurrDynFileName}.nc ${RunFileName}_y${year}.nc |
---|
131 | IGCM_sys_Get ${pisces_UserChoices_R_DYN}/${NextDynFileName}.nc ${RunFileName}_y${year_p1}.nc |
---|
132 | ln -sf ${RunFileName}_y${year}.nc ${RunFileName}.nc |
---|
133 | (( i = i + 1 )) |
---|
134 | done |
---|
135 | if [ ${year_forcing} = ${pisces_UserChoices_DynYearStart} ] ; then |
---|
136 | DYN_SSH_INI=.TRUE. |
---|
137 | else |
---|
138 | DYN_SSH_INI=.FALSE |
---|
139 | fi |
---|
140 | fi |
---|
141 | fi |
---|
142 | |
---|
143 | ##-- Restart configuration |
---|
144 | if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_MBG_Restart}" = "n" ] ) ; then |
---|
145 | |
---|
146 | #echo "NO RESTART FOR TOP" |
---|
147 | TOP_LRSTTR=.FALSE. |
---|
148 | TOP_NRSTTR=0 |
---|
149 | |
---|
150 | elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_MBG_Restart}" = "y" ] ) ; then |
---|
151 | |
---|
152 | #echo "RESTART TOP" |
---|
153 | TOP_LRSTTR=.TRUE. |
---|
154 | TOP_NRSTTR=0 |
---|
155 | |
---|
156 | else |
---|
157 | |
---|
158 | #echo "RESTART TOP" |
---|
159 | TOP_LRSTTR=.TRUE. |
---|
160 | TOP_NRSTTR=2 |
---|
161 | fi |
---|
162 | |
---|
163 | # on force les sorties PISCES comme les sorties OPA |
---|
164 | if [ X"${pisces_UserChoices_Offline_Mode}" = X"y" ] ; then |
---|
165 | IGCM_comp_modifyNamelist blocker namelist_cfg cn_exp ${config_UserChoices_JobName} |
---|
166 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_it000 ${OPA_NIT000} |
---|
167 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_itend ${OPA_NITEND} |
---|
168 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_stock ${OPA_NSTOCK} |
---|
169 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_date0 ${PeriodDateBegin} |
---|
170 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_leapy ${OPA_NLEAPY} |
---|
171 | |
---|
172 | # update domain_def.xml file |
---|
173 | case ${RESOL_OCE} in |
---|
174 | ( *ORCA025* ) |
---|
175 | sed -e 's/<zoom_domain id="1point" ibegin="139" jbegin="119"/<zoom_domain id="1point" ibegin="600" jbegin="600"/' domain_def_nemo.xml > domain_def.xml.tmp |
---|
176 | IGCM_sys_Mv domain_def.xml.tmp domain_def_nemo.xml ; |
---|
177 | esac |
---|
178 | |
---|
179 | IGCM_comp_modifyXmlFile force context_nemo.xml ref_year NONE ${InitYear} |
---|
180 | |
---|
181 | fi |
---|
182 | |
---|
183 | if [ X"${pisces_UserChoices_pis}" = X"y" ] ; then |
---|
184 | echo "Activate pisces outputs" |
---|
185 | [ ${VT1D_ENABLE} = ".TRUE." ] && IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file31 enabled .TRUE. |
---|
186 | [ ${VT5D_ENABLE} = ".TRUE." ] && IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file32 enabled .TRUE. |
---|
187 | [ ${VT1M_ENABLE} = ".TRUE." ] && IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file33 enabled .TRUE. |
---|
188 | [ ${VT1M_ENABLE} = ".TRUE." ] && IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file34 enabled .TRUE. |
---|
189 | [ ${VT1M_ENABLE} = ".TRUE." ] && IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file35 enabled .TRUE. |
---|
190 | [ ${VT1Y_ENABLE} = ".TRUE." ] && IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file36 enabled .TRUE. |
---|
191 | [ ${VT1Y_ENABLE} = ".TRUE." ] && IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file37 enabled .TRUE. |
---|
192 | fi |
---|
193 | |
---|
194 | if [ X"${pisces_UserChoices_age}" = X"y" ] ; then |
---|
195 | echo "Activate age tracer" |
---|
196 | TOP_AGE=.TRUE. |
---|
197 | IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file38 enabled .TRUE. |
---|
198 | else |
---|
199 | TOP_AGE=.FALSE. |
---|
200 | fi |
---|
201 | ## |
---|
202 | if [ X"${pisces_UserChoices_cfc11}" = X"y" ] ; then |
---|
203 | echo "Activate CFC11 tracer" |
---|
204 | TOP_CFC11=.TRUE. |
---|
205 | IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file39 enabled .TRUE. |
---|
206 | else |
---|
207 | TOP_CFC11=.FALSE. |
---|
208 | fi |
---|
209 | ## |
---|
210 | if [ X"${pisces_UserChoices_cfc12}" = X"y" ] ; then |
---|
211 | echo "Activate CFC12 tracer" |
---|
212 | TOP_CFC12=.TRUE. |
---|
213 | IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file40 enabled .TRUE. |
---|
214 | else |
---|
215 | TOP_CFC12=.FALSE. |
---|
216 | fi |
---|
217 | ## |
---|
218 | if [ X"${pisces_UserChoices_sf6}" = X"y" ] ; then |
---|
219 | echo "Activate SF6 tracer" |
---|
220 | TOP_SF6=.TRUE. |
---|
221 | IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file41 enabled .TRUE. |
---|
222 | else |
---|
223 | TOP_SF6=.FALSE. |
---|
224 | fi |
---|
225 | ## |
---|
226 | if [ X"${pisces_UserChoices_c14}" = X"y" ] ; then |
---|
227 | echo "Activate RC14 tracer" |
---|
228 | TOP_C14=.TRUE. |
---|
229 | IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file42 enabled .TRUE. |
---|
230 | else |
---|
231 | TOP_C14=.FALSE. |
---|
232 | fi |
---|
233 | |
---|
234 | if [ X"${pisces_UserChoices_gas}" = X"n" ] ; then |
---|
235 | LGAS=.FALSE. |
---|
236 | cp namelist_top_p4z_cfg namelist_top_cfg |
---|
237 | else |
---|
238 | echo "Activate gas tracer" |
---|
239 | LGAS=.TRUE. |
---|
240 | cp namelist_top_p4z_gas_cfg namelist_top_cfg |
---|
241 | [ ${VT1M_ENABLE} = ".TRUE." ] && IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file60 enabled .TRUE. |
---|
242 | [ ${VT1Y_ENABLE} = ".TRUE." ] && IGCM_comp_modifyXmlFile force file_def_nemo-top.xml file61 enabled .TRUE. |
---|
243 | fi |
---|
244 | ## |
---|
245 | if [ X"${pisces_UserChoices_AnthrGas}" = X"y" ] ; then |
---|
246 | # Read value for co2_ppm from file CO2.txt. If file not existing, take DEFAULT. |
---|
247 | if [ -f atmco2.txt ] ; then |
---|
248 | line_year=`awk '/'${year}'/{print NR}' atmco2.txt` |
---|
249 | PisCo2=`awk 'NR == '$line_year' {print $2 }' atmco2.txt` |
---|
250 | else |
---|
251 | PisCo2=${pisces_UserChoices_AtmCo2} |
---|
252 | fi |
---|
253 | else |
---|
254 | PisCo2=${pisces_UserChoices_AtmCo2} |
---|
255 | fi |
---|
256 | |
---|
257 | if [ X"${pisces_UserChoices_AnthrGas}" = X"y" ] && [ X"${pisces_UserChoices_gas}" = X"y" ] ; then |
---|
258 | if [ -f atmn2o.txt ] ; then |
---|
259 | line_year=`awk '/'${year}'/{print NR}' atmn2o.txt` |
---|
260 | PisNo2=`awk 'NR == '$line_year' {print $2 }' atmn2o.txt` |
---|
261 | else |
---|
262 | PisN2o=${pisces_UserChoices_AtmN2o} |
---|
263 | fi |
---|
264 | if [ -f atmcos.txt ] ; then |
---|
265 | line_year=`awk '/'${year}'/{print NR}' atmcos.txt` |
---|
266 | PisCos=`awk 'NR == '$line_year' {print $2 }' atmcos.txt` |
---|
267 | else |
---|
268 | PisCos=${pisces_UserChoices_AtmCos} |
---|
269 | fi |
---|
270 | else |
---|
271 | PisN2o=${pisces_UserChoices_AtmN2o} |
---|
272 | PisCos=${pisces_UserChoices_AtmCos} |
---|
273 | fi |
---|
274 | |
---|
275 | # Manage the diurnal cycle in TOP |
---|
276 | if [ X"${pisces_UserChoices_diurnal_cycle}" = X"y" ] ; then |
---|
277 | TOP_LDCY=.TRUE. |
---|
278 | else |
---|
279 | TOP_LDCY=.FALSE. |
---|
280 | fi |
---|
281 | |
---|
282 | ##-- Update namelist_top_cfg and namelist_pisces_cfg |
---|
283 | IGCM_comp_modifyNamelist blocker namelist_top_cfg ln_rsttr ${TOP_LRSTTR} |
---|
284 | IGCM_comp_modifyNamelist blocker namelist_top_cfg nn_rsttr ${TOP_NRSTTR} |
---|
285 | IGCM_comp_modifyNamelist blocker namelist_top_cfg ln_age ${TOP_AGE} |
---|
286 | IGCM_comp_modifyNamelist blocker namelist_top_cfg ln_cfc11 ${TOP_CFC11} |
---|
287 | IGCM_comp_modifyNamelist blocker namelist_top_cfg ln_cfc12 ${TOP_CFC12} |
---|
288 | IGCM_comp_modifyNamelist blocker namelist_top_cfg ln_sf6 ${TOP_SF6} |
---|
289 | IGCM_comp_modifyNamelist blocker namelist_top_cfg ln_c14 ${TOP_C14} |
---|
290 | IGCM_comp_modifyNamelist blocker namelist_top_cfg ln_trcdc2dm ${TOP_LDCY} |
---|
291 | if [ X"${pisces_UserChoices_pis}" = X"y" ] ; then |
---|
292 | IGCM_comp_modifyNamelist blocker namelist_pisces_cfg atcco2 ${PisCo2} |
---|
293 | IGCM_comp_modifyNamelist blocker namelist_pisces_cfg nrdttrc ${pisces_UserChoices_PisFreq} |
---|
294 | IGCM_comp_modifyNamelist blocker namelist_pisces_cfg nn_pisdmp ${OPA_NPDT_YEAR} |
---|
295 | IGCM_comp_modifyNamelist blocker namelist_pisces_cfg ln_dms ${LGAS} |
---|
296 | IGCM_comp_modifyNamelist blocker namelist_pisces_cfg ln_n2o ${LGAS} |
---|
297 | IGCM_comp_modifyNamelist blocker namelist_pisces_cfg ln_bvocs ${LGAS} |
---|
298 | IGCM_comp_modifyNamelist blocker namelist_pisces_cfg atcn2o ${PisN2o} |
---|
299 | IGCM_comp_modifyNamelist blocker namelist_pisces_cfg atccos ${PisCos} |
---|
300 | fi |
---|
301 | |
---|
302 | # Update iodef.xml |
---|
303 | |
---|
304 | IGCM_debug_Print 1 'Informations into iodef.xml : VT1D_ENABLE VT5D_ENABLE VT1M_ENABLE VT1Y_ENABLE ' |
---|
305 | IGCM_debug_Print 1 ${VT1D_ENABLE} ${VT5D_ENABLE} ${VT1M_ENABLE} ${VT1Y_ENABLE} |
---|
306 | |
---|
307 | IGCM_comp_modifyXmlFile nonblocker file_def_nemo-top.xml 1d_pis enabled ${VT1D_ENABLE} |
---|
308 | IGCM_comp_modifyXmlFile nonblocker file_def_nemo-top.xml 5d_pis enabled ${VT5D_ENABLE} |
---|
309 | IGCM_comp_modifyXmlFile nonblocker file_def_nemo-top.xml 1m_pis enabled ${VT1M_ENABLE} |
---|
310 | IGCM_comp_modifyXmlFile nonblocker file_def_nemo-top.xml 1y_pis enabled ${VT1Y_ENABLE} |
---|
311 | |
---|
312 | IGCM_comp_modifyXmlFile nonblocker file_def_nemo-top.xml 1d_pis output_level ${pisces_UserChoices_OutputLevel} |
---|
313 | IGCM_comp_modifyXmlFile nonblocker file_def_nemo-top.xml 5d_pis output_level ${pisces_UserChoices_OutputLevel} |
---|
314 | IGCM_comp_modifyXmlFile nonblocker file_def_nemo-top.xml 1m_pis output_level ${pisces_UserChoices_OutputLevel} |
---|
315 | IGCM_comp_modifyXmlFile nonblocker file_def_nemo-top.xml 1y_pis output_level ${pisces_UserChoices_OutputLevel} |
---|
316 | |
---|
317 | |
---|
318 | |
---|
319 | IGCM_debug_PopStack "MBG_Update" |
---|
320 | } |
---|
321 | |
---|
322 | #----------------------------------- |
---|
323 | function MBG_Finalize |
---|
324 | { |
---|
325 | IGCM_debug_PushStack "MBG_Finalize" |
---|
326 | |
---|
327 | echo FINALIZE MBG !!! |
---|
328 | |
---|
329 | IGCM_debug_PopStack "MBG_Finalize" |
---|
330 | } |
---|
331 | |
---|