1 | #!/bin/ksh |
---|
2 | #----------------------------------------------------------------- |
---|
3 | function OCE_Initialize |
---|
4 | { |
---|
5 | IGCM_debug_PushStack "OCE_Initialize" |
---|
6 | |
---|
7 | JOB_NAME=${config_UserChoices_JobName} |
---|
8 | |
---|
9 | #?? RESOL_OCE=$( echo $RESOL | awk "-Fx" '{print $2}' | awk "-F-" '{print $1}') |
---|
10 | #?? [ -f ${SUBMIT_DIR}/../.resol ] && eval $(grep RESOL_OCE_3D ${SUBMIT_DIR}/../.resol) || RESOL_OCE_3D=96x95x39 |
---|
11 | |
---|
12 | OPA_NDT_DAY=${opa9_UserChoices_OPA_NDT_DAY:=24} |
---|
13 | |
---|
14 | # Local function to find namelists parameters |
---|
15 | supergrep () { |
---|
16 | grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" |
---|
17 | } |
---|
18 | |
---|
19 | OPA_RDT=$( supergrep rn_rdt ${SUBMIT_DIR}/PARAM/namelist_cfg | sed 's/ *rn_rdt *=//' | sed 's/\. *,//' ) |
---|
20 | |
---|
21 | # Period Length In Days between DateBegin and first day of calendar 0001 01 01 |
---|
22 | # /!\ Needed by OPA namelist to compute file names /!\ |
---|
23 | (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 )) |
---|
24 | |
---|
25 | # Definition from opa9.card of List_jobsbc and List_runsbc used to do to interannual and climatological runs |
---|
26 | IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/opa9.card Interannual List_jobsbc |
---|
27 | set -A ListFormulationJobsbc -- \${opa9_Interannual_Listjobsc${opa9_Interannual_List_jobsbc}[*]} |
---|
28 | |
---|
29 | IGCM_debug_PopStack "OCE_Initialize" |
---|
30 | } |
---|
31 | |
---|
32 | #----------------------------------------------------------------- |
---|
33 | function OCE_Update |
---|
34 | { |
---|
35 | IGCM_debug_PushStack "OCE_Update" |
---|
36 | |
---|
37 | # Interannual run |
---|
38 | # In this case job need to calculate previous and following year and give, and if every run needs to add "_y" before every year |
---|
39 | if [ X${opa9_UserChoices_Interannual_Run} = Xy ] ; then |
---|
40 | |
---|
41 | typeset file |
---|
42 | |
---|
43 | (( PeriodCumulPeriod = ${CumulPeriod} - 1 )) |
---|
44 | (( PeriodInitYear =${InitYear} + ${PeriodCumulPeriod} * ${PeriodLengthInYears} )) |
---|
45 | (( PeriodFinalYear =${InitYear} + ${PeriodLengthInYears}*${CumulPeriod} - 1 )) |
---|
46 | |
---|
47 | NbFileInter=${#opa9_Interannual_List_jobsbc[*]} |
---|
48 | (( NbFileInter_tot=${#opa9_Interannual_List_jobsbc[*]} * ${PeriodLengthInYears} )) |
---|
49 | (( i = 0 )) |
---|
50 | |
---|
51 | while [ ${year} -le ${PeriodFinalYear} ] ; do #copy in ONCE of ALL necessary files for all PeriodLength |
---|
52 | |
---|
53 | while [ $i -lt ${NbFileInter} ] ; do |
---|
54 | |
---|
55 | eval file=${opa9_Interannual_List_jobsbc[$i]} |
---|
56 | if [ X${year} = X${PeriodInitYear} ] ; then |
---|
57 | if [ ${month} -eq 01 ] ; then |
---|
58 | # if year-1 does not exist we create a file _noym1.nc copy of year |
---|
59 | eval jobsbc_file_ym1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_m1}.nc |
---|
60 | if [ ! -f ${jobsbc_file_ym1} ] ; then |
---|
61 | eval jobsbc_file_ym1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year}.nc |
---|
62 | eval runsbc_file_ym1=${file}_noym1.nc |
---|
63 | else |
---|
64 | eval jobsbc_file_ym1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_m1}.nc |
---|
65 | eval runsbc_file_ym1=${file}_y${year_m1}.nc |
---|
66 | fi |
---|
67 | |
---|
68 | IGCM_sys_Get ${jobsbc_file_ym1} ${runsbc_file_ym1} |
---|
69 | fi |
---|
70 | fi |
---|
71 | |
---|
72 | # download year |
---|
73 | eval jobsbc_file_y=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year}.nc |
---|
74 | eval runsbc_file_y=${file}_y${year}.nc |
---|
75 | |
---|
76 | if [ ! -f ${runsbc_file_y} ] ; then |
---|
77 | IGCM_sys_Get ${jobsbc_file_y} ${runsbc_file_y} |
---|
78 | fi |
---|
79 | |
---|
80 | # download (year+1) if it is last year of run |
---|
81 | if [ X${year} = X${PeriodFinalYear} ] ; then |
---|
82 | |
---|
83 | eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_p1}.nc |
---|
84 | eval runsbc_file_yp1=${file}_y${year_p1}.nc |
---|
85 | |
---|
86 | if [ ! -f ${runsbc_file_yp1} ] ; then |
---|
87 | |
---|
88 | # if year+1 does not exist we create a file _noyp1.nc copy of year |
---|
89 | eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_p1}.nc |
---|
90 | if [ ! -f ${jobsbc_file_yp1} ] ; then |
---|
91 | eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year}.nc |
---|
92 | eval runsbc_file_yp1=${file}_noyp1.nc |
---|
93 | else |
---|
94 | eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_p1}.nc |
---|
95 | eval runsbc_file_yp1=${file}_y${year_p1}.nc |
---|
96 | fi |
---|
97 | IGCM_sys_Get ${jobsbc_file_yp1} ${runsbc_file_yp1} |
---|
98 | fi |
---|
99 | |
---|
100 | fi |
---|
101 | (( i = i + 1 )) |
---|
102 | |
---|
103 | done |
---|
104 | |
---|
105 | (( year = year + 1 )) |
---|
106 | |
---|
107 | (( i = 0 )) |
---|
108 | done |
---|
109 | |
---|
110 | # End interannual |
---|
111 | elif [ X${opa9_UserChoices_Interannual_Run} = Xn ] ; then |
---|
112 | # Climatological run |
---|
113 | typeset file |
---|
114 | |
---|
115 | eval NbFileInter=${#opa9_Interannual_List_jobsbc[*]} |
---|
116 | |
---|
117 | (( i = 0 )) |
---|
118 | while [ $i -lt ${NbFileInter} ] ; do |
---|
119 | eval file=${opa9_Interannual_List_jobsbc[$i]} |
---|
120 | eval jobsbc_file=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}.nc |
---|
121 | eval runsbc_file=${file}.nc |
---|
122 | |
---|
123 | IGCM_sys_Get ${jobsbc_file} ${runsbc_file} |
---|
124 | (( i = i + 1 )) |
---|
125 | done |
---|
126 | fi |
---|
127 | # End climatological |
---|
128 | |
---|
129 | # TEST year for EMPave_old.dat file |
---|
130 | # Needed if in namelist fwb=2 after firts year, because in EMPave_old.dat file first year is 0 |
---|
131 | eval year_EMPave_old=`awk '{ print $1 }' ${RUN_DIR}/EMPave_old.dat` |
---|
132 | (( PeriodCumulPeriod = ${CumulPeriod} - 1 )) |
---|
133 | (( PeriodInitYear =${InitYear} + ${PeriodCumulPeriod} * ${PeriodLengthInYears} )) |
---|
134 | echo "value year: X${year}" |
---|
135 | echo "value PeriodInitYear: X${PeriodInitYear}" |
---|
136 | # if [ "${CumulPeriod}" -ne 1 ] ; then |
---|
137 | # if [ ${year_m1} = ${year_EMPave_old} ] ; then |
---|
138 | # echo "OK. Date in EMPave_old.dat ${year_EMPave_old} is equal to date in EMPave.dat minus 1 : ${year_m1}" |
---|
139 | # else |
---|
140 | # echo "NOT CORRECT. Date in EMPave_old.dat ${year_EMPave_old} is not equal to date in EMPave.dat minus 1: ${year_m1} exit." |
---|
141 | # exit |
---|
142 | # fi |
---|
143 | # fi |
---|
144 | # END OF TEST |
---|
145 | |
---|
146 | NbFreq=$( echo ${config_OCE_WriteFrequency} | wc -w ) |
---|
147 | ##--Write Frequency Purpose .... |
---|
148 | typeset -Z1 i=1 |
---|
149 | while [ $i -le ${NbFreq} ]; do |
---|
150 | frequency=$( echo ${config_OCE_WriteFrequency} | awk -v var="$i" "-F " '{print $var}' ) |
---|
151 | factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" ) |
---|
152 | |
---|
153 | case ${frequency} in |
---|
154 | *Y|*y) |
---|
155 | eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}y_${DatesPeriod} ; |
---|
156 | eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_Y} ; |
---|
157 | eval WF${i}=${factor}Y ;; |
---|
158 | *M|*m) |
---|
159 | eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}m_${DatesPeriod} ; |
---|
160 | eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_M} ; |
---|
161 | eval WF${i}=${factor}M ;; |
---|
162 | *D|*d) |
---|
163 | eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}d_${DatesPeriod} ; |
---|
164 | eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_D} ; |
---|
165 | eval WF${i}=${factor}D ;; |
---|
166 | *) |
---|
167 | esac |
---|
168 | let i=$i+1 |
---|
169 | |
---|
170 | done |
---|
171 | # Period Length In Days between DateBegin and first day of calendar 0001 01 01 |
---|
172 | # Needed by OPA namelist to compute correct file names |
---|
173 | (( PeriodDaysSinceJC = $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1 )) |
---|
174 | |
---|
175 | ## Count of number of time steps from begin of OPA job |
---|
176 | (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NDT_DAY + 1 )) |
---|
177 | (( OPA_NDT = PeriodLengthInDays * OPA_NDT_DAY )) |
---|
178 | (( OPA_NITEND = OPA_NIT000 + OPA_NDT - 1)) |
---|
179 | |
---|
180 | ## Forcing to write one restart file at the end of period |
---|
181 | OPA_NSTOCK="${OPA_NITEND}" |
---|
182 | |
---|
183 | ## Verification of number of time steps per day |
---|
184 | (( NB_SEC_DAY_MODEL = OPA_NDT_DAY * OPA_RDT )) |
---|
185 | (( NB_SEC_DAY = 60 * 60 * 24 )) |
---|
186 | |
---|
187 | if [ ${NB_SEC_DAY_MODEL} -ne ${NB_SEC_DAY} ] |
---|
188 | then |
---|
189 | echo " NB_SEC_DAY_MODEL "${NB_SEC_DAY_MODEL} "NB_SEC_DAY" ${NB_SEC_DAY} "OPA_NDT_DAY" ${OPA_NDT_DAY} "OPA_RDT" ${OPA_RDT} |
---|
190 | echo " VERIFY OPA_NDT_DAY in opa9.card " |
---|
191 | exit |
---|
192 | fi |
---|
193 | |
---|
194 | ##-- Restart configuration |
---|
195 | if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then |
---|
196 | |
---|
197 | #echo "NO OPA RESTART" |
---|
198 | OPA_LRSTAR=.FALSE. |
---|
199 | OPA_NRSTDT=0 |
---|
200 | #Put OPA_NMSH=0 when OPA runnig in parallel mode |
---|
201 | OPA_NMSH=1 |
---|
202 | ( [ X${BATCH_NUM_PROC_TOT} != X ] && [ "${BATCH_NUM_PROC_TOT}" -gt 1 ] ) && OPA_NMSH=0 |
---|
203 | |
---|
204 | elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then |
---|
205 | |
---|
206 | #echo "OPA RESTART" |
---|
207 | OPA_LRSTAR=.TRUE. |
---|
208 | OPA_NRSTDT=1 |
---|
209 | OPA_NMSH=0 |
---|
210 | |
---|
211 | else |
---|
212 | |
---|
213 | #echo "OPA RESTART" |
---|
214 | OPA_LRSTAR=.TRUE. |
---|
215 | OPA_NRSTDT=2 |
---|
216 | OPA_NMSH=0 |
---|
217 | |
---|
218 | fi |
---|
219 | |
---|
220 | ## nleapy configuration |
---|
221 | case ${config_UserChoices_CalendarType} in |
---|
222 | leap) |
---|
223 | OPA_NLEAPY=1;; |
---|
224 | noleap) |
---|
225 | OPA_NLEAPY=0;; |
---|
226 | 360d) |
---|
227 | OPA_NLEAPY=30;; |
---|
228 | esac |
---|
229 | |
---|
230 | |
---|
231 | typeset -r PRECIS=8 |
---|
232 | NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) |
---|
233 | |
---|
234 | IGCM_comp_modifyNamelist blocker namelist_cfg cn_exp ${config_UserChoices_JobName} |
---|
235 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_it000 ${OPA_NIT000} |
---|
236 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_itend ${OPA_NITEND} |
---|
237 | IGCM_comp_modifyNamelist blocker namelist_cfg ln_rstart ${OPA_LRSTAR} |
---|
238 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_stock ${OPA_NSTOCK} |
---|
239 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_rstctl ${OPA_NRSTDT} |
---|
240 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_date0 ${PeriodDateBegin} |
---|
241 | IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_msh ${OPA_NMSH} |
---|
242 | IGCM_comp_modifyNamelist blocker namelist_cfg nn_leapy ${OPA_NLEAPY} |
---|
243 | |
---|
244 | |
---|
245 | |
---|
246 | |
---|
247 | # update xmlio_server.def |
---|
248 | |
---|
249 | #SF: commented for now, thinking at it for new version wityh xio server, sed in iodef.xml |
---|
250 | # if [ X${opa9_UserChoices_io_server} = Xy ] ; then |
---|
251 | # sed -e "s/${PAT_SERVER}/ using_server = .TRUE./" \ |
---|
252 | # xmlio_server.def > xmlio_server.def.tmp |
---|
253 | # IGCM_sys_Mv xmlio_server.def.tmp xmlio_server.def |
---|
254 | # fi |
---|
255 | |
---|
256 | IGCM_debug_PopStack "OCE_Update" |
---|
257 | } |
---|
258 | |
---|
259 | #----------------------------------- |
---|
260 | function OCE_Finalize |
---|
261 | { |
---|
262 | IGCM_debug_PushStack "OCE_Finalize" |
---|
263 | |
---|
264 | if [ -f date.file ] ; then |
---|
265 | # Prefix use in opa.card AND in lim2.card : |
---|
266 | DATE_OPA=$( cat date.file | \ |
---|
267 | sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" ) |
---|
268 | ###DATE_OPA=$( $DATE_OPABF | cut -c1-30 ) |
---|
269 | MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA} |
---|
270 | SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA} |
---|
271 | fi |
---|
272 | |
---|
273 | echo FINALIZE OCE !!! |
---|
274 | |
---|
275 | IGCM_debug_PopStack "OCE_Finalize" |
---|
276 | } |
---|
277 | |
---|