#!/bin/bash

if [ $# -lt 3 ]; then
  echo "USAGE: $0 [file] [col # for x] [col # for y] [col # for color]"
  echo "       (highlighted points)"
  exit 0
fi

file=$1
colx=$2
coly=$3
colc=$4
hlf1=$5
hlx1=$6
hly1=$7

echo "x=load('$file');"
echo "y=x(:,$coly);"
echo "c=x(:,$colc);"
echo "x=x(:,$colx);"

echo "bins=log2(max(c));"
echo "c=log2(c)/bins;"

if [[ -n "$hlf1" ]]; then
  echo "x1=load('$hlf1');"
  echo "y1=x1(:,$hly1);"
  echo "x1=x1(:,$hlx1);"
fi

echo "f=figure(1);"
echo "set(f,'visible','off');"

echo "hold off"
echo "plot(x(1),y(1),'.','color',hsv2rgb([c(1),1,1]),'markersize',3);"
echo "for i=2:length(x),"
echo "  hold on;"
echo "  plot(x(i),y(i),'.','color',hsv2rgb([c(i),1,1]),'markersize',3);"
echo "endfor;"

if [[ -n "$hlx1" ]] && [[ -n "$hly1" ]]; then
  echo "hold on"
  echo "plot(x1,y1,'ro','markersize',5);"
fi

echo "axis([0,rows(x),0,max(y)]);"

echo "H=113; W=9;"
echo "set(f,'PaperOrientation','landscape');"
echo "set(f,'PaperSize',[H,W]);"
echo "set(f,'PaperPosition',[0,0,H,W]);"
echo "ax=gca();"
echo "print(f,'${file}.${colx}.${coly}.${colc}.pdf','-dpdf');"
