use warnings;
use strict;

use ChemPlugin;

$|=1;

print "mReact -- Use ChemPlugin to emulate React\n\n";

# Create a ChemPlugin instance and capture output messages
my $cp = new ChemPlugin("stdout");

#Use React's dedault setttings;write print and plot-format output
$cp->Config('delxi = 0.01; step_increase = 1.5; pluses = banner');
$cp->Config('print = on; plot = on');

print 'Enter React input script: ';
my $inputf = <STDIN>;
chomp $inputf;


# Process input line-by-line while watching for "go" statements
open(my $file, '<',  $inputf) || die("Could not open file '$inputf' $!");
while (my $line = <$file>){
   chomp $line;
   if(!($line =~ /go/)) {

      $cp->Config($line);
   }
   else{
      $cp->Initialize();
      while(1){
         my $deltat = $cp->ReportTimeStep();
         if($cp->AdvanceTimeStep($deltat)){
            exit;
         }
         if($cp->AdvanceHeatTransport()){
            exit;
         }
         if($cp->AdvanceChemical()){
            exit;
         }
      }
   }
}

