source: CONFIG/UNIFORM/v6/IPSLCM6/GENERAL/DRIVER/opa9.driver @ 3835

Last change on this file since 3835 was 3835, checked in by cetlod, 6 years ago

Consolidation of +1=+1 restartablity option : change the date in all mpi NEMO restart file

File size: 11.9 KB
RevLine 
[583]1#!/bin/ksh
2#-----------------------------------------------------------------
3function OCE_Initialize
4{
5    IGCM_debug_PushStack "OCE_Initialize"
6
7    JOB_NAME=${config_UserChoices_JobName}
[2117]8
[2109]9    RESOL_OCE_ICE=$( echo ${RESOL} | awk "-Fx" '{print $1}' )
10    case ${RESOL_OCE_ICE} in
[2540]11        ( *LIM2* ) SEAICE_MODEL=LIM2 ;  LIM_VERSION=2 ;;
12        ( *LIM3* ) SEAICE_MODEL=LIM3 ;  LIM_VERSION=3 ;;
13        ( *CICE* ) SEAICE_MODEL=CICE                  ;;
14        ( *      ) SEAICE_MODEL=UNKNOWN               ;;
[2109]15    esac
16    RESOL_OCE=$( echo ${RESOL_OCE_ICE} | sed "s/${SEAICE_MODEL}//" )
[583]17
[2379]18    IGCM_debug_Print 1 "RESOL          : ${RESOL}"
19    IGCM_debug_Print 1 "RESOL_OCE_ICE  : ${RESOL_OCE_ICE}"
20    IGCM_debug_Print 1 "SEAICE_MODEL   : ${SEAICE_MODEL}"
21    IGCM_debug_Print 1 "LIM_VERSION    : ${LIM_VERSION}"
22    IGCM_debug_Print 1 "RESOL_OCE      : ${RESOL_OCE}"
[2109]23
[653]24    # Local function to find namelists parameters
[2540]25    #supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" ; }
26    supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" -e "s%^ *$1 *=%%" ; }
[583]27    ##--Variables used by OPA --
[2198]28    NAMELIST_OPA_CFG=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg
[2379]29    IGCM_debug_Print 1 "namelist_cfg : ${NAMELIST_OPA_CFG}"
[2198]30    if [ ! -r ${NAMELIST_OPA_CFG} ] ; then
[2540]31        IGCM_debug_Exit "${NAMELIST_OPA_CFG} not found"
32        IGCM_debug_Verif_Exit
[2198]33    fi
[2540]34    OPA_RDT=$(       supergrep rn_rdt        ${NAMELIST_OPA_CFG} )
35    OPA_NN_FSBC=$(   supergrep nn_fsbc       ${NAMELIST_OPA_CFG} )
36    #
37    # OPA_RDT=$(       supergrep rn_rdt        namelist_cfg )
38    # OPA_NN_FSBC=$(   supergrep nn_fsbc       namelist_cfg )
[2861]39    (( OPA_NPDT_DAY   =  86400 / OPA_RDT        ))
40    (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 365     ))
[2540]41    (( OPA_RDT_SBC    =  OPA_RDT * OPA_NN_FSBC ))
[2267]42 
[583]43    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
44    # /!\ Needed by OPA namelist to compute file names /!\
45    (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 ))
46
[2379]47    IGCM_debug_Print 1 " "
[2540]48    IGCM_debug_Print 1 "OPA_RDT        ${OPA_RDT}"
49    IGCM_debug_Print 1 "OPA_NN_FSBC    ${OPA_NN_FSBC}"
50    IGCM_debug_Print 1 "OPA_RDT_SBC    ${OPA_RDT_SBC}"
[2861]51    IGCM_debug_Print 1 "OPA_NPDT_DAY   ${OPA_NPDT_DAY}"
52    IGCM_debug_Print 1 "OPA_NPDT_YEAR  ${OPA_NPDT_YEAR}"
[2540]53    IGCM_debug_Print 1 "DaysSinceJC    ${DaysSinceJC}"
54
55    ## Check that nn_fsbc is correct compare to coupling frequency
56    FreqCoupling=${oasis_UserChoices_FreqCoupling:-86400}
[2267]57   
[2540]58    ## This informations are used for diaptr, trends and diagap files
59    ## only the first frequency is used for this files
60   
61    IGCM_debug_Print 1 "FreqCoupling    ${FreqCoupling}"
62    IGCM_debug_Print 1 "OPA_NN_FSBC    ${OPA_NN_FSBC}"
63    IGCM_debug_Print 1 "OPA_RDT        ${OPA_RDT}"
64    IGCM_debug_Print 1 "OPA_RDT_SBC    ${OPA_RDT_SBC}"
65   
66    if [[ ${OPA_RDT_SBC} -gt ${FreqCoupling} ]] ; then
67        IGCM_debug_Exit "OPA_RDT_SBC=${OPA_RDT_SBC} is greater than FreqCoupling=${FreqCoupling}"
68        IGCM_debug_Verif_Exit
69    fi
[3735]70
[583]71    IGCM_debug_PopStack "OCE_Initialize"
[2379]72   
[583]73}
74
75#-----------------------------------------------------------------
76function OCE_Update
77{
78    IGCM_debug_PushStack "OCE_Update"
[2540]79 
[777]80    ##--Write Frequency for iomput
[3434]81    ## Differents frequencies are allowed for OCE files
[777]82
83    V1D_ENABLE=".FALSE."
[2999]84    V5D_ENABLE=".FALSE."
[777]85    V1M_ENABLE=".FALSE."
86    V1Y_ENABLE=".FALSE."
87
88    for frequency in ${config_OCE_WriteFrequency} ; do
89        case ${frequency} in
[2540]90            ( 1D|1d ) V1D_ENABLE=".TRUE." ;;
[2999]91            ( 5D|5d ) V5D_ENABLE=".TRUE." ;;
[2540]92            ( 1M|1m ) V1M_ENABLE=".TRUE." ;;
93            ( *[yY] ) V1Y_ENABLE=".TRUE." ;;
[777]94        esac
95    done
96
[583]97    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
98    # Needed by OPA namelist to compute correct file names
99    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
100
101    ##-- Number of time steps updated : the first, the last and the number of time steps
[2861]102    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NPDT_DAY + 1 ))
103    (( OPA_NPDT   = PeriodLengthInDays * OPA_NPDT_DAY ))
[2540]104    (( OPA_NITEND = OPA_NIT000 + OPA_NPDT - 1))
[583]105
106    ##-- We force one restart file at the end of the trunk
[2540]107    OPA_NSTOCK="${OPA_NITEND}"
[583]108
[3193]109
110    ##-- Additionnal Restart Option to force reproducibility ; force kt to kt red in restart file
111    ## ${opa9_UserChoices_Reproducibility_after_restart}
112
113    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices Reproducibility_after_restart
114
115   ##-- Restart configuration
[3786]116    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] ) ; then
[3193]117      OPA_LRSTAR=.TRUE.
118      OPA_NRSTDT=2
119      #echo "OPA RESTART"
[3786]120      IGCM_debug_Print 1 'WARNING : dangerous option for NEMO opa9 pisces lim3'
[3193]121      IGCM_debug_Print 1 'Reproducibility_after_Restart forced ie kt forced to kt red in restart file : ' ${opa9_UserChoices_Reproducibility_after_restart}
[3786]122
[3193]123    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
124      OPA_LRSTAR=.FALSE.
125      OPA_NRSTDT=0
126      #echo "NO OPA RESTART"
[583]127    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
[3193]128      OPA_LRSTAR=.TRUE.
129      OPA_NRSTDT=0
130      #echo "OPA RESTART"
[583]131    else
[3193]132      OPA_LRSTAR=.TRUE.
133      OPA_NRSTDT=2
134      #echo "OPA RESTART"
[583]135    fi
136
[3523]137    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${opa9_UserChoices_Restart_TS_only}" = "y" ] ) ; then
[3518]138      OPA_LRSTAR_TS=.TRUE.
139    else
140      OPA_LRSTAR_TS=.FALSE.
141    fi
[3193]142
[3121]143    ##-- Meshmask option. Forced only once.
[902]144    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask
[819]145
[3121]146    OPA_NMSH=0
[819]147    if [ "${opa9_UserChoices_mesh_mask}" = "y" ]; then
[2540]148        OPA_NMSH=1
[902]149        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask "n"
[819]150    fi
151
[583]152    # nleapy configuration
153    case ${config_UserChoices_CalendarType} in
[2540]154        ( leap|gregorian) OPA_NLEAPY=1  ;;
155        ( noleap        ) OPA_NLEAPY=0  ;;
156        ( 360d          ) OPA_NLEAPY=30 ;;
157        ( *             ) OPA_NLEAPY=30 ;;
[583]158    esac
159
[3786]160    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] ) ; then
[3785]161      ##-- choose the right restart file
162      NEMO_RESTART_FILE=restartopa.nc
163      [ -f restartopa_0000.nc ] && NEMO_RESTART_FILE=restartopa_0000.nc
[3775]164      ##-- Getting from restart file the last time step of the run at which we want to re-start
[3785]165      NEMO_KT_FROM_RESTART=$(ncdump -v kt ${NEMO_RESTART_FILE}|grep 'kt ='|awk '{print $3}' )
[3798]166
167      if ( [ "${CumulPeriod}" -eq 1 ] ) ; then
168        ## Force the date in the restart file to be the last day before the begining of the new run
169        (( yearrst = year - 1 ))
170        IGCM_debug_Print 1 "cmd done to modify NEMO restartfile:   ncap2 -s ndastp=${yearrst}1231 ${NEMO_RESTART_FILE}  tmp.nc"
171        ## Take care : 1231 is forced here. Still to be done for monthly run or
172        ## make nrstdt=1 working for all NEMO component. Not done for sea ice yet.
[3835]173        if [ -f restartopa_0000.nc ] ; then
174           typeset -Z4 ncpu=0
175           while [ $ncpu -lt ${OCE_PROC_MPI} ] ; do
176              ncap2 -s "ndastp=${yearrst}1231" restartopa_${ncpu}.nc  tmp.nc
177              mv tmp.nc restartopa_${ncpu}.nc
178              (( ncpu = ncpu + 1 ))
179           done
180        else
181           ncap2 -s "ndastp=${yearrst}1231" ${NEMO_RESTART_FILE}  tmp.nc
182           mv tmp.nc ${NEMO_RESTART_FILE}
183        fi
[3798]184        ##-- Getting from restart file the "new" restart date of run at which we want to re-start
185        NEMO_NDASTP_FROM_RESTART=$(ncdump -v ndastp ${NEMO_RESTART_FILE}|grep 'ndastp ='|awk '{print $3}' )
186        IGCM_debug_Print 1 "NEMO_NDASTP (from Restart) for 1st Period       : ${NEMO_NDASTP_FROM_RESTART}"
187
188        IGCM_date_GetYearMonthDay ${PeriodDateBegin} Verif_repro_year Verif_repro_month Verif_repro_day
189
190        if [ X${Verif_repro_month}${Verif_repro_day} != X"0101" ] ; then
191          IGCM_debug_Exit " PeriodDateBegin = ${PeriodDateBegin}is uncompatible with Reproducibility_after_Restart=y, please start on 0101"
192        fi
193
194      fi
195
[3193]196      (( NEMO_NIT000 = NEMO_KT_FROM_RESTART + 1 ))
197      (( NEMO_NITEND = NEMO_KT_FROM_RESTART + OPA_NITEND - OPA_NIT000 + 1 ))
198      IGCM_debug_Print 1 "NEMO_NIT000 (from Restart)        : ${NEMO_NIT000}"
199      IGCM_debug_Print 1 "NEMO_NITEND (from Restart + ... ) : ${NEMO_NITEND}"
200      ##-- We force one restart file at the end of the trunk
201      OPA_NSTOCK="${NEMO_NITEND}"
202      OPA_NIT000="${NEMO_NIT000}"
203      OPA_NITEND="${NEMO_NITEND}"
204    fi
205
[583]206    typeset -r PRECIS=8
[2540]207    NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
[583]208
[3518]209    IGCM_comp_modifyNamelist blocker    namelist_cfg cn_exp       ${config_UserChoices_JobName}
210    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_it000     ${OPA_NIT000}
211    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_itend     ${OPA_NITEND}
212    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart    ${OPA_LRSTAR}
213    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart_ts ${OPA_LRSTAR_TS}
214    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_stock     ${OPA_NSTOCK}
215    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_rstctl    ${OPA_NRSTDT}
216    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_date0     ${PeriodDateBegin}
217    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_msh       ${OPA_NMSH}
[2625]218    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_rnf_depth_file  ${OPA_NMSH}
[3518]219    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_leapy     ${OPA_NLEAPY}
[2540]220   
221    # Update iodef.xml
[583]222
[2999]223    IGCM_debug_Print 1 'Informations into iodef.xml : V1D_ENABLE V5D_ENABLE V1M_ENABLE V1Y_ENABLE '
224    IGCM_debug_Print 1 ${V1D_ENABLE}  ${V5D_ENABLE} ${V1M_ENABLE} ${V1Y_ENABLE}
[1021]225
[3491]226    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1d_opa enabled ${V1D_ENABLE}
227    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 5d_opa enabled ${V5D_ENABLE}
228    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1m_opa enabled ${V1M_ENABLE}
229    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1y_opa enabled ${V1Y_ENABLE}
[3490]230
[3634]231    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1d_opa output_level ${opa9_UserChoices_OutputLevel}
232    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 5d_opa output_level ${opa9_UserChoices_OutputLevel}
233    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1m_opa output_level ${opa9_UserChoices_OutputLevel}
234    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1y_opa output_level ${opa9_UserChoices_OutputLevel}
235
236
[3748]237    IGCM_comp_modifyXmlFile force context_nemo.xml ref_year NONE ${InitYear} 
[2540]238       
[3434]239 
[3785]240    # for MPP and switch to different number of procs for NEMO.  We need to suppres restartopa the second period, if restartopa_0000 exist
[1436]241    # same thing for restart_trc and restart_ice_in
242
243    for restartfilenemo in restartopa restart_trc restart_ice_in ; do
244      [ -f ${restartfilenemo}.nc ] && [ -f ${restartfilenemo}_0000.nc ] && IGCM_sys_Rm -f ${restartfilenemo}.nc
245    done
246
[2270]247    # Add include of nemo context in iodef.xml
248    # In iodef.xml add on next line after "COMPONENT CONTEXT"
249    #  <context id="nemo" src="./context_nemo.xml"/>
250    echo '<context id="nemo" src="./context_nemo.xml"/>' > add.tmp
[3476]251    if [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] ; then
252        echo '<context id="nemo" src="./ping_nemo.xml"/>' >> add.tmp
253        echo '<context id="nemo" src="./dr2xml_opa9.xml"/>' >> add.tmp
254    fi
[2270]255    cp iodef.xml iodef.xml.tmp
256    sed -e "/COMPONENT CONTEXT/r add.tmp" \
257        iodef.xml.tmp > iodef.xml
258    rm iodef.xml.tmp add.tmp
259
[2833]260    #Long Name as global attribute (if LongName is not empty)
261    if [ ! "X${config_UserChoices_LongName}" = "X" ] ; then
[2876]262        listfile=$(ls file_def_nemo*.xml)
[2833]263        echo "<variable id=\"LongName\" type=\"string\">${config_UserChoices_LongName}</variable>" > add.tmp
264        for file in ${listfile}
265        do
266            cp ${file} ${file}.tmp
267            sed -e "/<file id/r add.tmp" \
268                ${file}.tmp > ${file}
269            rm ${file}.tmp
270        done
271        rm add.tmp
272    fi
273
[583]274    IGCM_debug_PopStack "OCE_Update"
275}
276
277#-----------------------------------
278function OCE_Finalize
279{
280    IGCM_debug_PushStack "OCE_Finalize"
281
[2379]282    IGCM_debug_Print 1 FINALIZE OCE !!!
[583]283
284    IGCM_debug_PopStack "OCE_Finalize"
285}
Note: See TracBrowser for help on using the repository browser.