# HG changeset patch # User Bettina Gruenbauer # Date 1358781560 -3600 # Node ID dd146d5ee99f57b5b340381e2ee606d2053b5659 # Parent 4ec9d7931b13971cec9ce53ea14f9b6321bb4421# Parent bcf25d8c183e6b8910c83d8ff972d76d0c1ae6b2 merge diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java Mon Jan 21 16:19:20 2013 +0100 @@ -1,18 +1,21 @@ package de.intevation.flys.artifacts.model; +import de.intevation.flys.artifacts.access.Calculation4Access; + import de.intevation.flys.artifacts.math.BackJumpCorrector; import de.intevation.flys.artifacts.math.Function; import de.intevation.flys.artifacts.math.Identity; import de.intevation.flys.artifacts.math.Linear; import de.intevation.flys.artifacts.model.RiverFactory; + import de.intevation.flys.artifacts.model.WstValueTable.QPosition; import de.intevation.flys.model.River; import de.intevation.flys.utils.DoubleUtil; -import de.intevation.flys.artifacts.access.Calculation4Access; +import gnu.trove.TDoubleArrayList; import java.util.ArrayList; import java.util.Arrays; @@ -273,12 +276,14 @@ } // Generate the "Umhuellende". - results = generateInfolding(table, results, from, to, step); + QKms [] qkms = generateInfolding(table, results, from, to, step); + + // TODO: Use qkms in a new result type. return new CalculationResult(results, this); } - protected WQKms [] generateInfolding( + protected QKms [] generateInfolding( WstValueTable wst, WQKms [] results, double from, @@ -290,43 +295,43 @@ InfoldingColumns ic = new InfoldingColumns(columns); ic.markInfoldingColumns(results); - List infoldings = new ArrayList(); + List infoldings = new ArrayList(); boolean [] infoldingColumns = ic.getInfoldingColumns(); + + double [] kms = null; + for (int i = 0; i < infoldingColumns.length; ++i) { if (!infoldingColumns[i]) { continue; } - double q = columns[i].getQRangeTree().findQ(from); - if (Double.isNaN(q)) { - addProblem(from, "cannot.find.q"); - continue; + + kms = kms == null + ? DoubleUtil.explode(from, to, step) + : (double [])kms.clone(); + + QRangeTree.QuickQFinder qf = + columns[i].getQRangeTree().new QuickQFinder(); + + int numProblemsBefore = numProblems(); + double [] qs = qf.findQs(kms, this); + + // TODO: i18n + String name = "Umh\u00fcllende " + columns[i].getName(); + + QKmsImpl qkms = new QKmsImpl( + new TDoubleArrayList(kms), + new TDoubleArrayList(qs), + name); + + if (numProblems() > numProblemsBefore) { + qkms.removeNaNs(); } - double [] kms = DoubleUtil.explode(from, to, step); - double [] oqs = new double[kms.length]; - double [] ows = new double[kms.length]; - boolean success = - wst.interpolate(q, from, kms, ows, oqs, this) != null; - if (success) { - // TODO: generate a better name. I18N. - String name = "Umh\u00fcllende " + columns[i].getName(); - WQKms wqkms = new WQKms(kms, oqs, ows, name); - infoldings.add(wqkms); - } + infoldings.add(qkms); } - int N = infoldings.size(); - if (N > 0) { - WQKms [] newResults = new WQKms[results.length + N]; - System.arraycopy(results, 0, newResults, 0, results.length); - for (int i = 0; i < N; ++i) { - newResults[i+results.length] = infoldings.get(i); - } - results = newResults; - } - - return results; + return infoldings.toArray(new QKms[infoldings.size()]); } protected String createName(int index) { diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/InfoldingColumns.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/InfoldingColumns.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/InfoldingColumns.java Mon Jan 21 16:19:20 2013 +0100 @@ -31,18 +31,18 @@ return infoldingColumns; } - public void markInfoldingColumns(WQKms [] wqkms) { - for (WQKms wqk: wqkms) { - markInfoldingColumns(wqk); + public void markInfoldingColumns(QKms [] qkms) { + for (QKms qk: qkms) { + markInfoldingColumns(qk); } } - public void markInfoldingColumns(WQKms wqkms) { - int N = wqkms.size(); + public void markInfoldingColumns(QKms qkms) { + int N = qkms.size(); int C = qFinders.length-1; for (int i = 0; i < N; ++i) { - double km = wqkms.getKm(i); - double q = wqkms.getQ(i); + double km = qkms.getKm(i); + double q = qkms.getQ(i); double above = Double.MAX_VALUE; double below = -Double.MAX_VALUE; int aboveIdx = -1; diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java Mon Jan 21 16:19:20 2013 +0100 @@ -2,6 +2,8 @@ import de.intevation.flys.artifacts.math.Linear; +import de.intevation.flys.utils.DoubleUtil; + import gnu.trove.TDoubleArrayList; import java.io.Serializable; @@ -124,7 +126,7 @@ } public void removeNaNs() { - W.removeNaNs(columns); + DoubleUtil.removeNaNs(columns); } public int [] columnIndices(String [] columns) { diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QKmsImpl.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QKmsImpl.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QKmsImpl.java Mon Jan 21 16:19:20 2013 +0100 @@ -2,6 +2,8 @@ import gnu.trove.TDoubleArrayList; +import de.intevation.flys.utils.DoubleUtil; + public class QKmsImpl extends NamedObjectImpl implements QKms @@ -73,4 +75,8 @@ public TDoubleArrayList allQs() { return qs; } + + public void removeNaNs() { + DoubleUtil.removeNaNs(new TDoubleArrayList [] { kms, qs }); + } } diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java Mon Jan 21 16:19:20 2013 +0100 @@ -145,6 +145,23 @@ last = QRangeTree.this.findNode(pos); return last != null ? last.q : Double.NaN; } + + public double [] findQs(double [] kms, Calculation report) { + return findQs(kms, new double[kms.length], report); + } + + public double [] findQs( + double [] kms, + double [] qs, + Calculation report + ) { + for (int i = 0; i < kms.length; ++i) { + if (Double.isNaN(qs[i] = findQ(kms[i]))) { + report.addProblem(kms[i], "cannot.find.q"); + } + } + return qs; + } } // class QuickQFinder protected Node root; diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java Mon Jan 21 16:19:20 2013 +0100 @@ -1,6 +1,7 @@ package de.intevation.flys.artifacts.model; import de.intevation.flys.utils.DataUtil; +import de.intevation.flys.utils.DoubleUtil; import gnu.trove.TDoubleArrayList; @@ -60,34 +61,8 @@ return ws.min(); } - public static void removeNaNs(TDoubleArrayList [] arrays) { - - int dest = 0; - - int A = arrays.length; - int N = arrays[0].size(); - - OUTER: for (int i = 0; i < N; ++i) { - for (int j = 0; j < A; ++j) { - TDoubleArrayList a = arrays[j]; - double v = a.getQuick(i); - if (Double.isNaN(v)) { - continue OUTER; - } - a.setQuick(dest, v); - } - ++dest; - } - - if (dest < N) { - for (int i = 0; i < A; ++i) { - arrays[i].remove(dest, N-dest); - } - } - } - public void removeNaNs() { - removeNaNs(new TDoubleArrayList [] { ws }); + DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws }); } public boolean guessWaterIncreasing() { diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java Mon Jan 21 16:19:20 2013 +0100 @@ -1,10 +1,12 @@ package de.intevation.flys.artifacts.model; +import de.intevation.flys.utils.DoubleUtil; + +import gnu.trove.TDoubleArrayList; + import java.util.regex.Matcher; import java.util.regex.Pattern; -import gnu.trove.TDoubleArrayList; - import org.apache.log4j.Logger; public class WQ @@ -96,7 +98,7 @@ @Override public void removeNaNs() { - removeNaNs(new TDoubleArrayList [] { ws, qs }); + DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs }); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQCKms.java Mon Jan 21 16:19:20 2013 +0100 @@ -1,5 +1,7 @@ package de.intevation.flys.artifacts.model; +import de.intevation.flys.utils.DoubleUtil; + import gnu.trove.TDoubleArrayList; /** @@ -32,7 +34,7 @@ @Override public void removeNaNs() { - removeNaNs(new TDoubleArrayList [] { ws, qs, cws, kms }); + DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs, cws, kms }); } /** diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java Mon Jan 21 16:19:20 2013 +0100 @@ -1,5 +1,7 @@ package de.intevation.flys.artifacts.model; +import de.intevation.flys.utils.DoubleUtil; + import gnu.trove.TDoubleArrayList; import org.apache.log4j.Logger; @@ -54,7 +56,7 @@ @Override public void removeNaNs() { - removeNaNs(new TDoubleArrayList [] { ws, qs, kms }); + DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs, kms }); } /** diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java Mon Jan 21 16:19:20 2013 +0100 @@ -3,6 +3,8 @@ import de.intevation.flys.artifacts.math.Function; import de.intevation.flys.artifacts.math.Identity; +import de.intevation.flys.utils.DoubleUtil; + import gnu.trove.TDoubleArrayList; public class WW @@ -175,7 +177,7 @@ @Override public void removeNaNs() { - removeNaNs(new TDoubleArrayList [] { ws, ws2 }); + DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, ws2 }); } public double minWs2() { diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWQQ.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWQQ.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WWQQ.java Mon Jan 21 16:19:20 2013 +0100 @@ -2,6 +2,8 @@ import de.intevation.flys.artifacts.math.Identity; +import de.intevation.flys.utils.DoubleUtil; + import gnu.trove.TDoubleArrayList; public class WWQQ @@ -91,7 +93,7 @@ @Override public void removeNaNs() { - removeNaNs(new TDoubleArrayList [] { ws, ws2, qs1, qs2 }); + DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, ws2, qs1, qs2 }); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 4ec9d7931b13 -r dd146d5ee99f flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java Mon Jan 21 15:55:08 2013 +0100 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java Mon Jan 21 16:19:20 2013 +0100 @@ -209,5 +209,31 @@ } return max; } + + public static void removeNaNs(TDoubleArrayList [] arrays) { + + int dest = 0; + + int A = arrays.length; + int N = arrays[0].size(); + + OUTER: for (int i = 0; i < N; ++i) { + for (int j = 0; j < A; ++j) { + TDoubleArrayList a = arrays[j]; + double v = a.getQuick(i); + if (Double.isNaN(v)) { + continue OUTER; + } + a.setQuick(dest, v); + } + ++dest; + } + + if (dest < N) { + for (int i = 0; i < A; ++i) { + arrays[i].remove(dest, N-dest); + } + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :