2 |
michaesp |
1 |
#!/bin/csh
|
|
|
2 |
|
|
|
3 |
# ---------------------------------------------------------------------
|
|
|
4 |
# Usage, parameter settings
|
|
|
5 |
# ---------------------------------------------------------------------
|
|
|
6 |
|
11 |
michaesp |
7 |
# Set Lagranto
|
|
|
8 |
set LAGRANTO = ${LAGRANTOBASE}.${MODEL}/
|
|
|
9 |
|
2 |
michaesp |
10 |
# Write usage information
|
|
|
11 |
if ( (${#argv} == 0) | (${#argv} < 4) ) then
|
|
|
12 |
echo
|
|
|
13 |
${LAGRANTO}/bin/lagrantohelp caltra short
|
|
|
14 |
echo
|
|
|
15 |
exit 0
|
|
|
16 |
endif
|
|
|
17 |
|
|
|
18 |
# Write title
|
|
|
19 |
echo
|
|
|
20 |
echo '========================================================='
|
|
|
21 |
echo ' *** START OF PREPROCESSOR CALTRA *** '
|
|
|
22 |
echo
|
|
|
23 |
|
|
|
24 |
# Get the arguments
|
|
|
25 |
set startdate = $1
|
|
|
26 |
set enddate = $2
|
|
|
27 |
set startf = $3
|
|
|
28 |
set outfile = $4
|
|
|
29 |
if ( ${#argv} > 4 ) then
|
|
|
30 |
set flags = $5
|
|
|
31 |
else
|
|
|
32 |
set flags=
|
|
|
33 |
endif
|
|
|
34 |
|
|
|
35 |
# Set base directories (run+prog)
|
|
|
36 |
set cdfdir=${PWD}
|
|
|
37 |
set tradir=${PWD}
|
|
|
38 |
|
|
|
39 |
# Set program paths and filenames
|
|
|
40 |
set parfile = ${tradir}/caltra.param
|
|
|
41 |
|
|
|
42 |
# Set the prefix of the primary and secondary data files
|
|
|
43 |
set charp = 'P'
|
|
|
44 |
set chars = 'S'
|
|
|
45 |
|
|
|
46 |
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
|
|
|
47 |
echo
|
|
|
48 |
echo "CDF directory : ${cdfdir}"
|
|
|
49 |
echo "TRA directory : ${tradir}"
|
|
|
50 |
echo "PROGRAM CALTRA : ${LAGRANTO}/caltra/caltra"
|
|
|
51 |
echo "PARAMETER file : ${parfile}"
|
|
|
52 |
echo
|
|
|
53 |
|
|
|
54 |
# ---------------------------------------------------------------------
|
|
|
55 |
# Set optional flags
|
|
|
56 |
# ---------------------------------------------------------------------
|
|
|
57 |
|
|
|
58 |
echo '---- OPTIONAL FLAGS -------------------------------------'
|
|
|
59 |
echo
|
|
|
60 |
|
|
|
61 |
# Set some default values ("nil" must be set according to input files)
|
|
|
62 |
set flag_j = "nil"
|
|
|
63 |
set flag_i = "nil"
|
|
|
64 |
set flag_t = "nil"
|
|
|
65 |
set flag_o = "nil"
|
|
|
66 |
set flag_p = "nil"
|
21 |
michaesp |
67 |
set flag_agl = "-999"
|
|
|
68 |
set flag_isen = "-999"
|
2 |
michaesp |
69 |
set noclean = 'false'
|
|
|
70 |
set timecheck = 'no'
|
|
|
71 |
set gridflag = 'real'
|
|
|
72 |
|
|
|
73 |
while ( $#argv > 0 )
|
|
|
74 |
|
|
|
75 |
switch ( $argv[1] )
|
|
|
76 |
|
|
|
77 |
case -j
|
|
|
78 |
set flag_j=1
|
|
|
79 |
echo "Flag '-j' -> ${flag_j} (user defined)"
|
|
|
80 |
breaksw
|
|
|
81 |
|
|
|
82 |
case -i
|
|
|
83 |
set flag_i=$argv[2]
|
|
|
84 |
echo "Flag '-i' -> ${flag_i} (user defined)"
|
|
|
85 |
shift;
|
|
|
86 |
breaksw
|
|
|
87 |
|
|
|
88 |
case -t
|
|
|
89 |
set flag_t=$argv[2]
|
|
|
90 |
echo "Flag '-t' -> ${flag_t} (user defined)"
|
|
|
91 |
shift;
|
|
|
92 |
breaksw
|
|
|
93 |
|
|
|
94 |
case -o
|
|
|
95 |
set flag_o=$argv[2]
|
|
|
96 |
echo "Flag '-o' -> ${flag_o} (user defined)"
|
|
|
97 |
shift;
|
|
|
98 |
breaksw
|
|
|
99 |
|
|
|
100 |
case -p
|
|
|
101 |
set flag_p=1
|
|
|
102 |
echo "Flag '-p' -> ${flag_p} (user defined)"
|
|
|
103 |
breaksw
|
21 |
michaesp |
104 |
|
|
|
105 |
case -agl
|
|
|
106 |
set flag_agl=$argv[2]
|
|
|
107 |
echo "Flag '-agl' -> ${flag_agl} (user defined)"
|
|
|
108 |
shift;
|
|
|
109 |
breaksw
|
|
|
110 |
|
|
|
111 |
case -isen
|
|
|
112 |
set flag_isen=$argv[2]
|
|
|
113 |
echo "Flag '-isen' -> ${flag_isen} (user defined)"
|
|
|
114 |
shift;
|
|
|
115 |
breaksw
|
|
|
116 |
|
2 |
michaesp |
117 |
case -noclean
|
|
|
118 |
set noclean = 'true'
|
|
|
119 |
echo "noclean -> true (user defined)"
|
|
|
120 |
breaksw
|
|
|
121 |
|
|
|
122 |
case -timecheck
|
|
|
123 |
set timecheck = 'yes'
|
|
|
124 |
echo "timecheck -> yes (user defined)"
|
|
|
125 |
breaksw
|
|
|
126 |
|
|
|
127 |
endsw
|
|
|
128 |
|
|
|
129 |
shift;
|
|
|
130 |
|
|
|
131 |
end
|
|
|
132 |
|
|
|
133 |
# Set some defaults
|
|
|
134 |
if ( "${flag_j}" == "nil" ) then
|
|
|
135 |
set flag_j = 0
|
|
|
136 |
echo "Flag '-j' -> 0 (default)"
|
|
|
137 |
endif
|
|
|
138 |
if ( "${flag_p}" == "nil" ) then
|
|
|
139 |
set flag_p = 0
|
|
|
140 |
echo "Flag '-p' -> 0 (default)"
|
|
|
141 |
endif
|
|
|
142 |
|
|
|
143 |
# ---------------------------------------------------------------------
|
|
|
144 |
# Handle the time specifier - startdate, enddate
|
|
|
145 |
# ---------------------------------------------------------------------
|
|
|
146 |
|
|
|
147 |
echo
|
|
|
148 |
echo '---- TIME RANGE -----------------------------------------'
|
|
|
149 |
echo
|
|
|
150 |
|
|
|
151 |
# Check format of start and end date - must be the same
|
|
|
152 |
set ns=`echo $startdate | sed -e 's/_[0-9]*//' | wc -c`
|
|
|
153 |
set ne=`echo $enddate | sed -e 's/_[0-9]*//' | wc -c`
|
|
|
154 |
if ( $ns != $ne ) then
|
|
|
155 |
echo " ERROR: start and end date must be in the same format ***"
|
|
|
156 |
exit 1
|
|
|
157 |
endif
|
|
|
158 |
if ( $ns != 9 ) then
|
|
|
159 |
echo " ERROR: Date format must be yyyymmdd ***"
|
|
|
160 |
exit 1
|
|
|
161 |
endif
|
|
|
162 |
set ns=`echo $startdate | sed -e 's/[0-9]*_//' | wc -c`
|
|
|
163 |
set ne=`echo $enddate | sed -e 's/[0-9]*_//' | wc -c`
|
|
|
164 |
if ( $ns != $ne ) then
|
|
|
165 |
echo " ERROR: start and end date must be in the same format ***"
|
|
|
166 |
exit 1
|
|
|
167 |
endif
|
|
|
168 |
if ( ( $ns != 5 ) & ( $ns != 3 ) ) then
|
|
|
169 |
echo " ERROR: Time format must be hh(mm) ***"
|
|
|
170 |
exit 1
|
|
|
171 |
endif
|
|
|
172 |
|
|
|
173 |
# Split the start and end date into <yymmdd_hh and mm>
|
|
|
174 |
set startdate_ymdh = `echo $startdate | cut -c 1-11`
|
|
|
175 |
set startdate_min = `echo $startdate | cut -c 12-13`
|
|
|
176 |
if ( $startdate_min == "" ) set startdate_min = 00
|
|
|
177 |
|
|
|
178 |
set enddate_ymdh = `echo $enddate | cut -c 1-11`
|
|
|
179 |
set enddate_min = `echo $enddate | cut -c 12-13`
|
|
|
180 |
if ( $enddate_min == "" ) set enddate_min = 00
|
|
|
181 |
|
|
|
182 |
# Get the time difference between <start_ymdh> and <end_ymdh> date
|
|
|
183 |
# Decide whether trajectoriesare forward or backward
|
|
|
184 |
set timediff_hh = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${startdate_ymdh}`
|
|
|
185 |
|
|
|
186 |
if ( $timediff_hh == 0 ) then
|
|
|
187 |
if ( $enddate_min > $startdate_min ) then
|
|
|
188 |
set direction = f
|
|
|
189 |
set idir = 1
|
|
|
190 |
else
|
|
|
191 |
set direction = b
|
|
|
192 |
set idir = -1
|
|
|
193 |
endif
|
|
|
194 |
else if ( $timediff_hh > 0 ) then
|
|
|
195 |
set direction = f
|
|
|
196 |
set idir = 1
|
|
|
197 |
else
|
|
|
198 |
set direction = b
|
|
|
199 |
set idir = -1
|
|
|
200 |
@ timediff_hh = $idir * $timediff_hh
|
|
|
201 |
endif
|
|
|
202 |
|
|
|
203 |
# Get also minutes for time difference, if <start_min> or <end_min> != 0
|
23 |
michaesp |
204 |
set timediff_mm=00
|
2 |
michaesp |
205 |
|
|
|
206 |
if ( $startdate_min != 00 || $enddate_min != 00 ) then
|
|
|
207 |
@ min = ( $enddate_min - $startdate_min )
|
|
|
208 |
if ( $min == 0 ) then
|
|
|
209 |
set timediff_mm=
|
|
|
210 |
else if ( $min > 0 ) then
|
|
|
211 |
if ( $idir == 1 ) then
|
|
|
212 |
set timediff_mm=$min
|
|
|
213 |
else
|
|
|
214 |
@ timediff_hh --
|
|
|
215 |
@ timediff_mm = 60 - $min
|
|
|
216 |
endif
|
|
|
217 |
else
|
|
|
218 |
if ( $idir == 1 ) then
|
|
|
219 |
@ timediff_hh --
|
|
|
220 |
@ timediff_mm = 60 + $min
|
|
|
221 |
else
|
|
|
222 |
@ timediff_mm = 0 - $min
|
|
|
223 |
endif
|
|
|
224 |
endif
|
|
|
225 |
endif
|
|
|
226 |
|
|
|
227 |
# Set the reference date equal to the satrtdate
|
|
|
228 |
set refdate=${startdate}
|
|
|
229 |
|
|
|
230 |
# Write status information
|
|
|
231 |
echo "Time range : ${startdate} -> ${enddate}"
|
|
|
232 |
if ( ${timediff_mm} != "" ) then
|
|
|
233 |
echo "Time difference : ${timediff_hh} h ${timediff_mm} min"
|
|
|
234 |
else
|
|
|
235 |
echo "Time difference : ${timediff_hh} h"
|
|
|
236 |
endif
|
|
|
237 |
echo "Direction : ${direction} (${idir})"
|
|
|
238 |
echo "Reference date : ${refdate}"
|
|
|
239 |
|
|
|
240 |
# ---------------------------------------------------------------------
|
|
|
241 |
# Check availability of input data
|
|
|
242 |
# ---------------------------------------------------------------------
|
|
|
243 |
|
|
|
244 |
echo
|
|
|
245 |
echo '---- INPUT FILES ----------------------------------------'
|
|
|
246 |
echo
|
|
|
247 |
|
|
|
248 |
# Take the time increment from flag list ('nil', if not defined)
|
|
|
249 |
set timeinc = ${flag_i}
|
|
|
250 |
|
|
|
251 |
# Find a first data file (if possible corresponding to start/end date
|
|
|
252 |
# If starttime is not a data time, take the first file in the direectory
|
|
|
253 |
if ( $direction == "f" ) then
|
|
|
254 |
set file=${charp}${startdate_ymdh}
|
|
|
255 |
else
|
|
|
256 |
set file=${charp}${enddate_ymdh}
|
|
|
257 |
endif
|
|
|
258 |
if ( ! -f $file ) then
|
23 |
michaesp |
259 |
set file=`\ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
|
2 |
michaesp |
260 |
endif
|
|
|
261 |
|
|
|
262 |
# Determine timeinc (the time difference in hours between two data file)
|
|
|
263 |
# if not already defined with option -i
|
|
|
264 |
if ( ${timeinc} == "nil" ) then
|
23 |
michaesp |
265 |
set date1=`echo $file | cut -c 2-`
|
|
|
266 |
set n=`\ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
|
2 |
michaesp |
267 |
@ n ++
|
23 |
michaesp |
268 |
set date2=`\ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-`
|
2 |
michaesp |
269 |
set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
|
|
|
270 |
endif
|
|
|
271 |
if ( $timeinc == 0 ) then
|
|
|
272 |
echo " ERROR: cannot set the time increment between input files ***"
|
|
|
273 |
exit 1
|
|
|
274 |
endif
|
|
|
275 |
|
23 |
michaesp |
276 |
# Decide whether the time increment is smaller than 1 h; if so set the hires
|
|
|
277 |
# flag and convert the timeincement into fractional hour
|
|
|
278 |
set flag = `echo ${timeinc} | grep -n '\.'`
|
|
|
279 |
set hires = 0
|
|
|
280 |
if ( "${flag}" != "" ) then
|
|
|
281 |
echo
|
|
|
282 |
echo "Input files availability < 1 hour ($timeinc): switch to hires"
|
|
|
283 |
echo "mode. All input files must be of form: P{yyyymmdd_hhmm}"
|
|
|
284 |
set hires = 1
|
|
|
285 |
set timeinc_min = `echo "(${timeinc} * 100 + 0.5)/1" | bc`
|
25 |
michaesp |
286 |
set timeinc = `echo "scale=8; ${timeinc} * 100 / 60" | bc`
|
23 |
michaesp |
287 |
goto hires
|
|
|
288 |
endif
|
|
|
289 |
|
2 |
michaesp |
290 |
# Search the first file to use: We step through all P files and see whether they are
|
|
|
291 |
# good P files. Let's first do the test for the first data file found. If it's ok, we
|
|
|
292 |
# take it; if not, we step through all P files and find the good one
|
|
|
293 |
set flag=0
|
|
|
294 |
set td=
|
|
|
295 |
|
|
|
296 |
set date = `echo $file | cut -c 2-12`
|
|
|
297 |
set td1 = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
|
|
|
298 |
set td2 = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${date}`
|
|
|
299 |
|
|
|
300 |
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
|
|
|
301 |
set datfiles=$date
|
|
|
302 |
if ( $td1 < $timeinc ) set td=$td1
|
|
|
303 |
if ( $td2 < $timeinc ) set td=$td2
|
|
|
304 |
if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
|
|
|
305 |
goto label2
|
|
|
306 |
endif
|
|
|
307 |
|
|
|
308 |
foreach i ( ${charp}????????_?? )
|
|
|
309 |
|
|
|
310 |
set date = `echo $i | cut -c 2-12`
|
|
|
311 |
set td1 = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
|
|
|
312 |
set td2 = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${date}`
|
|
|
313 |
|
|
|
314 |
if (( $td1 < $timeinc || $td2 < $timeinc ) && ( $td1 >= 0 || $td2 >= 0 )) then
|
|
|
315 |
set datfiles=$date
|
|
|
316 |
if ( $td1 < $timeinc ) set td=$td1
|
|
|
317 |
if ( $td2 < $timeinc ) set td=$td2
|
|
|
318 |
if ( ( $startdate_min > 0 ) || ( $enddate_min > 0 ) ) @ td ++
|
|
|
319 |
goto label2
|
|
|
320 |
endif
|
|
|
321 |
|
|
|
322 |
end
|
|
|
323 |
|
|
|
324 |
# if no P/T-files are available for the specified time period, then $td is
|
|
|
325 |
# still undefined
|
|
|
326 |
if ( $td == "" ) then
|
|
|
327 |
echo " ERROR: no data files available for the specified time period"
|
|
|
328 |
exit 1
|
|
|
329 |
endif
|
|
|
330 |
|
23 |
michaesp |
331 |
# If the input files come with time increment < 1 hour, handle it in this
|
|
|
332 |
# special section. The aim is not to 'interfere' with the well established
|
|
|
333 |
# code handling the standard case with time increment >= 1 hour. In this mode
|
|
|
334 |
# we require that the start and end date are available as P files: no start is
|
|
|
335 |
# allowed between the model output files
|
|
|
336 |
hires:
|
|
|
337 |
|
|
|
338 |
set flag=0
|
|
|
339 |
set td=0
|
|
|
340 |
|
|
|
341 |
if ( $direction == "f" ) then
|
|
|
342 |
set file=${charp}${startdate}
|
|
|
343 |
else
|
|
|
344 |
set file=${charp}${enddate}
|
|
|
345 |
endif
|
|
|
346 |
|
|
|
347 |
if ( -f $file ) then
|
|
|
348 |
set date = `echo ${file} | cut -c 2-14`
|
|
|
349 |
set datfiles = $date
|
|
|
350 |
set td = 0
|
|
|
351 |
goto label2
|
|
|
352 |
else
|
|
|
353 |
echo
|
|
|
354 |
echo " ERROR: no data files available for the specified time period"
|
|
|
355 |
exit 1
|
|
|
356 |
endif
|
|
|
357 |
|
2 |
michaesp |
358 |
# Everything is fine so far: proceed
|
|
|
359 |
label2:
|
|
|
360 |
|
|
|
361 |
# Check whether first date is ok - before or at needed dates
|
|
|
362 |
if ( $direction == "f" ) then
|
|
|
363 |
set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${startdate_ymdh} ${date}`
|
|
|
364 |
else
|
|
|
365 |
set tdiff0 = `${LAGRANTO}/goodies/gettidiff ${enddate_ymdh} ${date}`
|
|
|
366 |
endif
|
|
|
367 |
if ( $tdiff0 < 0 ) then
|
|
|
368 |
echo " ERROR: data files missing for the specified time period"
|
|
|
369 |
exit 1
|
|
|
370 |
endif
|
|
|
371 |
|
23 |
michaesp |
372 |
# Calculate the number of further files; handle hires (timeinc<1 h) and
|
|
|
373 |
# standard mode (timeinc >= 1 h) separately
|
|
|
374 |
if ( ${hires} == 0 ) then
|
|
|
375 |
@ num = ( $timediff_hh + $td ) / $timeinc + 1
|
|
|
376 |
@ dum1 = ( $num - 1 ) * $timeinc
|
|
|
377 |
@ dum2 = $timediff_hh + $td
|
|
|
378 |
if ( $dum1 != $dum2 ) @ num ++
|
|
|
379 |
else
|
|
|
380 |
set num = `echo "( ${timediff_hh}*60 + ${timediff_mm} ) / ( ${timeinc_min} ) + 1" | bc`
|
|
|
381 |
endif
|
2 |
michaesp |
382 |
|
|
|
383 |
# Get a list of all needed files
|
|
|
384 |
set numfiles=$num
|
|
|
385 |
set sfiles=1
|
23 |
michaesp |
386 |
echo $datfiles
|
2 |
michaesp |
387 |
while ( $num > 1 )
|
23 |
michaesp |
388 |
if ( $hires == 0 ) then
|
|
|
389 |
set date=`${LAGRANTO}/goodies/newtime $date $timeinc`
|
|
|
390 |
else
|
|
|
391 |
set date=`${LAGRANTO}/goodies/newtime $date $timeinc_min`
|
|
|
392 |
endif
|
|
|
393 |
|
|
|
394 |
echo ${date}
|
|
|
395 |
|
2 |
michaesp |
396 |
if ( ! -f ${charp}${date} ) then
|
|
|
397 |
echo " ERROR: file with primary data is missing for $date"
|
|
|
398 |
exit 1
|
|
|
399 |
else if ( ! -f ${chars}${date} ) then
|
|
|
400 |
set sfiles=0
|
|
|
401 |
set datfiles=`echo $datfiles $date`
|
|
|
402 |
else
|
|
|
403 |
set datfiles=`echo $datfiles $date`
|
|
|
404 |
endif
|
|
|
405 |
@ num --
|
|
|
406 |
end
|
|
|
407 |
|
|
|
408 |
# Write some status information
|
|
|
409 |
echo "Primary file prefix : ${charp}"
|
|
|
410 |
echo "Secondary file prefix : ${chars}"
|
23 |
michaesp |
411 |
if ( ${hires} == 0 ) then
|
|
|
412 |
echo "Time increment for input files : ${timeinc} h"
|
|
|
413 |
else
|
|
|
414 |
echo "Time increment for input files : ${timeinc_min} min (0$timeinc h) "
|
|
|
415 |
endif
|
2 |
michaesp |
416 |
echo "# input files : ${numfiles}"
|
|
|
417 |
echo "${charp} files availability : 1"
|
|
|
418 |
echo "${chars} files availability : ${sfiles}"
|
|
|
419 |
echo "First input file : $datfiles[1] "
|
|
|
420 |
echo "Last input file : $datfiles[$numfiles] "
|
|
|
421 |
|
|
|
422 |
# ---------------------------------------------------------------------
|
|
|
423 |
# Handle vertical wind - scaling factor
|
|
|
424 |
# ---------------------------------------------------------------------
|
|
|
425 |
|
|
|
426 |
set wfactor=1.
|
|
|
427 |
|
|
|
428 |
# ---------------------------------------------------------------------
|
|
|
429 |
# Time step and output interval
|
|
|
430 |
# ---------------------------------------------------------------------
|
|
|
431 |
|
|
|
432 |
echo
|
|
|
433 |
echo '---- TIME STEPS -----------------------------------------'
|
|
|
434 |
echo
|
|
|
435 |
|
|
|
436 |
# Take the time step and output step from flag list ('nil', if not defined)
|
|
|
437 |
set timestep = ${flag_t}
|
|
|
438 |
set deltout = ${flag_o}
|
|
|
439 |
|
|
|
440 |
# Calculate the time step
|
23 |
michaesp |
441 |
if ( $hires == 0 ) then
|
|
|
442 |
if ( $timestep == "nil" ) @ timestep = ( 60 * $timeinc ) / 12
|
|
|
443 |
else
|
|
|
444 |
if ( $timestep == "nil" ) set timestep = `echo "scale=2; $timeinc_min / 12" | bc`
|
|
|
445 |
endif
|
2 |
michaesp |
446 |
|
|
|
447 |
# Take the output interval from time increment
|
23 |
michaesp |
448 |
if ( $hires == 0 ) then
|
|
|
449 |
if ( $deltout == "nil" ) @ deltout = 60 * ${timeinc}
|
|
|
450 |
else
|
|
|
451 |
if ( $deltout == "nil" ) set deltout = ${timeinc_min}
|
|
|
452 |
endif
|
2 |
michaesp |
453 |
|
|
|
454 |
# Check whether the timestep is an integer ratio of deltout
|
23 |
michaesp |
455 |
#@ flag = $deltout / $timestep
|
|
|
456 |
#@ flag = $deltout - ( $flag * $timestep )
|
|
|
457 |
set flag = `echo "scale=2; $deltout / $timestep" | bc`
|
|
|
458 |
set flag = `echo "scale=2; $deltout - ( $flag * $timestep )" | bc`
|
2 |
michaesp |
459 |
if ( $flag != 0 ) then
|
|
|
460 |
echo " ERROR: output time interval should be multiple of timestep"
|
|
|
461 |
echo
|
|
|
462 |
echo " $deltout min : output time interval"
|
|
|
463 |
echo " $timestep min : time step"
|
|
|
464 |
exit 1
|
|
|
465 |
endif
|
|
|
466 |
|
|
|
467 |
# Calculate the start and the end time relative to the first datfile
|
|
|
468 |
if ( $direction == f ) then
|
|
|
469 |
set tstart = `${LAGRANTO}/goodies/gettidiff $startdate $datfiles[1]`
|
|
|
470 |
set tend = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $enddate`
|
|
|
471 |
else
|
|
|
472 |
set tstart = `${LAGRANTO}/goodies/gettidiff $datfiles[$numfiles] $startdate`
|
|
|
473 |
set tend = `${LAGRANTO}/goodies/gettidiff $enddate $datfiles[1]`
|
|
|
474 |
endif
|
|
|
475 |
|
|
|
476 |
# Check whether tstart and tend are a multiple of the output time interval
|
|
|
477 |
if ( $tstart != 0 ) then
|
|
|
478 |
if ( `echo $tstart | grep "\."` != "" ) then
|
|
|
479 |
set dum=`echo $tstart | sed -e 's/[-0-9]*\.//'`
|
|
|
480 |
@ flag = $dum / $deltout
|
|
|
481 |
@ flag = $dum - ( $flag * $deltout )
|
|
|
482 |
if ( $flag != 0 ) then
|
|
|
483 |
echo " ERROR : the start time should be shifted relative to the first"
|
|
|
484 |
echo " datafile by a multiple of the output time interval"
|
|
|
485 |
echo " hint: set the latter with the option -o"
|
|
|
486 |
exit 1
|
|
|
487 |
endif
|
|
|
488 |
endif
|
|
|
489 |
endif
|
|
|
490 |
if ( `echo $tend | grep "\."` != "" ) then
|
|
|
491 |
set dum=`echo $tend | sed -e 's/[-0-9]*\.//'`
|
|
|
492 |
@ flag = $dum / $deltout
|
|
|
493 |
@ flag = $dum - ( $flag * $deltout )
|
|
|
494 |
if ( $flag != 0 ) then
|
|
|
495 |
echo " ERROR : the end time should be shifted relative to the first"
|
|
|
496 |
echo " datafile by a multiple of the output time interval"
|
|
|
497 |
echo " hint: set the latter with the option -o"
|
|
|
498 |
exit 1
|
|
|
499 |
endif
|
|
|
500 |
endif
|
|
|
501 |
|
|
|
502 |
# Write status information
|
|
|
503 |
echo "Trajectory calculation time step [min] : ${timestep}"
|
|
|
504 |
echo "Output time step [min] : ${deltout}"
|
|
|
505 |
if ( $direction == f ) then
|
|
|
506 |
echo "Start time relative to first file : $datfiles[1] + ${tstart} "
|
|
|
507 |
echo "End time relative to first file : $datfiles[$numfiles] - ${tend} "
|
|
|
508 |
else
|
|
|
509 |
echo "Start time relative to first file : $datfiles[$numfiles] - ${tstart} "
|
|
|
510 |
echo "End time relative to last file : $datfiles[1] + ${tend} "
|
|
|
511 |
endif
|
|
|
512 |
|
|
|
513 |
# ---------------------------------------------------------------------
|
|
|
514 |
# Start file
|
|
|
515 |
# ---------------------------------------------------------------------
|
|
|
516 |
|
|
|
517 |
echo
|
|
|
518 |
echo '---- START FILE -----------------------------------------'
|
|
|
519 |
echo
|
|
|
520 |
|
|
|
521 |
# Check if start file is available
|
|
|
522 |
if ( ! -f ${startf} ) then
|
|
|
523 |
echo " ERROR : start file ${startf} is missing"
|
|
|
524 |
exit 1
|
|
|
525 |
endif
|
|
|
526 |
|
|
|
527 |
# Decide whether startfile has an explicit format specifier
|
|
|
528 |
set format = "0"
|
|
|
529 |
foreach app ( 1 2 3 4 5 6 7 8 9 )
|
|
|
530 |
set flag = `echo ${startf} | grep ".${app}"`
|
|
|
531 |
if ( "${flag}" != "" ) set format = "${app}"
|
|
|
532 |
end
|
|
|
533 |
|
|
|
534 |
# If format is 0, it might nevertheless be a hidden format 1
|
|
|
535 |
if ( "${format}" == "0" ) then
|
|
|
536 |
set ncol = `awk "{print NF}" ${startf} | tail -1`
|
|
|
537 |
if ( "${ncol}" != "3" ) then
|
|
|
538 |
set format = "1"
|
|
|
539 |
echo " WARNING: ${startf} is a hidden trajectory file of format 1"
|
|
|
540 |
echo " it will be renamed: ${startf} -> ${startf}.1"
|
|
|
541 |
echo
|
|
|
542 |
ln -sf ${startf} ${startf}.1
|
|
|
543 |
set startf = "${startf}.1"
|
|
|
544 |
endif
|
|
|
545 |
endif
|
|
|
546 |
|
|
|
547 |
# Get the number of trajectories
|
|
|
548 |
if ( "${format}" == "0" ) then
|
|
|
549 |
set ntra = `wc -l ${startf} | awk '{print $1}' `
|
|
|
550 |
set ncol = 3
|
|
|
551 |
else
|
|
|
552 |
set ntra = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntra`
|
|
|
553 |
set ncol = `${LAGRANTO}/goodies/trainfo.sh ${startf} ncol`
|
|
|
554 |
set ntim = `${LAGRANTO}/goodies/trainfo.sh ${startf} ntim`
|
|
|
555 |
|
|
|
556 |
if ( "${ntim}" != "1" ) then
|
|
|
557 |
echo " ERROR: starting trajectory file must only have one time... Stop"
|
|
|
558 |
exit 1
|
|
|
559 |
endif
|
|
|
560 |
|
|
|
561 |
endif
|
|
|
562 |
|
|
|
563 |
# Write status information
|
|
|
564 |
echo "Start file : ${startf} "
|
|
|
565 |
if ( "${format}" == "0" ) then
|
|
|
566 |
echo "Format : (x,y,z) list"
|
|
|
567 |
else
|
|
|
568 |
echo "Format : trajectory file (${format})"
|
|
|
569 |
endif
|
|
|
570 |
echo "# coordinates (lon,lat,lev) : ${ntra} "
|
|
|
571 |
echo "# columns : ${ncol} "
|
|
|
572 |
|
|
|
573 |
# ---------------------------------------------------------------------
|
|
|
574 |
# Prepare input file for caltra and run it
|
|
|
575 |
# ---------------------------------------------------------------------
|
|
|
576 |
|
|
|
577 |
# Split the reference date
|
|
|
578 |
set yyyy=`echo ${refdate} | cut -c 1-4`
|
|
|
579 |
set mm=`echo ${refdate} | cut -c 5-6`
|
|
|
580 |
set dd=`echo ${refdate} | cut -c 7-8`
|
|
|
581 |
set hh=`echo ${refdate} | cut -c 10-11`
|
|
|
582 |
set min=`echo ${refdate}00 | cut -c 12-13`
|
|
|
583 |
|
|
|
584 |
# Get the total tiem range
|
|
|
585 |
if ( ${timediff_mm} != '' ) then
|
|
|
586 |
@ timerange = 60 * ${timediff_hh} + ${timediff_mm}
|
|
|
587 |
else
|
|
|
588 |
@ timerange = 60 * ${timediff_hh}
|
|
|
589 |
endif
|
|
|
590 |
|
|
|
591 |
# Write parameter file
|
|
|
592 |
\rm -f ${parfile}
|
|
|
593 |
touch ${parfile}
|
|
|
594 |
|
|
|
595 |
\echo $idir >> $parfile
|
|
|
596 |
echo $numfiles >> $parfile
|
|
|
597 |
foreach i ( $datfiles )
|
|
|
598 |
echo $i >> $parfile
|
|
|
599 |
end
|
|
|
600 |
echo $timeinc >> $parfile
|
|
|
601 |
echo $flag_p >> $parfile
|
|
|
602 |
echo \"${startf}\" >> $parfile
|
|
|
603 |
echo ${ntra} >> $parfile
|
|
|
604 |
echo ${ncol} >> $parfile
|
|
|
605 |
echo \"${outfile}\" >> $parfile
|
|
|
606 |
echo $timestep >> $parfile
|
|
|
607 |
echo $tstart >> $parfile
|
|
|
608 |
echo $tend >> $parfile
|
|
|
609 |
echo $deltout >> $parfile
|
|
|
610 |
echo $flag_j >> $parfile
|
|
|
611 |
echo $wfactor >> $parfile
|
|
|
612 |
echo $yyyy >> $parfile
|
|
|
613 |
echo $mm >> $parfile
|
|
|
614 |
echo $dd >> $parfile
|
|
|
615 |
echo $hh >> $parfile
|
|
|
616 |
echo $min >> $parfile
|
|
|
617 |
echo $timerange >> $parfile
|
|
|
618 |
echo \"${timecheck}\" >> $parfile
|
21 |
michaesp |
619 |
echo ${flag_agl} >> $parfile
|
|
|
620 |
echo ${flag_isen} >> $parfile
|
2 |
michaesp |
621 |
|
|
|
622 |
# Finish the preprocessor
|
|
|
623 |
echo
|
|
|
624 |
echo ' *** END OF PREPROCESSOR CALTRA *** '
|
|
|
625 |
echo '========================================================='
|
|
|
626 |
echo
|
|
|
627 |
|
|
|
628 |
# Run caltra
|
|
|
629 |
${LAGRANTO}/caltra/caltra
|
|
|
630 |
|
|
|
631 |
if ( "${status}" != "0" ) then
|
|
|
632 |
echo "ERROR: Program <caltra> failed"
|
|
|
633 |
exit 1
|
|
|
634 |
endif
|
|
|
635 |
|
|
|
636 |
# ----------------------------------------------------------
|
|
|
637 |
# Final tasks (make clean)
|
|
|
638 |
# ----------------------------------------------------------
|
|
|
639 |
|
|
|
640 |
finish:
|
|
|
641 |
|
|
|
642 |
if ( "${noclean}" == "false" ) then
|
|
|
643 |
\rm -f ${parfile}
|
|
|
644 |
endif
|
|
|
645 |
|
|
|
646 |
exit 0
|
|
|
647 |
|