#!/bin/bash
date="$(date +%Y%m%dT%H%M%S)"
input="$HOME/tmp/carrier-chart-${date}.input"
plotd="$HOME/tmp/carrier-chart-${date}.data"
plotp="$HOME/tmp/carrier-chart-${date}.png"

wget  --http-user=admin --http-passwd=star-gate-2 \
      'http://62.93.174.65/data/jData_CarrierChart.html' \
      -O "$input" >/tmp/carrier-chart.log 2>&1
clisp -norc -ansi -q \
  -x "(with-open-file (in \"${input}\") 
        (with-open-file (out \"${plotd}\" 
                           :direction :output 
                           :if-does-not-exist :create 
                           :if-exists :supersede) 
          (loop for x from 0 by (/ 1130.0 264) 
                for y = (read in nil nil) 
                repeat 264
                do (format out \"~A ~A~%\" x (if (minusp y) 0 (* 0.25 y))))))" \
   >/tmp/carrier-chart.log 2>&1
/usr/bin/gnuplot -persist > "${plotp}" 2>/tmp/carrier-chart.log <<EOF
reset
set terminal png  small notransparent color 
set xrange [ 0.00000 : 1200.0000 ]
set yrange [ 0.00000 : 50.0000 ]
set label  "Carrier Chart" at 400, 47, 0 left norotate
set label  "Downstream" at 400, 45, 0 left norotate
set label  "Data Rate (kb/s)" at 4, 47, 0 left norotate
set label  "Frequency(kHz)" at 1010, 1, 0 left norotate
plot "${plotd}" notitle with lines 
EOF
echo "${plotp}"
