1 | #!/bin/ksh |
---|
2 | #----------------------------------------------------------------- |
---|
3 | function OCE_Initialize |
---|
4 | { |
---|
5 | IGCM_debug_PushStack "OCE_Initialize" |
---|
6 | |
---|
7 | JOB_NAME=${config_UserChoices_JobName} |
---|
8 | RESOL_OCE=$( echo $RESOL | awk "-Fx" '{print $1}' ) |
---|
9 | |
---|
10 | ORCA_NPDT_JOUR=${opa9_UserChoices_OPA_NPDT_JOURS:=15} |
---|
11 | |
---|
12 | # Local function to find namelists parameters |
---|
13 | supergrep () { |
---|
14 | grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" |
---|
15 | } |
---|
16 | |
---|
17 | ##--Variables used by OPA -- |
---|
18 | |
---|
19 | # cn_exp experience name |
---|
20 | # nn_it000 number of the first time step |
---|
21 | # nn_itend number of the last time step |
---|
22 | # nn_date0 initial calendar date yymmdd (used if nn_rstctl=1) |
---|
23 | # nn_leapy Leap year calendar (1) or not (0), or 360 days calendar (30) |
---|
24 | # nn_stock frequency of creation of a restart file (modulo referenced to 1) |
---|
25 | # nn_write frequency of write in the output file (modulo referenced to nn_it000) |
---|
26 | # ln_rstart start from rest (F) or from a restart file (T) |
---|
27 | # nn_rstctl restart control = 0 nn_it000 is not compared to the restart file value |
---|
28 | # = 1 use nn_date0 in namelist (not the value in the restart file) |
---|
29 | # = 2 calendar parameters read in the restart file |
---|
30 | # nn_msh =1 create a mesh file (coordinates, scale factors, masks) |
---|
31 | # rn_rdt time step in seconds for the dynamics (and tracer if nacc=0) ==> 5760 (coming from namelist) |
---|
32 | # nn_prg time-step frequency of gap print in model output |
---|
33 | # nf_ptr_wri frequency of zonal means and transport output |
---|
34 | |
---|
35 | PAT_CEXPER=$( supergrep cn_exp ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
36 | PAT_NIT000=$( supergrep nn_it000 ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
37 | PAT_NITEND=$( supergrep nn_itend ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
38 | PAT_NDATE0=$( supergrep nn_date0 ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
39 | PAT_NLEAPY=$( supergrep nn_leapy ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
40 | PAT_NSTOCK=$( supergrep nn_stock ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
41 | PAT_NWRITE=$( supergrep nn_write ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
42 | PAT_RESTAR=$( supergrep ln_rstart ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
43 | PAT_NRSTAR=$( supergrep nn_rstctl ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
44 | PAT_NMSH=$( supergrep nn_msh ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
45 | PAT_PRG=$( supergrep nn_prg ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
46 | PAT_NF_PTR=$( supergrep nf_ptr_wri ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} ) |
---|
47 | |
---|
48 | ORCA_RDT=$( supergrep rn_rdt ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE} | sed 's/ *rn_rdt *=//' | sed 's/\. *//' ) |
---|
49 | |
---|
50 | # Period Length In Days between DateBegin and first day of calendar 0001 01 01 |
---|
51 | # /!\ Needed by OPA namelist to compute file names /!\ |
---|
52 | (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 )) |
---|
53 | |
---|
54 | IGCM_debug_PopStack "OCE_Initialize" |
---|
55 | } |
---|
56 | |
---|
57 | #----------------------------------------------------------------- |
---|
58 | function OCE_Update |
---|
59 | { |
---|
60 | IGCM_debug_PushStack "OCE_Update" |
---|
61 | |
---|
62 | NbFreq=$( echo ${config_OCE_WriteFrequency} | wc -w ) |
---|
63 | |
---|
64 | ##--Write Frequency Purpose .... |
---|
65 | frequency=$( echo ${config_OCE_WriteFrequency} | awk "-F " '{print $1}' ) |
---|
66 | factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" ) |
---|
67 | case ${frequency} in |
---|
68 | 1Y|1y) |
---|
69 | (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInYear ${year} ) )) ; |
---|
70 | PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}y ; |
---|
71 | R_OUT_OCE_NWRITE=${R_OUT_OCE_O_Y} ; |
---|
72 | R_OUT_ICE_NWRITE=${R_OUT_ICE_O_Y} ; |
---|
73 | WF1=${factor}Y ;; |
---|
74 | 1M|1m) |
---|
75 | (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ; |
---|
76 | PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}m ; |
---|
77 | R_OUT_OCE_NWRITE=${R_OUT_OCE_O_M} ; |
---|
78 | R_OUT_ICE_NWRITE=${R_OUT_ICE_O_M} ; |
---|
79 | WF1=${factor}M ;; |
---|
80 | *D|*d) |
---|
81 | (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor )) ; |
---|
82 | PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}d ; |
---|
83 | R_OUT_OCE_NWRITE=${R_OUT_OCE_O_D} ; |
---|
84 | R_OUT_ICE_NWRITE=${R_OUT_ICE_O_D} ; |
---|
85 | WF1=${factor}D ;; |
---|
86 | *) |
---|
87 | (( ORCA_NWRITE = 0 )) ;; |
---|
88 | esac |
---|
89 | |
---|
90 | ##--Write Frequency Purpose .... concerning the second opa file type. |
---|
91 | if [ ${NbFreq} -eq 2 ] ; then |
---|
92 | frequency=$( echo ${config_OCE_WriteFrequency} | awk "-F " '{print $2}' ) |
---|
93 | factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" ) |
---|
94 | case ${frequency} in |
---|
95 | *Y|*y) |
---|
96 | (( ORCA_NWRIHF = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInYear ${year} ) )) ; |
---|
97 | PREFIX_NWRIHF=${config_UserChoices_JobName}_${factor}y ; |
---|
98 | R_OUT_OCE_NWRIHF=${R_OUT_OCE_O_Y} ; |
---|
99 | WF2=${factor}Y ;; |
---|
100 | *M|*m) |
---|
101 | (( ORCA_NWRIHF = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ; |
---|
102 | PREFIX_NWRIHF=${config_UserChoices_JobName}_${factor}m ; |
---|
103 | R_OUT_OCE_NWRIHF=${R_OUT_OCE_O_M} ; |
---|
104 | WF2=${factor}M ;; |
---|
105 | *D|*d) |
---|
106 | (( ORCA_NWRIHF = ORCA_NPDT_JOUR * factor )) ; |
---|
107 | PREFIX_NWRIHF=${config_UserChoices_JobName}_${factor}d ; |
---|
108 | R_OUT_OCE_NWRIHF=${R_OUT_OCE_O_D} ; |
---|
109 | WF2=${factor}D ;; |
---|
110 | *) |
---|
111 | (( ORCA_NWRIHF = 0 )) ;; |
---|
112 | esac |
---|
113 | else |
---|
114 | ORCA_NWRIHF=0 |
---|
115 | fi |
---|
116 | |
---|
117 | # Period Length In Days between DateBegin and first day of calendar 0001 01 01 |
---|
118 | # Needed by OPA namelist to compute correct file names |
---|
119 | (( PeriodDaysSinceJC = $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1 )) |
---|
120 | |
---|
121 | ##-- Number of time steps updated : the first, the last and the number of time steps |
---|
122 | (( ORCA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * ORCA_NPDT_JOUR + 1 )) |
---|
123 | (( ORCA_NPDT = PeriodLengthInDays * ORCA_NPDT_JOUR )) |
---|
124 | (( ORCA_NITEND = ORCA_NIT000 + ORCA_NPDT - 1)) |
---|
125 | |
---|
126 | ##-- We force one restart file at the end of the trunk |
---|
127 | ORCA_NSTOCK="${ORCA_NITEND}" |
---|
128 | |
---|
129 | ##-- Let verify the number of time steps per day |
---|
130 | (( NB_SEC_JOUR_MODEL = ORCA_NPDT_JOUR * ORCA_RDT )) |
---|
131 | (( NB_SEC_JOUR = 60 * 60 * 24 )) |
---|
132 | |
---|
133 | if [ ${NB_SEC_JOUR_MODEL} -ne ${NB_SEC_JOUR} ] ; then |
---|
134 | echo " VERIFY ORCA_NPDT_JOUR in opa9.card " |
---|
135 | exit |
---|
136 | fi |
---|
137 | |
---|
138 | ##-- Restart configuration |
---|
139 | if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then |
---|
140 | ORCA_LRSTAR=.FALSE. |
---|
141 | ORCA_NRSTDT=0 |
---|
142 | # Put ORCA_NMSH=0 when OPA running in parallel mode |
---|
143 | ORCA_NMSH=1 |
---|
144 | #echo "NO OPA RESTART" |
---|
145 | elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then |
---|
146 | ORCA_LRSTAR=.TRUE. |
---|
147 | ORCA_NRSTDT=0 |
---|
148 | ORCA_NMSH=0 |
---|
149 | #echo "OPA RESTART" |
---|
150 | else |
---|
151 | ORCA_LRSTAR=.TRUE. |
---|
152 | ORCA_NRSTDT=2 |
---|
153 | ORCA_NMSH=0 |
---|
154 | #echo "OPA RESTART" |
---|
155 | fi |
---|
156 | |
---|
157 | # nleapy configuration |
---|
158 | case ${config_UserChoices_CalendarType} in |
---|
159 | leap|gregorian) |
---|
160 | ORCA_NLEAPY=1;; |
---|
161 | noleap) |
---|
162 | ORCA_NLEAPY=0;; |
---|
163 | 360d) |
---|
164 | ORCA_NLEAPY=30;; |
---|
165 | *) |
---|
166 | ORCA_NLEAPY=30 |
---|
167 | esac |
---|
168 | |
---|
169 | typeset -r PRECIS=8 |
---|
170 | NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${ORCA_NITEND} }" ) ) |
---|
171 | |
---|
172 | |
---|
173 | sed -e "s/${PAT_CEXPER}/ cn_exp=\"${config_UserChoices_JobName}\"/" \ |
---|
174 | -e "s/${PAT_NIT000}/ nn_it000=${ORCA_NIT000}/" \ |
---|
175 | -e "s/${PAT_NITEND}/ nn_itend=${ORCA_NITEND}/" \ |
---|
176 | -e "s/${PAT_NDATE0}/ nn_date0=${PeriodDateBegin}/" \ |
---|
177 | -e "s%${PAT_NLEAPY}% nn_leapy=${ORCA_NLEAPY}%" \ |
---|
178 | -e "s/${PAT_NSTOCK}/ nn_stock=${ORCA_NSTOCK}/" \ |
---|
179 | -e "s/${PAT_NWRITE}/ nn_write=${ORCA_NWRITE}/" \ |
---|
180 | -e "s/${PAT_RESTAR}/ ln_rstart=${ORCA_LRSTAR}/" \ |
---|
181 | -e "s/${PAT_NRSTAR}/ nn_rstctl=${ORCA_NRSTDT}/" \ |
---|
182 | -e "s/${PAT_NMSH}/ nn_msh=${ORCA_NMSH}/" \ |
---|
183 | -e "s/${PAT_NPRG}/ nn_prg=${ORCA_NWRITE}/" \ |
---|
184 | -e "s/${PAT_NF_PTR}/ nf_ptr_wri=${ORCA_NWRITE}/" \ |
---|
185 | namelist > namelist.tmp |
---|
186 | |
---|
187 | IGCM_sys_Mv namelist.tmp namelist |
---|
188 | |
---|
189 | echo 'Variables automatically updated in ORCA namelist' |
---|
190 | grep AUTO namelist |
---|
191 | |
---|
192 | IGCM_debug_PopStack "OCE_Update" |
---|
193 | } |
---|
194 | |
---|
195 | #----------------------------------- |
---|
196 | function OCE_Finalize |
---|
197 | { |
---|
198 | IGCM_debug_PushStack "OCE_Finalize" |
---|
199 | |
---|
200 | if [ -f date.file ] ; then |
---|
201 | # Prefix use in opa9.card AND in lim2.card : |
---|
202 | DATE_OPA=$( cat date.file | \ |
---|
203 | sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" ) |
---|
204 | MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA} |
---|
205 | SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA} |
---|
206 | fi |
---|
207 | |
---|
208 | echo FINALIZE OCE !!! |
---|
209 | |
---|
210 | IGCM_debug_PopStack "OCE_Finalize" |
---|
211 | } |
---|