Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 402:eb22ffe4d74c
Implemented methods to retrieve and compute the data used to create discharge longitudinal sections.
flys-artifacts/trunk@1843 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 06 May 2011 14:19:27 +0000 |
parents | 53cc794fee07 |
children | 6ab62e5b05b5 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Thu May 05 12:34:53 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Fri May 06 14:19:27 2011 +0000 @@ -31,6 +31,7 @@ import de.intevation.artifactdatabase.transition.TransitionEngine; import de.intevation.flys.model.Gauge; +import de.intevation.flys.model.Range; import de.intevation.flys.model.River; import de.intevation.flys.artifacts.context.FLYSContext; @@ -492,6 +493,34 @@ /** + * This method returns the given distance + * + * @return an array with lower and upper kilometer range for each + * intersected gauge. + */ + public double[][] getSplittedDistance() { + double[] dist = getDistance(); + List<Gauge> gauges = getGauges(); + + int num = gauges != null ? gauges.size() : 0; + + double[][] res = new double[num][2]; + + for (int i = 0; i < num; i++) { + Range range = gauges.get(i).getRange(); + + double lower = range.getA().doubleValue(); + double upper = range.getB().doubleValue(); + + res[i][0] = dist[0] < lower ? lower : dist[0]; + res[i][1] = dist[1] > upper ? upper : dist[1]; + } + + return res; + } + + + /** * Returns the selected locations based on a given array of locations. * * @param locations The StateData that contains the locations. @@ -546,9 +575,11 @@ /** * Returns the selected Kms. * + * @param distance An 2dim array with [lower, upper] values. + * * @return the selected Kms. */ - public double[] getKms() { + public double[] getKms(double[] distance) { StateData dStep = getData("ld_step"); if (dStep == null) { @@ -556,9 +587,7 @@ return null; } - double step = Double.parseDouble((String) dStep.getValue()); - double[] distance = getDistance(); - double lower = distance[0]; + double step = Double.parseDouble((String) dStep.getValue()); // transform step from 'm' into 'km' step = step / 1000; @@ -572,6 +601,17 @@ /** + * Returns the selected Kms. + * + * @return the selected kms. + */ + public double[] getKms() { + double[] distance = getDistance(); + return getKms(distance); + } + + + /** * Returns the gauge based on the current distance and river. * * @return the gauge. @@ -635,6 +675,56 @@ /** + * Returns the Q values based on a specified kilometer range. + * + * @param range A 2dim array with lower and upper kilometer range. + * + * @return an array of Q values. + */ + public double[] getQs(double[] range) { + StateData dMode = getData("wq_mode"); + StateData dValues = getData("wq_values"); + + String mode = dMode != null ? (String) dMode.getValue() : ""; + + // TODO REMOVE THIS HARD CODED MODE VALUE! + mode = "Q"; + + if (mode.equals("Q")) { + return getWQForDist(range); + } + + logger.warn("You try to get Qs, but Ws has been inserted."); + return null; + } + + + /** + * Returns the W values based on a specified kilometer range. + * + * @param range A 2dim array with lower and upper kilometer range. + * + * @return an array of W values. + */ + public double[] getWs(double[] range) { + StateData dMode = getData("wq_mode"); + StateData dValues = getData("wq_values"); + + String mode = dMode != null ? (String) dMode.getValue() : ""; + + // TODO REMOVE THIS HARD CODED MODE VALUE! + mode = "W"; + + if (mode.equals("W")) { + return getWQForDist(range); + } + + logger.warn("You try to get Ws, but Qs has been inserted."); + return null; + } + + + /** * This method returns the W values. * * @return the selected W values or null, if no W values are selected. @@ -682,7 +772,6 @@ for (int i = 0; i < ws.length; i++) { qs[i] = dt.getQForW(values, ws[i]); - logger.debug("Q for " + ws[i] + " = " + qs[i]); } return qs; @@ -690,6 +779,57 @@ /** + * This method returns the given W or Q values for a specific range + * (inserted in the WQ input panel for discharge longitudinal sections). + * + * @param dist A 2dim array with lower und upper kilometer values. + * + * @return an array of W or Q values. + */ + protected double[] getWQForDist(double[] dist) { + logger.debug("Search wq values for range: " + dist[0] + " - " + dist[1]); + StateData data = getData("wq_values"); + + if (data == null) { + logger.warn("Missing wq values!"); + return null; + } + + String dataString = (String) data.getValue(); + String[] ranges = dataString.split(":"); + + for (String range: ranges) { + String[] parts = range.split(";"); + + double lower = Double.parseDouble(parts[0]); + double upper = Double.parseDouble(parts[1]); + + if (lower <= dist[0] && upper >= dist[1]) { + String[] values = parts[2].split(","); + + int num = values.length; + double[] res = new double[num]; + + for (int i = 0; i < num; i++) { + try { + res[i] = Double.parseDouble(values[i]); + } + catch (NumberFormatException nfe) { + logger.warn(nfe, nfe); + } + } + + return res; + } + } + + logger.warn("Specified range for WQ not found!"); + + return null; + } + + + /** * This method returns an array of inserted WQ triples that consist of from, * to and the step width. *