4 |
michaesp |
1 |
#!/bin/csh
|
|
|
2 |
|
|
|
3 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
4 |
# Usage and parameter handling
|
|
|
5 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
6 |
|
|
|
7 |
# Set Lagranto
|
|
|
8 |
set LAGRANTO = ${LAGRANTOBASE}.${MODEL}/
|
|
|
9 |
|
|
|
10 |
# Write usage information
|
|
|
11 |
if ( ${#argv} == 0 ) then
|
|
|
12 |
echo
|
|
|
13 |
${LAGRANTO}/bin/lagrantohelp create_startf short
|
|
|
14 |
echo
|
|
|
15 |
exit 1
|
|
|
16 |
endif
|
|
|
17 |
|
|
|
18 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
19 |
# Handle input parameters
|
|
|
20 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
21 |
|
|
|
22 |
# Prefix of primary and secondary file; and set the filenames
|
|
|
23 |
set charp='P'
|
|
|
24 |
set chars='S'
|
|
|
25 |
|
|
|
26 |
# Write title
|
|
|
27 |
echo
|
|
|
28 |
echo '========================================================='
|
|
|
29 |
echo ' *** START OF PREPROCESSOR CREATE_STARTF *** '
|
|
|
30 |
echo
|
|
|
31 |
|
|
|
32 |
# Extract arguments and split reference date
|
|
|
33 |
set refdate = $1
|
|
|
34 |
set ofile = $2
|
|
|
35 |
set specifier = `echo $3`
|
|
|
36 |
shift
|
|
|
37 |
shift
|
|
|
38 |
shift
|
|
|
39 |
|
|
|
40 |
# Check whether specifier is a file or whether it is explicitly written
|
|
|
41 |
set flag_criterion = 'file'
|
|
|
42 |
set test = `echo ${specifier} | grep '@' | wc -c`
|
|
|
43 |
if ( "${test}" != "0" ) then
|
|
|
44 |
set flag_criterion = 'criterion'
|
|
|
45 |
endif
|
|
|
46 |
|
|
|
47 |
# Get the criterion from the file
|
|
|
48 |
if ( "${flag_criterion}" == "file" ) then
|
|
|
49 |
if ( -f ${specifier} ) then
|
|
|
50 |
set filename = ${specifier}
|
|
|
51 |
set specifier = `cat ${specifier}`
|
|
|
52 |
else
|
|
|
53 |
echo " ERROR: cannot read criterion from file ${specifier}... Stop"
|
|
|
54 |
exit 1
|
|
|
55 |
endif
|
|
|
56 |
endif
|
|
|
57 |
|
|
|
58 |
echo "---- INPUT PARAMETERS ----------------------------------"
|
|
|
59 |
echo
|
|
|
60 |
echo "Reference date : ${refdate}"
|
|
|
61 |
if ( "${flag_criterion}" == "criterion" ) then
|
|
|
62 |
echo "Specifier : ${specifier}"
|
|
|
63 |
else
|
|
|
64 |
echo "Specifier : ${specifier} [from file ${filename}]"
|
|
|
65 |
endif
|
|
|
66 |
echo "Output file : ${ofile}"
|
|
|
67 |
echo
|
|
|
68 |
|
|
|
69 |
# Handle optional arguments
|
|
|
70 |
set tvfile = 'tracevars'
|
|
|
71 |
set changet = 'false'
|
|
|
72 |
set noclean = 'false'
|
|
|
73 |
set regionf = 'regionf'
|
|
|
74 |
set timecheck = 'no'
|
|
|
75 |
|
|
|
76 |
while ( $#argv > 0 )
|
|
|
77 |
|
|
|
78 |
switch ( $argv[1] )
|
|
|
79 |
|
|
|
80 |
case -t
|
|
|
81 |
set tvfile = $argv[2]
|
|
|
82 |
echo "tvfile -> ${tvfile} (user defined)"
|
|
|
83 |
shift;
|
|
|
84 |
breaksw
|
|
|
85 |
|
|
|
86 |
case -changet
|
|
|
87 |
set changet = 'true'
|
|
|
88 |
echo "changet -> true (user defined)"
|
|
|
89 |
breaksw
|
|
|
90 |
|
|
|
91 |
case -noclean
|
|
|
92 |
set noclean = 'true'
|
|
|
93 |
echo "noclean -> true (user defined)"
|
|
|
94 |
breaksw
|
|
|
95 |
|
|
|
96 |
case -timecheck
|
|
|
97 |
set timecheck = 'yes'
|
|
|
98 |
echo "timecheck -> yes (user defined)"
|
|
|
99 |
breaksw
|
|
|
100 |
|
|
|
101 |
case -regionf
|
|
|
102 |
set regionf = $argv[2]
|
|
|
103 |
echo "regionf -> ${regionf} (user defined)"
|
|
|
104 |
shift;
|
|
|
105 |
breaksw
|
|
|
106 |
|
|
|
107 |
endsw
|
|
|
108 |
|
|
|
109 |
shift;
|
|
|
110 |
|
|
|
111 |
end
|
|
|
112 |
|
|
|
113 |
# No change of times necessary if no check requested
|
|
|
114 |
if ( "${timecheck}" == "no" ) then
|
|
|
115 |
set changet = 'false'
|
|
|
116 |
endif
|
|
|
117 |
|
|
|
118 |
# Split the reference date
|
|
|
119 |
set yyyy=`echo ${refdate} | cut -c 1-4`
|
|
|
120 |
set mm=`echo ${refdate} | cut -c 5-6`
|
|
|
121 |
set dd=`echo ${refdate} | cut -c 7-8`
|
|
|
122 |
set hh=`echo ${refdate} | cut -c 10-11`
|
|
|
123 |
set min=`echo ${refdate}00 | cut -c 12-13`
|
|
|
124 |
|
|
|
125 |
# Set base directories (run+prog)
|
|
|
126 |
set tradir=${PWD}
|
|
|
127 |
|
|
|
128 |
# Set program paths and filenames
|
|
|
129 |
set parfile=${tradir}/create_startf.param
|
|
|
130 |
set crifile=${tradir}/create_startf.criterion
|
|
|
131 |
|
|
|
132 |
# Decide whether a tracing and selection is necessary
|
|
|
133 |
# If so, some intermediate file are writen (in Fortran binary)
|
|
|
134 |
set flag = `${LAGRANTO}/startf/create_startf.perl "${specifier}" | tail -1`
|
|
|
135 |
if ( "${flag}" != "nil" ) then
|
|
|
136 |
set format1 = ".3"
|
|
|
137 |
set format2 = ".3"
|
|
|
138 |
else
|
|
|
139 |
set format1 = ""
|
|
|
140 |
set format2 = ""
|
|
|
141 |
endif
|
|
|
142 |
|
|
|
143 |
# Write status information
|
|
|
144 |
echo
|
|
|
145 |
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
|
|
|
146 |
echo
|
|
|
147 |
echo "PROGRAM CREATE_STARTF : ${LAGRANTO}/startf/create_startf"
|
|
|
148 |
echo "PARAMETER file : ${parfile}"
|
|
|
149 |
echo "CRITERION file : ${crifile}"
|
|
|
150 |
echo "RUN directory : ${tradir}"
|
|
|
151 |
echo
|
|
|
152 |
|
|
|
153 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
154 |
# Set the primary and scecondary data files (necessary for interpolation if intermediate reference date)
|
|
|
155 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
156 |
|
|
|
157 |
# Find a first data file (if possible corresponding to reference date)
|
|
|
158 |
set file=${charp}${yyyy}${mm}${dd}_${hh}
|
|
|
159 |
if ( ( -f ${file} ) && ( ${min} == 0 ) ) then
|
|
|
160 |
set timeshift=0
|
|
|
161 |
set date0=${yyyy}${mm}${dd}_${hh}
|
|
|
162 |
set date1=${yyyy}${mm}${dd}_${hh}
|
|
|
163 |
set pfile0=${file1}
|
|
|
164 |
set pfile1=${file}
|
|
|
165 |
goto label3
|
|
|
166 |
else
|
|
|
167 |
set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
|
|
|
168 |
endif
|
|
|
169 |
|
|
|
170 |
# Determine time increment (in hours) between data files
|
|
|
171 |
set date1=`echo $file | cut -c 2-12`
|
|
|
172 |
set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
|
|
|
173 |
@ n ++
|
|
|
174 |
set date2=`ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-12`
|
|
|
175 |
set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
|
|
|
176 |
endif
|
|
|
177 |
if ( $timeinc == 0 ) then
|
|
|
178 |
echo " ERROR: cannot set the time increment between input files ***"
|
|
|
179 |
exit 1
|
|
|
180 |
endif
|
|
|
181 |
|
|
|
182 |
# Search the first file to use
|
|
|
183 |
set timeshift=
|
|
|
184 |
foreach i ( ${charp}????????_?? )
|
|
|
185 |
|
|
|
186 |
set date0 = `echo $i | cut -c 2-12`
|
|
|
187 |
set td1 = `${LAGRANTO}/goodies/gettidiff ${yyyy}${mm}${dd}_${hh} ${date0}`
|
|
|
188 |
|
|
|
189 |
if ( ( $td1 >= 0 ) && ( $td1 < $timeinc ) ) then
|
|
|
190 |
set timeshift=$td1
|
|
|
191 |
set pfile0=${charp}${date0}
|
|
|
192 |
goto label2
|
|
|
193 |
endif
|
|
|
194 |
|
|
|
195 |
end
|
|
|
196 |
|
|
|
197 |
# Check if no P files are available for the specified time period
|
|
|
198 |
if ( $timeshift == "" ) then
|
|
|
199 |
echo " ERROR: no data files available for the specified reference date"
|
|
|
200 |
exit 1
|
|
|
201 |
endif
|
|
|
202 |
|
|
|
203 |
# Everything is fine so far: proceed
|
|
|
204 |
label2:
|
|
|
205 |
|
|
|
206 |
# Set the next date and check its availability
|
|
|
207 |
if ( ( ${timeshift} != 0 ) || ( ${min} > 0 ) ) then
|
|
|
208 |
set date1=`${LAGRANTO}/goodies/newtime $date0 $timeinc`
|
|
|
209 |
if ( ! -f ${charp}${date1} ) then
|
|
|
210 |
echo " ERROR: file with primary data is missing for $date1"
|
|
|
211 |
exit 1
|
|
|
212 |
else
|
|
|
213 |
set pfile1=${charp}${date1}
|
|
|
214 |
endif
|
|
|
215 |
else
|
|
|
216 |
set date1=${date0}
|
|
|
217 |
set pfile1=${pfile0}
|
|
|
218 |
endif
|
|
|
219 |
|
|
|
220 |
# Set the final timeshift
|
|
|
221 |
if ( ${min} != 00 ) then
|
|
|
222 |
set timeshift=${timeshift}.${min}
|
|
|
223 |
endif
|
|
|
224 |
|
|
|
225 |
# Everything is fine!
|
|
|
226 |
label3:
|
|
|
227 |
|
|
|
228 |
# Set secondary files and check their availability
|
|
|
229 |
set sfile0=${chars}${date0}
|
|
|
230 |
set sfile1=${chars}${date1}
|
|
|
231 |
|
|
|
232 |
# Write status information
|
|
|
233 |
echo '---- DATA FILES -----------------------------------------'
|
|
|
234 |
echo
|
|
|
235 |
echo "Primary files : ${pfile0}"
|
|
|
236 |
echo " : ${pfile1}"
|
|
|
237 |
echo "Secondary files : ${sfile0}"
|
|
|
238 |
echo " : ${sfile1}"
|
|
|
239 |
echo "Timeshift to first data file (hh.mm) : ${timeshift}"
|
|
|
240 |
echo "Time increment of data files : ${timeinc}"
|
|
|
241 |
echo
|
|
|
242 |
|
|
|
243 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
244 |
# Create the start positions (without selection)
|
|
|
245 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
246 |
|
|
|
247 |
# Set times relative to the reference date
|
|
|
248 |
if ( "${changet}" == "true" ) then
|
|
|
249 |
echo '---- CHANGE TIMES ON DATA FILES ------------------------'
|
|
|
250 |
echo
|
|
|
251 |
${LAGRANTO}/goodies/changet.sh ${refdate} ${pfile0}
|
|
|
252 |
${LAGRANTO}/goodies/changet.sh ${refdate} ${pfile1}
|
|
|
253 |
if ( -f ${sfile0} ) then
|
|
|
254 |
${LAGRANTO}/goodies/changet.sh ${refdate} ${sfile0}
|
|
|
255 |
endif
|
|
|
256 |
if ( -f ${sfile1} ) then
|
|
|
257 |
${LAGRANTO}/goodies/changet.sh ${refdate} ${sfile1}
|
|
|
258 |
endif
|
|
|
259 |
endif
|
|
|
260 |
|
|
|
261 |
# Write parameters to parameter file and create the starting positions
|
|
|
262 |
\rm -f ${parfile}
|
|
|
263 |
echo \"${pfile0}\" \"${pfile1}\" >! ${parfile}
|
|
|
264 |
echo \"${sfile0}\" \"${sfile1}\" >> ${parfile}
|
|
|
265 |
echo \"${ofile}${format1}\" >> ${parfile}
|
|
|
266 |
echo \"${regionf}\" >> ${parfile}
|
|
|
267 |
echo ${yyyy} >> ${parfile}
|
|
|
268 |
echo ${mm} >> ${parfile}
|
|
|
269 |
echo ${dd} >> ${parfile}
|
|
|
270 |
echo ${hh} >> ${parfile}
|
|
|
271 |
echo ${min} >> ${parfile}
|
|
|
272 |
echo 00 >> ${parfile}
|
|
|
273 |
echo ${timeshift} >> ${parfile}
|
|
|
274 |
echo ${timeinc} >> ${parfile}
|
|
|
275 |
|
|
|
276 |
# Analyse the specifier and append to parameter file
|
|
|
277 |
${LAGRANTO}/startf/create_startf.perl "${specifier}" >> ${parfile}
|
|
|
278 |
|
|
|
279 |
if ( "${status}" != "0" ) then
|
|
|
280 |
echo "ERROR: Preprocessor <create_startf> failed"
|
|
|
281 |
exit 1
|
|
|
282 |
endif
|
|
|
283 |
|
|
|
284 |
# Write selection criterion to file
|
|
|
285 |
\rm -f ${crifile}
|
|
|
286 |
tail -1 ${parfile} >! ${crifile}
|
|
|
287 |
|
|
|
288 |
# Write flag for no time check
|
|
|
289 |
echo \"${timecheck}\" >> ${parfile}
|
|
|
290 |
|
|
|
291 |
# Write title
|
|
|
292 |
echo
|
|
|
293 |
echo ' *** END OF PREPROCESSOR CREATE_STARTF ***'
|
|
|
294 |
echo '========================================================='
|
|
|
295 |
echo
|
|
|
296 |
|
|
|
297 |
# Create the startf
|
|
|
298 |
cd ${tradir}
|
|
|
299 |
${LAGRANTO}/startf/create_startf
|
|
|
300 |
|
|
|
301 |
if ( "${status}" != "0" ) then
|
|
|
302 |
echo "ERROR: Program <create_startf> failed"
|
|
|
303 |
exit 1
|
|
|
304 |
endif
|
|
|
305 |
|
|
|
306 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
307 |
# Apply selection (first tracing then selection)
|
|
|
308 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
309 |
|
|
|
310 |
# Stop if no tracing and selection is necessary
|
|
|
311 |
if ( "${flag}" == "nil" ) goto finish
|
|
|
312 |
|
|
|
313 |
# Tracing of extra variables
|
|
|
314 |
if ( -f ${ofile}${format2} ) then
|
|
|
315 |
\rm -f ${ofile}${format2}
|
|
|
316 |
endif
|
|
|
317 |
if ( "${timecheck}" == "no" ) then
|
|
|
318 |
${LAGRANTO}/trace/trace.sh ${ofile}${format1} ${ofile}${format2} -v ${tvfile} -notimecheck
|
|
|
319 |
else
|
|
|
320 |
${LAGRANTO}/trace/trace.sh ${ofile}${format1} ${ofile}${format2} -v ${tvfile}
|
|
|
321 |
endif
|
|
|
322 |
\rm -f ${ofile}${format1}
|
|
|
323 |
|
|
|
324 |
# Selection
|
|
|
325 |
if ( -f ${ofile} ) then
|
|
|
326 |
\rm -f ${ofile}
|
|
|
327 |
endif
|
|
|
328 |
${LAGRANTO}/select/select.sh ${ofile}${format2} ${ofile} `cat ${crifile}`
|
|
|
329 |
\rm -f ${ofile}${format2}
|
|
|
330 |
|
|
|
331 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
332 |
# Final tasks (make clean)
|
|
|
333 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
334 |
|
|
|
335 |
finish:
|
|
|
336 |
|
|
|
337 |
echo $noclean
|
|
|
338 |
|
|
|
339 |
if ( "${noclean}" == "false" ) then
|
|
|
340 |
\rm -f ${crifile}
|
|
|
341 |
\rm -f ${parfile}
|
|
|
342 |
endif
|
|
|
343 |
|
|
|
344 |
exit 0
|
|
|
345 |
|
|
|
346 |
|
|
|
347 |
|