1 | #!/bin/ksh |
---|
2 | |
---|
3 | #----------------------------------- |
---|
4 | function MBG_Initialize |
---|
5 | { |
---|
6 | IGCM_debug_PushStack "MBG_Initialize" |
---|
7 | |
---|
8 | JOB_NAME=${config_UserChoices_JobName} |
---|
9 | |
---|
10 | OPA_NDT_DAY=${pisces_UserChoices_OPA_NDT_DAY:=4} |
---|
11 | |
---|
12 | |
---|
13 | # Local function to find namelists parameters |
---|
14 | supergrep () { |
---|
15 | grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" |
---|
16 | } |
---|
17 | |
---|
18 | ##--Variables used by OPA -- |
---|
19 | |
---|
20 | # cexper experience name for vairmer format |
---|
21 | # nit000 number of the first time step |
---|
22 | # nitend number of the last time step |
---|
23 | # nleapy leap year calendar (0/1) (30 for 360d) |
---|
24 | # nwrite frequency of OUTPUT file |
---|
25 | # ln_rstart boolean term for restart (true or false) |
---|
26 | # nstock frequency of restart file |
---|
27 | # ndate0 initial calendar date aammjj |
---|
28 | # rdt time step in seconds (coming from namelist) |
---|
29 | |
---|
30 | |
---|
31 | PAT_CEXPER=$( supergrep cexper ${SUBMIT_DIR}/PARAM/namelist ) |
---|
32 | PAT_NIT000=$( supergrep nit000 ${SUBMIT_DIR}/PARAM/namelist ) |
---|
33 | PAT_NITEND=$( supergrep nitend ${SUBMIT_DIR}/PARAM/namelist ) |
---|
34 | PAT_NLEAPY=$( supergrep nleapy ${SUBMIT_DIR}/PARAM/namelist ) |
---|
35 | PAT_NSTOCK=$( supergrep nstock ${SUBMIT_DIR}/PARAM/namelist ) |
---|
36 | PAT_NDATE0=$( supergrep ndate0 ${SUBMIT_DIR}/PARAM/namelist ) |
---|
37 | |
---|
38 | |
---|
39 | OPA_RDT=$( supergrep rdt ${SUBMIT_DIR}/PARAM/namelist | sed 's/ *rdt *=//' | sed 's/\. *,//' ) |
---|
40 | |
---|
41 | # Period Length In Days between DateBegin and first day of calendar 0001 01 01 |
---|
42 | # /!\ Needed by OPA namelist to compute file names /!\ |
---|
43 | (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 )) |
---|
44 | |
---|
45 | ##--Variables used by MBG -- |
---|
46 | |
---|
47 | # nwritetrc frequency of write in the tracer output file |
---|
48 | # lrsttr boolean term for tracer model restart (true or false) |
---|
49 | # nrsttr control of the time step (0, 1 or 2) |
---|
50 | # ntrd_trc time step frequency of write in the trends file for tracers |
---|
51 | # ln_trdmld_trc_restart boolean term for trc trends restart (true or false) |
---|
52 | |
---|
53 | ##--Variables used by PISCES -- |
---|
54 | |
---|
55 | # nwritedia frequency of write in the additional diag output file |
---|
56 | |
---|
57 | PAT_TOP_NWRITETRC=$( supergrep nwritetrc ${SUBMIT_DIR}/PARAM/namelist_top ) |
---|
58 | PAT_TOP_LRSTTR=$( supergrep ln_rsttr ${SUBMIT_DIR}/PARAM/namelist_top ) |
---|
59 | PAT_TOP_NRSTTR=$( supergrep nrsttr ${SUBMIT_DIR}/PARAM/namelist_top ) |
---|
60 | PAT_TOP_NWRITETRD=$( supergrep ntrd_trc ${SUBMIT_DIR}/PARAM/namelist_top ) |
---|
61 | PAT_TOP_RSTRTTRD=$( supergrep ln_trdmld_trc_restart ${SUBMIT_DIR}/PARAM/namelist_top ) |
---|
62 | |
---|
63 | PAT_PIS_NWRITEDIA=$( supergrep nwritedia ${SUBMIT_DIR}/PARAM/namelist_pisces ) |
---|
64 | PAT_PIS_LRIVER=$( supergrep ln_river ${SUBMIT_DIR}/PARAM/namelist_pisces ) |
---|
65 | |
---|
66 | ##--Variables used for XMLIO_SERVER configuration file |
---|
67 | |
---|
68 | # using_server: .TRUE.(.FALSE.) to use(bypass) the io_server |
---|
69 | |
---|
70 | PAT_SERVER=$( supergrep using_server ${SUBMIT_DIR}/PARAM/xmlio_server.def ) |
---|
71 | |
---|
72 | |
---|
73 | IGCM_debug_PopStack "MBG_Initialize" |
---|
74 | } |
---|
75 | |
---|
76 | #----------------------------------- |
---|
77 | function MBG_Update |
---|
78 | { |
---|
79 | IGCM_debug_PushStack "MBG_Update" |
---|
80 | |
---|
81 | # Period Length In Days between DateBegin and first day of calendar 0001 01 01 |
---|
82 | # Needed by OPA namelist to compute correct file names |
---|
83 | (( PeriodDaysSinceJC = $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1 )) |
---|
84 | |
---|
85 | ## Count of number of time steps from begin of OPA job |
---|
86 | (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NDT_DAY + 1 )) |
---|
87 | (( OPA_NDT = PeriodLengthInDays * OPA_NDT_DAY )) |
---|
88 | (( OPA_NITEND = OPA_NIT000 + OPA_NDT - 1)) |
---|
89 | |
---|
90 | ## Forcing to write one restart file at the end of period |
---|
91 | OPA_NSTOCK="${OPA_NITEND}" |
---|
92 | |
---|
93 | ## Verification of number of time steps per day |
---|
94 | (( NB_SEC_DAY_MODEL = OPA_NDT_DAY * OPA_RDT )) |
---|
95 | (( NB_SEC_DAY = 60 * 60 * 24 )) |
---|
96 | |
---|
97 | if [ ${NB_SEC_DAY_MODEL} -ne ${NB_SEC_DAY} ] |
---|
98 | then |
---|
99 | echo " VERIFY OPA_NDT_DAY in opa9.card " |
---|
100 | exit |
---|
101 | fi |
---|
102 | |
---|
103 | ## nleapy configuration |
---|
104 | case ${config_UserChoices_CalendarType} in |
---|
105 | leap) |
---|
106 | OPA_NLEAPY=1;; |
---|
107 | noleap) |
---|
108 | OPA_NLEAPY=0;; |
---|
109 | 360d) |
---|
110 | OPA_NLEAPY=30;; |
---|
111 | esac |
---|
112 | |
---|
113 | |
---|
114 | typeset -r PRECIS=8 |
---|
115 | NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) |
---|
116 | |
---|
117 | sed -e "s%${PAT_CEXPER}% cexper=\"${config_UserChoices_JobName}\"%" \ |
---|
118 | -e "s%${PAT_NIT000}% nit000=${OPA_NIT000}%" \ |
---|
119 | -e "s%${PAT_NITEND}% nitend=${OPA_NITEND}%" \ |
---|
120 | -e "s%${PAT_NSTOCK}% nstock=${OPA_NSTOCK}%" \ |
---|
121 | -e "s%${PAT_NDATE0}% ndate0=${PeriodDateBegin}%" \ |
---|
122 | -e "s%${PAT_NLEAPY}% nleapy=${OPA_NLEAPY}%" \ |
---|
123 | namelist > namelist.tmp |
---|
124 | |
---|
125 | IGCM_sys_Mv namelist.tmp namelist |
---|
126 | |
---|
127 | echo 'Variables automatically updated in namelists' |
---|
128 | grep AUTO namelist* |
---|
129 | |
---|
130 | ##--Write Frequency Purpose .... |
---|
131 | topfrequency=$( echo ${config_MBG_WriteFrequency} | awk "-F " '{print $1}' ) |
---|
132 | topfactor=$( echo ${topfrequency} | sed -e "s/[yYmMdD]//" ) |
---|
133 | case ${topfrequency} in |
---|
134 | *Y|*y) |
---|
135 | (( TOP_NWRITE = OPA_NDT_DAY * topfactor * $( IGCM_date_DaysInYear ${year} ) )) ; |
---|
136 | (( WriteFrequencyInDays = topfactor * $( IGCM_date_DaysInYear ${year} ) )) ; |
---|
137 | PREFIX_NWRITETRC=${config_UserChoices_JobName}_${topfactor}y ; |
---|
138 | R_OUT_MBG_NWRITE=${R_OUT_MBG_O_Y} ; |
---|
139 | WFT1=${topfactor}Y ;; |
---|
140 | 1M|1m) |
---|
141 | (( TOP_NWRITE = OPA_NDT_DAY * topfactor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ; |
---|
142 | (( WriteFrequencyInDays = topfactor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ; |
---|
143 | PREFIX_NWRITETRC=${config_UserChoices_JobName}_${topfactor}m ; |
---|
144 | R_OUT_MBG_NWRITE=${R_OUT_MBG_O_M} ; |
---|
145 | WFT1=${topfactor}M ;; |
---|
146 | *D|*d) |
---|
147 | (( TOP_NWRITE = OPA_NDT_DAY * topfactor )) ; |
---|
148 | (( WriteFrequencyInDays = topfactor )) ; |
---|
149 | PREFIX_NWRITETRC=${config_UserChoices_JobName}_${topfactor}d ; |
---|
150 | R_OUT_MBG_NWRITE=${R_OUT_MBG_O_D} ; |
---|
151 | WFT1=${topfactor}D ;; |
---|
152 | *) |
---|
153 | esac |
---|
154 | |
---|
155 | ##-- Restart configuration |
---|
156 | if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_MBG_Restart}" = "n" ] ) ; then |
---|
157 | |
---|
158 | #echo "NO RESTART FOR TOP" |
---|
159 | TOP_LRSTTR=.FALSE. |
---|
160 | TOP_NRSTTR=0 |
---|
161 | |
---|
162 | if ( [ "${pisces_UserChoices_OPA_dyn}" = "cpl" ] ) ; then |
---|
163 | PISCES_LRIVER=.FALSE. |
---|
164 | else |
---|
165 | PISCES_LRIVER=.TRUE. |
---|
166 | fi |
---|
167 | |
---|
168 | elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_MBG_Restart}" = "y" ] ) ; then |
---|
169 | |
---|
170 | #echo "RESTART TOP" |
---|
171 | TOP_LRSTTR=.TRUE. |
---|
172 | TOP_NRSTTR=0 |
---|
173 | |
---|
174 | if ( [ "${pisces_UserChoices_OPA_dyn}" = "cpl" ] ) ; then |
---|
175 | PISCES_LRIVER=.TRUE. |
---|
176 | else |
---|
177 | PISCES_LRIVER=.TRUE. |
---|
178 | fi |
---|
179 | |
---|
180 | |
---|
181 | else |
---|
182 | |
---|
183 | #echo "RESTART TOP" |
---|
184 | TOP_LRSTTR=.TRUE. |
---|
185 | TOP_NRSTTR=2 |
---|
186 | |
---|
187 | if ( [ "${pisces_UserChoices_OPA_dyn}" = "cpl" ] ) ; then |
---|
188 | PISCES_LRIVER=.TRUE. |
---|
189 | else |
---|
190 | PISCES_LRIVER=.TRUE. |
---|
191 | fi |
---|
192 | |
---|
193 | fi |
---|
194 | |
---|
195 | sed -e "s%${PAT_TOP_NWRITETRC}% nwritetrc=${TOP_NWRITE}%" \ |
---|
196 | -e "s%${PAT_TOP_NWRITETRD}% ntrd_trc=${TOP_NWRITE}%" \ |
---|
197 | -e "s%${PAT_TOP_LRSTTR}% ln_rsttr=${TOP_LRSTTR}%" \ |
---|
198 | -e "s%${PAT_TOP_NRSTTR}% nrsttr=${TOP_NRSTTR}%" \ |
---|
199 | namelist_top > namelist_top.tmp |
---|
200 | |
---|
201 | IGCM_sys_Mv namelist_top.tmp namelist_top |
---|
202 | |
---|
203 | # on force les sorties PISCES comme les sorties OPA |
---|
204 | |
---|
205 | sed -e "s%${PAT_PIS_NWRITEDIA}% nwritedia=${TOP_NWRITE}%" \ |
---|
206 | -e "s%${PAT_PIS_LRIVER}% ln_river=${PISCES_LRIVER}%" \ |
---|
207 | namelist_pisces > namelist_pisces.tmp |
---|
208 | |
---|
209 | IGCM_sys_Mv namelist_pisces.tmp namelist_pisces |
---|
210 | |
---|
211 | |
---|
212 | # output_frequency_trc : output frequency of pisces output files in seconds |
---|
213 | (( output_frequency_trc = $WriteFrequencyInDays * 86400 )) |
---|
214 | |
---|
215 | # file_name_ptrc_T : name of output file on ptrc |
---|
216 | # file_name_diad_T : name of output file on diad |
---|
217 | # output_frequency_trc : output frequency of pisces output files |
---|
218 | |
---|
219 | |
---|
220 | sed -e "s/<file_name_ptrc_T>/ \"${PREFIX}_${WFT1}_ptrc_T.nc\"/" \ |
---|
221 | -e "s/<file_name_diad_T>/ \"${PREFIX}_${WFT1}_diad_T.nc\"/" \ |
---|
222 | -e "s/<output_frequency_trc>/ \"${output_frequency_trc}\"/g" \ |
---|
223 | iodef.xml > iodef.xml.tmp |
---|
224 | |
---|
225 | IGCM_sys_Mv iodef.xml.tmp iodef.xml |
---|
226 | |
---|
227 | |
---|
228 | echo 'Variables automatically updated in namelists' |
---|
229 | grep AUTO namelist* |
---|
230 | |
---|
231 | IGCM_debug_PopStack "MBG_Update" |
---|
232 | } |
---|
233 | |
---|
234 | #----------------------------------- |
---|
235 | function MBG_Finalize |
---|
236 | { |
---|
237 | IGCM_debug_PushStack "MBG_Finalize" |
---|
238 | |
---|
239 | if [ -f date.file ] ; then |
---|
240 | # Prefix use in opa.card AND in lim2.card : |
---|
241 | DATE_OPA=$( cat date.file | \ |
---|
242 | sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" ) |
---|
243 | ###DATE_OPA=$( $DATE_OPABF | cut -c1-30 ) |
---|
244 | MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA} |
---|
245 | SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA} |
---|
246 | fi |
---|
247 | |
---|
248 | echo FINALIZE MBG !!! |
---|
249 | |
---|
250 | IGCM_debug_PopStack "MBG_Finalize" |
---|
251 | } |
---|
252 | |
---|