Strabon

view examples/teleios/instantiate.sh @ 866:c94a157459eb

minor changes to README file
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Jan 23 16:04:16 2013 +0200 (2013-01-23)
parents 9723ad99e922
children
line source
1 #!/bin/bash
3 #
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 #
8 # Copyright (C) 2010, 2011, 2012, Pyravlos Team
9 #
10 # http://www.strabon.di.uoa.gr/
11 #
13 #
14 # Script for instantiating NOA refinement queries.
15 #
16 # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
17 #
19 # command name
20 CMD="$(basename ${0})"
22 # absolute directory name of this command
23 LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25 function help() {
26 echo "Usage: ${CMD} [OPTIONS] QUERY_FILE..."
27 echo
28 echo "Script for instantiating NOA refinement queries."
29 echo
30 echo "OPTIONS can be any of the following (variable names and values are case sensitive)"
31 echo " -s, --sensor : the sensor to use, e.g., \`MSG1' or \`MSG2'"
32 echo " (determines the value for satellite, template variable \`SAT'"
33 echo " and number of acquisitions in an hour, template variable"
34 echo " \`ACQUISITIONS_IN_HALF_AN_HOUR')"
35 echo " -c, --chain : the processing chain to use, e.g., \`DynamicThresholds'"
36 echo " -t, --timestamp : the timestamp to use, e.g., \`2010-08-21T19:50:00'"
37 echo " -m, --min_acq_time : the minimum acquisition time (used in a persistence query only)"
38 echo " -M, --max_acq_time : the maximum acquisition time (used in a discovery query only)"
39 echo " -p, --persistence : "
40 echo " -r, --repeat_in_persistence : "
41 echo
42 echo "Example run:"
43 echo " ./instantiate.sh -s MSG1 -t '2010-08-21T19:50:00' -c "DynamicThresholds" -m '2010-08-21T19:50:00' -M '2010-08-21T19:50:00' *.rq"
44 }
46 SENSOR=
47 CHAIN=
48 SAT=
49 N_ACQUISITIONS=
50 N_ACQUISITIONS_PER_HOUR=
51 TIMESTAMP=
52 MIN_ACQ_TIME=
53 MAX_ACQ_TIME=
54 PERSISTENCE=
55 REPEAT_IN_PERS=
57 if test $# -eq 0; then
58 help
59 exit 1
60 fi
62 # read script options
63 while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
64 case "${1}" in
65 -h|--help)
66 help
67 exit 0
68 ;;
69 -s|--sensor)
70 shift
71 SENSOR="${1}"
73 # determine satellite and number of acquisitions per hour
74 if test "${SENSOR}" = "MSG2"; then
75 SAT="METEOSAT9"
76 N_ACQUISITIONS=3.0
77 N_ACQUISITIONS_PER_HOUR=5.0
78 else
79 SAT="METEOSAT8"
80 N_ACQUISITIONS=7.0
81 N_ACQUISITIONS_PER_HOUR=13.0
83 # change MSG1 to MSG1_RSS (for whatever reason NOA uses it :-))
84 SENSOR="MSG1_RSS"
85 fi
86 shift
87 ;;
88 -c|--chain)
89 shift
90 CHAIN="${1}"
91 shift
92 ;;
93 -t|--timestamp)
94 shift
95 TIMESTAMP="${1}"
96 shift
97 ;;
98 -m|--min_acq_time)
99 shift
100 MIN_ACQ_TIME="${1}"
101 shift
102 ;;
103 -M|--max_acq_time)
104 shift
105 MAX_ACQ_TIME="${1}"
106 shift
107 ;;
108 -p|--persistence)
109 shift
110 PERSISTENCE="${1}"
111 shift
112 ;;
113 -r|--repeat_in_persistence)
114 shift
115 REPEAT_IN_PERS="${1}"
116 shift
117 ;;
118 -*)
119 echo "${CMD}: unknown option \"${1}\""
120 help
121 exit 1
122 ;;
123 esac
124 done
126 # build sed expression
127 ARGS=
129 if test ! -z "${CHAIN}"; then
130 ARGS="${ARGS} -e 's/PROCESSING_CHAIN/${CHAIN}/g'"
131 fi
133 if test ! -z "${SENSOR}"; then
134 ARGS="${ARGS} -e 's/SENSOR/${SENSOR}/g'"
135 fi
137 if test ! -z "${SAT}"; then
138 ARGS="${ARGS} -e 's/SAT/${SAT}/g'"
139 fi
141 if test ! -z "${N_ACQUISITIONS}"; then
142 ARGS="${ARGS} -e 's/ACQUISITIONS_IN_HALF_AN_HOUR/${N_ACQUISITIONS}/g'"
143 fi
145 if test ! -z "${N_ACQUISITIONS_PER_HOUR}"; then
146 ARGS="${ARGS} -e 's/ACQUISITIONS_IN_AN_HOUR/${N_ACQUISITIONS_PER_HOUR}/g'"
147 fi
149 if test ! -z "${TIMESTAMP}"; then
150 ARGS="${ARGS} -e 's/TIMESTAMP/${TIMESTAMP}/g'"
151 fi
153 if test ! -z "${MIN_ACQ_TIME}"; then
154 ARGS="${ARGS} -e 's/MIN_ACQUISITION_TIME/${MIN_ACQ_TIME}/g'"
155 fi
157 if test ! -z "${MAX_ACQ_TIME}"; then
158 ARGS="${ARGS} -e 's/MAX_ACQUISITION_TIME/${MAX_ACQ_TIME}/g'"
159 fi
161 if test ! -z "${PERSISTENCE}"; then
162 ARGS="${ARGS} -e 's/PERSISTENCE/${PERSISTENCE}/g'"
163 fi
165 if test ! -z "${REPEAT_IN_PERS}"; then
166 ARGS="${ARGS} -e 's/REPEAT_IN_PERS/${REPEAT_IN_PERS}/g'"
167 fi
169 if test -z "${ARGS}"; then
170 echo "${CMD}: You would be so kind to provide at least one OPTION."
171 help
172 exit 2
173 fi
175 QUERY="`eval sed ${ARGS} ${@}`"
176 #echo "$QUERY"
177 #echo eval sed ${ARGS} ${@}
179 # check for unbounded variables
180 GREP_RESULT=`echo "${QUERY}" | egrep -o 'PROCESSING_CHAIN|SENSOR|"SAT"|ACQUISITIONS_IN_HALF_AN_HOUR|TIMESTAMP|MIN_ACQUISITION_TIME|MAX_ACQUISITION_TIME|PERSISTENCE|REPEAT_IN_PERS'`
182 if ! test $? -eq 0; then
183 echo "${QUERY}"
184 else
185 echo -e "${CMD}: WARNING: found unbounded variables "$(echo "${GREP_RESULT}"|sort -u)""
186 echo
187 help
188 fi