New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
opa9.driver in branches/UKMO/2015_CO6_CO5_shelfdiagnostic/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/IGCM00/COMP – NEMO

source: branches/UKMO/2015_CO6_CO5_shelfdiagnostic/NEMOGCM/CONFIG/ORCA2_LIM_PISCES/IGCM00/COMP/opa9.driver @ 5422

Last change on this file since 5422 was 5422, checked in by deazer, 9 years ago

Pre removal of svn keywords

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