summaryrefslogtreecommitdiffstats
path: root/noise/modules/temp
blob: a11c37205ed82ce387791027c0598baff7ae63ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /bin/bash

temper=/krebs/temper/temper

main() {
  case "${1--K}" in
    (--help)
      echo "report temperature in K, °C, °R, or °F."
      exit
    ;;
    (-C|--celsius)    unit='Grad Zelsius'   ; formula='x - 273.15'       ;;
    (-F|--fahrenheit) unit='Grad Fahrenheit'; formula='x * 9/5 - 459.67' ;;
    (-R|--rankine)    unit='Grad Renkin'    ; formula='x * 9/5'          ;;
    (-K|--kelvin)     unit='Kelvin'         ; formula='x'                ;;
    (*)
      echo 'Error 1: you are made of stupid!'
      exit 23
    ;;
  esac
  if test -f $temper -a -x $temper; then
    espeak_inside `inside_temp "$formula"` $unit
  fi
  espeak_outside `outside_temp "$formula"` $unit
}

## temp [<formula with temperature as x>]
## Echo temperature in K.  If formula is given then return that result instead.
inside_temp() {
  echo "scale=2; x=`$temper` + 273.15; ${1-x}" | bc
}

outside_temp() {
  echo "scale=2; x=`dig +short txt outside.elwood.temp.citecs.de |
          sed 's/^"DEG \([0-9]\+\.[0-9]\+\)"$/\1/'
       ` + 273.15; ${1-x}" | bc
}

espeak_inside()  { echo Die Krebs-tempera-tur beträgt $@ | to_espeak; }
espeak_outside() { echo Die Außen-tempera-tur beträgt $@ | to_espeak; }

to_espeak() {
  sed '
    s/\(\.[0-9]\)0\+/\1/g
    s/\(\.[0-9]\)\([0-9]\)[0-9]*/ \1 \2 /;
    s/^-/minus /;
    s/\./ komma /;
  ' | tee $NOISE_linefeed
}

main "$@"