use warnings;
use strict;

use ChemPlugin;

$|=1;

print "ChemPlugin example -- pH titration\n\n";

# create the ChemPlugin instance
my $cp = new ChemPlugin('stdout');

# Configure the instance
$cp->Config('Ca++ = 1 mmol/kg; Na+ = 1 mmol/kg');
$cp->Config('Cl- = 3 mmol/kg; HCO3- = 2 mmol/kg; pH = 4');
$cp->Config('react 3 mmol/kg NaOH; delxi = 0.1');

# Initialize the instance.
$cp->Initialize();
my $Xi = $cp->Report1("Xi");
my $pH = $cp->Report1("pH");
printf(" Xi = %4.2f pH = %4.2f\n", $Xi, $pH);

my $deltat = 0;

while(1){
   $deltat = $cp->ReportTimeStep();
   if($cp->AdvanceTimeStep($deltat)){
      last; 
   }
   if($cp->AdvanceChemical()){
      last;
   }
   $Xi = $cp->Report("Xi");
   $pH = $cp->Report("pH");
   printf(" Xi = %4.2f pH = %4.2f\n", $Xi, $pH);
}

$cp->destroy();

