Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 362:d79a51fc4f1d
Added necessary methods to start the computation of waterlevel data.
flys-artifacts/trunk@1770 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 29 Apr 2011 07:46:27 +0000 |
parents | d97982627596 |
children | 3e66a5705c39 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Fri Apr 29 07:27:05 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Fri Apr 29 07:46:27 2011 +0000 @@ -61,6 +61,10 @@ /** The constant string that shows that an operation failed.*/ public static final String OPERATION_FAILED = "FAILURE"; + /** The default number of steps between the start end end of a selected Q + * range.*/ + public static final int DEFAULT_Q_STEPS = 30; + /** The identifier of the current state. */ protected String currentStateId; @@ -476,6 +480,30 @@ /** + * Returns the selected Kms. + * + * @return the selected Kms. + */ + public double[] getKms() { + StateData dStep = getData("ld_step"); + + if (dStep == null) { + logger.warn("No step width given. Cannot compute Kms."); + return null; + } + + double step = Double.parseDouble((String) dStep.getValue()); + double[] distance = getDistance(); + double lower = distance[0]; + + // transform step from 'm' into 'km' + step = step / 1000; + + return getExplodedValues(distance[0], distance[1], step); + } + + + /** * Returns the gauge based on the current distance and river. * * @return the gauge. @@ -497,5 +525,76 @@ return gauge; } + + + /** + * This method returns the Q values. + * + * @return the selected Q values or null, if no Q values are selected. + */ + public double[] getQs() { + StateData dFrom = getData("wq_from"); + StateData dTo = getData("wq_to"); + + if (dFrom == null || dTo == null) { + logger.warn("Missing start or end value for Q range."); + return null; + } + + double from = Double.parseDouble((String) dFrom.getValue()); + double to = Double.parseDouble((String) dTo.getValue()); + + StateData dStep = getData("wq_step"); + + if (dStep == null) { + logger.warn("No step width given. Cannot compute Qs."); + return null; + } + + double step = Double.parseDouble((String) dStep.getValue()); + + // if no width is given, the DEFAULT_Q_STEPS is used to compute the step + // width. Maybe, we should round the value to a number of digits. + if (step == 0d) { + double diff = to - from; + step = diff / DEFAULT_Q_STEPS; + } + + return getExplodedValues(from, to, step); + } + + + /** + * Returns an array of double values. The values contained in this array + * begin with the value <i>from</i> and end with the value <i>to</i>. The + * number of values in the result array depends on the <i>step</i> width. + * + * @param from The lower value. + * @param to The upper value. + * @param step The step width between two values in the result array. + * + * @return an array of double values. + */ + public double[] getExplodedValues(double from, double to, double step) { + double lower = from; + + double diff = to - from; + double tmp = (diff * 100 / step); + int tmpN = (int) (tmp / 100); + int num = tmpN + 2; + + double[] values = new double[num]; + int idx = 0; + + do { + values[idx++] = lower; + lower += step; + } + while (lower < to); + + values[idx] = to; + + return values; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :