Show Simulator.java syntax highlighted
/******************************************************************************
*
* File: $Id: Simulator.java,v 1.2 2005/11/07 18:20:20 emeryconrad Exp $
* Author: Emery Conrad
*
* Descritption:
* ...
*
* Oscill8 Dynamical Systems Toolset
* Copyright (C) 2005, Emery Conrad
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*****************************************************************************/
package com.oscill8.o8biospice;
import java.io.*;
import java.lang.*;
import org.biospice.analyzer.Analyzer;
import org.biospice.analyzer.AnalysisException;
import org.biospice.analyzer.AnalyzerFactory;
import org.biospice.analyzer.ParameterDeclaration;
import org.biospice.analyzer.ParameterDeclarationGroup;
import org.biospice.analyzer.ParameterValue;
import org.biospice.analyzer.ParameterValueGroup;
import org.biospice.datatypes.*;
import org.biospice.datatypes.impl.*;
public class Simulator extends AnalyzerFactory implements Analyzer
{
private static final ParameterDeclarationGroup INPUTS =
new ParameterDeclarationGroup(new ParameterDeclaration[] {
new ParameterDeclaration("odefile",
BiodataFile.class,
false,
true,
null,
null),
new ParameterDeclaration("workdir",
String.class,
false,
true,
null,
"c:\\tmp"),
new ParameterDeclaration("t_end",
Double.class,
false,
true,
null,
250.0),
new ParameterDeclaration("n_points",
Integer.class,
false,
true,
null,
500)});
private static final ParameterDeclarationGroup OUTPUTS =
new ParameterDeclarationGroup(new ParameterDeclaration[] {
new ParameterDeclaration("plot",
String.class,
false,
true,
null,
null)});
public Simulator()
{
ICON_NAME = "/com/oscill8/o8biospice/o8sim_icon.gif";
}
/******************************************************************
*
* analyze
*
*****************************************************************/
public ParameterValueGroup analyze(ParameterValueGroup inputs) throws AnalysisException
{
BiodataFileImpl f = (BiodataFileImpl)inputs.getParameterValue("odefile").getValue();
String odefile = (String)f.getPathname();
String workdir = (String)inputs.getParameterValue("workdir").getValue();
Double t_end = (Double)inputs.getParameterValue("t_end").getValue();
Integer n_points = (Integer)inputs.getParameterValue("n_points").getValue();
// get input files to external simulator prep'd
String o8r =
"<o8r>\n" +
" <run name=\"sim\" type=\"TimeSeries\">\n" +
" <t_end>" + t_end.toString() + "</t_end>\n" +
" <n_points>" + n_points.toString() + "</n_points>\n" +
" <output format=\"o8p\">sim.o8p</output>\n" +
" </run>\n" +
"</o8r>\n";
try
{
FileWriter fw = new FileWriter(workdir + "/sim.o8r");
fw.write(o8r, 0, o8r.length());
fw.close();
}
catch(IOException e)
{
throw new AnalysisException("couldn't save o8r file: " + e.getMessage());
}
// run o8core
try
{
Runtime rt = Runtime.getRuntime();
String []cmd = new String[]
{
System.getenv("OSCILL8_DIR") + "/bin/o8core",
"-m", odefile, "-r", "sim.o8r", "-l", "sim.log"
};
Process p = rt.exec(cmd, null, new File(workdir));
p.waitFor();
}
catch(Exception e)
{
throw new AnalysisException("couldn't run o8r text: " + e.getMessage());
}
// do output
ParameterValueGroup pvg = new ParameterValueGroup(OUTPUTS);
pvg.setParameterValue("plot", workdir + "/sim.o8p");
return pvg;
}
/******************************************************************
*
* factory implementation
*
*****************************************************************/
public Analyzer getAnalyzer()
{
return this;
}
public String getDisplayName()
{
return "Oscill8 Simulator";
}
public String getName()
{
return "com.oscill8.o8biospice.Simulator";
}
public String getDescription()
{
return "Integrates an ODE model";
}
public ParameterDeclarationGroup getInputs()
{
return INPUTS;
}
public ParameterDeclarationGroup getOutputs()
{
return OUTPUTS;
}
public String getReferences()
{
return "http://oscill8.sourceforge.net";
}
}
See more files for this project here