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

Last change on this file since 2198 was 2198, checked in by aclsce, 10 years ago

Modifications to use Oasis-MCT coupler.
Modifications to use namelist*cfg for NEMO components.

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