# HG changeset patch # User Andre Heinecke # Date 1371045706 -7200 # Node ID d5af7b17efc255f6349c3055659c57747ae7ba3d # Parent 20a32dbdbb596f0018ec87ea33d057f039512a55 Add conversion function that prepares a WQ table for export at gauge This substracts the datum of the gauge and converts the W values to cm. Returns a copy if the WQ table is modified. diff -r 20a32dbdbb59 -r d5af7b17efc2 artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQ.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQ.java Wed Jun 12 10:54:27 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQ.java Wed Jun 12 16:01:46 2013 +0200 @@ -12,6 +12,8 @@ import gnu.trove.TDoubleArrayList; +import java.math.BigDecimal; + import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -108,5 +110,26 @@ public void removeNaNs() { DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs }); } + + /** Returns either a modified copy or the same Object with fixed W values. + * If a conversion takes place converted is set to true + */ + public static WQ getFixedWQforExportAtGauge(WQ wq, BigDecimal datum) { + if (wq.getReferenceSystem() == wq.CENTIMETER_AT_GAUGE) { + // Do nothing + return wq; + } + // If we convert we work on a copy to avoid side effects. + WQ ret = new WQ(wq.size(), wq.getName()); + + // When we convert and have a datum we have a calculated + // result at a gauge so we must subtract the datum. + double subtractDatum = datum == null ? 0 : datum.doubleValue(); + for (int i=0; i < wq.size(); i++) { + ret.add((wq.get(i)[0] - subtractDatum)* 100, wq.get(i)[1]); + } + log.debug("Converted W values to centimeter and substracted: " + subtractDatum); + return ret; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :