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

Last change on this file since 2109 was 2109, checked in by omamce, 9 years ago

O.M. : detection of sea ice model use.

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