#! /usr/bin/perl -w
# Xqt <.ccft file> 
#
#  Runs a stateless "theory" file by tablelookup, so that
#  "Xqt C.ccf" acts like executing the code file there, but
#  using the approximation in C.ccft
#
unless (defined($ARGV[0])) {
  die "A .ccft file must be given";
}
$ccf = $ARGV[0];
open(CCF, $ccf) || die "given file ",$ccf," not found";
chop($name = <CCF>);
if ($name !~ /^theory/) { 
  die "parameter file must be a `theory' file";
}
@option = split(" ",$name);
$name = $option[0]; 
$X = <STDIN>;  #read input
#should use binary search!
  while ($line = <CCF>) {
    @vals = split(" ",$line);
    if ($X >= $vals[0] && $X < $vals[1]) { #in this subdomain
        $Y = $X*$vals[2] + $vals[3];
        $T = $X*$vals[4] + $vals[5];
      print "$Y\n"; #functional value
      print STDERR "$T\n"; #run time
      exit(1); #normal exit
    }
  }
die "input ",$X," out of range for ",$name;
