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

source: branches/libIGCM/ORCA2_LIM/IGCM00/COMP/opa9.driver @ 1616

Last change on this file since 1616 was 1616, checked in by flavoni, 15 years ago

Fixed a little bug for interannaul run, see ticket : #524

File size: 9.7 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    # cexper experience name for vairmer format
15    # nit000 number of the first time step
16    # nitend number of the last time step
17    # nleapy leap year calendar (0/1) (30 for 360d)
18    # nwrite frequency of OUTPUT file
19    # ln_rstart boolean term for restart (true or false)
20    # nstock frequency of restart file
21    # nrstdt control of the time step (0, 1 or 2)
22    # ndate0 initial calendar date aammjj
23    # nmsh  =1 create a mesh file (coordinates, scale factors, masks)
24    # nwrihf frequency of HF OUTPUT file
25    # rdt time step in seconds (coming from namelist)
26    # nf_ptr_wri frequency of zonal means and transport output
27
28
29# Local function to find namelists parameters
30supergrep () {
31    grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%"
32}
33
34
35    PAT_CEXPER=$( supergrep cexper    ${SUBMIT_DIR}/PARAM/namelist )
36    PAT_NIT000=$( supergrep nit000    ${SUBMIT_DIR}/PARAM/namelist )
37    PAT_NITEND=$( supergrep nitend    ${SUBMIT_DIR}/PARAM/namelist )
38    PAT_NLEAPY=$( supergrep nleapy    ${SUBMIT_DIR}/PARAM/namelist )
39    PAT_NWRITE=$( supergrep nwrite    ${SUBMIT_DIR}/PARAM/namelist )
40    PAT_RESTAR=$( supergrep ln_rstart ${SUBMIT_DIR}/PARAM/namelist )
41    PAT_NSTOCK=$( supergrep nstock    ${SUBMIT_DIR}/PARAM/namelist )
42    PAT_NRSTAR=$( supergrep nrstdt    ${SUBMIT_DIR}/PARAM/namelist )
43    PAT_NDATE0=$( supergrep ndate0    ${SUBMIT_DIR}/PARAM/namelist )
44    PAT_NMSH=$(   supergrep nmsh      ${SUBMIT_DIR}/PARAM/namelist ) 
45    PAT_NF_PTR=$( supergrep nf_ptr_wri ${SUBMIT_DIR}/PARAM/namelist )
46   
47
48    OPA_RDT=$( supergrep rdt  ${SUBMIT_DIR}/PARAM/namelist | sed 's/ *rdt *=//' | sed 's/\. *,//' )
49
50    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
51    # /!\ Needed by OPA namelist to compute file names /!\
52    (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 ))
53
54    # Definition from opa9.card of List_jobsbc and List_runsbc used to do to interannual and climatological runs
55   IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/opa9.card Interannual List_jobsbc
56   IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/COMP/opa9.card Interannual List_runsbc
57        set -A ListFormulationJobsbc -- \${opa9_Interannual_Listjobsc${opa9_Interannual_List_jobsbc}[*]}
58        set -A ListFormulationRunsbc -- \${opa9_Interannual_Listrunsbc${opa9_Interannual_List_runsbc}[*]}
59
60    IGCM_debug_PopStack "OCE_Initialize"
61}
62
63#-----------------------------------------------------------------
64function OCE_Update
65{
66    IGCM_debug_PushStack "OCE_Update"
67
68    # Interannual run
69    # In this case job need to calculate previous and following year and give, and if every run needs to add "_y" before every year
70    if [ X${opa9_UserChoices_Interannual_Run} = Xy ] ; then
71
72   typeset file fileo
73
74        eval NbFileInter=${#opa9_Interannual_List_jobsbc[*]}
75
76   (( i = 0 ))
77   while [ $i -lt ${NbFileInter} ] ; do
78       eval file=${opa9_Interannual_List_jobsbc[$i]}
79       eval jobsbc_file_ym1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_$(( year - 1 )).nc
80       eval jobsbc_file_y=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_${year}.nc
81       eval jobsbc_file_yp1=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}_$(( year + 1 )).nc
82     # Copy of List_jobsbc in List_runsbc if this last one is empty
83            if [ X${opa9_Interannual_List_runsbc[0]} = X${NULL_STR} ] ; then
84         eval fileo=${opa9_Interannual_List_jobsbc[$i]}
85               eval runsbc_file_ym1=${file}_y$(( year - 1 )).nc
86               eval runsbc_file_y=${file}_y${year}.nc
87               eval runsbc_file_yp1=${file}_y$(( year + 1 )).nc
88       else
89         eval fileo=${opa9_Interannual_List_runsbc[$i]}
90               eval runsbc_file_ym1=${fileo}_y$(( year - 1 )).nc
91               eval runsbc_file_y=${fileo}_y${year}.nc
92               eval runsbc_file_yp1=${fileo}_y$(( year + 1 )).nc
93      fi
94
95       if [ X${Period} = X1 ] ; then
96      if [ ${month} -eq 01 ] ; then
97          IGCM_sys_Get ${jobsbc_file_ym1} ${runsbc_file_ym1}
98      fi
99      if [ ! -f ${runsbc_file_y} ] ; then
100          IGCM_sys_Get ${jobsbc_file_y} ${runsbc_file_y}
101      fi
102      if [ ! -f ${runsbc_file_yp1} ] ; then
103          IGCM_sys_Get ${jobsbc_file_yp1} ${runsbc_file_yp1}
104      fi
105       else
106      if [ ! -f ${runsbc_file_yp1} ] ; then
107          IGCM_sys_Get ${jobsbc_file_yp1} ${runsbc_file_yp1}
108      fi
109       fi 
110
111       (( i = i + 1 ))
112   done
113    # End interannual
114    elif [ X${opa9_UserChoices_Interannual_Run} = Xn ] ; then
115    # Climatological run
116       typeset file fileo
117
118       eval NbFileInter=${#opa9_Interannual_List_jobsbc[*]}
119
120        (( i = 0 ))
121        while [ $i -lt ${NbFileInter} ] ; do
122            eval file=${opa9_Interannual_List_jobsbc[$i]}
123            eval jobsbc_file=${R_BC}/OCE/${config_UserChoices_TagName}/${opa9_UserChoices_OPA_version}/${file}.nc
124            if [ X${opa9_Interannual_List_runsbc[0]} = X${NULL_STR} ] ; then
125         eval fileo=${opa9_Interannual_List_jobsbc[$i]}
126               eval runsbc_file=${fileo}.nc
127       else
128         eval fileo=${opa9_Interannual_List_runsbc[$i]}
129               eval runsbc_file=${fileo}.nc
130      fi
131
132            IGCM_sys_Get ${jobsbc_file} ${runsbc_file}
133            (( i = i + 1 ))
134   done
135    fi
136    # End climatological
137
138    NbFreq=$( echo ${config_OCE_WriteFrequency} | wc -w )
139
140    ##--Write Frequency Purpose ....
141    frequency=$( echo ${config_OCE_WriteFrequency} | awk "-F " '{print $1}' )
142    factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" )
143    case ${frequency} in
144   1Y|1y)
145       (( OPA_NWRITE = OPA_NDT_DAY * factor * $( IGCM_date_DaysInYear  ${year} ) ))          ;
146       PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}y ;
147       R_OUT_OCE_NWRITE=${R_OUT_OCE_O_Y} ;
148       R_OUT_ICE_NWRITE=${R_OUT_ICE_O_Y} ;
149       WF1=${factor}Y ;;
150   1M|1m)
151       (( OPA_NWRITE = OPA_NDT_DAY * factor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ;
152       PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}m ;
153       R_OUT_OCE_NWRITE=${R_OUT_OCE_O_M} ;
154       R_OUT_ICE_NWRITE=${R_OUT_ICE_O_M} ;
155       WF1=${factor}M ;;
156   *D|*d)
157       (( OPA_NWRITE = OPA_NDT_DAY * factor  ))  ;
158       PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}d ;
159       R_OUT_OCE_NWRITE=${R_OUT_OCE_O_D} ;
160       R_OUT_ICE_NWRITE=${R_OUT_ICE_O_D} ;
161       WF1=${factor}D ;;
162   *)
163       (( OPA_NWRITE = 0 ))                                                            ;;
164    esac
165
166    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
167    # Needed by OPA namelist to compute correct file names
168    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
169
170    ## Count of number of time steps from begin of OPA job
171    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NDT_DAY + 1 ))
172    (( OPA_NDT   = PeriodLengthInDays * OPA_NDT_DAY ))
173    (( OPA_NITEND = OPA_NIT000 + OPA_NDT - 1))
174
175    ## Forcing to write one restart file at the end of period
176    OPA_NSTOCK="${OPA_NITEND}"
177
178    ## Verification of number of time steps per day
179    (( NB_SEC_DAY_MODEL = OPA_NDT_DAY * OPA_RDT ))
180    (( NB_SEC_DAY = 60 * 60 * 24 ))
181
182    if [ ${NB_SEC_DAY_MODEL} -ne ${NB_SEC_DAY} ]
183   then
184        echo " VERIFY OPA_NDT_DAY in opa9.card "
185        exit
186    fi
187
188    ##-- Restart configuration
189    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
190
191        #echo "NO OPA RESTART"
192   OPA_LRSTAR=.FALSE.
193   OPA_NRSTDT=0
194        #Put OPA_NMSH=0 when OPA runnig in parallel mode
195   OPA_NMSH=1
196   ( [ X${BATCH_NUM_PROC_TOT} != X ] && [ "${BATCH_NUM_PROC_TOT}" -gt 1 ] ) && OPA_NMSH=0
197
198    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
199
200        #echo "OPA RESTART"
201   OPA_LRSTAR=.TRUE.
202   OPA_NRSTDT=1
203   OPA_NMSH=0
204
205    else
206
207        #echo "OPA RESTART"
208   OPA_LRSTAR=.TRUE.
209   OPA_NRSTDT=2
210   OPA_NMSH=0
211
212    fi
213   
214     ## nleapy configuration
215   case ${config_UserChoices_CalendarType} in
216         leap)
217               OPA_NLEAPY=1;;
218         noleap)
219               OPA_NLEAPY=0;;
220         360d)
221               OPA_NLEAPY=30;;
222      esac
223
224
225        typeset -r PRECIS=8
226   NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
227
228    sed -e "s%${PAT_CEXPER}%       cexper=\"${config_UserChoices_JobName}\"%" \
229   -e "s%${PAT_NIT000}%       nit000=${OPA_NIT000}%"                    \
230   -e "s%${PAT_NITEND}%       nitend=${OPA_NITEND}%"                    \
231   -e "s%${PAT_NWRITE}%       nwrite=${OPA_NWRITE}%"                    \
232   -e "s%${PAT_RESTAR}%       ln_rstart=${OPA_LRSTAR}%"                 \
233   -e "s%${PAT_NSTOCK}%       nstock=${OPA_NSTOCK}%"                    \
234   -e "s%${PAT_NRSTAR}%       nrstdt=${OPA_NRSTDT}%"                    \
235   -e "s%${PAT_NDATE0}%       ndate0=${PeriodDateBegin}%"                \
236   -e "s%${PAT_NMSH}%         nmsh=${OPA_NMSH}%"                        \
237   -e "s%${PAT_NLEAPY}%       nleapy=${OPA_NLEAPY}%"                \
238        -e "s%${PAT_NF_PTR}%       nf_ptr_wri=${OPA_NWRITE}%"                \
239   namelist > namelist.tmp
240
241    IGCM_sys_Mv namelist.tmp namelist
242
243    echo 'Variables automatically updated in namelists'
244    grep AUTO namelist*
245
246    IGCM_debug_PopStack "OCE_Update"
247}
248
249#-----------------------------------
250function OCE_Finalize
251{
252    IGCM_debug_PushStack "OCE_Finalize"
253
254    if [ -f date.file ] ; then
255        # Prefix use in opa.card AND in lim2.card :
256   DATE_OPA=$( cat date.file | \
257       sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" )
258        ###DATE_OPA=$( $DATE_OPABF | cut -c1-30 )
259   MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA}
260   SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA}
261    fi
262
263    echo FINALIZE OCE !!!
264
265    IGCM_debug_PopStack "OCE_Finalize"
266}
Note: See TracBrowser for help on using the repository browser.