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

Last change on this file since 2814 was 2814, checked in by cetlod, 8 years ago

Phase NEMO_v6 configuration with new eORCA1 reference for CMIP6

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