From e5d0d391a98909d32501798d5c8f39479a360dd0 Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 3 May 2011 06:43:16 +0000 Subject: [PATCH] Changed the Modelica simulation result format from .plt to .csv. With a complex and multidimensional model, the result file size was reduced from 5 MB to 1.8 MB and reading of the results (SysdynModel:246-256) was 6 seconds faster (from 8.9 s to 2.9 s) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20732 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../simantics/modelica/ModelicaManager.java | 6 +- .../modelica/data/CSVSimulationResult.java | 55 +++++++++++++++++++ .../simantics/sysdyn/manager/SysdynModel.java | 7 ++- 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index f8e4b18e..ee9e4738 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -243,7 +243,7 @@ public class ModelicaManager { modelName = modelName.replace(" ", ""); File modelFile = new File(simulationDir, modelName + ".mo"); File scriptFile = new File(simulationDir, modelName + ".mos"); - + String outputFormat = inits.containsKey("outputFormat") ? inits.get("outputFormat") : "\"plt\""; { PrintStream s = new PrintStream(modelFile); s.print(modelText); @@ -259,7 +259,7 @@ public class ModelicaManager { ",startTime="+inits.get("start value")+ ",stopTime="+inits.get("stop value")+ ",method="+inits.get("method")+ - ",outputFormat=\"plt\"" + ",outputFormat="+ outputFormat ); if(inits.containsKey("tolerance")) { s.print(",tolerance="+inits.get("tolerance")); @@ -275,7 +275,7 @@ public class ModelicaManager { return new SimulationLocation( simulationDir, new File(simulationDir, modelName + ".mos"), - new File(simulationDir, modelName + "_res.plt"), + new File(simulationDir, modelName + "_res." + outputFormat.substring(1, outputFormat.length()-1)), new File(simulationDir, modelName + "_init.txt"), new File(simulationDir, modelName + suffix) ); diff --git a/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java b/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java new file mode 100644 index 00000000..49abb2b5 --- /dev/null +++ b/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java @@ -0,0 +1,55 @@ +package org.simantics.modelica.data; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + + +public class CSVSimulationResult extends SimulationResult { + + HashMap> valueMap = new HashMap>(); + + @Override + public void read(InputStream stream) { + + // First line contains the variable names in format "name" (including quotes); + String line = getLine(stream); + if(line == null) + return; + + // FIXME: yks elementti liikaa alusta. + line = line.substring(1, line.lastIndexOf("\"")); + String[] names = line.split("\",\""); + + // Create lists for receiving values for each variable. Names still with quotes. + for(String name : names) { + if(!name.isEmpty()) + valueMap.put(name, new ArrayList()); + } + + // Data sets + while((line = getLine(stream)) != null) { + if(line.isEmpty()) + break; + String[] values = line.split(","); + for(int i = 0; i