use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class OutputTimeSpec method readVCML.
/**
* Insert the method's description here.
* Creation date: (9/7/2005 9:10:09 AM)
* @return cbit.vcell.solver.OutputTimeSpec
*/
public static OutputTimeSpec readVCML(CommentStringTokenizer tokens) throws DataAccessException {
//
// read format as follows:
//
// OutputOptions {
// KeepEvery 1
// KeepAtMost 1000
// }
//
// OR
// OutputOptions {
// OutputTimes 0.1,0.3,0.4,... (no spaces or line feeds between numbers)
// }
//
// OR
// OutputOptions {
// OutputTimeStep 10
// }
//
OutputTimeSpec ots = null;
try {
String token = tokens.nextToken();
if (token.equalsIgnoreCase(VCML.OutputOptions)) {
token = tokens.nextToken();
}
if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
throw new DataAccessException("unexpected token " + token + " expecting " + VCML.BeginBlock);
}
while (tokens.hasMoreTokens()) {
token = tokens.nextToken();
if (token.equalsIgnoreCase(VCML.EndBlock)) {
break;
}
if (token.equalsIgnoreCase(VCML.KeepEvery)) {
token = tokens.nextToken();
int keepEvery = Integer.parseInt(token);
token = tokens.nextToken();
if (!token.equalsIgnoreCase(VCML.KeepAtMost)) {
throw new DataAccessException("unexpected identifier " + token);
}
token = tokens.nextToken();
int keepAtMost = Integer.parseInt(token);
ots = new DefaultOutputTimeSpec(keepEvery, keepAtMost);
continue;
} else if (token.equalsIgnoreCase(VCML.OutputTimeStep)) {
token = tokens.nextToken();
double outputTimeStep = Double.parseDouble(token);
ots = new UniformOutputTimeSpec(outputTimeStep);
continue;
} else if (token.equalsIgnoreCase(VCML.OutputTimes)) {
token = tokens.nextToken();
java.util.StringTokenizer st = new java.util.StringTokenizer(token, ",");
double[] times = new double[st.countTokens()];
int count = 0;
while (st.hasMoreTokens()) {
token = st.nextToken();
times[count++] = Double.parseDouble(token);
}
ots = new ExplicitOutputTimeSpec(times);
continue;
}
throw new DataAccessException("unexpected identifier " + token);
}
} catch (Throwable e) {
throw new DataAccessException("line #" + (tokens.lineIndex() + 1) + " Exception: " + e.getMessage());
}
return ots;
}
use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class SundialsPdeSolverOptions method readVCML.
private void readVCML(CommentStringTokenizer tokens) throws DataAccessException {
String token = tokens.nextToken();
if (token.equalsIgnoreCase(VCML.SundialsSolverOptions)) {
token = tokens.nextToken();
if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
throw new DataAccessException("unexpected token " + token + " expecting " + VCML.BeginBlock);
}
}
while (tokens.hasMoreTokens()) {
token = tokens.nextToken();
if (token.equalsIgnoreCase(VCML.EndBlock)) {
break;
}
if (token.equalsIgnoreCase(VCML.SundialsSolverOptions_maxOrderAdvection)) {
token = tokens.nextToken();
maxOrderAdvection = Integer.parseInt(token);
} else if (token.equalsIgnoreCase("maxOrder")) {
// old way
token = tokens.nextToken();
} else {
throw new DataAccessException("unexpected identifier " + token);
}
}
}
use of org.vcell.util.DataAccessException in project vcell by virtualcell.
the class TimeBounds method readVCML.
/**
* Insert the method's description here.
* Creation date: (10/24/00 3:45:12 PM)
* @return java.lang.String
*/
public void readVCML(CommentStringTokenizer tokens) throws DataAccessException {
//
try {
String token = tokens.nextToken();
if (token.equalsIgnoreCase(VCML.TimeBounds)) {
token = tokens.nextToken();
if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
throw new DataAccessException("unexpected token " + token + " expecting " + VCML.BeginBlock);
}
}
while (tokens.hasMoreTokens()) {
token = tokens.nextToken();
if (token.equalsIgnoreCase(VCML.EndBlock)) {
break;
}
if (token.equalsIgnoreCase(VCML.StartingTime)) {
token = tokens.nextToken();
fieldStartingTime = Double.parseDouble(token);
continue;
}
if (token.equalsIgnoreCase(VCML.EndingTime)) {
token = tokens.nextToken();
fieldEndingTime = Double.parseDouble(token);
continue;
}
throw new DataAccessException("unexpected identifier " + token);
}
} catch (Throwable e) {
throw new DataAccessException("line #" + (tokens.lineIndex() + 1) + " Exception: " + e.getMessage());
}
}
use of org.vcell.util.DataAccessException 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 org.vcell.util.DataAccessException 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;
}
Aggregations