annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/DischargeTables.java @ 8202:e4606eae8ea5

sed src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:58:17 +0200
parents 20a32dbdbb59
children 0a5239a1e46e
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5340
diff changeset
9 package org.dive4elements.river.artifacts.model;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.util.List;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import java.util.Map;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.util.HashMap;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.util.Arrays;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import java.io.Serializable;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 import org.hibernate.Session;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import org.hibernate.Query;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 import org.apache.log4j.Logger;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5340
diff changeset
23 import org.dive4elements.river.backend.SessionHolder;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5340
diff changeset
24 import org.dive4elements.river.model.Gauge;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5340
diff changeset
25 import org.dive4elements.river.model.DischargeTable;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5340
diff changeset
26 import org.dive4elements.river.model.DischargeTableValue;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
28 import gnu.trove.TDoubleArrayList;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
29
3050
02254d763bc0 cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2418
diff changeset
30 /** Documentation goes here. */
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 public class DischargeTables
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 implements Serializable
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6301
diff changeset
34 /** Private log. */
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
35 private static Logger log = Logger.getLogger(DischargeTables.class);
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
36
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
37 public static final int MASTER = 0;
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
38
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 protected List<String> gaugeNames;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 protected String riverName;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
43 protected int kind;
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
44
150
c904d52cdfd0 Don't used interleaved x/y data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
45 protected Map<String, double [][]> values;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 public DischargeTables() {
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
50 public DischargeTables(String riverName, String gaugeName) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
51 this(riverName, gaugeName, MASTER);
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
54 public DischargeTables(String riverName, String gaugeName, int kind) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
55 this(riverName, new String [] { gaugeName }, kind);
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
56 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
57
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
58 public DischargeTables(String riverName, String [] gaugeNames) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
59 this(riverName, gaugeNames, MASTER);
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
60 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
61
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
62 public DischargeTables(String riverName, String [] gaugeNames, int kind) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
63 this(riverName, Arrays.asList(gaugeNames), kind);
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
64 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
65
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
66 public DischargeTables(
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
67 String riverName,
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
68 List<String> gaugeNames,
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
69 int kind
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
70 ) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
71 this.kind = kind;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 this.riverName = riverName;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 this.gaugeNames = gaugeNames;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
76 public double [][] getFirstTable() {
6301
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
77 Map<String, double [][]> values = getValues();
328
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
78 for (double [][] table: values.values()) {
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
79 return table;
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
80 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
81 return null;
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
82 }
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
83
07e642030172 Discharge tables: Added convenience constructors/methods to ease the access to the master discharge table of a gauge.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 315
diff changeset
84 public Map<String, double [][]> getValues() {
6301
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
85 if (values == null) {
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
86 values = loadValues();
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 return values;
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
1929
6b0ae0f2cae6 (Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 735
diff changeset
91 /**
6b0ae0f2cae6 (Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 735
diff changeset
92 * Returns mapping of gauge name to values.
6b0ae0f2cae6 (Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 735
diff changeset
93 */
6301
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
94 protected Map<String, double [][]> loadValues() {
150
c904d52cdfd0 Don't used interleaved x/y data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 146
diff changeset
95 Map<String, double [][]> values = new HashMap<String, double [][]>();
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
97 Session session = SessionHolder.HOLDER.get();
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
99 Query gaugeQuery = session.createQuery(
336
7f13ed751277 Fixed broken HQL statement.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 334
diff changeset
100 "from Gauge where name=:gauge and river.name=:river");
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
101 gaugeQuery.setParameter("river", riverName);
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
103 for (String gaugeName: gaugeNames) {
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
104 gaugeQuery.setParameter("gauge", gaugeName);
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
105 List<Gauge> gauges = gaugeQuery.list();
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
106 if (gauges.isEmpty()) {
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
107 log.warn(
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
108 "no gauge '"+gaugeName+"' at river '"+riverName+"'");
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
109 continue;
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
110 }
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
111 Gauge gauge = gauges.get(0);
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
113 List<DischargeTable> tables = gauge.getDischargeTables();
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
115 if (tables.isEmpty()) {
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
116 log.warn(
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
117 "no discharge table for gauge '" + gaugeName + "'");
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
118 continue;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
121 // TODO: Filter by time interval
4919
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
122 DischargeTable table = null;
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
123 for (DischargeTable dt : tables) {
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
124 if (dt.getKind() == 0) {
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
125 table = dt;
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
126 break;
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
127 }
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
128 }
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
129 if (table == null) {
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
130 table = tables.get(0);
dbe9b7d6b80b Find correct discharge table for gauge.
Raimund Renkert <rrenkert@intevation.de>
parents: 4226
diff changeset
131 }
6301
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
132 double [][] vs = loadDischargeTableValues(table);
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
133
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
134 values.put(gaugeName, vs);
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 }
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
136
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 154
diff changeset
137 return values;
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 }
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
139
2230
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
140
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
141 /**
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
142 * @param table The discharge table
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
143 *
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
144 * @return the values of a discharge table.
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
145 */
6301
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
146 public static double[][] loadDischargeTableValues(DischargeTable table) {
2230
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
147 List<DischargeTableValue> dtvs = table.getDischargeTableValues();
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
148
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
149 final double [][] vs = new double[2][dtvs.size()];
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
150
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
151 int idx = 0;
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
152 for (DischargeTableValue dtv: dtvs) {
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
153 double q = dtv.getQ().doubleValue();
6301
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
154 vs[0][idx] = q;
20a32dbdbb59 Remove discharge table scaling but add reference system to W
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
155 vs[1][idx] = dtv.getW().doubleValue();
2230
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
156 ++idx;
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
157 }
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
158
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
159 return vs;
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
160 }
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
161
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
162 private static final double EPSILON = 1e-5;
2230
59af81364eb1 Improved the 'historical discharge' calculation: implemented findValueForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1929
diff changeset
163
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
164 private static final boolean epsEquals(double a, double b) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
165 return Math.abs(a - b) < EPSILON;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
166 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
167
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
168 private static final boolean between(double a, double b, double x) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
169 if (a > b) { double t = a; a = b; b = t; }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
170 return x > a && x < b;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
171 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
172
5340
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
173 /**
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
174 * Find or interpolate Qs from q/w array.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
175 * @param values [[q0,q1,q2],[w0,w1,w2]]
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
176 * @param w W value to look for in values.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4919
diff changeset
177 */
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
178 public static double [] getQsForW(double [][] values, double w) {
378
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
179
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
180 boolean debug = log.isDebugEnabled();
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
181
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
182 if (debug) {
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
183 log.debug("getQsForW: W = " + w);
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
184 }
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
185
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
186 double [] qs = values[0];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
187 double [] ws = values[1];
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
188
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
189 int N = Math.min(qs.length, ws.length);
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
190
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
191 if (N == 0) {
378
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
192 if (debug) {
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
193 log.debug("Q(" + w + ") = []");
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
194 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
195 return new double [0];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
196 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
197
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
198 TDoubleArrayList outQs = new TDoubleArrayList();
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
199
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
200 if (epsEquals(ws[0], w)) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
201 outQs.add(qs[0]);
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
202 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
203
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
204 for (int i = 1; i < N; ++i) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
205 if (epsEquals(ws[i], w)) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
206 outQs.add(qs[i]);
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
207 }
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
208 else if (between(ws[i-1], ws[i], w)) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
209 double w1 = ws[i-1];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
210 double w2 = ws[i];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
211 double q1 = qs[i-1];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
212 double q2 = qs[i];
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
213
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
214 // q1 = m*w1 + b
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
215 // q2 = m*w2 + b
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
216 // q2 - q1 = m*(w2 - w1)
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
217 // m = (q2 - q1)/(w2 - w1) # w2 != w1
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
218 // b = q1 - m*w1
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
219 // w1 != w2
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
220
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
221 double m = (q2 - q1)/(w2 - w1);
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
222 double b = q1 - m*w1;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
223 double q = w*m + b;
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
224
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
225 outQs.add(q);
378
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
226 }
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
227 }
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
228
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
229 double [] result = outQs.toNativeArray();
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
230
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
231 if (debug) {
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
232 log.debug("Q(" + w + ") = " + Arrays.toString(result));
378
20c3a5b36434 Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 376
diff changeset
233 }
2418
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
234
899ca89f497e Another partial fix for flys/issue499: Do the W to Q conversions
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2230
diff changeset
235 return result;
329
0b2358bc716d Discharge table: Added static method getWForQ() to interpolate a w value for a given q value based on a given discharge table.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 328
diff changeset
236 }
4226
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
237
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
238 public static double [] getWsForQ(double [][] values, double q) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
239
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
240 boolean debug = log.isDebugEnabled();
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
241
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
242 if (debug) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
243 log.debug("getWsForQ: W = " + q);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
244 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
245
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
246 double [] qs = values[0];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
247 double [] ws = values[1];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
248
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
249 int N = Math.min(qs.length, ws.length);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
250
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
251 if (N == 0) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
252 if (debug) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
253 log.debug("W(" + q + ") = []");
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
254 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
255 return new double [0];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
256 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
257
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
258 TDoubleArrayList outWs = new TDoubleArrayList();
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
259
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
260 if (epsEquals(qs[0], q)) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
261 outWs.add(ws[0]);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
262 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
263
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
264 for (int i = 1; i < N; ++i) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
265 if (epsEquals(qs[i], q)) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
266 outWs.add(ws[i]);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
267 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
268 else if (between(qs[i-1], qs[i], q)) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
269 double w1 = ws[i-1];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
270 double w2 = ws[i];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
271 double q1 = qs[i-1];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
272 double q2 = qs[i];
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
273
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
274 // w1 = m*q1 + b
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
275 // w2 = m*q2 + b
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
276 // w2 - w1 = m*(q2 - q1)
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
277 // m = (w2 - w1)/(q2 - q1) # q2 != q1
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
278 // b = w1 - m*q1
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
279 // q1 != q2
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
280
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
281 double m = (w2 - w1)/(q2 - q1);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
282 double b = w1 - m*q1;
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
283 double w = q*m + b;
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
284
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
285 outWs.add(w);
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
286 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
287 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
288
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
289 double [] result = outWs.toNativeArray();
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
290
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
291 if (debug) {
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
292 log.debug("W(" + q + ") = " + Arrays.toString(result));
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
293 }
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
294
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
295 return result;
cb9f22c3553f DischargeTables: Added missing getWsForQ()
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4138
diff changeset
296 }
146
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
297 }
e8dfe6ba2000 Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
298 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org