## Copyright (C) 2012, SRI International.  All Rights Reserved.

## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.


#$abs_path =  "~/SRI/teleolog/dimension-checker/examples/sldemo_househeat/ge/";
#$path =  "../examples/sldemo_househeat/ge/";
#$modelname = "sldemo_househeat";

#$abs_path =  "~/SRI/teleolog/dimension-checker/examples/cruise_ctrl/ge/";
#$path =  "../examples/cruise_ctrl/ge/";
#$modelname = "cruise_ctrl";

#$abs_path =  "~/SRI/teleolog/dimension-checker/examples/sldemo_clutch/ge/";
#$path =  "../examples/sldemo_clutch/ge/";
#$modelname = "sldemo_clutch_if";

#$abs_path =  "~/SRI/teleolog/dimension-checker/examples/sldemo_engine/ge/";
#$path =  "../examples/sldemo_engine/ge/";
#$modelname = "sldemo_enginewc";

#$abs_path =  "~/SRI/teleolog/dimension-checker/examples/prb/ge/";
#$path =  "../examples/prb/ge/";
#$modelname = "hybrid_analysis_prb2";

#$abs_path =  "~/SRI/teleolog/dimension-checker/examples/cd2d/ge/";
#$path = "../examples/cd2d/ge/";
#$modelname = "cd2d";



$file1 = join("", $path, $modelname, "_subsystems_ge");
print "Opening $file1 ..\n";
open(FH, $file1);
@lines = <FH>;
close(FH); 

$file2 = join("", $path, $modelname);
print "Opening $file2 ..\n";
open(FH2, $file2);
@lines2 = <FH2>;
$count = ($lines2[0] =~ tr/://) / 2;
close(FH);


$file2 = join("", $path, $modelname, "_run");
open(FH, ">$file2");

print FH ":reset\n\n";

$content = join("", "(load \"", $abs_path, "../../../src/GaussElim2", "\")\n\n");
#print FH "(load \"~/SRI/teleolog/dimension-checker/src/GaussElim.lisp\")\n\n";
print FH "$content";

$content = join("", "(init-state ", $count, ")");
print FH "$content\n\n";
foreach $line (@lines)
{
  $line =~ s/[\n]//g;
  $content = join("", "(time (load \"", $abs_path, $line, "\"))", "\n");
  print $content;
  print FH "$content";
}
close(FH);
