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

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

Adapt NEMO config for libIGCM v2.7

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