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