/*
INPUT: mass_W, mass_S, density, activity, time_step, temp
OUTPUT: mass_W, mass_S, density, activity
*/
#include "mex.h"
#define printf mexPrintf
#include "RC_helper.h"
#include <iostream>
#include <string>
#include "RC_helper.cpp"
using namespace std;
void pipe(double &mass_W, double &mass_S, double &density, double &activity, string time_step, string temp)
{
/**************************************************************/
/************************ Code for GWB ************************/
/**************************************************************/
char* script1[] =
{
"reset",
"temperature = 7",
"swap e- for O2(aq)",
"swap CO2(g) for HCO3-",
"1 free kg H2O",
"13.05 pe",
".006 fugacity CO2(g)",
"balance on H+",
".1 mg/kg H+",
"230 mg/kg Cl-",
"200 mg/kg Ca++",
"243 mg/kg Mg++",
"27 mg/kg K+",
"447 mg/kg Fe++",
"2000 mg/kg SO4--",
"184 mg/kg Na+",
"react -999.999 gram of H2O",
"fix Eh",
"fix fugacity of CO2(g)",
"delxi = .0001 linear",
"step_increase = 1",
"go",
""
};
/**************************************************************/
/************************ Main Program ************************/
/**************************************************************/
char line1[200];
char discard[20];
char** command1;
Pipe pipe1("pipe1");
/* Interation Variable(s) */
int i;
/* Two copies of react are opened */
cout << "Open two copies of React." << endl;
OpenGwbApplic(pipe1, "\\Program Files (x86)\\Gwb\\react.exe");
/* This for loops sets one dimension of the two dimensional array that is formed from the
char pointers equal to the two pre-defined structures */
for (command1 = script1, i = 0; **command1; **command1 ? command1++ : 0, i++)
{
if (**command1){
SendCommand(pipe1, *command1);
}
}
/**************************************************************/
/********************** Remaining Masses **********************/
/**************************************************************/
/* The remaining mass of water is reported */
SendCommand(pipe1, "report Wmass H2O", line1, sizeof(line1));
ReceiveLine(pipe1, line1, sizeof(line1));
sscanf(line1, "%lg", &mass_W);
/* The density of the solution is reported */
SendCommand(pipe1, "report soln_density", line1, sizeof(line1));
ReceiveLine(pipe1, line1, sizeof(line1));
sscanf(line1, "%lg", &density);
/* The activity of the water is reported */
SendCommand(pipe1, "report Watact", line1, sizeof(line1));
ReceiveLine(pipe1, line1, sizeof(line1));
sscanf(line1, "%lg", &activity);
/* The mass of the solution is reported */
SendCommand(pipe1, "report soln_mass", line1, sizeof(line1));
ReceiveLine(pipe1, line1, sizeof(line1));
sscanf(line1, "%lg", mass_S);
/* The react programs are closed */
SendCommand(pipe1, "quit");
printf("press return to exit> ");
gets(discard);
/* The pertinent variables are returned */
return;
}
/* This is useless, but I don't know what to replace with it so and still account for the check done by the following function */
int main()
{
cout << "hello world" << endl;
return 0;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[])
{
if( main() )
mexErrMsgTxt("main returned non-zero value");
}