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 trunk/CONFIG/ORCA2_LIM/IGCM00/COMP – NEMO

source: trunk/CONFIG/ORCA2_LIM/IGCM00/COMP/opa9.driver @ 1851

Last change on this file since 1851 was 1851, checked in by flavoni, 14 years ago

removed bad sed in opa9.driver, see ticket: #666

File size: 10.3 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 copy year in (year-1)
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}_noy.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 copy year in (year+1)
119         if  [ ! -f ${jobsbc_file_yp1} ] ; then
120             eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year}.nc
121                eval runsbc_file_yp1=${file}_noy.nc
122         else
123             eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_$(( year + 1 )).nc
124             eval runsbc_file_yp1=${file}_y$(( year + 1 )).nc
125         fi
126         IGCM_sys_Get ${jobsbc_file_yp1} ${runsbc_file_yp1}
127          fi
128         
129      fi
130      (( i = i + 1 ))
131   
132       done
133   
134       (( year = year + 1 ))
135   
136       (( i = 0 ))
137   done
138
139    # End interannual
140    elif [ X${opa9_UserChoices_Interannual_Run} = Xn ] ; then
141    # Climatological run
142       typeset file
143
144       eval NbFileInter=${#opa9_Interannual_List_jobsbc[*]}
145
146        (( i = 0 ))
147        while [ $i -lt ${NbFileInter} ] ; do
148            eval file=${opa9_Interannual_List_jobsbc[$i]}
149            eval jobsbc_file=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}.nc
150            eval runsbc_file=${file}.nc
151
152            IGCM_sys_Get ${jobsbc_file} ${runsbc_file}
153            (( i = i + 1 ))
154   done
155    fi
156    # End climatological
157
158    NbFreq=$( echo ${config_OCE_WriteFrequency} | wc -w )
159
160    ##--Write Frequency Purpose ....
161    typeset -Z1 i=1
162    while [ $i -le ${NbFreq} ]; do
163        frequency=$( echo ${config_OCE_WriteFrequency} | awk -v var="$i" "-F " '{print $var}' )
164      factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" )
165      case ${frequency} in
166          *Y|*y)
167              eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}y_${DatesPeriod} ;
168              eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_Y} ;
169              eval WF${i}=${factor}Y ;;
170          *M|*m)
171              eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}m_${DatesPeriod} ;
172              eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_M} ;
173              eval WF${i}=${factor}M ;;
174          *D|*d)
175              eval PREFIX_WF${i}=${config_UserChoices_JobName}_${factor}d_${DatesPeriod} ;
176              eval R_OUT_OCE_WF${i}=${R_OUT_OCE_O_D} ;
177              eval WF${i}=${factor}D ;;
178          *)
179      esac
180        let i=$i+1
181
182    done
183    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
184    # Needed by OPA namelist to compute correct file names
185    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
186
187    ## Count of number of time steps from begin of OPA job
188    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NDT_DAY + 1 ))
189    (( OPA_NDT   = PeriodLengthInDays * OPA_NDT_DAY ))
190    (( OPA_NITEND = OPA_NIT000 + OPA_NDT - 1))
191
192    ## Forcing to write one restart file at the end of period
193    OPA_NSTOCK="${OPA_NITEND}"
194
195    ## Verification of number of time steps per day
196    (( NB_SEC_DAY_MODEL = OPA_NDT_DAY * OPA_RDT ))
197    (( NB_SEC_DAY = 60 * 60 * 24 ))
198
199    if [ ${NB_SEC_DAY_MODEL} -ne ${NB_SEC_DAY} ]
200   then
201        echo " VERIFY OPA_NDT_DAY in opa9.card "
202        exit
203    fi
204
205    ##-- Restart configuration
206    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
207
208        #echo "NO OPA RESTART"
209   OPA_LRSTAR=.FALSE.
210   OPA_NRSTDT=0
211        #Put OPA_NMSH=0 when OPA runnig in parallel mode
212   OPA_NMSH=1
213   ( [ X${BATCH_NUM_PROC_TOT} != X ] && [ "${BATCH_NUM_PROC_TOT}" -gt 1 ] ) && OPA_NMSH=0
214
215    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
216
217        #echo "OPA RESTART"
218   OPA_LRSTAR=.TRUE.
219   OPA_NRSTDT=1
220   OPA_NMSH=0
221
222    else
223
224        #echo "OPA RESTART"
225   OPA_LRSTAR=.TRUE.
226   OPA_NRSTDT=2
227   OPA_NMSH=0
228
229    fi
230   
231     ## nleapy configuration
232   case ${config_UserChoices_CalendarType} in
233         leap)
234               OPA_NLEAPY=1;;
235         noleap)
236               OPA_NLEAPY=0;;
237         360d)
238               OPA_NLEAPY=30;;
239      esac
240
241
242        typeset -r PRECIS=8
243   NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
244
245    sed -e "s%${PAT_CEXPER}%       cn_exp=\"${config_UserChoices_JobName}\"%"  \
246   -e "s%${PAT_NIT000}%       nn_it000=${OPA_NIT000}%"                    \
247   -e "s%${PAT_NITEND}%       nn_itend=${OPA_NITEND}%"                    \
248   -e "s%${PAT_RESTAR}%       ln_rstart=${OPA_LRSTAR}%"                   \
249   -e "s%${PAT_NSTOCK}%       nn_stock=${OPA_NSTOCK}%"                    \
250   -e "s%${PAT_NRSTAR}%       nn_rstctl=${OPA_NRSTDT}%"                   \
251   -e "s%${PAT_NDATE0}%       nn_date0=${PeriodDateBegin}%"               \
252   -e "s%${PAT_NMSH}%         nn_msh=${OPA_NMSH}%"                        \
253   -e "s%${PAT_NLEAPY}%       nn_leapy=${OPA_NLEAPY}%"                  \
254   namelist > namelist.tmp
255
256    IGCM_sys_Mv namelist.tmp namelist
257
258
259    # update iodef.xml
260   
261    iodef.xml > iodef.xml.tmp
262    IGCM_sys_Mv iodef.xml.tmp iodef.xml
263   
264
265    # update xmlio_server.def
266
267    if [ X${opa9_UserChoices_io_server} = Xy ] ; then
268        sed -e "s/${PAT_SERVER}/  using_server = .TRUE./" \
269        xmlio_server.def > xmlio_server.def.tmp
270        IGCM_sys_Mv xmlio_server.def.tmp xmlio_server.def
271    fi
272   
273    IGCM_debug_PopStack "OCE_Update"
274}
275
276#-----------------------------------
277function OCE_Finalize
278{
279    IGCM_debug_PushStack "OCE_Finalize"
280
281    if [ -f date.file ] ; then
282        # Prefix use in opa.card AND in lim2.card :
283   DATE_OPA=$( cat date.file | \
284       sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" )
285        ###DATE_OPA=$( $DATE_OPABF | cut -c1-30 )
286   MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA}
287   SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA}
288    fi
289
290    echo FINALIZE OCE !!!
291
292    IGCM_debug_PopStack "OCE_Finalize"
293}
Note: See TracBrowser for help on using the repository browser.