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

Last change on this file since 2663 was 2663, checked in by cetlod, 6 years ago

Minors corrections on NEMO_v6 configurations

File size: 9.9 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/[yYmMdD]//" )
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            *)
165        esac
166        let i=$i+1
167
168    done
169    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
170    # Needed by OPA namelist to compute correct file names
171    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
172
173    ## Count of number of time steps from begin of OPA job
174    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NDT_DAY + 1 ))
175    (( OPA_NDT   = PeriodLengthInDays * OPA_NDT_DAY ))
176    (( OPA_NITEND = OPA_NIT000 + OPA_NDT - 1))
177
178    ## Forcing to write one restart file at the end of period
179    OPA_NSTOCK="${OPA_NITEND}"
180
181    ## Verification of number of time steps per day
182    (( NB_SEC_DAY_MODEL = OPA_NDT_DAY * OPA_RDT ))
183    (( NB_SEC_DAY = 60 * 60 * 24 ))
184
185    if [ ${NB_SEC_DAY_MODEL} -ne ${NB_SEC_DAY} ]
186        then
187        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}
188        echo " VERIFY OPA_NDT_DAY in opa9.card "
189        exit
190    fi
191
192    ##-- Restart configuration
193    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
194
195        #echo "NO OPA RESTART"
196        OPA_LRSTAR=.FALSE.
197        OPA_NRSTDT=0
198        #Put OPA_NMSH=0 when OPA runnig in parallel mode
199        OPA_NMSH=1
200        ( [ X${mpiTasks} != X ] && [ "${mpiTasks}" -gt 1 ] ) && OPA_NMSH=0
201
202    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
203
204        #echo "OPA RESTART"
205        OPA_LRSTAR=.TRUE.
206        OPA_NRSTDT=1
207        OPA_NMSH=0
208
209    else
210
211        #echo "OPA RESTART"
212        OPA_LRSTAR=.TRUE.
213        OPA_NRSTDT=2
214        OPA_NMSH=0
215
216    fi
217   
218     ## nleapy configuration
219        case ${config_UserChoices_CalendarType} in
220                leap)
221                OPA_NLEAPY=1;;
222                noleap)
223                OPA_NLEAPY=0;;
224                360d)
225                OPA_NLEAPY=30;;
226        esac
227
228
229        typeset -r PRECIS=8
230        NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
231
232   IGCM_comp_modifyNamelist blocker    namelist_cfg cn_exp    ${config_UserChoices_JobName}
233   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_it000  ${OPA_NIT000}
234   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_itend  ${OPA_NITEND}
235   IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart ${OPA_LRSTAR}
236   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_stock ${OPA_NSTOCK}
237   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_rstctl ${OPA_NRSTDT}
238   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_date0 ${PeriodDateBegin}
239   IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_msh    ${OPA_NMSH}
240   IGCM_comp_modifyNamelist blocker    namelist_cfg nn_leapy  ${OPA_NLEAPY} 
241
242   # update domain_def.xml file
243   case ${RESOL_OCE} in
244       ( *ORCA2* ) 
245          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
246          IGCM_sys_Mv domain_def.xml.tmp domain_def.xml  ;
247   esac
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 opa.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        ###DATE_OPA=$( $DATE_OPABF | cut -c1-30 )
262        MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA}
263        SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA}
264    fi
265
266    echo FINALIZE OCE !!!
267
268    IGCM_debug_PopStack "OCE_Finalize"
269}
270
Note: See TracBrowser for help on using the repository browser.