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

Last change on this file since 6238 was 6238, checked in by acosce, 20 months ago

fixed 2 bug in IPSLCM5A2CHT.2 configuration

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