diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 676:c501f27c1f71

Added error reporting to 'Dauerzahlen' calculation. flys-artifacts/trunk@2100 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 10 Jun 2011 12:38:08 +0000
parents 913b52064449
children a95f34f1f39a
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Fri Jun 10 10:10:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Fri Jun 10 12:38:08 2011 +0000
@@ -107,7 +107,8 @@
             double        km,
             double []     iqs,
             double []     ows,
-            WstValueTable table
+            WstValueTable table,
+            Calculation   errors
         ) {
             double kmWeight = Linear.factor(km, this.km, other.km);
 
@@ -117,9 +118,23 @@
                 if (table.getQPosition(km, iqs[i], qPosition) != null) {
                     double wt =       getW(qPosition);
                     double wo = other.getW(qPosition);
-                    ows[i] = Linear.weight(kmWeight, wt, wo);
+                    if (Double.isNaN(wt) || Double.isNaN(wo)) {
+                        if (errors != null) {
+                            // TODO: I18N
+                            errors.addProblem(
+                                km, "cannot find w for q = " + iqs[i]);
+                        }
+                        ows[i] = Double.NaN;
+                    }
+                    else {
+                        ows[i] = Linear.weight(kmWeight, wt, wo);
+                    }
                 }
                 else {
+                    if (errors != null) {
+                        // TODO: I18N
+                        errors.addProblem(km, "cannot find q = " + iqs[i]);
+                    }
                     ows[i] = Double.NaN;
                 }
             }
@@ -282,7 +297,15 @@
     }
 
     public double [] interpolateW(double km, double [] qs, double [] ws) {
+        return interpolateW(km, qs, ws, null);
+    }
 
+    public double [] interpolateW(
+        double      km,
+        double []   qs, 
+        double []   ws,
+        Calculation errors
+    ) {
         int rowIndex = Collections.binarySearch(rows, new Row(km));
 
         QPosition qPosition = new QPosition();
@@ -290,9 +313,21 @@
         if (rowIndex >= 0) { // direct row match
             Row row = rows.get(rowIndex);
             for (int i = 0; i < qs.length; ++i) {
-                ws[i] = getQPosition(km, qs[i], qPosition) != null
-                    ? row.getW(qPosition)
-                    : Double.NaN;
+                if (getQPosition(km, qs[i], qPosition) == null) {
+                    if (errors != null) {
+                        // TODO: I18N
+                        errors.addProblem(km, "cannot find q = " + qs[i]);
+                    }
+                    ws[i] = Double.NaN;
+                }
+                else {
+                    if (Double.isNaN(ws[i] = row.getW(qPosition))
+                    && errors != null) {
+                        // TODO: I18N
+                        errors.addProblem(
+                            km, "cannot find w for q = " + qs[i]);
+                    }
+                }
             }
         }
         else { // needs bilinear interpolation
@@ -301,11 +336,14 @@
             if (rowIndex < 1 || rowIndex >= rows.size()) {
                 // do not extrapolate
                 Arrays.fill(ws, Double.NaN);
+                if (errors != null) {
+                    errors.addProblem(km, "km not found");
+                }
             }
             else {
                 Row r1 = rows.get(rowIndex-1);
                 Row r2 = rows.get(rowIndex);
-                r1.interpolateW(r2, km, qs, ws, this);
+                r1.interpolateW(r2, km, qs, ws, this, errors);
             }
         }
 

http://dive4elements.wald.intevation.org