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

Last change on this file since 2186 was 2117, checked in by omamce, 11 years ago

O.M.

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