source: CONFIG/IPSLCM/IPSLCM5/branches/IPSLCM5_v2/EXP00/COMP/opa9.driver @ 819

Last change on this file since 819 was 819, checked in by aclsce, 15 years ago
  • Added the use of mask patch in opa9.card and lim2.card
  • Added the possibility to generate mesh_mask file by activating mesh_mash variable in opa9.card
  • Use of ORCA2.3 configuration


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