From ee8afd2465a283e0acc33f535199daa24cbeee9d Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 6 May 2011 10:14:31 +0000 Subject: [PATCH] Print number format errors to console, when modelica gives results like INF and IND instead of numbers git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20801 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../modelica/data/CSVSimulationResult.java | 22 ++++++++++--- .../modelica/data/SimulationResult.java | 32 +++++++++++++++++++ .../simantics/sysdyn/ui/trend/TrendView.java | 14 ++++++-- .../simantics/sysdyn/manager/SysdynModel.java | 7 +++- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java b/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java index 49abb2b5..19043005 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java +++ b/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ package org.simantics.modelica.data; import java.io.InputStream; @@ -12,13 +23,13 @@ public class CSVSimulationResult extends SimulationResult { @Override public void read(InputStream stream) { + errors.clear(); // 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("\",\""); @@ -38,8 +49,12 @@ public class CSVSimulationResult extends SimulationResult { try { valueMap.get(names[i]).add(Double.parseDouble(values[i])); } catch (NumberFormatException e) { - e.printStackTrace(); - break; + ArrayList list = errors.get(names[i]); + if(list == null) { + list = new ArrayList(); + errors.put(names[i], list); + } + list.add(new TimeValuePair(values[0], values[i])); } } } @@ -51,5 +66,4 @@ public class CSVSimulationResult extends SimulationResult { variables.add(ds); } } - } diff --git a/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java b/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java index 85779106..2e104443 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java +++ b/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java @@ -30,6 +30,18 @@ public class SimulationResult { List variables = new ArrayList(); List initials = new ArrayList(); + + class TimeValuePair { + public String time; + public String value; + + public TimeValuePair(String time, String value) { + this.time = time; + this.value = value; + } + } + + HashMap> errors = new HashMap>(); static String getLine(InputStream stream) { if(stream == null) @@ -172,4 +184,24 @@ public class SimulationResult { return set; return null; } + + + /** + * Return errors encountered during reading of the results. + * + * @return + */ + public String getResultReadErrors() { + StringBuilder errorString = new StringBuilder(); + if(!errors.isEmpty()) { + errorString.append("Number format errors (Time, Value):\n"); + for(String key : errors.keySet()) { + errorString.append("\n" + key + ":\n"); + for(TimeValuePair tv : errors.get(key)) { + errorString.append(" " + tv.time + ", " + tv.value + "\n"); + } + } + } + return errorString.toString(); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java index fcc2f104..c11c57b7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java @@ -35,7 +35,7 @@ public class TrendView extends ViewPart { Frame frame; ChartPanel panel; SysdynDatasets sysdynDatasets = new SysdynDatasets(); - + SysdynDatasetSelectionListener sysdynDatasetSelectionListener; @SuppressWarnings("serial") class SysdynDatasets extends AbstractXYDataset { @@ -107,7 +107,7 @@ public class TrendView extends ViewPart { }); - getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(new SysdynDatasetSelectionListener() { + sysdynDatasetSelectionListener = new SysdynDatasetSelectionListener() { @Override protected void selectionChanged(final Collection activeDatasets) { @@ -120,9 +120,17 @@ public class TrendView extends ViewPart { }); } - }); + }; + + getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(sysdynDatasetSelectionListener); } + + @Override + public void dispose() { + super.dispose(); + getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(sysdynDatasetSelectionListener); + } @Override public void setFocus() { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java index ed8941b4..748841a9 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java @@ -155,7 +155,7 @@ public class SysdynModel implements IMappingListener, IModel { this.modelResource = modelResource; } - public synchronized void simulate(IModelicaMonitor monitor, final IProgressMonitor progressMonitor, final Experiment experiment) throws IOException { + public synchronized void simulate(final IModelicaMonitor monitor, final IProgressMonitor progressMonitor, final Experiment experiment) throws IOException { canceled = false; progressMonitor.subTask("Write modelica classes"); ModelicaWriter writer = new ModelicaWriter(); @@ -255,6 +255,10 @@ public class SysdynModel implements IMappingListener, IModel { resultChanged(); setExperimentStopped(experiment); + + String errorString = result.getResultReadErrors(); + if(errorString != null && !errorString.isEmpty()) + monitor.message(errorString); } } catch (FileNotFoundException e) { e.printStackTrace(); @@ -351,6 +355,7 @@ public class SysdynModel implements IMappingListener, IModel { public void resultChanged() { synchronized(resultListeners) { for(Runnable listener : resultListeners) { + System.out.println("Run resultListener"); listener.run(); } } -- 2.47.1