7 |
michaesp |
1 |
#!/bin/csh
|
|
|
2 |
|
|
|
3 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
4 |
# Usage and parameter handling
|
|
|
5 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
6 |
|
|
|
7 |
# Write usage information
|
|
|
8 |
if ( ${#argv} == 0 ) then
|
|
|
9 |
echo
|
|
|
10 |
echo "-----------------------------------------------------------------------------------------------------------"
|
|
|
11 |
echo "Usage: startf <date> <ofile> <specifier> [ -t tvfile ] [ -changet ] [-noclean]"
|
|
|
12 |
echo
|
|
|
13 |
echo " date : Date of input P and S file (e.g. 20100101_00)"
|
|
|
14 |
echo " ofile : Output file with start points (e.g. startf)"
|
|
|
15 |
echo " tvfile : Tracing file with variables for selection criteria "
|
|
|
16 |
echo " changet : Flag whether to change times on P,S files before calculation"
|
|
|
17 |
echo " clean : Flag whether to remove temporary files"
|
|
|
18 |
echo " specifier : Detailed description of starting positions"
|
|
|
19 |
echo
|
|
|
20 |
echo "The specification <specifier> is of the form:"
|
|
|
21 |
echo
|
|
|
22 |
echo " <specifier> = <horizontal> @ <vertical> @ <unit> @ <selection>"
|
|
|
23 |
echo
|
|
|
24 |
echo " <horizontal> = file[filename] : Read lat/lon from file"
|
|
|
25 |
echo " line[lon1,lon2,lat1,lat2,n] : n points from (lon1,la1) to (lon2,lat2)"
|
|
|
26 |
echo " box.eqd[lon1,lon2,lat1,lat2,ds] : lat/lon box with equdistant points (ds in [km])"
|
|
|
27 |
echo " box.grid[lon1,lon2,lat1,lat2,] : lat/lon box with grid points"
|
|
|
28 |
echo " point[lon,lat] : Single lon/lat point"
|
|
|
29 |
echo " shift[lon,lat,dlon,dlat] : lon/at points and dlon/dlat shifhted ones"
|
|
|
30 |
echo " polygon.eqd[filename,ds] : Equidistant within arbirtrary polygon (ds in [km])"
|
|
|
31 |
echo " polygon.grid[filename] : Grid points within arbirtrary polygon"
|
|
|
32 |
echo
|
|
|
33 |
echo " Polygon file is of the format : lat/lon within polygon"
|
|
|
34 |
echo " lat1,lon1"
|
|
|
35 |
echo " lat2,lon2"
|
|
|
36 |
echo " ..."
|
|
|
37 |
echo
|
|
|
38 |
echo " <vertical> = file[filename] : Read lev from file"
|
|
|
39 |
echo " = level[lev] : Start from single level"
|
|
|
40 |
echo " = list[l1v1,lev2,lev3,...] : List of levels"
|
|
|
41 |
echo " = profile[lev1,lev2,n] : n equdistant levels betwenn lev1 and lev2"
|
|
|
42 |
echo
|
|
|
43 |
echo " <unit> = hPa : Pressure [hPa]"
|
|
|
44 |
echo " = hPa,agl : Pressure above ground [hPa]"
|
|
|
45 |
echo " = K : Isentropic level [K]"
|
|
|
46 |
echo " = PVU : PV surface [PVU]"
|
|
|
47 |
echo
|
|
|
48 |
echo " <selection> = same syntax as for the programme <select>"
|
|
|
49 |
echo
|
|
|
50 |
echo " If <vertical=nil>, then <horizontal> must be equal to <file> and all lat/lon/lev coordinates are"
|
|
|
51 |
echo " read from a file. "
|
|
|
52 |
echo
|
|
|
53 |
echo " Example: 'box.eqd[10,30,30,70,50] @ profile[100,500,10] @ hPa @ GT:PV:2'"
|
|
|
54 |
echo "------------------------------------------------------------------------------------------------------------"
|
|
|
55 |
exit 1
|
|
|
56 |
endif
|
|
|
57 |
|
|
|
58 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
59 |
# Handle input parameters
|
|
|
60 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
61 |
|
|
|
62 |
# Prefix of primary and secondary file; and set the filenames
|
|
|
63 |
set charp='P'
|
|
|
64 |
set chars='S'
|
|
|
65 |
|
|
|
66 |
# Write title
|
|
|
67 |
echo
|
|
|
68 |
echo '========================================================='
|
|
|
69 |
echo ' *** START OF PREPROCESSOR STARTF *** '
|
|
|
70 |
echo
|
|
|
71 |
|
|
|
72 |
# Extract arguments and split reference date
|
|
|
73 |
set refdate = $1
|
|
|
74 |
set ofile = $2
|
|
|
75 |
set specifier = `echo $3`
|
|
|
76 |
shift
|
|
|
77 |
shift
|
|
|
78 |
shift
|
|
|
79 |
|
|
|
80 |
# Check whether specifier is a file or whether it is explicitly written
|
|
|
81 |
set flag_criterion = 'file'
|
|
|
82 |
set test = `echo ${specifier} | grep '@' | wc -c`
|
|
|
83 |
if ( "${test}" != "0" ) then
|
|
|
84 |
set flag_criterion = 'criterion'
|
|
|
85 |
endif
|
|
|
86 |
|
|
|
87 |
# Get the criterion from the file
|
|
|
88 |
if ( "${flag_criterion}" == "file" ) then
|
|
|
89 |
if ( -f ${specifier} ) then
|
|
|
90 |
set filename = ${specifier}
|
|
|
91 |
set specifier = `cat ${specifier}`
|
|
|
92 |
else
|
|
|
93 |
echo " ERROR: cannot read criterion from file ${specifier}... Stop"
|
|
|
94 |
exit 1
|
|
|
95 |
endif
|
|
|
96 |
endif
|
|
|
97 |
|
|
|
98 |
echo "---- INPUT PARAMETERS ----------------------------------"
|
|
|
99 |
echo
|
|
|
100 |
echo "Reference date : ${refdate}"
|
|
|
101 |
if ( "${flag_criterion}" == "criterion" ) then
|
|
|
102 |
echo "Specifier : ${specifier}"
|
|
|
103 |
else
|
|
|
104 |
echo "Specifier : ${specifier} [from file ${filename}]"
|
|
|
105 |
endif
|
|
|
106 |
echo "Output file : ${ofile}"
|
|
|
107 |
echo
|
|
|
108 |
|
|
|
109 |
# Handle optional arguments
|
|
|
110 |
set tvfile = 'tracevars'
|
|
|
111 |
set changet = 'false'
|
|
|
112 |
set noclean = 'false'
|
|
|
113 |
set regionf = 'regionf'
|
|
|
114 |
set timecheck = 'no'
|
|
|
115 |
|
|
|
116 |
while ( $#argv > 0 )
|
|
|
117 |
|
|
|
118 |
switch ( $argv[1] )
|
|
|
119 |
|
|
|
120 |
case -t
|
|
|
121 |
set tvfile = $argv[2]
|
|
|
122 |
echo "tvfile -> ${tvfile} (user defined)"
|
|
|
123 |
shift;
|
|
|
124 |
breaksw
|
|
|
125 |
|
|
|
126 |
case -changet
|
|
|
127 |
set changet = 'true'
|
|
|
128 |
echo "changet -> true (user defined)"
|
|
|
129 |
breaksw
|
|
|
130 |
|
|
|
131 |
case -noclean
|
|
|
132 |
set noclean = 'true'
|
|
|
133 |
echo "noclean -> true (user defined)"
|
|
|
134 |
breaksw
|
|
|
135 |
|
|
|
136 |
case -notimecheck
|
|
|
137 |
set timecheck = 'no'
|
|
|
138 |
echo "timecheck -> no (user defined)"
|
|
|
139 |
breaksw
|
|
|
140 |
|
|
|
141 |
case -regionf
|
|
|
142 |
set regionf = $argv[2]
|
|
|
143 |
echo "regionf -> ${regionf} (user defined)"
|
|
|
144 |
shift;
|
|
|
145 |
breaksw
|
|
|
146 |
|
|
|
147 |
endsw
|
|
|
148 |
|
|
|
149 |
shift;
|
|
|
150 |
|
|
|
151 |
end
|
|
|
152 |
|
|
|
153 |
# No change of times necessary if no check requested
|
|
|
154 |
if ( "${timecheck}" == "no" ) then
|
|
|
155 |
set changet = 'false'
|
|
|
156 |
endif
|
|
|
157 |
|
|
|
158 |
# Split the reference date
|
|
|
159 |
set yyyy=`echo ${refdate} | cut -c 1-4`
|
|
|
160 |
set mm=`echo ${refdate} | cut -c 5-6`
|
|
|
161 |
set dd=`echo ${refdate} | cut -c 7-8`
|
|
|
162 |
set hh=`echo ${refdate} | cut -c 10-11`
|
|
|
163 |
set min=`echo ${refdate}00 | cut -c 12-13`
|
|
|
164 |
|
|
|
165 |
# Set base directories (run+prog)
|
|
|
166 |
set tradir=${PWD}
|
|
|
167 |
|
|
|
168 |
# Set program paths and filenames
|
|
|
169 |
set parfile=${tradir}/startf.param
|
|
|
170 |
set crifile=${tradir}/startf.criterion
|
|
|
171 |
|
|
|
172 |
# Decide whether a tracing and selection is necessary
|
|
|
173 |
# If so, some intermediate file are writen (in Fortran binary)
|
|
|
174 |
set flag_criterion = `${LAGRANTO}/startf/startf.perl "${specifier}" | tail -1`
|
|
|
175 |
if ( "${flag_criterion}" != "nil" ) then
|
|
|
176 |
set format1 = ".3"
|
|
|
177 |
set format2 = ".3"
|
|
|
178 |
else
|
|
|
179 |
set format1 = ""
|
|
|
180 |
set format2 = ""
|
|
|
181 |
endif
|
|
|
182 |
|
|
|
183 |
# Write status information
|
|
|
184 |
echo
|
|
|
185 |
echo '---- DIRECTORIES AND PROGRAMS ---------------------------'
|
|
|
186 |
echo
|
|
|
187 |
echo "PROGRAM CREATE_STARTF : ${LAGRANTO}/startf/startf"
|
|
|
188 |
echo "PARAMETER file : ${parfile}"
|
|
|
189 |
echo "CRITERION file : ${crifile}"
|
|
|
190 |
echo "RUN directory : ${tradir}"
|
|
|
191 |
echo
|
|
|
192 |
|
|
|
193 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
194 |
# Set the primary and secondary data files (necessary for interpolation if intermediate reference date)
|
|
|
195 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
196 |
|
|
|
197 |
# Find a first data file (if possible corresponding to reference date) -> <file>
|
|
|
198 |
set file=${charp}${yyyy}${mm}${dd}_${hh}
|
|
|
199 |
if ( ( -f ${file} ) && ( ${min} == 0 ) ) then
|
|
|
200 |
set timeshift=0
|
|
|
201 |
set date0=${yyyy}${mm}${dd}_${hh}
|
|
|
202 |
set date1=${yyyy}${mm}${dd}_${hh}
|
|
|
203 |
set pfile0=${file}
|
|
|
204 |
set pfile1=${file}
|
|
|
205 |
goto label3
|
|
|
206 |
else
|
|
|
207 |
set file=`ls ${charp}[0-9_]*[0-9] | head -1 | sed -e 's/@//'`
|
|
|
208 |
endif
|
|
|
209 |
|
|
|
210 |
# Determine time increment (in hours) between data files -> <timeinc>
|
|
|
211 |
set date1=`echo $file | cut -c 2-`
|
|
|
212 |
set n=`ls ${charp}[0-9_]*[0-9] | grep -n $date1 | awk -F: '{print $1}'`
|
|
|
213 |
@ n ++
|
|
|
214 |
set date2=`ls ${charp}[0-9_]*[0-9] | head -$n | tail -1 | cut -c 2-`
|
|
|
215 |
set timeinc=`${LAGRANTO}/goodies/gettidiff $date2 $date1`
|
|
|
216 |
if ( $timeinc == 0 ) then
|
|
|
217 |
echo " ERROR: cannot set the time increment between input files ***"
|
|
|
218 |
exit 1
|
|
|
219 |
endif
|
|
|
220 |
|
|
|
221 |
# Decide whether the time increment is smaller than 1 h; if so set the hires
|
|
|
222 |
# flag and convert the time increment into fractional hour
|
|
|
223 |
set flag = `echo ${timeinc} | grep -n '\.'`
|
|
|
224 |
set hires = 0
|
|
|
225 |
|
|
|
226 |
if ( "${flag}" != "" ) then
|
|
|
227 |
echo "Input files availability < 1 hour ($timeinc): switch to hires"
|
|
|
228 |
echo "mode. All input files must be of form: P{yyyymmdd_hhmm}"
|
|
|
229 |
set hires = 1
|
|
|
230 |
set timeinc_min = `echo "(${timeinc} * 100 + 0.5)/1" | bc`
|
|
|
231 |
set timeinc = `echo "scale=2; ${timeinc} * 100 / 60" | bc`
|
|
|
232 |
goto hires
|
|
|
233 |
endif
|
|
|
234 |
|
|
|
235 |
# Search the first file to use
|
|
|
236 |
set timeshift=
|
|
|
237 |
foreach i ( ${charp}????????_?? )
|
|
|
238 |
|
|
|
239 |
set date0 = `echo $i | cut -c 2-12`
|
|
|
240 |
set td1 = `${LAGRANTO}/goodies/gettidiff ${yyyy}${mm}${dd}_${hh} ${date0}`
|
|
|
241 |
|
|
|
242 |
if ( ( $td1 >= 0 ) && ( $td1 < $timeinc ) ) then
|
|
|
243 |
set timeshift=$td1
|
|
|
244 |
set pfile0=${charp}${date0}
|
|
|
245 |
goto label2
|
|
|
246 |
endif
|
|
|
247 |
|
|
|
248 |
end
|
|
|
249 |
|
|
|
250 |
# Check if no P files are available for the specified time period
|
|
|
251 |
if ( $timeshift == "" ) then
|
|
|
252 |
echo " ERROR: no data files available for the specified reference date"
|
|
|
253 |
exit 1
|
|
|
254 |
endif
|
|
|
255 |
|
|
|
256 |
# If the input files come with time increment < 1 hour, handle it in this
|
|
|
257 |
# special section. The aim is not to 'interfere' with the well established
|
|
|
258 |
# code handling the standard case with time increment >= 1 hour. In this mode
|
|
|
259 |
# we require that the start and end date are available as P files: no start is
|
|
|
260 |
# allowed between the model output files
|
|
|
261 |
hires:
|
|
|
262 |
|
|
|
263 |
set flag = "nil"
|
|
|
264 |
set td = 0
|
|
|
265 |
|
|
|
266 |
set timeshift = 0
|
|
|
267 |
set date0 = ${yyyy}${mm}${dd}_${hh}${min}
|
|
|
268 |
set date1 = `${LAGRANTO}/goodies/newtime ${date0} ${timeinc_min}`
|
|
|
269 |
|
|
|
270 |
set pfile0 = ${charp}${date0}
|
|
|
271 |
set pfile1 = ${charp}${date1}
|
|
|
272 |
|
|
|
273 |
if ( ! -f ${pfile0} ) then
|
|
|
274 |
echo
|
|
|
275 |
echo " ERROR: no data files available for the specified time period (hires,$date0)"
|
|
|
276 |
exit 1
|
|
|
277 |
endif
|
|
|
278 |
if ( ! -f ${pfile1} ) then
|
|
|
279 |
echo
|
|
|
280 |
echo " ERROR: no data files available for the specified time period (hires,$date1)"
|
|
|
281 |
exit 1
|
|
|
282 |
endif
|
|
|
283 |
|
|
|
284 |
goto label3
|
|
|
285 |
|
|
|
286 |
# Everything is fine so far: proceed
|
|
|
287 |
label2:
|
|
|
288 |
|
|
|
289 |
# Set the next date and check its availability
|
|
|
290 |
if ( ( ${timeshift} != 00 ) || ( ${min} > 0 ) ) then
|
|
|
291 |
set date1=`${LAGRANTO}/goodies/newtime $date0 $timeinc`
|
|
|
292 |
if ( ! -f ${charp}${date1} ) then
|
|
|
293 |
echo " ERROR: file with primary data is missing for $date"
|
|
|
294 |
exit 1
|
|
|
295 |
else
|
|
|
296 |
set pfile1=${charp}${date1}
|
|
|
297 |
endif
|
|
|
298 |
else
|
|
|
299 |
set date1=${date0}
|
|
|
300 |
set pfile1=${pfile0}
|
|
|
301 |
endif
|
|
|
302 |
|
|
|
303 |
# Set the final timeshift
|
|
|
304 |
if ( ${min} != 00 ) then
|
|
|
305 |
set timeshift=${timeshift}.${min}
|
|
|
306 |
endif
|
|
|
307 |
|
|
|
308 |
# Everything is fine!
|
|
|
309 |
label3:
|
|
|
310 |
|
|
|
311 |
# Set secondary files and check their availability
|
|
|
312 |
set sfile0=${chars}${date0}
|
|
|
313 |
set sfile1=${chars}${date1}
|
|
|
314 |
|
|
|
315 |
# Write status information
|
|
|
316 |
echo '---- DATA FILES -----------------------------------------'
|
|
|
317 |
echo
|
|
|
318 |
echo "Primary files : ${pfile0}"
|
|
|
319 |
echo " : ${pfile1}"
|
|
|
320 |
echo "Secondary files : ${sfile0}"
|
|
|
321 |
echo " : ${sfile1}"
|
|
|
322 |
echo "Timeshift to first data file (hh.mm) : ${timeshift}"
|
|
|
323 |
echo "Time increment of data files : ${timeinc}"
|
|
|
324 |
echo
|
|
|
325 |
|
|
|
326 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
327 |
# Create the start positions (without selection)
|
|
|
328 |
# -----------------------------------------------------------------------------------------------------------------
|
|
|
329 |
|
|
|
330 |
# Set times relative to the reference date
|
|
|
331 |
if ( "${changet}" == "true" ) then
|
|
|
332 |
echo '---- CHANGE TIMES ON DATA FILES ------------------------'
|
|
|
333 |
echo
|
|
|
334 |
${LAGRANTO}/goodies/changet.sh ${refdate} ${pfile0}
|
|
|
335 |
${LAGRANTO}/goodies/changet.sh ${refdate} ${pfile1}
|
|
|
336 |
if ( -f ${sfile0} ) then
|
|
|
337 |
${LAGRANTO}/goodies/changet.sh ${refdate} ${sfile0}
|
|
|
338 |
endif
|
|
|
339 |
if ( -f ${sfile1} ) then
|
|
|
340 |
${LAGRANTO}/goodies/changet.sh ${refdate} ${sfile1}
|
|
|
341 |
endif
|
|
|
342 |
endif
|
|
|
343 |
|
|
|
344 |
# Write parameters to parameter file and create the starting positions
|
|
|
345 |
\rm -f ${parfile}
|
|
|
346 |
echo \"${pfile0}\" \"${pfile1}\" >! ${parfile}
|
|
|
347 |
echo \"${sfile0}\" \"${sfile1}\" >> ${parfile}
|
|
|
348 |
echo \"${ofile}${format1}\" >> ${parfile}
|
|
|
349 |
echo \"${regionf}\" >> ${parfile}
|
|
|
350 |
echo ${yyyy} >> ${parfile}
|
|
|
351 |
echo ${mm} >> ${parfile}
|
|
|
352 |
echo ${dd} >> ${parfile}
|
|
|
353 |
echo ${hh} >> ${parfile}
|
|
|
354 |
echo ${min} >> ${parfile}
|
|
|
355 |
echo 00 >> ${parfile}
|
|
|
356 |
echo ${timeshift} >> ${parfile}
|
|
|
357 |
echo ${timeinc} >> ${parfile}
|
|
|
358 |
|
|
|
359 |
# Analyse the specifier and append to parameter file
|
|
|
360 |
${LAGRANTO}/startf/startf.perl "${specifier}" >> ${parfile}
|
|
|
361 |
|
|
|
362 |
if ( "${status}" != "0" ) then
|
|
|
363 |
echo "ERROR: Preprocessor <startf> failed"
|
|
|
364 |
exit 1
|
|
|
365 |
endif
|
|
|
366 |
|
|
|
367 |
# Write selection criterion to file
|
|
|
368 |
\rm -f ${crifile}
|
|
|
369 |
tail -1 ${parfile} >! ${crifile}
|
|
|
370 |
|
|
|
371 |
# Write flag for no time check
|
|
|
372 |
echo \"${timecheck}\" >> ${parfile}
|
|
|
373 |
|
|
|
374 |
# Write title
|
|
|
375 |
echo
|
|
|
376 |
echo ' *** END OF PREPROCESSOR STARTF ***'
|
|
|
377 |
echo '========================================================='
|
|
|
378 |
echo
|
|
|
379 |
|
|
|
380 |
# Create the startf
|
|
|
381 |
cd ${tradir}
|
|
|
382 |
${LAGRANTO}/startf/startf
|
|
|
383 |
|
|
|
384 |
if ( "${status}" != "0" ) then
|
|
|
385 |
echo "ERROR: Program <startf> failed"
|
|
|
386 |
exit 1
|
|
|
387 |
endif
|
|
|
388 |
|
|
|
389 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
390 |
# Apply selection (first tracing then selection)
|
|
|
391 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
392 |
|
|
|
393 |
# Stop if no tracing and selection is necessary
|
|
|
394 |
if ( "${flag_criterion}" == "nil" ) goto finish
|
|
|
395 |
|
|
|
396 |
# Tracing of extra variables
|
|
|
397 |
if ( -f ${ofile}${format2} ) then
|
|
|
398 |
\rm -f ${ofile}${format2}
|
|
|
399 |
endif
|
|
|
400 |
if ( "${timecheck}" == "no" ) then
|
|
|
401 |
${LAGRANTO}/trace/trace.sh ${ofile}${format1} ${ofile}${format2} -v ${tvfile} -notimecheck
|
|
|
402 |
else
|
|
|
403 |
${LAGRANTO}/trace/trace.sh ${ofile}${format1} ${ofile}${format2} -v ${tvfile}
|
|
|
404 |
endif
|
|
|
405 |
\rm -f ${ofile}${format1}
|
|
|
406 |
|
|
|
407 |
# Selection
|
|
|
408 |
if ( -f ${ofile} ) then
|
|
|
409 |
\rm -f ${ofile}
|
|
|
410 |
endif
|
|
|
411 |
${LAGRANTO}/select/select.sh ${ofile}${format2} ${ofile} `cat ${crifile}`
|
|
|
412 |
\rm -f ${ofile}${format2}
|
|
|
413 |
|
|
|
414 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
415 |
# Final tasks (make clean)
|
|
|
416 |
# --------------------------------------------------------------------------------------------------------------
|
|
|
417 |
|
|
|
418 |
finish:
|
|
|
419 |
|
|
|
420 |
echo $noclean
|
|
|
421 |
|
|
|
422 |
if ( "${noclean}" == "false" ) then
|
|
|
423 |
\rm -f ${crifile}
|
|
|
424 |
\rm -f ${parfile}
|
|
|
425 |
endif
|
|
|
426 |
|
|
|
427 |
exit 0
|
|
|
428 |
|
|
|
429 |
|
|
|
430 |
|