comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQ.java @ 6302:d5af7b17efc2

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.
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 12 Jun 2013 16:01:46 +0200
parents af13ceeba52a
children ebba1a795d76
comparison
equal deleted inserted replaced
6301:20a32dbdbb59 6302:d5af7b17efc2
9 package org.dive4elements.river.artifacts.model; 9 package org.dive4elements.river.artifacts.model;
10 10
11 import org.dive4elements.river.utils.DoubleUtil; 11 import org.dive4elements.river.utils.DoubleUtil;
12 12
13 import gnu.trove.TDoubleArrayList; 13 import gnu.trove.TDoubleArrayList;
14
15 import java.math.BigDecimal;
14 16
15 import java.util.regex.Matcher; 17 import java.util.regex.Matcher;
16 import java.util.regex.Pattern; 18 import java.util.regex.Pattern;
17 19
18 import org.apache.log4j.Logger; 20 import org.apache.log4j.Logger;
106 108
107 @Override 109 @Override
108 public void removeNaNs() { 110 public void removeNaNs() {
109 DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs }); 111 DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs });
110 } 112 }
113
114 /** Returns either a modified copy or the same Object with fixed W values.
115 * If a conversion takes place converted is set to true
116 */
117 public static WQ getFixedWQforExportAtGauge(WQ wq, BigDecimal datum) {
118 if (wq.getReferenceSystem() == wq.CENTIMETER_AT_GAUGE) {
119 // Do nothing
120 return wq;
121 }
122 // If we convert we work on a copy to avoid side effects.
123 WQ ret = new WQ(wq.size(), wq.getName());
124
125 // When we convert and have a datum we have a calculated
126 // result at a gauge so we must subtract the datum.
127 double subtractDatum = datum == null ? 0 : datum.doubleValue();
128 for (int i=0; i < wq.size(); i++) {
129 ret.add((wq.get(i)[0] - subtractDatum)* 100, wq.get(i)[1]);
130 }
131 log.debug("Converted W values to centimeter and substracted: " + subtractDatum);
132 return ret;
133 }
111 } 134 }
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 135 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org