#!/usr/bin/env dvo

list filters
 green
 blue
 red
 indigo
 black
 gold
end

macro skyplot
  if ($0 != 3)
    echo "skyplot (input) (output)"
    break
  end

  data $1
  read r 1 d 2 f 3

  resize 1000 500
  region +ns -ew 0 0 85 ait; cgrid -ra-by-hour -c grey80

  set R = r * 180/3.14
  set D = d * 180/3.14

  for i 0 $filters:n
    subset R1 = R if (f == $i)
    subset D1 = D if (f == $i)
    if (R1[]) 
      cplot R1 D1 -sz 1.0 -pt 7 -c $filters:$i
    end
  end

  style -c red -pt 0 -sz 0.5; ecliptic
  style -c blue -pt 0 -sz 0.5; galactic

  png -name $2
end

macro galactic
 create l 720 -360 0.1
 set b = l * 0
 csystem G C l b
 cplot l b
end

macro ecliptic
 create l 720 -360 0.1
 set b = l * 0
 csystem E C l b
 cplot l b
end

if ($SCRIPT)
  $KAPA = kapa -noX
  if ($argv:n != 2)
    echo "USAGE: skyplot (input) (output)"
    exit 1
  end
  skyplot $argv:0 $argv:1
  exit 0
end
