[1676] | 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 | IGCM_debug_PopStack "MBG_Initialize" |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | #----------------------------------- |
---|
| 70 | function MBG_Update |
---|
| 71 | { |
---|
| 72 | IGCM_debug_PushStack "MBG_Update" |
---|
| 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_NDT_DAY + 1 )) |
---|
| 80 | (( OPA_NDT = PeriodLengthInDays * OPA_NDT_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 | ## Verification of number of time steps per day |
---|
| 87 | (( NB_SEC_DAY_MODEL = OPA_NDT_DAY * OPA_RDT )) |
---|
| 88 | (( NB_SEC_DAY = 60 * 60 * 24 )) |
---|
| 89 | |
---|
| 90 | if [ ${NB_SEC_DAY_MODEL} -ne ${NB_SEC_DAY} ] |
---|
| 91 | then |
---|
| 92 | echo " VERIFY OPA_NDT_DAY in opa9.card " |
---|
| 93 | exit |
---|
| 94 | fi |
---|
| 95 | |
---|
| 96 | ## nleapy configuration |
---|
| 97 | case ${config_UserChoices_CalendarType} in |
---|
| 98 | leap) |
---|
| 99 | OPA_NLEAPY=1;; |
---|
| 100 | noleap) |
---|
| 101 | OPA_NLEAPY=0;; |
---|
| 102 | 360d) |
---|
| 103 | OPA_NLEAPY=30;; |
---|
| 104 | esac |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | typeset -r PRECIS=8 |
---|
| 108 | NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) |
---|
| 109 | |
---|
| 110 | sed -e "s%${PAT_CEXPER}% cexper=\"${config_UserChoices_JobName}\"%" \ |
---|
| 111 | -e "s%${PAT_NIT000}% nit000=${OPA_NIT000}%" \ |
---|
| 112 | -e "s%${PAT_NITEND}% nitend=${OPA_NITEND}%" \ |
---|
| 113 | -e "s%${PAT_NSTOCK}% nstock=${OPA_NSTOCK}%" \ |
---|
| 114 | -e "s%${PAT_NDATE0}% ndate0=${PeriodDateBegin}%" \ |
---|
| 115 | -e "s%${PAT_NLEAPY}% nleapy=${OPA_NLEAPY}%" \ |
---|
| 116 | namelist > namelist.tmp |
---|
| 117 | |
---|
| 118 | IGCM_sys_Mv namelist.tmp namelist |
---|
| 119 | |
---|
| 120 | echo 'Variables automatically updated in namelists' |
---|
| 121 | grep AUTO namelist* |
---|
| 122 | |
---|
| 123 | ##--Write Frequency Purpose .... |
---|
| 124 | topfrequency=$( echo ${config_MBG_WriteFrequency} | awk "-F " '{print $1}' ) |
---|
| 125 | topfactor=$( echo ${topfrequency} | sed -e "s/[yYmMdD]//" ) |
---|
| 126 | case ${topfrequency} in |
---|
| 127 | *Y|*y) |
---|
| 128 | (( TOP_NWRITE = OPA_NDT_DAY * topfactor * $( IGCM_date_DaysInYear ${year} ) )) ; |
---|
| 129 | PREFIX_NWRITETRC=${config_UserChoices_JobName}_${topfactor}y ; |
---|
| 130 | R_OUT_MBG_NWRITE=${R_OUT_MBG_O_Y} ; |
---|
| 131 | WFT1=${topfactor}Y ;; |
---|
| 132 | 1M|1m) |
---|
| 133 | (( TOP_NWRITE = OPA_NDT_DAY * topfactor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ; |
---|
| 134 | PREFIX_NWRITETRC=${config_UserChoices_JobName}_${topfactor}m ; |
---|
| 135 | R_OUT_MBG_NWRITE=${R_OUT_MBG_O_M} ; |
---|
| 136 | WFT1=${topfactor}M ;; |
---|
| 137 | *D|*d) |
---|
| 138 | (( TOP_NWRITE = OPA_NDT_DAY * topfactor )) ; |
---|
| 139 | PREFIX_NWRITETRC=${config_UserChoices_JobName}_${topfactor}d ; |
---|
| 140 | R_OUT_MBG_NWRITE=${R_OUT_MBG_O_D} ; |
---|
| 141 | WFT1=${topfactor}D ;; |
---|
| 142 | *) |
---|
| 143 | esac |
---|
| 144 | |
---|
| 145 | ##-- Restart configuration |
---|
| 146 | if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_MBG_Restart}" = "n" ] ) ; then |
---|
| 147 | |
---|
| 148 | #echo "NO RESTART FOR TOP" |
---|
| 149 | TOP_LRSTTR=.FALSE. |
---|
| 150 | TOP_NRSTTR=0 |
---|
| 151 | |
---|
| 152 | if ( [ "${pisces_UserChoices_OPA_dyn}" = "cpl" ] ) ; then |
---|
| 153 | PISCES_LRIVER=.FALSE. |
---|
| 154 | else |
---|
| 155 | PISCES_LRIVER=.TRUE. |
---|
| 156 | fi |
---|
| 157 | |
---|
| 158 | elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_MBG_Restart}" = "y" ] ) ; then |
---|
| 159 | |
---|
| 160 | #echo "RESTART TOP" |
---|
| 161 | TOP_LRSTTR=.TRUE. |
---|
| 162 | TOP_NRSTTR=0 |
---|
| 163 | |
---|
| 164 | if ( [ "${pisces_UserChoices_OPA_dyn}" = "cpl" ] ) ; then |
---|
| 165 | PISCES_LRIVER=.TRUE. |
---|
| 166 | else |
---|
| 167 | PISCES_LRIVER=.TRUE. |
---|
| 168 | fi |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | else |
---|
| 172 | |
---|
| 173 | #echo "RESTART TOP" |
---|
| 174 | TOP_LRSTTR=.TRUE. |
---|
| 175 | TOP_NRSTTR=2 |
---|
| 176 | |
---|
| 177 | if ( [ "${pisces_UserChoices_OPA_dyn}" = "cpl" ] ) ; then |
---|
| 178 | PISCES_LRIVER=.TRUE. |
---|
| 179 | else |
---|
| 180 | PISCES_LRIVER=.TRUE. |
---|
| 181 | fi |
---|
| 182 | |
---|
| 183 | fi |
---|
| 184 | |
---|
| 185 | sed -e "s%${PAT_TOP_NWRITETRC}% nwritetrc=${TOP_NWRITE}%" \ |
---|
| 186 | -e "s%${PAT_TOP_NWRITETRD}% ntrd_trc=${TOP_NWRITE}%" \ |
---|
| 187 | -e "s%${PAT_TOP_LRSTTR}% ln_rsttr=${TOP_LRSTTR}%" \ |
---|
| 188 | -e "s%${PAT_TOP_NRSTTR}% nrsttr=${TOP_NRSTTR}%" \ |
---|
| 189 | namelist_top > namelist_top.tmp |
---|
| 190 | |
---|
| 191 | IGCM_sys_Mv namelist_top.tmp namelist_top |
---|
| 192 | |
---|
| 193 | # on force les sorties PISCES comme les sorties OPA |
---|
| 194 | |
---|
| 195 | sed -e "s%${PAT_PIS_NWRITEDIA}% nwritedia=${TOP_NWRITE}%" \ |
---|
| 196 | -e "s%${PAT_PIS_LRIVER}% ln_river=${PISCES_LRIVER}%" \ |
---|
| 197 | namelist_pisces > namelist_pisces.tmp |
---|
| 198 | |
---|
| 199 | IGCM_sys_Mv namelist_pisces.tmp namelist_pisces |
---|
| 200 | |
---|
| 201 | echo 'Variables automatically updated in namelists' |
---|
| 202 | grep AUTO namelist* |
---|
| 203 | |
---|
| 204 | IGCM_debug_PopStack "MBG_Update" |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | #----------------------------------- |
---|
| 208 | function MBG_Finalize |
---|
| 209 | { |
---|
| 210 | IGCM_debug_PushStack "MBG_Finalize" |
---|
| 211 | |
---|
| 212 | if [ -f date.file ] ; then |
---|
| 213 | # Prefix use in opa.card AND in lim2.card : |
---|
| 214 | DATE_OPA=$( cat date.file | \ |
---|
| 215 | sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" ) |
---|
| 216 | ###DATE_OPA=$( $DATE_OPABF | cut -c1-30 ) |
---|
| 217 | MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA} |
---|
| 218 | SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA} |
---|
| 219 | fi |
---|
| 220 | |
---|
| 221 | echo FINALIZE MBG !!! |
---|
| 222 | |
---|
| 223 | IGCM_debug_PopStack "MBG_Finalize" |
---|
| 224 | } |
---|
| 225 | |
---|