# HG changeset patch # User Felix Wolfsteller # Date 1372741825 -7200 # Node ID 641ec405c4aca0c90532c800293574fba3550a05 # Parent 5afb1cda5885d993ba3d4ec5c13ebcdb9dabca9f MainValuesArtifact: Added method to determine whether at gauge or not. diff -r 5afb1cda5885 -r 641ec405c4ac artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java Tue Jul 02 07:09:19 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java Tue Jul 02 07:10:25 2013 +0200 @@ -316,6 +316,21 @@ return spawnState(); } + /** + * Access the Gauge that the mainvalues are taken from. + * @return Gauge that main values are taken from or null in case of + * invalid parameterization. + */ + protected Gauge getGauge(double km) { + River river = RiverUtils.getRiver(this); + + if (river == null) { + logger.error("River is null"); + return null; + } + + return river.determineGaugeByPosition(km); + } /** * Access the Gauge that the mainvalues are taken from. @@ -389,12 +404,53 @@ } - /** - * Get a list of "W" main values. - * @param atGauge if true, do not interpolate - * @return list of W main values. - */ - public List getMainValuesW(boolean atGauge) { + /** Get main values of km. */ + public List getMainValuesW(double[] kms) { + List filteredList = new ArrayList(); + boolean atGauge = false; + double gaugeDatum = 0d; + Gauge gauge = getGauge(kms[0]); + if (gauge == null) { + return filteredList; + } + else if (Math.abs(kms[0] - gauge.getStation().doubleValue()) < 1e-4) { + atGauge = true; + gaugeDatum = gauge.getDatum().doubleValue(); + } + + WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this)); + Calculation c = new Calculation(); + + double gaugeStation = gauge.getStation().doubleValue(); + double w_out[] = {0.0f}; + double q_out[] = {0.0f}; + if (gauge != null) { + List orig = gauge.getMainValues(); + for (MainValue mv : orig) { + if (atGauge) { + if (mv.getMainValue().getType().getName().equals("W")) { + filteredList.add(new NamedDouble(mv.getMainValue().getName(), + mv.getValue().doubleValue())); + } + } else + // We cannot interpolate the W values, so derive them + // from given Q values. + if (mv.getMainValue().getType().getName().equals("Q")) { + interpolator.interpolate(mv.getValue().doubleValue(), + gaugeStation, kms, w_out, q_out, c); + + filteredList.add(new NamedDouble( + "W(" + mv.getMainValue().getName() +")", + w_out[0] + )); + } + } + } + return filteredList; + } + + + public List getMainValuesW(boolean atGauge, double[] kms) { List filteredList = new ArrayList(); Gauge gauge = getGauge(); WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this));