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

Last change on this file since 5066 was 5066, checked in by cetlod, 4 years ago

First step towards IPSLCM6.5 with the use of NEMOv4 model

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