changeset 636:58276db49b16

Generate fields for w/q input depend on flow direction. flys-artifacts/trunk@2012 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 26 May 2011 15:55:48 +0000
parents acf3b49ec31f
children f0c1250d1e7b
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java
diffstat 3 files changed, 52 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu May 26 14:27:06 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu May 26 15:55:48 2011 +0000
@@ -1,3 +1,10 @@
+2011-05-26	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java:
+	  Generate fields for w/q input depend on flow direction.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Moved km up question out of loop.
 2011-05-26	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu May 26 14:27:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu May 26 15:55:48 2011 +0000
@@ -324,10 +324,11 @@
 
         ArrayList<WQKms> results = new ArrayList<WQKms>();
 
+        int referenceIndex = up ? 0 : kms.length-1; 
+
         for (int i = 0; i < qs.length; i++) {
             double [] oqs = new double[kms.length];
             double [] ows = new double[kms.length];
-            int referenceIndex = up ? 0 : kms.length-1; 
             WstValueTable.QPosition qPosition =
                 wst.interpolate(qs[i], referenceIndex, kms, ows, oqs);
             if (qPosition != null) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java	Thu May 26 14:27:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQAdapted.java	Thu May 26 15:55:48 2011 +0000
@@ -2,6 +2,8 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Comparator;
+import java.util.Collections;
 
 import org.apache.log4j.Logger;
 
@@ -38,6 +40,20 @@
 
     public static final String FIELD_WQ_VALUES = "wq_values";
 
+    public static final class GaugeOrder implements Comparator<Gauge> {
+        private int order;
+
+        public GaugeOrder(boolean up) {
+            order = up ? 1 : 1;
+        }
+
+        public int compare(Gauge a, Gauge b) {
+            return order * a.getRange().getA().compareTo(b.getRange().getA());
+        }
+    } // class GaugeOrder
+
+    public static final GaugeOrder GAUGE_UP   = new GaugeOrder(true);
+    public static final GaugeOrder GAUGE_DOWN = new GaugeOrder(false);
 
     /**
      * This method creates one element for each gauge of the selected river that
@@ -112,19 +128,38 @@
 
         Element[] elements = new Element[num];
 
+        double rangeFrom = dist[0];
+        double rangeTo   = dist[1];
+
         int idx = 0;
 
-        for (Gauge gauge: gauges) {
-            Range range  = gauge.getRange();
-            double lower = range.getA().doubleValue();
-            double upper = range.getB().doubleValue();
+        if (rangeFrom < rangeTo) {
+            Collections.sort(gauges, GAUGE_UP);
+            for (Gauge gauge: gauges) {
+                Range range = gauge.getRange();
+                double lower = range.getA().doubleValue();
+                double upper = range.getB().doubleValue();
 
-            double from = dist[0] < lower ? lower : dist[0];
-            double to   = dist[1] > upper ? upper : dist[1];
+                double from = lower < rangeFrom ? rangeFrom : lower;
+                double to   = upper > rangeTo   ? rangeTo   : upper;
 
-            String key = Double.toString(from) + ";" + Double.toString(to);
+                elements[idx++] = createItem(
+                    cr, new String[] { from + ";" + to, ""});
+            }
+        }
+        else {
+            Collections.sort(gauges, GAUGE_DOWN);
+            for (Gauge gauge: gauges) {
+                Range range = gauge.getRange();
+                double lower = range.getA().doubleValue();
+                double upper = range.getB().doubleValue();
 
-            elements[idx++] = createItem(cr, new String[] {key, ""});
+                double to   = upper < rangeTo   ? rangeTo   : upper;
+                double from = lower > rangeFrom ? rangeFrom : lower;
+
+                elements[idx++] = createItem(
+                    cr, new String[] { to + ";" + from, ""});
+            }
         }
 
         return elements;

http://dive4elements.wald.intevation.org