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.
gyre.driver in branches/libIGCM/GYRE_LOBSTER/IGCM00/COMP – NEMO

source: branches/libIGCM/GYRE_LOBSTER/IGCM00/COMP/gyre.driver @ 1343

Last change on this file since 1343 was 1343, checked in by cetlod, 15 years ago

suppression of blank spaces when using supergrep command in gyre.driver, see ticket:376

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    ORCA_NPDT_JOUR=${gyre_UserChoices_GYRE_NPDT_JOURS:=12}
10
11    # Attention : ORCA_RDT must be an integer
12    (( ORCA_RDT = 60 * 60 * 24 / ${ORCA_NPDT_JOUR} ))
13
14    ##--Variables used by OPA --
15
16    # cexper experience name
17    # ln_rstart boolean term for restart (true or false)
18    # nrstdt control of the time step (0, 1 or 2)
19    # nit000 number of the first time step
20    # nitend number of the last time step
21    # ndate0 initial calendar date aammjj (used if nrstdt=1)
22    # nleapy Leap year calendar (1) or not (0), or 360 days calendar (30)
23    # nstock frequency of creation of a restart file
24    # nwrite frequency of write in the output file
25    # nmsh  =1 create a mesh file (coordinates, scale factors, masks) not in parallel
26    # rdt time step in seconds (coming from gyre.card)
27    # ntrd time step frequency of write in the trends file for dynamics
28    # ln_trdmld_restart boolean term for trends restart (true or false)
29
30    ##--Variables used by TOP --
31
32    # nwritetrc frequency of write in the tracer output file
33    # lrsttr   boolean term for tracer model restart (true or false)
34    # nrsttr control of the time step (0, 1 or 2)
35    # ntrd_trc time step frequency of write in the trends file for tracers
36    # ln_trdmld_trc_restart boolean term for trc trends restart (true or false)
37
38    ##--Variables used by LOBSTER --
39
40    # nwritedia frequency of write in the additional diag output file
41
42# Local function to find namelists parameters
43supergrep () {
44    grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%"
45}
46
47
48    PAT_CEXPER=$( supergrep cexper    ${SUBMIT_DIR}/PARAM/namelist )
49    PAT_NIT000=$( supergrep nit000    ${SUBMIT_DIR}/PARAM/namelist )
50    PAT_NITEND=$( supergrep nitend    ${SUBMIT_DIR}/PARAM/namelist )
51    PAT_NWRITE=$( supergrep nwrite    ${SUBMIT_DIR}/PARAM/namelist )
52    PAT_RDT=$( supergrep rdt       ${SUBMIT_DIR}/PARAM/namelist )
53    PAT_NTRD=$( supergrep ntrd      ${SUBMIT_DIR}/PARAM/namelist )
54    PAT_RESTAR=$( supergrep ln_rstart ${SUBMIT_DIR}/PARAM/namelist )
55    PAT_NSTOCK=$( supergrep nstock    ${SUBMIT_DIR}/PARAM/namelist )
56    PAT_NRSTAR=$( supergrep nrstdt    ${SUBMIT_DIR}/PARAM/namelist )
57    PAT_NDATE0=$( supergrep ndate0    ${SUBMIT_DIR}/PARAM/namelist )
58    PAT_NLEAPY=$( supergrep nleapy    ${SUBMIT_DIR}/PARAM/namelist )
59    PAT_NMSH=$( supergrep nmsh      ${SUBMIT_DIR}/PARAM/namelist ) 
60    PAT_RSTRTTRD=$( supergrep ln_trdmld_restart ${SUBMIT_DIR}/PARAM/namelist )
61
62    PAT_TOP_NWRITETRC=$( supergrep nwritetrc             ${SUBMIT_DIR}/PARAM/namelist_top )
63    PAT_TOP_NWRITETRD=$( supergrep ntrd_trc              ${SUBMIT_DIR}/PARAM/namelist_top )
64    PAT_TOP_LRSTTR=$( supergrep lrsttr                ${SUBMIT_DIR}/PARAM/namelist_top )
65    PAT_TOP_NRSTTR=$( supergrep nrsttr                ${SUBMIT_DIR}/PARAM/namelist_top )
66    PAT_TOP_RSTRTTRD=$( supergrep ln_trdmld_trc_restart ${SUBMIT_DIR}/PARAM/namelist_top )
67
68    PAT_LOB_NWRITEDIA=$( supergrep nwritedia         ${SUBMIT_DIR}/PARAM/namelist_lobster )
69
70    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
71    # /!\ Needed by OPA namelist to compute file names /!\
72    (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 ))
73
74    IGCM_debug_PopStack "OCE_Initialize"
75}
76
77#-----------------------------------------------------------------
78function OCE_Update
79{
80###    set -vx
81    IGCM_debug_PushStack "OCE_Update"
82
83    NbFreq=$( echo ${config_OCE_WriteFrequency} | wc -w )
84
85    ##--Write Frequency Purpose ....
86    frequency=$( echo ${config_OCE_WriteFrequency} | awk "-F " '{print $1}' )
87    factor=$( echo ${frequency} | sed -e "s/[yYmMdD]//" )
88    case ${frequency} in
89   1Y|1y)
90       (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInYear  ${year} ) ))          ;
91       PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}y ;
92       R_OUT_OCE_NWRITE=${R_OUT_OCE_O_Y} ;
93       R_OUT_TOP_NWRITE=${R_OUT_TOP_O_Y} ;
94       R_OUT_TRENDS_NWRITE=${R_OUT_TRENDS_O_Y} ;
95       WF1=${factor}Y ;;
96   1M|1m)
97       (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor * $( IGCM_date_DaysInMonth ${year} ${month} ) )) ;
98       PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}m ;
99       R_OUT_OCE_NWRITE=${R_OUT_OCE_O_M} ;
100       R_OUT_TOP_NWRITE=${R_OUT_TOP_O_M} ;
101       R_OUT_TRENDS_NWRITE=${R_OUT_TRENDS_O_M} ;
102       WF1=${factor}M ;;
103   *D|*d)
104       (( ORCA_NWRITE = ORCA_NPDT_JOUR * factor  ))  ;
105       PREFIX_NWRITE=${config_UserChoices_JobName}_${factor}d ;
106       R_OUT_OCE_NWRITE=${R_OUT_OCE_O_D} ;
107       R_OUT_TOP_NWRITE=${R_OUT_TOP_O_D} ;
108       R_OUT_TRENDS_NWRITE=${R_OUT_TRENDS_O_D} ;
109       WF1=${factor}D ;;
110   *)
111       (( ORCA_NWRITE = 0 ))                                                            ;;
112    esac
113
114    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
115    # Needed by OPA namelist to compute correct file names
116    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
117
118    ##-- Calcul du numero de pas de temps de debut de job ORCA
119    (( ORCA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * ORCA_NPDT_JOUR + 1 ))
120    (( ORCA_NPDT   = PeriodLengthInDays * ORCA_NPDT_JOUR ))
121    (( ORCA_NITEND = ORCA_NIT000 + ORCA_NPDT - 1))
122
123    ## On force 1 restart par simulation à la fin
124    ORCA_NSTOCK="${ORCA_NITEND}"
125
126    ##-- verification du nb de pas de temps par jour
127    (( NB_SEC_JOUR_MODEL = ORCA_NPDT_JOUR * ORCA_RDT ))
128    (( NB_SEC_JOUR = 60 * 60 * 24 ))
129
130    if [ ${NB_SEC_JOUR_MODEL} -ne ${NB_SEC_JOUR} ]
131   then
132        echo " VERIFIER ORCA_NPDT_JOUR dans gyre.card "
133        exit
134    fi
135
136    ##-- Restart configuration
137    if ( [ "${CumulPeriod}" -eq 1 ] )
138       
139    then
140
141        if ( [ "${config_OCE_Restart}" = "n" ] )
142
143        then
144
145        #echo "PAS DE RESTART OPA"
146   ORCA_LRSTAR=.FALSE.
147   ORCA_NRSTDT=0
148        #echo pas de meshmask en parallele
149   ORCA_NMSH=1
150   ( [ X${BATCH_NUM_PROC_TOT} != X ] && [ "${BATCH_NUM_PROC_TOT}" -gt 1 ] ) && ORCA_NMSH=0
151
152        else 
153
154        #    "${config_OCE_Restart}" = "y"
155
156        #echo "RESTART OPA" et pas de verif pour cumulperiod=1
157   ORCA_LRSTAR=.TRUE.
158   ORCA_NRSTDT=0
159   ORCA_NMSH=0
160        fi
161
162        if ( [ "${config_TOP_Restart}" = "n" ] )
163
164        then
165
166        #echo "PAS DE RESTART TOP"
167        TOP_LRSTTR=.FALSE.
168        TOP_NRSTTR=0
169
170        else 
171
172        #    "${config_TOP_Restart}" = "y"
173
174        #echo "RESTART TOP"
175        TOP_LRSTTR=.TRUE.
176        TOP_NRSTTR=0
177
178        fi
179
180        if ( [ "${config_TRENDS_Restart}" = "n" ] )
181
182        then
183
184        #echo "PAS DE RESTART TRENDS"
185        TRENDS_LRSTTR=.FALSE.
186
187        else
188
189        #    "${config_TRENDS_Restart}" = "y"
190
191        #echo "RESTART TRENDS"
192        TRENDS_LRSTTR=.TRUE.
193
194        fi
195
196    else
197
198        #echo "RESTART OPA"
199   ORCA_LRSTAR=.TRUE.
200   ORCA_NRSTDT=2
201   ORCA_NMSH=0
202
203        #echo "RESTART TOP"
204        TOP_LRSTTR=.TRUE.
205        TOP_NRSTTR=2
206
207        #echo "RESTART TRENDS"
208        TRENDS_LRSTTR=.TRUE.
209
210    fi
211
212       # nleapy configuration
213       case ${config_UserChoices_CalendarType} in
214                leap)
215                ORCA_NLEAPY=1;;
216                noleap)
217                ORCA_NLEAPY=0;;
218                360d)
219                ORCA_NLEAPY=30;;
220                *)
221                ORCA_NLEAPY=30
222        esac
223
224        typeset -r PRECIS=8
225   NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${ORCA_NITEND} }" ) ) 
226
227    sed -e "s%${PAT_CEXPER}%       cexper=\"${config_UserChoices_JobName}\"%" \
228   -e "s%${PAT_NIT000}%       nit000=${ORCA_NIT000}%"                    \
229   -e "s%${PAT_NITEND}%       nitend=${ORCA_NITEND}%"                    \
230   -e "s%${PAT_NWRITE}%       nwrite=${ORCA_NWRITE}%"                    \
231   -e "s%${PAT_NTRD}%         ntrd=${ORCA_NWRITE}%"                      \
232   -e "s%${PAT_RESTAR}%       ln_rstart=${ORCA_LRSTAR}%"                 \
233   -e "s%${PAT_RDT}%          rdt=${ORCA_RDT}%"                          \
234   -e "s%${PAT_NSTOCK}%       nstock=${ORCA_NSTOCK}%"                    \
235   -e "s%${PAT_NRSTAR}%       nrstdt=${ORCA_NRSTDT}%"                    \
236   -e "s%${PAT_NDATE0}%       ndate0=${PeriodDateBegin}%"                \
237   -e "s%${PAT_NLEAPY}%       nleapy=${ORCA_NLEAPY}%"                    \
238   -e "s%${PAT_NMSH}%         nmsh=${ORCA_NMSH}%"                        \
239        -e "s%${PAT_RSTRTTRD}%     ln_trdmld_restart=${TRENDS_LRSTTR}%"       \
240   namelist > namelist.tmp
241
242    IGCM_sys_Mv namelist.tmp namelist
243
244# on force les sorties TOP comme les sorties OPA
245
246    sed -e "s%${PAT_TOP_NWRITETRC}%       nwritetrc=${ORCA_NWRITE}%"               \
247        -e "s%${PAT_TOP_NWRITETRD}%       ntrd_trc=${ORCA_NWRITE}%"                \
248        -e "s%${PAT_TOP_LRSTTR}%          lrsttr=${TOP_LRSTTR}%"                   \
249        -e "s%${PAT_TOP_NRSTTR}%          nrsttr=${TOP_NRSTTR}%"                   \
250        -e "s%${PAT_TOP_RSTRTTRD}%        ln_trdmld_trc_restart=${TRENDS_LRSTTR}%" \
251        namelist_top > namelist_top.tmp
252
253    IGCM_sys_Mv namelist_top.tmp namelist_top
254
255# on force les sorties LOBSTER comme les sorties OPA
256
257    sed -e "s%${PAT_LOB_NWRITEDIA}%       nwritedia=${ORCA_NWRITE}%"              \
258        namelist_lobster > namelist_lobster.tmp
259
260    IGCM_sys_Mv namelist_lobster.tmp namelist_lobster
261
262    echo 'Variables automatically updated in namelists'
263    grep AUTO namelist*
264
265    IGCM_debug_PopStack "OCE_Update"
266}
267
268#-----------------------------------
269function OCE_Finalize
270{
271    IGCM_debug_PushStack "OCE_Finalize"
272
273    if [ -f date.file ] ; then
274        # Prefix use in gyre.card AND in lobster.card :
275   DATE_OPA=$( cat date.file | \
276       sed "s/\ ${config_UserChoices_JobName}_[0-9]*[a-z]_\([0-9]*_[0-9]*\)_.*\ */\1/g" )
277   MainPrefix=${config_UserChoices_JobName}_1d_${DATE_OPA}
278   SecondPrefix=${config_UserChoices_JobName}_5d_${DATE_OPA}
279    fi
280
281    echo FINALIZE OCE !!!
282
283    IGCM_debug_PopStack "OCE_Finalize"
284}
285
Note: See TracBrowser for help on using the repository browser.