#!/bin/bash

gen_plot_3d()
{ 
    TITLE="${1}"
    shift 1
    
    printf "set title \"%s\"; " "${TITLE}"
    printf "set xlabel \"a_1\"; "
    printf "set ylabel \"a_2\"; "
    printf "set zlabel \"z(a_1, a_2)\"; "
    printf "set terminal postscript landscape enhanced color; "
    printf "splot [0:2*pi] [0:2*pi] [0:1]"
    
    comma=""
    for i in $*; do
	F=`echo "${i}" | cut -d: -f1`
	T=`echo "${i}" | cut -d: -f2-`
	
	printf "${comma} \'${F}\' title \"${T}\" with lines linewidth 1";
	comma=",";
    done
    printf "\n"
}

gen_plot_2d()
{ 
    TITLE="${1}"
    shift 1
    
    YLABEL="${1}"
    shift 1
    
    printf "set title \"%s\"; " "${TITLE}"
    printf "set xlabel \"r_1\"; "
    printf "set ylabel \"%s\"; " "${YLABEL}"
    printf "set terminal postscript landscape enhanced color; "
    printf "plot "
    
    comma=""
    for i in $*; do
	F=`echo "${i}" | cut -d: -f1`
	T=`echo "${i}" | cut -d: -f2-`
	
	printf "${comma} \'${F}\' title \"${T}\" with lines linewidth 1";
	comma=",";
    done
    printf "\n"
}

gen_plot_3d \
"screen/ray intersection surface (hit: z = 1, miss: z = 0)" \
fast.txt:'z(a_1,a_2)' | gnuplot > fast.ps

gen_plot_2d \
"ray radius versus horizontal refresh frequency" \
"Hertz" \
plot_freq_2.xy:'frequency' | gnuplot > freq_2.ps

gen_plot_2d \
"ray radius versus RGB unit frequency" \
"Hertz" \
plot_freq_RGB.xy:'frequency' | gnuplot > freq_RGB.ps

gen_plot_2d \
"ray radius versus logical horizontal resolution" \
"pixels" \
plot_L2.xy:'resolution' | gnuplot > L2.ps

gen_plot_2d \
"ray radius versus logical vertical resolution" \
"pixels" \
plot_L1.xy:'resolution' | gnuplot > L1.ps

