Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 735:db68806e6563
Fixed "W am Pegel" calculations.
flys-artifacts/trunk@2230 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 25 Jun 2011 17:35:50 +0000 |
parents | 4800230fba8a |
children | 5abdb2fa8eb1 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Fri Jun 24 12:05:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Sat Jun 25 17:35:50 2011 +0000 @@ -1,5 +1,6 @@ package de.intevation.flys.artifacts; +import java.util.Arrays; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -493,17 +494,30 @@ * @return the selected distance or points. */ public double[] getDistance() { + StateData dMode = getData("ld_mode"); StateData dFrom = getData("ld_from"); StateData dTo = getData("ld_to"); StateData dLocations = getData("ld_locations"); + if (dMode != null) { + String mode = (String)dMode.getValue(); + if ("location".equals(mode)) { + double[] locations = getLocations(); + return new double[] { locations[0], locations[locations.length-1] }; + } + if (dFrom != null && dTo != null) { + return getDistanceByRange(dFrom, dTo); + } + } + + if (dLocations != null) { + double[] locations = getLocations(); + return new double[] { locations[0], locations[locations.length-1] }; + } + if (dFrom != null && dTo != null) { return getDistanceByRange(dFrom, dTo); } - else if (dLocations != null) { - double[] locations = getLocations(); - return new double[] { locations[0], locations[locations.length-1] }; - } logger.warn("No data found for distance determination!"); @@ -664,8 +678,19 @@ */ public Gauge getGauge() { River river = getRiver(); + + if (river == null) { + logger.debug("no river found"); + return null; + } + double[] dist = getDistance(); + if (dist == null) { + logger.debug("no range found"); + return null; + } + if (logger.isDebugEnabled()) { logger.debug("Determine gauge for:"); logger.debug("... river: " + river.getName()); @@ -848,10 +873,39 @@ * @return an array of Q values. */ public double[] getQsForWs(double[] ws) { - logger.debug("FLYSArtifact.getQsForWs"); + + boolean debug = logger.isDebugEnabled(); + + if (debug) { + logger.debug("FLYSArtifact.getQsForWs"); + } River r = getRiver(); - Gauge g = getGauge(); + if (r == null) { + logger.warn("no river found"); + return null; + + } + + double [] range = getDistance(); + if (range == null) { + logger.warn("no ranges found"); + return null; + } + + if (debug) { + logger.debug("range: " + Arrays.toString(range)); + } + + Gauge g = r.determineGaugeByPosition(range[0]); + if (g == null) { + logger.warn("no gauge found for km: " + range[0]); + return null; + } + + if (debug) { + logger.debug("convert w->q with gauge '" + g.getName() + "'"); + } DischargeTables dt = new DischargeTables(r.getName(), g.getName()); Map<String, double [][]> tmp = dt.getValues(); @@ -861,6 +915,9 @@ for (int i = 0; i < ws.length; i++) { qs[i] = dt.getQForW(values, ws[i]); + if (debug) { + logger.debug("w: " + ws[i] + " -> q: " + qs[i]); + } } return qs;