function Extend1(varargin)
disp('ChemPlugin example -- extending a pH titration');
% Create a chemplugin instance
cp = ChemPlugin('Extend_stdout.txt');

% Configure the instance
Config(cp, 'Ca++ = 1 mmol/kg; Na+ = 1 mmol/kg');
Config(cp, 'Cl- = 3 mmol/kg; HCO3- = 2 mmol/kg; pH = 4');
Config(cp, 'react 3 mmol/kg NaOH; delxi = 0.1');

Initialize(cp, 1.0, 'hour');
fprintf('Xi = %f, pH = %f\n', Report1(cp, 'Xi'), Report1(cp, 'pH'));

while 1
    deltat = ReportTimeStep(cp);
    if AdvanceTimeStep(cp, deltat)
        break;
    end
    if AdvanceChemical(cp)
        break;
    end
    fprintf('Xi = %f, pH = %f\n', Report1(cp, 'Xi'), Report1(cp, 'pH'));
end


% Reconfigure and extend run
fprintf('Extending run to Xi = 2\n');
Config(cp, 'remove reactant NaOH');
Config(cp, 'react 3 mmol/kg HCl');
ExtendRun(cp, 1.0, 'hour');

while 1
    deltat = ReportTimeStep(cp);
    if AdvanceTimeStep(cp, deltat)
        break;
    end
    if AdvanceChemical(cp)
        break;
    end
    fprintf('Xi = %f, pH = %f\n', Report1(cp, 'Xi'), Report1(cp, 'pH'));
end
end
