changeset 2165:637dd38d0e2f

Handle the case in "W auf freier Strecke" where more than ne Q is related to a W. flys-artifacts/trunk@3753 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 23 Jan 2012 17:39:51 +0000
parents d548e2e13524
children 2898b1ff6013
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java
diffstat 2 files changed, 30 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Jan 23 16:55:42 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jan 23 17:39:51 2012 +0000
@@ -1,3 +1,9 @@
+2012-01-23	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Handle the case in "W auf freier Strecke" where more than
+	  one Q is related to a W. TODO: Generate user report.
+
 2012-01-23	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	Mon Jan 23 16:55:42 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Mon Jan 23 17:39:51 2012 +0000
@@ -364,10 +364,16 @@
             logger.debug("Determine Q values based on a set of W values.");
             qSel = false;
             ws   = getWs();
-            qs   = getQsForWs(ws);
-            if (qs == null) {
+            double [][] qws = getQsForWs(ws);
+            if (qws == null) {
                 return error(new WQKms[0], "conversion ws to qs failed.");
             }
+            qs = qws[0];
+
+            if (qws[1] != null) { // If new ws where generated.
+                // TODO: Inform user!
+                ws = qws[1];
+            }
         }
 
         WstValueTable wst = WstValueTableFactory.getTable(river);
@@ -714,7 +720,7 @@
      *
      * @return an array of Q values.
      */
-    public double[] getQsForWs(double[] ws) {
+    public double [][] getQsForWs(double[] ws) {
 
         boolean debug = logger.isDebugEnabled();
 
@@ -735,6 +741,8 @@
         }
 
         if (isFreeW()) {
+            // The simple case of the "Bezugslinienverfahren"
+            // "W auf freier Strecke".
             WstValueTable wst = WstValueTableFactory.getTable(r);
             if (wst == null) {
                 logger.warn("no wst value table found");
@@ -742,22 +750,24 @@
             }
             double km = range[0];
 
-            double [] outQs = new double[ws.length];
+            TDoubleArrayList outQs = new TDoubleArrayList(ws.length);
+            TDoubleArrayList outWs = new TDoubleArrayList(ws.length);
+
+            boolean generatedWs = false;
 
             for (int i = 0; i < ws.length; ++i) {
+                // There could bemore than one Q per W.
                 double [] qs = wst.findQsForW(km, ws[i]);
-                if (qs.length < 1) {
-                    logger.warn("no q found for w = " + ws[i]);
-                    outQs[i] = Double.NaN;
+                for (int j = 0; j < qs.length; ++j) {
+                    outWs.add(ws[i]);
+                    outQs.add(qs[j]);
                 }
-                if (qs.length > 1) {
-                    // TODO: Generate more than w/q line!
-                    logger.warn("more than one q found for w = " + ws[i]);
-                }
-                outQs[i] = qs[0];
+                generatedWs |= qs.length != 1;
             }
 
-            return outQs;
+            return new double [][] { 
+                outQs.toNativeArray(), 
+                generatedWs ? outWs.toNativeArray() : null };
         }
 
         if (debug) {
@@ -787,7 +797,7 @@
             }
         }
 
-        return qs;
+        return new double [][] { qs, null };
     }
 
 

http://dive4elements.wald.intevation.org