Strabon

changeset 566:81ac0fc6733e

added instantiate.sh script under examples/teleios for instantiating NOA refinement queries
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Sep 27 19:57:02 2012 +0300 (2012-09-27)
parents 8251379cab30
children f0e942e210e0
files examples/teleios/instantiate.sh
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/teleios/instantiate.sh	Thu Sep 27 19:57:02 2012 +0300
     1.3 @@ -0,0 +1,148 @@
     1.4 +#!/bin/bash
     1.5 +
     1.6 +#
     1.7 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.8 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
    1.10 +#
    1.11 +# Copyright (C) 2010, 2011, 2012, Pyravlos Team
    1.12 +#
    1.13 +# http://www.strabon.di.uoa.gr/
    1.14 +#
    1.15 +
    1.16 +#
    1.17 +# Script for instantiating NOA refinement queries.
    1.18 +#
    1.19 +# Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
    1.20 +#
    1.21 +
    1.22 +# command name
    1.23 +CMD="$(basename ${0})"
    1.24 +
    1.25 +# absolute directory name of this command
    1.26 +LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
    1.27 +
    1.28 +function help() {
    1.29 +	echo "Usage: ${CMD} [OPTIONS] QUERY_FILE..."
    1.30 +	echo
    1.31 +	echo "Script for instantiating NOA refinement queries."
    1.32 +	echo
    1.33 +	echo "OPTIONS can be any of the following (variable names and values are case sensitive)"
    1.34 +	echo "	-s, --sensor		: the sensor to use, e.g., \`MSG1' or \`MSG2'"
    1.35 +	echo "				  (determines the value for satellite, template variable \`SAT'"
    1.36 +	echo "				   and number of acquisitions in an hour, template variable"
    1.37 +	echo "				   \`ACQUISITIONS_IN_HALF_AN_HOUR')"
    1.38 +	echo "	-c, --chain		: the processing chain to use, e.g., \`DynamicThresholds'"
    1.39 +	echo "	-t, --timestamp		: the timestamp to use, e.g., \`2010-08-21T19:50:00'"
    1.40 +	echo "	-m, --min_acq_time	: the minimum acquisition time (used in a persistence query only)"
    1.41 +	echo
    1.42 +	echo "Example run:"
    1.43 +	echo "	instantiate.sh -s MSG1 -t '2010-08-21T19:50:00' -c "DynamicThresholds" -m '2010-08-21T19:50:00' *.rq"
    1.44 +}
    1.45 +
    1.46 +SENSOR=
    1.47 +CHAIN=
    1.48 +SAT=
    1.49 +N_ACQUISITIONS=
    1.50 +TIMESTAMP=
    1.51 +MIN_ACQUISITIONS=
    1.52 +
    1.53 +if test $# -eq 0; then
    1.54 +	help
    1.55 +	exit 1
    1.56 +fi
    1.57 +
    1.58 +# read script options
    1.59 +while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
    1.60 +	case "${1}" in
    1.61 +		-h|--help)
    1.62 +			help
    1.63 +			exit 0
    1.64 +			;;
    1.65 +		-s|--sensor)
    1.66 +			shift
    1.67 +			SENSOR="${1}"
    1.68 +
    1.69 +			# determine satellite and number of acquisitions per hour
    1.70 +			if test "${SENSOR}" = "MSG2"; then
    1.71 +				SAT="METEOSAT9"
    1.72 +				N_ACQUISITIONS=3.0
    1.73 +			else
    1.74 +				SAT="METEOSAT8"
    1.75 +				N_ACQUISITIONS=7.0
    1.76 +
    1.77 +				# change MSG1 to MSG1_RSS (for whatever reason NOA uses it :-))
    1.78 +				SENSOR="MSG1_RSS"
    1.79 +			fi
    1.80 +			shift
    1.81 +			;;
    1.82 +		-c|--chain)
    1.83 +			shift
    1.84 +			CHAIN="${1}"
    1.85 +			shift
    1.86 +			;;
    1.87 +		-t|--timestamp)
    1.88 +			shift
    1.89 +			TIMESTAMP="${1}"
    1.90 +			shift
    1.91 +			;;
    1.92 +		-m|--min_acq_time)
    1.93 +			shift
    1.94 +			MIN_ACQ_TIME="${1}"
    1.95 +			shift
    1.96 +			;;
    1.97 +		-*)
    1.98 +			echo "${CMD}: unknown option \"${1}\""
    1.99 +			help
   1.100 +			exit 1
   1.101 +			;;
   1.102 +	esac
   1.103 +done
   1.104 +
   1.105 +# build sed expression
   1.106 +ARGS=
   1.107 +
   1.108 +if test ! -z "${CHAIN}"; then
   1.109 +	ARGS="${ARGS} -e 's/PROCESSING_CHAIN/${CHAIN}/g'"
   1.110 +fi
   1.111 +
   1.112 +if test ! -z "${SENSOR}"; then
   1.113 +	ARGS="${ARGS} -e 's/SENSOR/${SENSOR}/g'"
   1.114 +fi
   1.115 +
   1.116 +if test ! -z "${SAT}"; then
   1.117 +	ARGS="${ARGS} -e 's/SAT/${SAT}/g'"
   1.118 +fi
   1.119 +
   1.120 +if test ! -z "${N_ACQUISITIONS}"; then
   1.121 +	ARGS="${ARGS} -e 's/ACQUISITIONS_IN_HALF_AN_HOUR/${N_ACQUISITIONS}/g'"
   1.122 +fi
   1.123 +
   1.124 +if test ! -z "${TIMESTAMP}"; then
   1.125 +	ARGS="${ARGS} -e 's/TIMESTAMP/${TIMESTAMP}/g'"
   1.126 +fi
   1.127 +
   1.128 +if test ! -z "${MIN_ACQ_TIME}"; then
   1.129 +	ARGS="${ARGS} -e 's/MIN_ACQUISITION_TIME/${MIN_ACQ_TIME}/g'"
   1.130 +fi
   1.131 +
   1.132 +if test -z "${ARGS}"; then
   1.133 +	echo "${CMD}: You would be so kind to provide at least one OPTION."
   1.134 +	help
   1.135 +	exit 2
   1.136 +fi
   1.137 +
   1.138 +QUERY="`eval sed ${ARGS} ${@}`"
   1.139 +#echo "$QUERY"
   1.140 +#echo eval sed ${ARGS} ${@}
   1.141 +
   1.142 +# check for unbounded variables
   1.143 +GREP_RESULT=`echo "${QUERY}" | egrep -o 'PROCESSING_CHAIN|SENSOR|"SAT"|ACQUISITIONS_IN_HALF_AN_HOUR|TIMESTAMP|MIN_ACQUISITION_TIME'`
   1.144 +if ! test $? -eq 0; then
   1.145 +	echo "${QUERY}"
   1.146 +
   1.147 +else
   1.148 +	echo -e "${CMD}: WARNING: found unbounded variables "$(echo "${GREP_RESULT}"|sort -u)""
   1.149 +	echo
   1.150 +	help
   1.151 +fi