File simulationDir;\r
File inputFile;\r
File outputFile;\r
+ File initFile;\r
\r
public SimulationLocation(File simulationDir, File inputFile,\r
- File outputFile) {\r
+ File outputFile, File initFile) {\r
this.simulationDir = simulationDir;\r
this.inputFile = inputFile;\r
this.outputFile = outputFile;\r
+ this.initFile = initFile;\r
}\r
}\r
\r
return new SimulationLocation(\r
simulationDir,\r
new File(simulationDir, modelName + ".mos"),\r
- new File(simulationDir, modelName + "_res.plt")\r
+ new File(simulationDir, modelName + "_res.plt"),\r
+ new File(simulationDir, modelName + "_init.txt")\r
);\r
}\r
\r
\r
SimulationResult result = new SimulationResult();\r
result.read(simulationLocation.outputFile);\r
- \r
+ result.readInits(simulationLocation.initFile);\r
result.filter(); \r
\r
return result;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
import java.util.List;\r
import java.util.regex.Matcher;\r
import java.util.regex.Pattern;\r
* @author Hannu Niemistö\r
*/\r
public class SimulationResult { \r
- \r
+\r
List<DataSet> dataSets = new ArrayList<DataSet>();\r
\r
static String getLine(InputStream stream) {\r
} catch (IOException e) {\r
return null;\r
} \r
+\r
+ }\r
+\r
+\r
+ public void readInits(File file) throws FileNotFoundException {\r
+ readInits(new FileInputStream(file));\r
+ }\r
+\r
+ public void readInits(InputStream stream) {\r
+ HashMap<String, Double> mappedInitials = new HashMap<String, Double>();\r
+ while(true) {\r
+ String line = getLine(stream);\r
+ if(line == null)\r
+ return;\r
+ if(line.isEmpty())\r
+ break;\r
+\r
+ if(line.contains("//")) {\r
+ String[] nn = line.split("//", 2);\r
+ try {\r
+ double value = Double.parseDouble(nn[0].trim());\r
+ String key = nn[1].trim();\r
+ mappedInitials.put(key, value);\r
+ } catch (NumberFormatException nfe) {\r
+ continue; // Not a valid double\r
+ }\r
+ \r
+ }\r
+\r
+ }\r
\r
+ double startTime = mappedInitials.get("start value");\r
+ double stopTime = mappedInitials.get("stop value");\r
+ double[] times = {startTime, stopTime};\r
+ \r
+ for(String key : mappedInitials.keySet()) {\r
+ double[] values = {mappedInitials.get(key), mappedInitials.get(key)};\r
+ dataSets.add(new DataSet(key, times , values));\r
+ }\r
}\r
- \r
+\r
+\r
final static Pattern p1 = Pattern.compile("DataSet: ([^ ]*)");\r
- \r
+\r
public void read(File file) throws FileNotFoundException {\r
read(new FileInputStream(file));\r
}\r
- \r
+\r
public void read(InputStream stream) {\r
while(true) {\r
String line = getLine(stream);\r
if(line.isEmpty())\r
break;\r
}\r
- \r
+\r
// Data sets\r
while(true) { \r
Matcher matcher = p1.matcher(getLine(stream));\r
if(!matcher.matches())\r
return;\r
String name = matcher.group(1);\r
- \r
+\r
TDoubleArrayList times = new TDoubleArrayList();\r
TDoubleArrayList values = new TDoubleArrayList();\r
while(true) {\r
times.add(Double.parseDouble(nn[0]));\r
values.add(Double.parseDouble(nn[1]));\r
}\r
- \r
+\r
dataSets.add(new DataSet(name, times.toNativeArray(), values.toNativeArray()));\r
}\r
}\r
- \r
+\r
public void filter() {\r
ArrayList<DataSet> newDataSets = new ArrayList<DataSet>();\r
for(DataSet dataSet : dataSets) {\r
}\r
dataSets = newDataSets;\r
}\r
- \r
+\r
public List<DataSet> getDataSets() {\r
return dataSets;\r
}\r
- \r
+\r
public DataSet getDataSet(String name) {\r
for(DataSet set : dataSets)\r
if(set.name.equals(name))\r