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

Last change on this file since 2352 was 2270, checked in by aclsce, 7 years ago
  • Treatment of new oasis-MCT output files
  • Ouput of oasis-MCT output files in 2D (instead of 1D)
  • Use of new syntax for XIOS xml configuration file (only for NEMO)
File size: 12.3 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* )
12        SEAICE_MODEL=LIM2
13        LIM_VERSION=2
14        ;;
15
16        ( *LIM3* )
17        SEAICE_MODEL=LIM3
18        LIM_VERSION=3
19        ;;
20        ( *CICE*) SEAICE_MODEL=CICE ;;
21        ( *     ) SEAICE_MODEL=UNKNOWN ;;
22    esac
23    RESOL_OCE=$( echo ${RESOL_OCE_ICE} | sed "s/${SEAICE_MODEL}//" )
24
25    echo "RESOL          : ${RESOL}"
26    echo "RESOL_OCE_ICE  : ${RESOL_OCE_ICE}"
27    echo "SEAICE_MODEL   : ${SEAICE_MODEL}"
28    echo "LIM_VERSION    : ${LIM_VERSION}"
29    echo "RESOL_OCE      : ${RESOL_OCE}"
30
31    # Local function to find namelists parameters
32    supergrep () {
33        grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%"
34    }
35
36    ##--Variables used by OPA --
37
38    # cn_exp    experience name
39    # nn_it000  number of the first time step
40    # nn_itend  number of the last time step
41    # nn_date0  initial calendar date yymmdd (used if  nn_rstctl=1)
42    # nn_leapy  Leap year calendar (1) or not (0), or 360 days calendar (30)
43    # nn_stock  frequency of creation of a restart file (modulo referenced to 1)
44    # nn_write  frequency of write in the output file   (modulo referenced to nn_it000)
45    # ln_rstart start from rest (F) or from a restart file (T)
46    # nn_rstctl restart control = 0 nn_it000 is not compared to the restart file value
47    #                           = 1 use nn_date0 in namelist_cfg (not the value in the restart file)
48    #                           = 2 calendar parameters read in the restart file
49    # nn_msh    =1 create a mesh file (coordinates, scale factors, masks)
50    # rn_rdt    time step in seconds for the dynamics (and tracer if nacc=0)   ==> 5760 (coming from namelist)
51    # nn_prg    time-step frequency of gap print in model output
52    # nn_fwri   frequency of zonal means and transport output
53
54    NAMELIST_OPA_CFG=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg
55    NAMELIST_OPA_REF=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_ref
56    echo "namelist_ref : ${NAMELIST_OPA_REF}"
57    if [ ! -r ${NAMELIST_OPA_REF} ] ; then
58        echo "${NAMELIST_OPA_REF} non trouve"
59    fi
60    echo "namelist_cfg : ${NAMELIST_OPA_CFG}"
61    if [ ! -r ${NAMELIST_OPA_CFG} ] ; then
62        echo "${NAMELIST_OPA_CFG} non trouve"
63    fi
64
65    PAT_CEXPER=$(   supergrep cn_exp      ${NAMELIST_OPA_CFG} )
66    PAT_NIT000=$(   supergrep nn_it000    ${NAMELIST_OPA_CFG} )
67    PAT_NITEND=$(   supergrep nn_itend    ${NAMELIST_OPA_CFG} )
68    PAT_NDATE0=$(   supergrep nn_date0    ${NAMELIST_OPA_CFG} )
69    PAT_NLEAPY=$(   supergrep nn_leapy    ${NAMELIST_OPA_CFG} )
70    PAT_NSTOCK=$(   supergrep nn_stock    ${NAMELIST_OPA_CFG} )
71    PAT_NWRITE=$(   supergrep nn_write    ${NAMELIST_OPA_CFG} )
72    PAT_RESTAR=$(   supergrep ln_rstart   ${NAMELIST_OPA_CFG} )
73    PAT_NRSTAR=$(   supergrep nn_rstctl   ${NAMELIST_OPA_CFG} )
74    PAT_NMSH=$(     supergrep nn_msh      ${NAMELIST_OPA_CFG} )
75    PAT_NN_WRITE=$( supergrep nn_write    ${NAMELIST_OPA_CFG} )
76    PAT_NN_FWRI=$(  supergrep nn_fwri     ${NAMELIST_OPA_CFG} )
77    PAT_ICE_EMBD=$( supergrep nn_ice_embd ${NAMELIST_OPA_CFG} )
78    PAT_ICEFLX=$(   supergrep cn_iceflx   ${NAMELIST_OPA_CFG} )
79    PAT_JPNI=$(     supergrep jpni        ${NAMELIST_OPA_CFG} )
80    PAT_JPNJ=$(     supergrep jpnj        ${NAMELIST_OPA_CFG} )
81    PAT_JPNIJ=$(    supergrep jpnij       ${NAMELIST_OPA_CFG} )
82    PAT_NN_FSBC=$(  supergrep nn_fsbc     ${NAMELIST_OPA_CFG} ) 
83
84    ORCA_RDT=$(       supergrep rn_rdt        ${NAMELIST_OPA_CFG} | sed 's/ *rn_rdt *=//'  | sed 's/\. *//' )
85    ORCA_NN_FSBC=$(   supergrep nn_fsbc       ${NAMELIST_OPA_CFG} | sed 's/ *nn_fsbc *=//' | sed 's/\. *//' )
86    (( ORCA_NPDT_JOUR  = 86400 / ORCA_RDT     ))
87    (( ORCA_NPDT_SBC   = ORCA_NPDT_JOUR / ORCA_NN_FSBC ))
88 
89
90    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
91    # /!\ Needed by OPA namelist to compute file names /!\
92    (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 ))
93
94    echo "PAT_CEXPER   $PAT_CEXPER "
95    echo "PAT_NIT000   $PAT_NIT000"
96    echo "PAT_NITEND   $PAT_NITEND"
97    echo "PAT_NDATE0   $PAT_NDATE0"
98    echo "PAT_NLEAPY   $PAT_NLEAPY"
99    echo "PAT_NSTOCK   $PAT_NSTOCK"
100    echo "PAT_NWRITE   $PAT_NWRITE"
101    echo "PAT_RESTAR   $PAT_RESTAR"
102    echo "PAT_NRSTAR   $PAT_NRSTAR"
103    echo "PAT_NMSH     $PAT_NMSH"
104    echo "PAT_NN_WRITE $PAT_NN_WRITE"
105    echo "PAT_NN_FWRI  $PAT_NN_FWRI"
106    echo "PAT_ICE_EMBD $PAT_ICE_EMBD"
107    echo "PAT_ICEFLX   $PAT_ICEFLX"
108    echo "PAT_JPNI     $PAT_JPNI"
109    echo "PAT_JPNJ     $PAT_JPNJ"
110    echo "PAT_JPNIJ    $PAT_JPNIJ"
111    echo "PAT_NN_FSBC  $PAT_NN_FSBC"
112    echo " "
113    echo "ORCA_RDT     $ORCA_RDT"
114    echo "DaysSinceJC  $DaysSinceJC"
115   
116    IGCM_debug_PopStack "OCE_Initialize"
117
118   
119}
120
121#-----------------------------------------------------------------
122function OCE_Update
123{
124    IGCM_debug_PushStack "OCE_Update"
125
126    ## Check that nn_fsbc is correct compare to coupling frequency
127
128    FreqCoupling=${oasis_UserChoices_FreqCoupling:-86400}
129    if [[ ${FreqCoupling} -gt 0 ]] ; then
130        (( ORCA_NPDT_COUP  = 86400 / FreqCoupling ))
131    else
132        ORCA_NPDT_COUP=${ORCA_NPDT_SBC}
133    fi
134   
135    if [[ ${ORCA_NN_FSBC} -lt ${ORCA_NPDT_COUP} ]] ; then
136        (( ORCA_NN_FSBC = ORCA_NPDT_JOUR / ORCA_NPDT_COUP ))
137    fi
138
139    ## This informations are used for diaptr, trends and diagap files
140    ## only the first frequency is used for this files
141   
142
143    echo "FreqCoupling    $FreqCoupling"
144    echo "ORCA_NN_FSBC    $ORCA_NN_FSBC"
145    echo "ORCA_NPDT_JOUR  $ORCA_NPDT_JOUR"
146    echo "ORCA_NPDT_COUP  $ORCA_NPDT_COUP"
147    echo "ORCA_NPDT_SBC   $ORCA_NPDT_SBC"
148
149    ##--Write Frequency Purpose ....
150    frequency=$( echo ${config_OCE_WriteFrequency} | awk "-F " '{print $1}' )
151    factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" )
152    case ${frequency} in
153        1Y|1y)
154            (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInYear  ${year} ) ))          ;
155            PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}y ;
156            R_OUT_OCE_NWRITE=${R_OUT_OCE_O_Y} ;
157            WF1=${factor}Y ;;
158        1M|1m)
159            (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ;
160            PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}m ;
161            R_OUT_OCE_NWRITE=${R_OUT_OCE_O_M} ;
162            WF1=${factor}M ;;
163        *D|*d)
164            (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor  ))  ;
165            PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}d ;
166            R_OUT_OCE_NWRITE=${R_OUT_OCE_O_D} ;
167            WF1=${factor}D ;;
168        *)
169            (( ORCA_NWRITE = 0 ))                                                            ;;
170    esac
171
172    ##--Write Frequency for iomput
173    ## Differents frequencies are allowed for grid_[TUVW] and icemod files
174
175    V1D_ENABLE=".FALSE."
176    V1M_ENABLE=".FALSE."
177    V1Y_ENABLE=".FALSE."
178
179    for frequency in ${config_OCE_WriteFrequency} ; do
180        case ${frequency} in
181            1D|1d) V1D_ENABLE=".TRUE." ;;
182        esac
183        case ${frequency} in
184            1M|1m) V1M_ENABLE=".TRUE." ;;
185        esac
186        case ${frequency} in
187            *[yY]) V1Y_ENABLE=".TRUE." ;;
188        esac
189    done
190
191
192    ##-- Output level : 3 for more 1D variables
193    eval opa9_OUTPUT_LEVEL=\${opa9_UserChoices_OUTPUT_LEVEL} > /dev/null 2>&1
194    OUTPUT_LEVEL=${opa9_OUTPUT_LEVEL}
195
196
197    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
198    # Needed by OPA namelist to compute correct file names
199    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
200
201    ##-- Number of time steps updated : the first, the last and the number of time steps
202    (( ORCA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * ORCA_NPDT_JOUR + 1 ))
203    (( ORCA_NPDT   = PeriodLengthInDays * ORCA_NPDT_JOUR ))
204    (( ORCA_NITEND = ORCA_NIT000 + ORCA_NPDT - 1))
205
206    ##-- We force one restart file at the end of the trunk
207    ORCA_NSTOCK="${ORCA_NITEND}"
208
209    ##-- Restart configuration
210    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
211        ORCA_LRSTAR=.FALSE.
212        ORCA_NRSTDT=0
213        # Put ORCA_NMSH=0 when OPA running in parallel mode
214        ORCA_NMSH=1
215        #echo "NO OPA RESTART"
216    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
217        ORCA_LRSTAR=.TRUE.
218        ORCA_NRSTDT=0
219        ORCA_NMSH=1
220        #echo "OPA RESTART"
221    else
222        ORCA_LRSTAR=.TRUE.
223        ORCA_NRSTDT=2
224        ORCA_NMSH=0
225        #echo "OPA RESTART"
226    fi
227
228    ##-- Meshmask option
229    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask
230
231    if [ "${opa9_UserChoices_mesh_mask}" = "y" ]; then
232        ORCA_NMSH=1
233        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask "n"
234    fi
235
236    # nleapy configuration
237    case ${config_UserChoices_CalendarType} in
238        leap|gregorian)
239            ORCA_NLEAPY=1;;
240        noleap)
241            ORCA_NLEAPY=0;;
242        360d)
243            ORCA_NLEAPY=30;;
244        *)
245            ORCA_NLEAPY=30
246    esac
247
248    typeset -r PRECIS=8
249    NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${ORCA_NITEND} }" ) ) 
250
251
252    case ${SEAICE_MODEL} in
253        ( LIM2 ) 
254        NN_ICE_EMBD=0
255        ICEFLX=none
256        ;;
257        ( LIM3 ) 
258        NN_ICE_EMBD=1
259        ICEFLX=${opa9_UserChoices_iceflx:-linear}
260        ;;
261    esac
262
263    echo "NUM_PROC_OCE : " ${NUM_PROC_OCE}
264
265    sed -e "s/${PAT_CEXPER}/       cn_exp=\"${config_UserChoices_JobName}\"/"   \
266        -e "s/${PAT_NIT000}/       nn_it000=${ORCA_NIT000}/"                    \
267        -e "s/${PAT_NITEND}/       nn_itend=${ORCA_NITEND}/"                    \
268        -e "s/${PAT_NDATE0}/       nn_date0=${PeriodDateBegin}/"                \
269        -e "s%${PAT_NLEAPY}%       nn_leapy=${ORCA_NLEAPY}%"                    \
270        -e "s/${PAT_NSTOCK}/       nn_stock=${ORCA_NSTOCK}/"                    \
271        -e "s/${PAT_NWRITE}/       nn_write=${ORCA_NWRITE}/"                    \
272        -e "s/${PAT_RESTAR}/       ln_rstart=${ORCA_LRSTAR}/"                   \
273        -e "s/${PAT_NRSTAR}/       nn_rstctl=${ORCA_NRSTDT}/"                   \
274        -e "s/${PAT_NMSH}/         nn_msh=${ORCA_NMSH}/"                        \
275        -e "s/${PAT_NN_WRITE}/     nn_prg=${ORCA_NWRITE}/"                      \
276        -e "s/${PAT_NN_FWRI}/      nn_fwri=${ORCA_NWRITE}/"                     \
277        -e "s/${PAT_NN_FSBC}/      nn_fsbc=${ORCA_NN_FSBC}/"                    \
278        -e "s/${PAT_ICE_EMBD}/     nn_ice_embd=${NN_ICE_EMBD}/"                 \
279        -e "s/${PAT_ICEFLX}/       cn_iceflx=\'${ICEFLX}'/"                     \
280        -e "s/${PAT_JPNI}/         jpni=1/"                                     \
281        -e "s/${PAT_JPNJ}/         jpnj=${NUM_PROC_OCE}/"                       \
282        -e "s/${PAT_JPNIJ}/        jpnij=${NUM_PROC_OCE}/"                      \
283        namelist_cfg > namelist_cfg.tmp
284
285    IGCM_sys_Mv namelist_cfg.tmp namelist_cfg
286
287    echo 'Variables automatically updated in ORCA namelist_cfg'
288    grep AUTO namelist_cfg
289
290    # update iodef.xml
291
292    echo 'Informations into iodef.xml : V1D_ENABLE V1M_ENABLE V1Y_ENABLE OUTPUT_LEVEL'
293    echo ${V1D_ENABLE} ${V1M_ENABLE} ${V1Y_ENABLE} ${OUTPUT_LEVEL}
294
295    sed -e "s/_1D_ENABLE_/${V1D_ENABLE}/" \
296        -e "s/_1M_ENABLE_/${V1M_ENABLE}/" \
297        -e "s/_1Y_ENABLE_/${V1Y_ENABLE}/" \
298        -e "s/_OUTPUT_LEVEL_/${OUTPUT_LEVEL}/" \
299        context_nemo.xml > context_nemo.xml.tmp
300
301    IGCM_sys_Mv context_nemo.xml.tmp context_nemo.xml
302
303    # vargas/titane/MPP and switch from 1 proc to 5 procs. We need to suppres restartopa the second month, if restartopa_0000 exist
304    # same thing for restart_trc and restart_ice_in
305
306    for restartfilenemo in restartopa restart_trc restart_ice_in ; do
307      [ -f ${restartfilenemo}.nc ] && [ -f ${restartfilenemo}_0000.nc ] && IGCM_sys_Rm -f ${restartfilenemo}.nc
308    done
309
310    # Add include of nemo context in iodef.xml
311    # In iodef.xml add on next line after "COMPONENT CONTEXT"
312    #  <context id="nemo" src="./context_nemo.xml"/>
313    echo '<context id="nemo" src="./context_nemo.xml"/>' > add.tmp
314    cp iodef.xml iodef.xml.tmp
315    sed -e "/COMPONENT CONTEXT/r add.tmp" \
316        iodef.xml.tmp > iodef.xml
317    rm iodef.xml.tmp add.tmp
318
319
320    IGCM_debug_PopStack "OCE_Update"
321}
322
323#-----------------------------------
324function OCE_Finalize
325{
326    IGCM_debug_PushStack "OCE_Finalize"
327
328    if [ -f date.file ] ; then
329        # Prefix use in opa9.card AND in lim2.card :
330        DATE_OPA=$( cat date.file | \
331            sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" )
332        MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA}
333        SecondPrefix=${config_UserChoices_JobName}_1m_${DATE_OPA}
334    fi
335
336    echo FINALIZE OCE !!!
337
338    IGCM_debug_PopStack "OCE_Finalize"
339}
Note: See TracBrowser for help on using the repository browser.