use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class ODESimData method readIn.
/**
* JMW : This really should be synchronized...
*/
public void readIn(DataInputStream input) throws IOException {
formatID = input.readUTF();
if (formatID.equals(SIMPLE_ODE_DATA_FORMAT_ID)) {
this.mathName = input.readUTF();
// read data from old format file
double saveInterval = input.readDouble();
int savedNumber = input.readInt();
int variableNumber = input.readInt();
String[] variableNames = new String[variableNumber];
double[][] dataValues = new double[savedNumber][variableNumber];
for (int i = 0; i < variableNumber; i++) {
int flag = input.readInt();
variableNames[i] = input.readUTF();
for (int j = 0; j < savedNumber; j++) {
dataValues[j][i] = input.readDouble();
}
}
// now put data in new data structure
int rowCount = savedNumber;
int columnCount = variableNumber + 1;
addDataColumn(new ODESolverResultSetColumnDescription("t", "t"));
for (int c = 1; c < columnCount; c++) {
addDataColumn(new ODESolverResultSetColumnDescription(variableNames[c - 1], variableNames[c - 1]));
}
double[] values = new double[columnCount];
for (int c = 0; c < columnCount; c++) values[c] = 0.0;
for (int r = 0; r < rowCount; r++) {
values[0] = r * saveInterval / 1000.0;
addRow(values);
}
for (int c = 1; c < columnCount; c++) {
for (int r = 0; r < rowCount; r++) {
setValue(r, c, dataValues[r][c - 1]);
}
}
} else if (formatID.equals(GENERIC_ODE_DATA_FORMAT_ID)) {
this.mathName = input.readUTF();
int rowCount = input.readInt();
int columnCount = input.readInt();
for (int c = 0; c < columnCount; c++) {
String columnName = input.readUTF();
String columnDisplayName = input.readUTF();
addDataColumn(new ODESolverResultSetColumnDescription(columnName, columnDisplayName));
}
double[] values = new double[columnCount];
for (int r = 0; r < rowCount; r++) {
for (int c = 0; c < columnCount; c++) {
values[c] = input.readDouble();
}
addRow(values);
}
} else if (formatID.equals(COMPACT_ODE_DATA_FORMAT_ID)) {
this.mathName = input.readUTF();
int rowCount = input.readInt();
int columnCount = input.readInt();
for (int c = 0; c < columnCount; c++) {
String columnName = input.readUTF();
String columnDisplayName = input.readUTF();
String columnParameterName = input.readUTF();
if (columnParameterName.equals("null")) {
columnParameterName = null;
}
addDataColumn(new ODESolverResultSetColumnDescription(columnName, columnParameterName, columnDisplayName));
}
double[] values = new double[columnCount];
for (int r = 0; r < rowCount; r++) {
for (int c = 0; c < columnCount; c++) {
values[c] = input.readDouble();
}
addRow(values);
}
try {
int functionCount = input.readInt();
for (int c = 0; c < functionCount; c++) {
String columnName = input.readUTF();
String columnDisplayName = input.readUTF();
String columnParameterName = input.readUTF();
if (columnParameterName.equals("null")) {
columnParameterName = null;
}
String expressionString = input.readUTF();
try {
Expression expression = new Expression(expressionString);
addFunctionColumn(new FunctionColumnDescription(expression, columnName, columnParameterName, columnDisplayName, false));
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
System.out.println("ODESimData.readIn(): unable to bind expression '" + expressionString + "'");
} catch (ExpressionException e) {
e.printStackTrace(System.out);
System.out.println("ODESimData.readIn(): unable to parse expression '" + expressionString + "'");
}
}
} catch (EOFException e) {
}
} else {
throw new IOException("DataInputStream is wrong format '" + formatID + "'");
}
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class ODESimData method readIDADataFile.
public static ODESimData readIDADataFile(VCDataIdentifier vcdId, File dataFile, int keepMost, File functionsFile) throws DataAccessException {
// read ida file
System.out.println("reading ida file : " + dataFile);
ODESimData odeSimData = new ODESimData();
odeSimData.formatID = IDA_DATA_FORMAT_ID;
odeSimData.mathName = vcdId.getID();
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile)));
// Read header
String line = bufferedReader.readLine();
if (line == null) {
// throw exception
return null;
}
StringTokenizer st = new StringTokenizer(line, ":");
while (st.hasMoreTokens()) {
odeSimData.addDataColumn(new ODESolverResultSetColumnDescription(st.nextToken()));
}
// Read data
while ((line = bufferedReader.readLine()) != null) {
st = new StringTokenizer(line);
double[] values = new double[odeSimData.getDataColumnCount()];
int count = 0;
while (st.hasMoreTokens()) {
values[count++] = Double.valueOf(st.nextToken()).doubleValue();
}
if (count == odeSimData.getDataColumnCount()) {
odeSimData.addRow(values);
} else {
break;
}
}
//
} catch (Exception e) {
e.printStackTrace(System.out);
return null;
} finally {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
}
if (!odeSimData.getColumnDescriptions(0).getName().equals(SimDataConstants.HISTOGRAM_INDEX_NAME)) {
Vector<AnnotatedFunction> funcList;
try {
funcList = FunctionFileGenerator.readFunctionsFile(functionsFile, vcdId.getID());
for (AnnotatedFunction func : funcList) {
try {
Expression expression = new Expression(func.getExpression());
odeSimData.addFunctionColumn(new FunctionColumnDescription(expression, func.getName(), null, func.getName(), false));
} catch (ExpressionException e) {
throw new RuntimeException("Could not add function " + func.getName() + " to annotatedFunctionList");
}
}
} catch (FileNotFoundException e1) {
e1.printStackTrace(System.out);
throw new DataAccessException(e1.getMessage());
} catch (IOException e1) {
e1.printStackTrace(System.out);
throw new DataAccessException(e1.getMessage());
}
}
if (keepMost > 0) {
odeSimData.trimRows(keepMost);
}
return odeSimData;
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class ODESimData method readNFSIMDataFile.
public static ODESimData readNFSIMDataFile(VCDataIdentifier vcdId, File dataFile, File functionsFile) throws DataAccessException, IOException {
System.out.println("reading NetCDF file : " + dataFile);
ODESimData odeSimData = new ODESimData();
odeSimData.formatID = NETCDF_DATA_FORMAT_ID;
odeSimData.mathName = vcdId.getID();
String file = dataFile.getPath();
BufferedReader reader = new BufferedReader(new FileReader(file));
String firstLine = reader.readLine();
StringTokenizer st = new StringTokenizer(firstLine);
// #
st.nextToken();
// time
st.nextToken();
// first column will be time t.
odeSimData.addDataColumn(new ODESolverResultSetColumnDescription("t"));
int count = st.countTokens();
String varName = new String();
for (int i = 0; i < count; i++) {
varName = st.nextToken();
odeSimData.addDataColumn(new ODESolverResultSetColumnDescription(varName));
}
// Read data
// String ls = System.getProperty("line.separator");
// StringBuilder stringBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
double[] values = new double[odeSimData.getDataColumnCount()];
st = new StringTokenizer(line);
count = st.countTokens();
String sData = new String();
for (int i = 0; i < count; i++) {
sData = st.nextToken();
double dData = Double.parseDouble(sData);
values[i] = dData;
}
odeSimData.addRow(values);
}
if (!odeSimData.getColumnDescriptions(0).getName().equals(SimDataConstants.HISTOGRAM_INDEX_NAME)) {
Vector<AnnotatedFunction> funcList;
try {
funcList = FunctionFileGenerator.readFunctionsFile(functionsFile, vcdId.getID());
for (AnnotatedFunction func : funcList) {
try {
Expression expression = new Expression(func.getExpression());
odeSimData.addFunctionColumn(new FunctionColumnDescription(expression, func.getName(), null, func.getName(), false));
} catch (ExpressionException e) {
throw new RuntimeException("Could not add function " + func.getName() + " to annotatedFunctionList");
}
}
} catch (FileNotFoundException e1) {
e1.printStackTrace(System.out);
throw new DataAccessException(e1.getMessage());
} catch (IOException e1) {
e1.printStackTrace(System.out);
throw new DataAccessException(e1.getMessage());
}
}
return odeSimData;
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class RungeKuttaFehlbergSolver method step.
/**
* Integrate over time step using the forward Euler method (1st order explicit)
* results must be stored in NumVectors-1 = vector(4);
* t is the current time
* h is the time step
*/
protected void step(double t, double h) throws SolverException {
try {
double[] oldValues = getValueVector(0);
double[] newValues = getValueVector(1);
//
// update time
oldValues[getTimeIndex()] = t;
//
for (int i = 0; i < 6; i++) {
newValues[getTimeIndex()] = t + a[i] * h;
for (int j = 0; j < getStateVariableCount(); j++) {
int J = getVariableIndex(j);
newValues[J] = oldValues[J];
for (int m = 0; m < i; m++) {
newValues[J] += b[i][m] * k[m][J];
}
}
for (int j = 0; j < getStateVariableCount(); j++) {
k[i][getVariableIndex(j)] = h * evaluate(newValues, j);
}
}
for (int i = 0; i < getStateVariableCount(); i++) {
int I = getVariableIndex(i);
newValues[I] = oldValues[I];
for (int j = 0; j < 6; j++) {
newValues[I] += c[j] * k[j][I];
}
}
} catch (ExpressionException expressionException) {
throw new SolverException(expressionException.getMessage());
}
}
use of cbit.vcell.parser.ExpressionException in project vcell by virtualcell.
the class XmlBase method unMangleExpression.
public static Expression unMangleExpression(String expStr) {
Expression tempExp = null;
//
try {
tempExp = new Expression(unMangle(expStr));
tempExp = MathFunctionDefinitions.fixFunctionSyntax(tempExp);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
return tempExp;
}
Aggregations