#! /usr/bin/perl -w
# Xcomp [options for stateless/state]
#
#  Compares and plots the measured and calculated behavior of
#   a component-based system.
#
#  Uses a SystemCode file that has a built-in
#   loop, driven by an input series from here
#
#  Assumes that the SYN script has been run in the current directory 
#   so that "SystemCode" is available to execute and "system.scf"
#   has the name of the calculated file in its first line.
#   These are the functions compared.
#
#  Invokes either Xcompl for a stateless system, or Xcompt for
#    one with state/concurrency, passing each the full set of
#    arguments.
#

$allargs = "";
for ($n=0; defined($ARGV[$n]); $n++) {
  $allargs .= " $ARGV[$n]";
}

open(ST,"system.scf") or die "must have a system.scf file";
chop($lastheory = <ST>);
close(ST); 
open(TCCF,$lastheory) or die "A calculated ", $lastheory, " file must be present";
chop($line = <TCCF>);
#print "$line \n";  #debug
if ($line !~ /^theory/) {die "doesn't seem to be a theory file";}
@codes = split('\.',$lastheory);
if (defined($codes[1])) { #extension
  if ($codes[1] eq "ccf") { #stateless
    system "perl Xcompl $allargs";
  } else {
    system "perl Xcompt $allargs";
  }
}
