source: CONFIG/UNIFORM/v6/IPSLCM5A2CHT.2/GENERAL/DRIVER/opa9.driver @ 6035

Last change on this file since 6035 was 6035, checked in by acosce, 2 years ago

in IPSLCM5A2CHT configuration :

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