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

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

CM6.2 : update MR025 configuration according to latest results within QUEST project

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