#!/bin/sh

if [ "$1" == "" ] ; then
  echo "Usage: obloha.sh YYYYMMDD_HHMM"
  exit
fi

DATE=$1

DATETIME=`echo $DATE | awk '{ print substr($0,1,4) "/" substr($0,5,2) "/" substr($0,7,2) " " substr($0,10,2) ":" substr($0,12,2) ":00"}'`
OBS=HK

echo "$DATETIME UT"

./comets.sh

for F in YBS Messier other comets; do
  echo -e "$DATETIME\n$OBS\n\n$F.edb" > eq2az.in
  ./eq2az < eq2az.in > $F"_"DATE.edb
  ./edb2mp < $F"_"DATE.edb > $F"_"DATE.mp
done

cd milkyway
for F in 1 2 ; do
  ./dat2plt.awk < mw_ol$F.dat > $F.dat
  echo -e "$DATETIME\n$OBS\n\n$F.dat" > eq2az.in
  ./eq2az2 < eq2az.in | ./dat2mp.awk > mw"$F"_DATE.mp
done
cd ..

mpost obloha_$DATE
mptopdf obloha_$DATE.1

if [ -e obloha_$DATE.tex ] ; then
  csplain obloha_$DATE
  dvips -t landscape -o obloha_$DATE.ps obloha_$DATE.dvi
fi

echo "\\input epsf\\nopagenumbers\\epsfbox{obloha_$DATE.1}\\end" > tmp.tex
csplain tmp
dvips -E -t landscape -o obloha_$DATE.eps tmp.dvi
./pstogif obloha_$DATE.eps
./pstopcx obloha_$DATE.eps
rm tmp.*

