modelName = modelName.replace(" ", "");\r
File modelFile = new File(simulationDir, modelName + ".mo");\r
File scriptFile = new File(simulationDir, modelName + ".mos");\r
-\r
+ String outputFormat = inits.containsKey("outputFormat") ? inits.get("outputFormat") : "\"plt\"";\r
{\r
PrintStream s = new PrintStream(modelFile);\r
s.print(modelText);\r
",startTime="+inits.get("start value")+\r
",stopTime="+inits.get("stop value")+\r
",method="+inits.get("method")+\r
- ",outputFormat=\"plt\""\r
+ ",outputFormat="+ outputFormat\r
);\r
if(inits.containsKey("tolerance")) {\r
s.print(",tolerance="+inits.get("tolerance"));\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." + outputFormat.substring(1, outputFormat.length()-1)),\r
new File(simulationDir, modelName + "_init.txt"),\r
new File(simulationDir, modelName + suffix)\r
);\r
--- /dev/null
+package org.simantics.modelica.data;\r
+\r
+import java.io.InputStream;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+\r
+\r
+public class CSVSimulationResult extends SimulationResult {\r
+\r
+ HashMap<String, List<Double>> valueMap = new HashMap<String, List<Double>>();\r
+ \r
+ @Override\r
+ public void read(InputStream stream) {\r
+ \r
+ // First line contains the variable names in format "name" (including quotes);\r
+ String line = getLine(stream);\r
+ if(line == null)\r
+ return;\r
+ \r
+ // FIXME: yks elementti liikaa alusta.\r
+ line = line.substring(1, line.lastIndexOf("\""));\r
+ String[] names = line.split("\",\"");\r
+ \r
+ // Create lists for receiving values for each variable. Names still with quotes.\r
+ for(String name : names) {\r
+ if(!name.isEmpty())\r
+ valueMap.put(name, new ArrayList<Double>());\r
+ }\r
+\r
+ // Data sets\r
+ while((line = getLine(stream)) != null) { \r
+ if(line.isEmpty())\r
+ break;\r
+ String[] values = line.split(",");\r
+ for(int i = 0; i<values.length; i++) {\r
+ if(values[i] != null && !values[i].isEmpty() && i < names.length) {\r
+ try {\r
+ valueMap.get(names[i]).add(Double.parseDouble(values[i]));\r
+ } catch (NumberFormatException e) {\r
+ e.printStackTrace();\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ // Create datasets for variables. Substring quotes from variable names.\r
+ for(String key : valueMap.keySet()) {\r
+ DataSet ds = new DataSet(key, valueMap.get("time"), valueMap.get(key));\r
+ variables.add(ds);\r
+ }\r
+ }\r
+ \r
+}\r
import org.simantics.modelica.ModelicaException;\r
import org.simantics.modelica.ModelicaManager;\r
import org.simantics.modelica.SimulationLocation;\r
+import org.simantics.modelica.data.CSVSimulationResult;\r
import org.simantics.modelica.data.SimulationResult;\r
import org.simantics.objmap.IMapping;\r
import org.simantics.objmap.IMappingListener;\r
Double numberOfIntervals = model.getOutputInterval();\r
inits.put("start value", startTime.toString());\r
inits.put("stop value", stopTime.toString());\r
+ String outputFormat = "\"csv\"";\r
+ inits.put("outputFormat", outputFormat);\r
if(numberOfIntervals != null) {\r
inits.put("step value", numberOfIntervals.toString());\r
} else {\r
previousImportantInits.put("start value", startTime.toString());\r
previousImportantInits.put("stop value", stopTime.toString());\r
previousImportantInits.put("method", method);\r
+ previousImportantInits.put("outputFormat", outputFormat);\r
} catch (ModelicaException e) {\r
if(e.getMessage() != null)\r
monitor.message(e.getMessage());\r
if(!canceled) {\r
progressMonitor.worked(1);\r
progressMonitor.subTask("Read results");\r
- result = new SimulationResult();\r
+ result = new CSVSimulationResult();\r
result.read(simulationLocation.outputFile);\r
result.readInits(simulationLocation.initFile);\r
result.filter();\r
sysdynResult.setResult(result);\r
progressMonitor.worked(1);\r
- \r
resultChanged();\r
\r
setExperimentStopped(experiment);\r