IS-ENES/core2_cmip: opa9.driver

File opa9.driver, 10.1 KB (added by flavoni, 10 years ago)
Line 
1#!/bin/ksh
2#-----------------------------------------------------------------
3function OCE_Initialize
4{
5    IGCM_debug_PushStack "OCE_Initialize"
6
7    JOB_NAME=${config_UserChoices_JobName}
8
9    OPA_NDT_DAY=${opa_UserChoices_OPA_NDT_DAY:=15}
10
11
12    ##--Variables used by OPA --
13
14    # cn_exp experience name for vairmer format
15    # nn_it000 number of the first time step
16    # nn_itend number of the last time step
17    # nn_leapy leap year calendar (0/1) (30 for 360d)
18    # nn_write frequency of OUTPUT file
19    # ln_rstart boolean term for restart (true or false)
20    # nn_stock frequency of restart file
21    # nn_rstctl control of the time step (0, 1 or 2)
22    # nn_date0 initial calendar date aammjj
23    # nn_msh  =1 create a mesh file (coordinates, scale factors, masks)
24    # rn_rdt time step in seconds (coming from namelist)
25    # nf_ptr_wri frequency of zonal means and transport output
26
27
28# Local function to find namelists parameters
29supergrep () {
30    grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%"
31}
32
33
34    PAT_CEXPER=$( supergrep cn_exp    ${SUBMIT_DIR}/PARAM/namelist )
35    PAT_NIT000=$( supergrep nn_it000    ${SUBMIT_DIR}/PARAM/namelist )
36    PAT_NITEND=$( supergrep nn_itend    ${SUBMIT_DIR}/PARAM/namelist )
37    PAT_NLEAPY=$( supergrep nn_leapy    ${SUBMIT_DIR}/PARAM/namelist )
38    PAT_RESTAR=$( supergrep ln_rstart ${SUBMIT_DIR}/PARAM/namelist )
39    PAT_NSTOCK=$( supergrep nn_stock    ${SUBMIT_DIR}/PARAM/namelist )
40    PAT_NRSTAR=$( supergrep nn_rstctl    ${SUBMIT_DIR}/PARAM/namelist )
41    PAT_NDATE0=$( supergrep nn_date0    ${SUBMIT_DIR}/PARAM/namelist )
42    PAT_NMSH=$(   supergrep nn_msh      ${SUBMIT_DIR}/PARAM/namelist ) 
43   
44
45    OPA_RDT=$( supergrep rn_rdt  ${SUBMIT_DIR}/PARAM/namelist | sed 's/ *rn_rdt *=//' | sed 's/\. *,//' )
46
47    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
48    # /!\ Needed by OPA namelist to compute file names /!\
49    (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 ))
50
51    # Definition from opa9.card of List_jobsbc and List_runsbc used to do to interannual and climatological runs
52   IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/opa9.card Interannual List_jobsbc
53   IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/opa9.card Interannual List_runsbc
54        set -A ListFormulationJobsbc -- \${opa9_Interannual_Listjobsc${opa9_Interannual_List_jobsbc}[*]}
55        set -A ListFormulationRunsbc -- \${opa9_Interannual_Listrunsbc${opa9_Interannual_List_runsbc}[*]}
56
57    ##--Variables used for XMLIO_SERVER configuration file
58       # using_server: .TRUE.(.FALSE.) to use(bypass) the io_server
59       PAT_SERVER=$( supergrep using_server ${SUBMIT_DIR}/PARAM/xmlio_server.def )
60   
61    IGCM_debug_PopStack "OCE_Initialize"
62}
63
64#-----------------------------------------------------------------
65function OCE_Update
66{
67    IGCM_debug_PushStack "OCE_Update"
68
69    # Interannual run
70    # In this case job need to calculate previous and following year and give, and if every run needs to add "_y" before every year
71    if [ X${opa9_UserChoices_Interannual_Run} = Xy ] ; then
72
73   typeset file fileo
74
75        eval NbFileInter=${#opa9_Interannual_List_jobsbc[*]}
76
77   (( i = 0 ))
78   while [ $i -lt ${NbFileInter} ] ; do
79       eval file=${opa9_Interannual_List_jobsbc[$i]}
80       eval jobsbc_file_ym1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_$(( year - 1 )).nc
81       eval jobsbc_file_y=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year}.nc
82       eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_$(( year + 1 )).nc
83     # Copy of List_jobsbc in List_runsbc if this last one is empty
84            if [ X${opa9_Interannual_List_runsbc[0]} = X${NULL_STR} ] ; then
85         eval fileo=${opa9_Interannual_List_jobsbc[$i]}
86               eval runsbc_file_ym1=${file}_y$(( year - 1 )).nc
87               eval runsbc_file_y=${file}_y${year}.nc
88               eval runsbc_file_yp1=${file}_y$(( year + 1 )).nc
89       else
90         eval fileo=${opa9_Interannual_List_runsbc[$i]}
91               eval runsbc_file_ym1=${fileo}_y$(( year - 1 )).nc
92               eval runsbc_file_y=${fileo}_y${year}.nc
93               eval runsbc_file_yp1=${fileo}_y$(( year + 1 )).nc
94      fi
95
96       if [ X${Period} = X1 ] ; then
97      if [ ${month} -eq 01 ] ; then
98          IGCM_sys_Get ${jobsbc_file_ym1} ${runsbc_file_ym1}
99      fi
100      if [ ! -f ${runsbc_file_y} ] ; then
101          IGCM_sys_Get ${jobsbc_file_y} ${runsbc_file_y}
102      fi
103      if [ ! -f ${runsbc_file_yp1} ] ; then
104          IGCM_sys_Get ${jobsbc_file_yp1} ${runsbc_file_yp1}
105      fi
106       else
107      if [ ! -f ${runsbc_file_yp1} ] ; then
108          IGCM_sys_Get ${jobsbc_file_yp1} ${runsbc_file_yp1}
109      fi
110       fi 
111
112       (( i = i + 1 ))
113   done
114    # End interannual
115    elif [ X${opa9_UserChoices_Interannual_Run} = Xn ] ; then
116    # Climatological run
117       typeset file fileo
118
119       eval NbFileInter=${#opa9_Interannual_List_jobsbc[*]}
120
121        (( i = 0 ))
122        while [ $i -lt ${NbFileInter} ] ; do
123            eval file=${opa9_Interannual_List_jobsbc[$i]}
124            eval jobsbc_file=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}.nc
125            if [ X${opa9_Interannual_List_runsbc[0]} = X${NULL_STR} ] ; then
126         eval fileo=${opa9_Interannual_List_jobsbc[$i]}
127               eval runsbc_file=${fileo}.nc
128       else
129         eval fileo=${opa9_Interannual_List_runsbc[$i]}
130               eval runsbc_file=${fileo}.nc
131      fi
132
133            IGCM_sys_Get ${jobsbc_file} ${runsbc_file}
134            (( i = i + 1 ))
135   done
136    fi
137    # End climatological
138
139    NbFreq=$( echo ${config_OCE_WriteFrequency} | wc -w )
140
141    ##--Write Frequency Purpose ....
142    typeset -Z1 i=1
143    while [ $i -le ${NbFreq} ]; do
144        frequency=$( echo ${config_OCE_WriteFrequency} | awk -v var="$i" "-F " '{print $var}' )
145      factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" )
146      case ${frequency} in
147          *Y|*y)
148              eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}y_${DatesPeriod} ;
149              eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_Y} ;
150              eval WF${i}=${factor}Y ;;
151          *M|*m)
152              eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}m_${DatesPeriod} ;
153              eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_M} ;
154              eval WF${i}=${factor}M ;;
155          *D|*d)
156              eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}d_${DatesPeriod} ;
157              eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_D} ;
158              eval WF${i}=${factor}D ;;
159          *)
160      esac
161        let i=$i+1
162
163    done
164    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
165    # Needed by OPA namelist to compute correct file names
166    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
167
168    ## Count of number of time steps from begin of OPA job
169    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NDT_DAY + 1 ))
170    (( OPA_NDT   = PeriodLengthInDays * OPA_NDT_DAY ))
171    (( OPA_NITEND = OPA_NIT000 + OPA_NDT - 1))
172
173    ## Forcing to write one restart file at the end of period
174    OPA_NSTOCK="${OPA_NITEND}"
175
176    ## Verification of number of time steps per day
177    (( NB_SEC_DAY_MODEL = OPA_NDT_DAY * OPA_RDT ))
178    (( NB_SEC_DAY = 60 * 60 * 24 ))
179
180    if [ ${NB_SEC_DAY_MODEL} -ne ${NB_SEC_DAY} ]
181   then
182        echo " VERIFY OPA_NDT_DAY in opa9.card "
183        exit
184    fi
185
186    ##-- Restart configuration
187    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
188
189        #echo "NO OPA RESTART"
190   OPA_LRSTAR=.FALSE.
191   OPA_NRSTDT=0
192        #Put OPA_NMSH=0 when OPA runnig in parallel mode
193   OPA_NMSH=1
194   ( [ X${BATCH_NUM_PROC_TOT} != X ] && [ "${BATCH_NUM_PROC_TOT}" -gt 1 ] ) && OPA_NMSH=0
195
196    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
197
198        #echo "OPA RESTART"
199   OPA_LRSTAR=.TRUE.
200   OPA_NRSTDT=1
201   OPA_NMSH=0
202
203    else
204
205        #echo "OPA RESTART"
206   OPA_LRSTAR=.TRUE.
207   OPA_NRSTDT=2
208   OPA_NMSH=0
209
210    fi
211   
212     ## nleapy configuration
213   case ${config_UserChoices_CalendarType} in
214         leap)
215               OPA_NLEAPY=1;;
216         noleap)
217               OPA_NLEAPY=0;;
218         360d)
219               OPA_NLEAPY=30;;
220      esac
221
222
223        typeset -r PRECIS=8
224   NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
225
226    sed -e "s%${PAT_CEXPER}%       cn_exp=\"${config_UserChoices_JobName}\"%"  \
227   -e "s%${PAT_NIT000}%       nn_it000=${OPA_NIT000}%"                    \
228   -e "s%${PAT_NITEND}%       nn_itend=${OPA_NITEND}%"                    \
229   -e "s%${PAT_RESTAR}%       ln_rstart=${OPA_LRSTAR}%"                   \
230   -e "s%${PAT_NSTOCK}%       nn_stock=${OPA_NSTOCK}%"                    \
231   -e "s%${PAT_NRSTAR}%       nn_rstctl=${OPA_NRSTDT}%"                   \
232   -e "s%${PAT_NDATE0}%       nn_date0=${PeriodDateBegin}%"               \
233   -e "s%${PAT_NMSH}%         nn_msh=${OPA_NMSH}%"                        \
234   -e "s%${PAT_NLEAPY}%       nn_leapy=${OPA_NLEAPY}%"                  \
235   namelist > namelist.tmp
236
237    IGCM_sys_Mv namelist.tmp namelist
238
239
240    # update iodef.xml
241   
242  if ( [ "${CumulPeriod}" -eq 5 ] || [ "${CumulPeriod}" -eq 10 ] || [ "${CumulPeriod}" -eq 50 ] || [ "${CumulPeriod}" -eq 100 ] || [ "${CumulPeriod}" -eq 150 ] || [ "${CumulPeriod}" -eq 200 ] ) ; then
243
244   sed -e "s/<group\ id=\"1m\"\ output_freq=\"-1\"\ output_level=\"10\"\ enabled=\".FALSE.\">/<group\ id=\"1m\"\ output_freq=\"-1\"\ output_level=\"10\"\ enabled=\".TRUE.\">/" \
245           iodef.xml > iodef.xml.tmp
246       IGCM_sys_Mv iodef.xml.tmp iodef.xml
247  fi 
248   
249
250    # update xmlio_server.def
251
252    if [ X${opa9_UserChoices_io_server} = Xy ] ; then
253        sed -e "s/${PAT_SERVER}/  using_server = .TRUE./" \
254        xmlio_server.def > xmlio_server.def.tmp
255        IGCM_sys_Mv xmlio_server.def.tmp xmlio_server.def
256    fi
257   
258    IGCM_debug_PopStack "OCE_Update"
259}
260
261#-----------------------------------
262function OCE_Finalize
263{
264    IGCM_debug_PushStack "OCE_Finalize"
265
266    if [ -f date.file ] ; then
267        # Prefix use in opa.card AND in lim2.card :
268   DATE_OPA=$( cat date.file | \
269       sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" )
270        ###DATE_OPA=$( $DATE_OPABF | cut -c1-30 )
271   MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA}
272   SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA}
273    fi
274
275    echo FINALIZE OCE !!!
276
277    IGCM_debug_PopStack "OCE_Finalize"
278}