[1588] | 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 | ##--Variables used for XMLIO_SERVER configuration file |
---|
| 55 | # using_server: .TRUE.(.FALSE.) to use(bypass) the io_server |
---|
| 56 | PAT_SERVER=$( supergrep using_server ${SUBMIT_DIR}/PARAM/xmlio_server.def ) |
---|
| 57 | |
---|
| 58 | IGCM_debug_PopStack "OCE_Initialize" |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | #----------------------------------------------------------------- |
---|
| 62 | function OCE_Update |
---|
| 63 | { |
---|
| 64 | IGCM_debug_PushStack "OCE_Update" |
---|
| 65 | |
---|
| 66 | ## This informations are used for diaptr, trends and diagap files |
---|
| 67 | ## only the first frequency is used for this files |
---|
| 68 | |
---|
| 69 | ##--Write Frequency Purpose .... |
---|
| 70 | frequency=$( echo ${config_OCE_WriteFrequency} | awk "-F " '{print $1}' ) |
---|
| 71 | factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" ) |
---|
| 72 | case ${frequency} in |
---|
| 73 | 1Y|1y) |
---|
| 74 | (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInYear ${year} ) )) ; |
---|
| 75 | PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}y ; |
---|
| 76 | R_OUT_OCE_NWRITE=${R_OUT_OCE_O_Y} ; |
---|
| 77 | WF1=${factor}Y ;; |
---|
| 78 | 1M|1m) |
---|
| 79 | (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ; |
---|
| 80 | PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}m ; |
---|
| 81 | R_OUT_OCE_NWRITE=${R_OUT_OCE_O_M} ; |
---|
| 82 | WF1=${factor}M ;; |
---|
| 83 | *D|*d) |
---|
| 84 | (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor )) ; |
---|
| 85 | PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}d ; |
---|
| 86 | R_OUT_OCE_NWRITE=${R_OUT_OCE_O_D} ; |
---|
| 87 | WF1=${factor}D ;; |
---|
| 88 | *) |
---|
| 89 | (( ORCA_NWRITE = 0 )) ;; |
---|
| 90 | esac |
---|
| 91 | |
---|
| 92 | ##--Write Frequency for iomput |
---|
| 93 | ## Differents frequencies are allowed for grid_[TUVW] and icemod files |
---|
| 94 | |
---|
| 95 | V1D_ENABLE=".FALSE." |
---|
| 96 | V5D_ENABLE=".FALSE." |
---|
| 97 | V1M_ENABLE=".FALSE." |
---|
| 98 | V1Y_ENABLE=".FALSE." |
---|
| 99 | |
---|
| 100 | for frequency in ${config_OCE_WriteFrequency} ; do |
---|
| 101 | case ${frequency} in |
---|
| 102 | 1D|1d) V1D_ENABLE=".TRUE." ;; |
---|
| 103 | esac |
---|
| 104 | case ${frequency} in |
---|
| 105 | 5D|5d) V5D_ENABLE=".TRUE." ;; |
---|
| 106 | esac |
---|
| 107 | case ${frequency} in |
---|
| 108 | 1M|1m) V1M_ENABLE=".TRUE." ;; |
---|
| 109 | esac |
---|
| 110 | case ${frequency} in |
---|
| 111 | *[yY]) V1Y_ENABLE=".TRUE." ;; |
---|
| 112 | esac |
---|
| 113 | done |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | ##-- Output level : 3 for more 1D variables |
---|
| 117 | eval opa9_OUTPUT_LEVEL=\${opa9_UserChoices_OUTPUT_LEVEL} > /dev/null 2>&1 |
---|
| 118 | OUTPUT_LEVEL=${opa9_OUTPUT_LEVEL} |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | # Period Length In Days between DateBegin and first day of calendar 0001 01 01 |
---|
| 122 | # Needed by OPA namelist to compute correct file names |
---|
| 123 | (( PeriodDaysSinceJC = $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1 )) |
---|
| 124 | |
---|
| 125 | ##-- Number of time steps updated : the first, the last and the number of time steps |
---|
| 126 | (( ORCA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * ORCA_NPDT_JOUR + 1 )) |
---|
| 127 | (( ORCA_NPDT = PeriodLengthInDays * ORCA_NPDT_JOUR )) |
---|
| 128 | (( ORCA_NITEND = ORCA_NIT000 + ORCA_NPDT - 1)) |
---|
| 129 | |
---|
| 130 | ##-- We force one restart file at the end of the trunk |
---|
| 131 | ORCA_NSTOCK="${ORCA_NITEND}" |
---|
| 132 | |
---|
| 133 | ##-- Let verify the number of time steps per day |
---|
| 134 | (( NB_SEC_JOUR_MODEL = ORCA_NPDT_JOUR * ORCA_RDT )) |
---|
| 135 | (( NB_SEC_JOUR = 60 * 60 * 24 )) |
---|
| 136 | |
---|
| 137 | if [ ${NB_SEC_JOUR_MODEL} -ne ${NB_SEC_JOUR} ] ; then |
---|
| 138 | echo " VERIFY ORCA_NPDT_JOUR in opa9.card " |
---|
| 139 | exit |
---|
| 140 | fi |
---|
| 141 | |
---|
| 142 | ##-- Restart configuration |
---|
| 143 | if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then |
---|
| 144 | ORCA_LRSTAR=.FALSE. |
---|
| 145 | ORCA_NRSTDT=0 |
---|
| 146 | # Put ORCA_NMSH=0 when OPA running in parallel mode |
---|
| 147 | ORCA_NMSH=1 |
---|
| 148 | #echo "NO OPA RESTART" |
---|
| 149 | elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then |
---|
| 150 | ORCA_LRSTAR=.TRUE. |
---|
| 151 | ORCA_NRSTDT=0 |
---|
| 152 | ORCA_NMSH=1 |
---|
| 153 | #echo "OPA RESTART" |
---|
| 154 | else |
---|
| 155 | ORCA_LRSTAR=.TRUE. |
---|
| 156 | ORCA_NRSTDT=2 |
---|
| 157 | ORCA_NMSH=0 |
---|
| 158 | #echo "OPA RESTART" |
---|
| 159 | fi |
---|
| 160 | |
---|
| 161 | ##-- Meshmask option |
---|
| 162 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask |
---|
| 163 | |
---|
| 164 | if [ "${opa9_UserChoices_mesh_mask}" = "y" ]; then |
---|
| 165 | ORCA_NMSH=1 |
---|
| 166 | IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask "n" |
---|
| 167 | fi |
---|
| 168 | |
---|
| 169 | # nleapy configuration |
---|
| 170 | case ${config_UserChoices_CalendarType} in |
---|
| 171 | leap|gregorian) |
---|
| 172 | ORCA_NLEAPY=1;; |
---|
| 173 | noleap) |
---|
| 174 | ORCA_NLEAPY=0;; |
---|
| 175 | 360d) |
---|
| 176 | ORCA_NLEAPY=30;; |
---|
| 177 | *) |
---|
| 178 | ORCA_NLEAPY=30 |
---|
| 179 | esac |
---|
| 180 | |
---|
| 181 | typeset -r PRECIS=8 |
---|
| 182 | NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${ORCA_NITEND} }" ) ) |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | sed -e "s/${PAT_CEXPER}/ cn_exp=\"${config_UserChoices_JobName}\"/" \ |
---|
| 186 | -e "s/${PAT_NIT000}/ nn_it000=${ORCA_NIT000}/" \ |
---|
| 187 | -e "s/${PAT_NITEND}/ nn_itend=${ORCA_NITEND}/" \ |
---|
| 188 | -e "s/${PAT_NDATE0}/ nn_date0=${PeriodDateBegin}/" \ |
---|
| 189 | -e "s%${PAT_NLEAPY}% nn_leapy=${ORCA_NLEAPY}%" \ |
---|
| 190 | -e "s/${PAT_NSTOCK}/ nn_stock=${ORCA_NSTOCK}/" \ |
---|
| 191 | -e "s/${PAT_NWRITE}/ nn_write=${ORCA_NWRITE}/" \ |
---|
| 192 | -e "s/${PAT_RESTAR}/ ln_rstart=${ORCA_LRSTAR}/" \ |
---|
| 193 | -e "s/${PAT_NRSTAR}/ nn_rstctl=${ORCA_NRSTDT}/" \ |
---|
| 194 | -e "s/${PAT_NMSH}/ nn_msh=${ORCA_NMSH}/" \ |
---|
| 195 | -e "s/${PAT_NPRG}/ nn_prg=${ORCA_NWRITE}/" \ |
---|
| 196 | -e "s/${PAT_NF_PTR}/ nf_ptr_wri=${ORCA_NWRITE}/" \ |
---|
| 197 | namelist > namelist.tmp |
---|
| 198 | |
---|
| 199 | IGCM_sys_Mv namelist.tmp namelist |
---|
| 200 | |
---|
| 201 | echo 'Variables automatically updated in ORCA namelist' |
---|
| 202 | grep AUTO namelist |
---|
| 203 | |
---|
| 204 | # update iodef.xml |
---|
| 205 | |
---|
| 206 | echo 'Informations into iodef.xml : V1D_ENABLE V5D_ENABLE V1M_ENABLE V1Y_ENABLE OUTPUT_LEVEL' |
---|
| 207 | echo ${V1D_ENABLE} ${V5D_ENABLE} ${V1M_ENABLE} ${V1Y_ENABLE} ${OUTPUT_LEVEL} |
---|
| 208 | |
---|
| 209 | sed -e "s/<1D_ENABLE>/${V1D_ENABLE}/" \ |
---|
| 210 | -e "s/<5D_ENABLE>/${V5D_ENABLE}/" \ |
---|
| 211 | -e "s/<1M_ENABLE>/${V1M_ENABLE}/" \ |
---|
| 212 | -e "s/<1Y_ENABLE>/${V1Y_ENABLE}/" \ |
---|
| 213 | -e "s/<OUTPUT_LEVEL>/${OUTPUT_LEVEL}/" \ |
---|
| 214 | iodef.xml > iodef.xml.tmp |
---|
| 215 | |
---|
| 216 | IGCM_sys_Mv iodef.xml.tmp iodef.xml |
---|
| 217 | |
---|
| 218 | # update xmlio_server.def |
---|
| 219 | |
---|
| 220 | if [ X${opa9_UserChoices_io_server} = Xy ] ; then |
---|
| 221 | sed -e "s/${PAT_SERVER}/ using_server = .TRUE./" \ |
---|
| 222 | xmlio_server.def > xmlio_server.def.tmp |
---|
| 223 | IGCM_sys_Mv xmlio_server.def.tmp xmlio_server.def |
---|
| 224 | fi |
---|
| 225 | |
---|
| 226 | # vargas/titane/MPP and switch from 1 proc to 5 procs. We need to suppres restartopa the second month, if restartopa_0000 exist |
---|
| 227 | # same thing for restart_trc and restart_ice_in |
---|
| 228 | |
---|
| 229 | for restartfilenemo in restartopa restart_trc restart_ice_in ; do |
---|
| 230 | [ -f ${restartfilenemo}.nc ] && [ -f ${restartfilenemo}_0000.nc ] && IGCM_sys_Rm -f ${restartfilenemo}.nc |
---|
| 231 | done |
---|
| 232 | |
---|
| 233 | IGCM_debug_PopStack "OCE_Update" |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | #----------------------------------- |
---|
| 237 | function OCE_Finalize |
---|
| 238 | { |
---|
| 239 | IGCM_debug_PushStack "OCE_Finalize" |
---|
| 240 | |
---|
| 241 | if [ -f date.file ] ; then |
---|
| 242 | # Prefix use in opa9.card AND in lim2.card : |
---|
| 243 | DATE_OPA=$( cat date.file | \ |
---|
| 244 | sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" ) |
---|
| 245 | MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA} |
---|
| 246 | SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA} |
---|
| 247 | fi |
---|
| 248 | |
---|
| 249 | echo FINALIZE OCE !!! |
---|
| 250 | |
---|
| 251 | IGCM_debug_PopStack "OCE_Finalize" |
---|
| 252 | } |
---|