source: CONFIG/UNIFORM/v6/NEMO_v6/GENERAL/DRIVER/opa9.driver @ 2719

Last change on this file since 2719 was 2719, checked in by cetlod, 9 years ago

Update opa driver to take into account high frequency output

File size: 10.1 KB
Line 
1#!/bin/ksh
2#-----------------------------------------------------------------
3function OCE_Initialize
4{
5    IGCM_debug_PushStack "OCE_Initialize"
6
7    RESOL_OCE=$( echo ${config_UserChoices_ExperimentName} | cut -c1-5 )
8    EXPTYPE=$( echo ${config_UserChoices_ExperimentName} | cut -c6- )
9
10# Local function to find namelists parameters
11supergrep () {
12    grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%"
13}
14
15    OPA_RDT=$( supergrep rn_rdt  ${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}${EXPTYPE}_cfg | sed 's/ *rn_rdt *=//' | sed 's/\. *,//' )
16
17    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
18    # /!\ Needed by OPA namelist to compute file names /!\
19    (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 ))
20
21    (( OPA_NDT_DAY  =  86400 / OPA_RDT ))
22
23    # Definition from opa9.card of List_jobsbc and List_runsbc used to do to interannual and climatological runs
24        IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/opa9.card Interannual List_jobsbc
25        set -A ListFormulationJobsbc -- \${opa9_Interannual_Listjobsc${opa9_Interannual_List_jobsbc}[*]}
26
27    IGCM_debug_PopStack "OCE_Initialize"
28}
29
30#-----------------------------------------------------------------
31function OCE_Update
32{
33    IGCM_debug_PushStack "OCE_Update"
34
35    # Interannual run
36    # In this case job need to calculate previous and following year and give, and if every run needs to add "_y" before every year
37    if [ X${opa9_UserChoices_Interannual_Run} = Xy ] ; then
38
39        typeset file
40
41        (( PeriodCumulPeriod =  ${CumulPeriod} - 1 )) 
42        (( PeriodInitYear =${InitYear} + ${PeriodCumulPeriod} * ${PeriodLengthInYears} ))
43        (( PeriodFinalYear =${InitYear} + ${PeriodLengthInYears}*${CumulPeriod} - 1 ))
44
45        NbFileInter=${#opa9_Interannual_List_jobsbc[*]}
46        (( NbFileInter_tot=${#opa9_Interannual_List_jobsbc[*]} * ${PeriodLengthInYears} ))
47        (( i = 0 ))
48
49        while [ ${year} -le ${PeriodFinalYear} ] ; do #copy in ONCE of ALL necessary files for all PeriodLength
50           
51            while [ $i -lt ${NbFileInter} ] ; do
52               
53                eval file=${opa9_Interannual_List_jobsbc[$i]}
54                if [ X${year} = X${PeriodInitYear} ] ; then 
55                                if [ ${month} -eq 01 ] ; then
56                                        # if year-1 does not exist we create a file _noym1.nc copy of year
57                                        eval jobsbc_file_ym1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_m1}.nc
58                                        if  [ ! -f ${jobsbc_file_ym1} ] ; then
59                                                eval jobsbc_file_ym1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year}.nc
60                                                eval runsbc_file_ym1=${file}_noym1.nc
61                                        else
62                                            eval jobsbc_file_ym1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_m1}.nc
63                                            eval runsbc_file_ym1=${file}_y${year_m1}.nc
64                                        fi
65
66                            IGCM_sys_Get ${jobsbc_file_ym1} ${runsbc_file_ym1}
67                                fi
68                fi
69               
70                # download year
71                eval jobsbc_file_y=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year}.nc
72                eval runsbc_file_y=${file}_y${year}.nc
73               
74                if [ ! -f ${runsbc_file_y} ] ; then
75                    IGCM_sys_Get ${jobsbc_file_y} ${runsbc_file_y}
76                fi
77               
78                # download (year+1) if it is last year of run
79                if [ X${year} = X${PeriodFinalYear} ] ; then   
80       
81                    eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_p1}.nc
82                    eval runsbc_file_yp1=${file}_y${year_p1}.nc
83                   
84                    if  [ ! -f ${runsbc_file_yp1} ] ; then
85                       
86                        # if year+1 does not exist we create a file _noyp1.nc copy of year
87                        eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_p1}.nc
88                        if  [ ! -f ${jobsbc_file_yp1} ] ; then
89                            eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year}.nc
90                            eval runsbc_file_yp1=${file}_noyp1.nc
91                        else
92                            eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year_p1}.nc
93                            eval runsbc_file_yp1=${file}_y${year_p1}.nc
94                        fi
95                        IGCM_sys_Get ${jobsbc_file_yp1} ${runsbc_file_yp1}
96                    fi
97                   
98                fi
99                (( i = i + 1 ))
100       
101            done
102       
103            (( year = year + 1 ))
104         
105            (( i = 0 ))
106        done
107
108    # End interannual
109    elif [ X${opa9_UserChoices_Interannual_Run} = Xn ] ; then
110    # Climatological run
111       typeset file
112
113       eval NbFileInter=${#opa9_Interannual_List_jobsbc[*]}
114
115        (( i = 0 ))
116        while [ $i -lt ${NbFileInter} ] ; do
117            eval file=${opa9_Interannual_List_jobsbc[$i]}
118            eval jobsbc_file=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}.nc
119            eval runsbc_file=${file}.nc
120
121            IGCM_sys_Get ${jobsbc_file} ${runsbc_file}
122            (( i = i + 1 ))
123        done
124    fi
125    # End climatological
126   
127    # TEST year for EMPave_old.dat file
128    # Needed if in namelist fwb=2 after firts year, because in EMPave_old.dat file first year is 0
129#    eval year_EMPave_old=`awk '{ print $1 }' ${RUN_DIR}/EMPave_old.dat`
130#    (( PeriodCumulPeriod =  ${CumulPeriod} - 1 ))
131#    (( PeriodInitYear =${InitYear} + ${PeriodCumulPeriod} * ${PeriodLengthInYears} ))
132#    echo "value year: X${year}"
133#    echo "value PeriodInitYear: X${PeriodInitYear}"
134#    if [ "${CumulPeriod}" -ne 1 ] ; then
135#       if [ ${year_m1} = ${year_EMPave_old} ] ; then
136#               echo "OK. Date in EMPave_old.dat ${year_EMPave_old} is equal to date in EMPave.dat minus 1 : ${year_m1}"
137#       else
138#               echo "NOT CORRECT. Date in EMPave_old.dat ${year_EMPave_old} is not equal to date in EMPave.dat minus 1: ${year_m1} exit."
139#               exit
140#       fi
141#   fi
142    # END OF TEST
143
144    NbFreq=$( echo ${config_OCE_WriteFrequency} | wc -w )
145    ##--Write Frequency Purpose ....
146    typeset -Z1 i=1
147    while [ $i -le ${NbFreq} ]; do
148        frequency=$( echo ${config_OCE_WriteFrequency} | awk -v var="$i" "-F " '{print $var}' )
149        factor=$( echo ${frequency} | sed -e "s/[yYmMdDhH]//" )
150
151        case ${frequency} in
152            *Y|*y)
153                eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}y_${DatesPeriod} ;
154                eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_Y} ;
155                eval WF${i}=${factor}Y ;;
156            *M|*m)
157                eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}m_${DatesPeriod} ;
158                eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_M} ;
159                eval WF${i}=${factor}M ;;
160            *D|*d)
161                eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}d_${DatesPeriod} ;
162                eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_D} ;
163                eval WF${i}=${factor}D ;;
164            *H|*h)
165                eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}h_${DatesPeriod} ;
166                eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_H} ;
167                eval WF${i}=${factor}H ;;
168            *)
169        esac
170        let i=$i+1
171
172    done
173    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
174    # Needed by OPA namelist to compute correct file names
175    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
176
177    ## Count of number of time steps from begin of OPA job
178    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NDT_DAY + 1 ))
179    (( OPA_NDT   = PeriodLengthInDays * OPA_NDT_DAY ))
180    (( OPA_NITEND = OPA_NIT000 + OPA_NDT - 1))
181
182    ## Forcing to write one restart file at the end of period
183    OPA_NSTOCK="${OPA_NITEND}"
184
185    ## Verification of number of time steps per day
186    (( NB_SEC_DAY_MODEL = OPA_NDT_DAY * OPA_RDT ))
187    (( NB_SEC_DAY = 60 * 60 * 24 ))
188
189    if [ ${NB_SEC_DAY_MODEL} -ne ${NB_SEC_DAY} ]
190        then
191        echo " NB_SEC_DAY_MODEL "${NB_SEC_DAY_MODEL} "NB_SEC_DAY" ${NB_SEC_DAY} "OPA_NDT_DAY" ${OPA_NDT_DAY} "OPA_RDT" ${OPA_RDT}
192        echo " VERIFY OPA_NDT_DAY in opa9.card "
193        exit
194    fi
195
196    ##-- Restart configuration
197    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
198
199        #echo "NO OPA RESTART"
200        OPA_LRSTAR=.FALSE.
201        OPA_NRSTDT=0
202        #Put OPA_NMSH=0 when OPA runnig in parallel mode
203        OPA_NMSH=1
204        ( [ X${mpiTasks} != X ] && [ "${mpiTasks}" -gt 1 ] ) && OPA_NMSH=0
205
206    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
207
208        #echo "OPA RESTART"
209        OPA_LRSTAR=.TRUE.
210        OPA_NRSTDT=0
211        OPA_NMSH=0
212
213    else
214
215        #echo "OPA RESTART"
216        OPA_LRSTAR=.TRUE.
217        OPA_NRSTDT=2
218        OPA_NMSH=0
219
220    fi
221   
222     ## nleapy configuration
223        case ${config_UserChoices_CalendarType} in
224                leap)
225                OPA_NLEAPY=1;;
226                noleap)
227                OPA_NLEAPY=0;;
228                360d)
229                OPA_NLEAPY=30;;
230        esac
231
232
233        typeset -r PRECIS=8
234        NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
235
236   IGCM_comp_modifyNamelist blocker    namelist_cfg cn_exp    ${config_UserChoices_JobName}
237   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_it000  ${OPA_NIT000}
238   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_itend  ${OPA_NITEND}
239   IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart ${OPA_LRSTAR}
240   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_stock ${OPA_NSTOCK}
241   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_rstctl ${OPA_NRSTDT}
242   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_date0 ${PeriodDateBegin}
243   IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_msh    ${OPA_NMSH}
244   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_leapy  ${OPA_NLEAPY} 
245
246   # update domain_def.xml file
247   case ${RESOL_OCE} in
248       ( *ORCA2* ) 
249          sed -e 's/<domain id="1point" zoom_ibegin="150" zoom_jbegin="150"/<domain id="1point" zoom_ibegin="10" zoom_jbegin="10"/' domain_def.xml > domain_def.xml.tmp
250          IGCM_sys_Mv domain_def.xml.tmp domain_def.xml  ;
251   esac
252
253    IGCM_debug_PopStack "OCE_Update"
254}
255
256#-----------------------------------
257function OCE_Finalize
258{
259    IGCM_debug_PushStack "OCE_Finalize"
260
261    if [ -f date.file ] ; then
262        # Prefix use in opa.card AND in lim2.card :
263        DATE_OPA=$( cat date.file | \
264            sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" )
265        ###DATE_OPA=$( $DATE_OPABF | cut -c1-30 )
266        MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA}
267        SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA}
268    fi
269
270    echo FINALIZE OCE !!!
271
272    IGCM_debug_PopStack "OCE_Finalize"
273}
274
Note: See TracBrowser for help on using the repository browser.