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 @ 1600

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

Correct little bug for climatological 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[$i]} = 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            eval NbFilerunsbc=${#opa9_Interannual_List_runsbc[*]}
125            if [ X${opa9_Interannual_List_runsbc[$i]} = X${NULL_STR} ] ; then
126         eval fileo=${opa9_Interannual_List_jobsbc[$i]}
127               eval runsbc_file=${file}.nc
128       else
129         eval fileo=${opa9_Interannual_List_runsbc[$i]}
130               eval runsbc_file=${fileo}.nc
131      fi
132
133            IGCM_sys_Get ${jobsbc_file} ${runsbc_file}
134            (( i = i + 1 ))
135   done
136    fi
137    # End climatological
138
139    NbFreq=$( echo ${config_OCE_WriteFrequency} | wc -w )
140
141    ##--Write Frequency Purpose ....
142    frequency=$( echo ${config_OCE_WriteFrequency} | awk "-F " '{print $1}' )
143    factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" )
144    case ${frequency} in
145   1Y|1y)
146       (( OPA_NWRITE = OPA_NDT_DAY * factor * $( IGCM_date_DaysInYear  ${year} ) ))          ;
147       PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}y ;
148       R_OUT_OCE_NWRITE=${R_OUT_OCE_O_Y} ;
149       R_OUT_ICE_NWRITE=${R_OUT_ICE_O_Y} ;
150       WF1=${factor}Y ;;
151   1M|1m)
152       (( OPA_NWRITE = OPA_NDT_DAY * factor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ;
153       PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}m ;
154       R_OUT_OCE_NWRITE=${R_OUT_OCE_O_M} ;
155       R_OUT_ICE_NWRITE=${R_OUT_ICE_O_M} ;
156       WF1=${factor}M ;;
157   *D|*d)
158       (( OPA_NWRITE = OPA_NDT_DAY * factor  ))  ;
159       PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}d ;
160       R_OUT_OCE_NWRITE=${R_OUT_OCE_O_D} ;
161       R_OUT_ICE_NWRITE=${R_OUT_ICE_O_D} ;
162       WF1=${factor}D ;;
163   *)
164       (( OPA_NWRITE = 0 ))                                                            ;;
165    esac
166
167    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
168    # Needed by OPA namelist to compute correct file names
169    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
170
171    ## Count of number of time steps from begin of OPA job
172    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NDT_DAY + 1 ))
173    (( OPA_NDT   = PeriodLengthInDays * OPA_NDT_DAY ))
174    (( OPA_NITEND = OPA_NIT000 + OPA_NDT - 1))
175
176    ## Forcing to write one restart file at the end of period
177    OPA_NSTOCK="${OPA_NITEND}"
178
179    ## Verification of number of time steps per day
180    (( NB_SEC_DAY_MODEL = OPA_NDT_DAY * OPA_RDT ))
181    (( NB_SEC_DAY = 60 * 60 * 24 ))
182
183    if [ ${NB_SEC_DAY_MODEL} -ne ${NB_SEC_DAY} ]
184   then
185        echo " VERIFY OPA_NDT_DAY in opa9.card "
186        exit
187    fi
188
189    ##-- Restart configuration
190    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
191
192        #echo "NO OPA RESTART"
193   OPA_LRSTAR=.FALSE.
194   OPA_NRSTDT=0
195        #Put OPA_NMSH=0 when OPA runnig in parallel mode
196   OPA_NMSH=1
197   ( [ X${BATCH_NUM_PROC_TOT} != X ] && [ "${BATCH_NUM_PROC_TOT}" -gt 1 ] ) && OPA_NMSH=0
198
199    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
200
201        #echo "OPA RESTART"
202   OPA_LRSTAR=.TRUE.
203   OPA_NRSTDT=1
204   OPA_NMSH=0
205
206    else
207
208        #echo "OPA RESTART"
209   OPA_LRSTAR=.TRUE.
210   OPA_NRSTDT=2
211   OPA_NMSH=0
212
213    fi
214   
215     ## nleapy configuration
216   case ${config_UserChoices_CalendarType} in
217         leap)
218               OPA_NLEAPY=1;;
219         noleap)
220               OPA_NLEAPY=0;;
221         360d)
222               OPA_NLEAPY=30;;
223      esac
224
225
226        typeset -r PRECIS=8
227   NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
228
229    sed -e "s%${PAT_CEXPER}%       cexper=\"${config_UserChoices_JobName}\"%" \
230   -e "s%${PAT_NIT000}%       nit000=${OPA_NIT000}%"                    \
231   -e "s%${PAT_NITEND}%       nitend=${OPA_NITEND}%"                    \
232   -e "s%${PAT_NWRITE}%       nwrite=${OPA_NWRITE}%"                    \
233   -e "s%${PAT_RESTAR}%       ln_rstart=${OPA_LRSTAR}%"                 \
234   -e "s%${PAT_NSTOCK}%       nstock=${OPA_NSTOCK}%"                    \
235   -e "s%${PAT_NRSTAR}%       nrstdt=${OPA_NRSTDT}%"                    \
236   -e "s%${PAT_NDATE0}%       ndate0=${PeriodDateBegin}%"                \
237   -e "s%${PAT_NMSH}%         nmsh=${OPA_NMSH}%"                        \
238   -e "s%${PAT_NLEAPY}%       nleapy=${OPA_NLEAPY}%"                \
239        -e "s%${PAT_NF_PTR}%       nf_ptr_wri=${OPA_NWRITE}%"                \
240   namelist > namelist.tmp
241
242    IGCM_sys_Mv namelist.tmp namelist
243
244    echo 'Variables automatically updated in namelists'
245    grep AUTO namelist*
246
247    IGCM_debug_PopStack "OCE_Update"
248}
249
250#-----------------------------------
251function OCE_Finalize
252{
253    IGCM_debug_PushStack "OCE_Finalize"
254
255    if [ -f date.file ] ; then
256        # Prefix use in opa.card AND in lim2.card :
257   DATE_OPA=$( cat date.file | \
258       sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_\ */\1/g" )
259        ###DATE_OPA=$( $DATE_OPABF | cut -c1-30 )
260   MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA}
261   SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA}
262    fi
263
264    echo FINALIZE OCE !!!
265
266    IGCM_debug_PopStack "OCE_Finalize"
267}
Note: See TracBrowser for help on using the repository browser.