Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java @ 2190:2792d2617be9
Introduced an abstract MinMaxState and a concrete class IntRangeState to add min/max value pairs.
flys-artifacts/trunk@3800 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 27 Jan 2012 13:23:56 +0000 |
parents | 6b0ae0f2cae6 |
children | 59af81364eb1 |
rev | line source |
---|---|
146
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 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
|
4 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
|
5 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
|
6 import java.util.Arrays; |
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
|
7 import java.util.Comparator; |
146
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 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
|
10 |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 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
|
12 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
|
13 |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 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
|
15 |
315
94c176fdcb89
Removed the SessionHolder and adapted imports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
16 import de.intevation.flys.backend.SessionHolder; |
146
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.flys.model.Gauge; |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.flys.model.DischargeTable; |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.flys.model.DischargeTableValue; |
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 public class DischargeTables |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 implements Serializable |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 { |
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
|
24 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
|
25 |
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
|
26 public static final double DEFAULT_SCALE = 100.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
|
27 |
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
|
28 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
|
29 |
146
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 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
|
31 |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 protected String riverName; |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
154
03362976fa0f
DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
34 protected double scale; |
03362976fa0f
DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
35 |
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
|
36 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
|
37 |
150
c904d52cdfd0
Don't used interleaved x/y data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
38 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
|
39 |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 public DischargeTables() { |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 } |
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 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
|
44 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
|
45 } |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
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
|
47 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
|
48 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
|
49 } |
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 |
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 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
|
52 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
|
53 } |
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 |
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 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
|
56 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
|
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 |
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 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
|
60 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
|
61 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
|
62 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 ) { |
154
03362976fa0f
DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
64 scale = Double.NaN; |
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
|
65 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
|
66 this.riverName = riverName; |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 this.gaugeNames = gaugeNames; |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 } |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 |
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
|
70 public double [][] getFirstTable() { |
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 return getFirstTable(DEFAULT_SCALE); |
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
|
72 } |
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
|
73 |
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
|
74 public double [][] getFirstTable(double scale) { |
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
|
75 Map<String, double [][]> values = getValues(scale); |
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 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
|
77 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
|
78 } |
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 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
|
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 |
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 public Map<String, double [][]> getValues() { |
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 return getValues(DEFAULT_SCALE); |
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 } |
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
|
85 |
153
c97f9bc9b642
The out() operation of the WINFO artifact draws discharge tables for gauges specified by the user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
150
diff
changeset
|
86 public Map<String, double [][]> getValues(double scale) { |
154
03362976fa0f
DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
87 if (values == null || scale != this.scale) { |
153
c97f9bc9b642
The out() operation of the WINFO artifact draws discharge tables for gauges specified by the user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
150
diff
changeset
|
88 values = loadValues(scale); |
154
03362976fa0f
DischargeTables: Cache the scale, too. Otherwise two calls to getValues() with different arguments will result in the same output.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
153
diff
changeset
|
89 this.scale = scale; |
146
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 return values; |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 } |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 |
1929
6b0ae0f2cae6
(Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
735
diff
changeset
|
94 /** |
6b0ae0f2cae6
(Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
735
diff
changeset
|
95 * Returns mapping of gauge name to values. |
6b0ae0f2cae6
(Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
735
diff
changeset
|
96 */ |
153
c97f9bc9b642
The out() operation of the WINFO artifact draws discharge tables for gauges specified by the user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
150
diff
changeset
|
97 protected Map<String, double [][]> loadValues(double scale) { |
150
c904d52cdfd0
Don't used interleaved x/y data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
98 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
|
99 |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
100 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
|
101 |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
102 Query gaugeQuery = session.createQuery( |
336
7f13ed751277
Fixed broken HQL statement.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
334
diff
changeset
|
103 "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
|
104 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
|
105 |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 if (gauges.isEmpty()) { |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
110 log.warn( |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
111 "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
|
112 continue; |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
113 } |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
114 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
|
115 |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
116 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
|
117 |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
118 if (tables.isEmpty()) { |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
119 log.warn( |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
120 "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
|
121 continue; |
146
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 } |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
124 // TODO: Filter by time interval |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
125 DischargeTable table = tables.get(0); |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
126 |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
127 List<DischargeTableValue> dtvs = |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
128 table.getDischargeTableValues(); |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
129 |
333
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
130 final double [][] vs = new double[2][dtvs.size()]; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
131 |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
132 boolean qSorted = true; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
133 |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
134 double lastQ = -Double.MAX_VALUE; |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
135 |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
136 int idx = 0; |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
137 for (DischargeTableValue dtv: dtvs) { |
333
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
138 double q = dtv.getQ().doubleValue(); |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
139 vs[0][idx] = q * scale; |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
140 vs[1][idx] = dtv.getW().doubleValue() * scale; |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
141 ++idx; |
333
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
142 |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
143 if (qSorted && lastQ > q) { |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
144 qSorted = false; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
145 } |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
146 lastQ = q; |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
147 } |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
148 |
333
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
149 if (!qSorted) { |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
150 log.debug("need to sort by q values"); |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
151 // TODO: Do this db level. |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
152 // XXX: This is so ugly :-( |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
153 Integer [] indices = new Integer[vs[0].length]; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
154 for (int i = 0; i < indices.length; ++i) { |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
155 indices[i] = i; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
156 } |
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
|
157 |
333
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
158 Arrays.sort(indices, new Comparator<Integer>() { |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
159 public int compare(Integer a, Integer b) { |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
160 double va = vs[1][a]; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
161 double vb = vs[1][b]; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
162 double d = va - vb; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
163 if (d < 0.0) return -1; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
164 if (d > 0.0) return +1; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
165 return 0; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
166 } |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
167 }); |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
168 |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
169 double [][] vs2 = new double[2][vs[0].length]; |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
170 for (int i = 0; i < indices.length; ++i) { |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
171 vs2[0][i] = vs[0][indices[i]]; |
337
ec17fad34061
Discharge table: Fix problem when sorting by q (copied w instead of q).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
336
diff
changeset
|
172 vs2[1][i] = vs[1][indices[i]]; |
333
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
173 } |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
174 values.put(gaugeName, vs2); |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
175 } |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
176 else { |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
177 values.put(gaugeName, vs); |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
178 } |
67b3f54188aa
Discharge tables: Sorting of q values was done wrong.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
329
diff
changeset
|
179 |
146
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 } |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
181 |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
154
diff
changeset
|
182 return values; |
146
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 } |
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 |
376
aa0889141b15
Removed an unused parameter from DischargeTables.getQForW().
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
337
diff
changeset
|
185 public static double getQForW(double [][] values, double w) { |
378
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
186 |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
187 boolean debug = log.isDebugEnabled(); |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
188 |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
189 if (debug) { |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
190 log.debug("calculating getQForW(" + w + ")"); |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
191 } |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
192 |
735
db68806e6563
Fixed "W am Pegel" calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
378
diff
changeset
|
193 int index = Arrays.binarySearch(values[1], 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
|
194 if (index >= 0) { |
334
b7c8df643dc4
Discharge table: we need a getQForW() and not a getWForQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
333
diff
changeset
|
195 return values[0][index]; |
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
|
196 } |
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
|
197 |
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
|
198 index = -index - 1; // insert position |
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
|
199 |
378
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
200 if (index < 1 || index >= values[0].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
|
201 // do not extraploate |
378
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
202 if (debug) { |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
203 log.debug("we do not extrapolate: NaN"); |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
204 } |
334
b7c8df643dc4
Discharge table: we need a getQForW() and not a getWForQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
333
diff
changeset
|
205 return Double.NaN; |
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
|
206 } |
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
|
207 |
735
db68806e6563
Fixed "W am Pegel" calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
378
diff
changeset
|
208 double w1 = values[1][index-1]; |
db68806e6563
Fixed "W am Pegel" calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
378
diff
changeset
|
209 double w2 = values[1][index ]; |
db68806e6563
Fixed "W am Pegel" calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
378
diff
changeset
|
210 double q1 = values[0][index-1]; |
db68806e6563
Fixed "W am Pegel" calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
378
diff
changeset
|
211 double q2 = values[0][index ]; |
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
|
212 |
334
b7c8df643dc4
Discharge table: we need a getQForW() and not a getWForQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
333
diff
changeset
|
213 // q1 = m*w1 + b |
b7c8df643dc4
Discharge table: we need a getQForW() and not a getWForQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
333
diff
changeset
|
214 // q2 = m*w2 + b |
b7c8df643dc4
Discharge table: we need a getQForW() and not a getWForQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
333
diff
changeset
|
215 // q2 - q1 = m*(w2 - w1) |
b7c8df643dc4
Discharge table: we need a getQForW() and not a getWForQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
333
diff
changeset
|
216 // m = (q2 - q1)/(w2 - w1) # w2 != w1 |
b7c8df643dc4
Discharge table: we need a getQForW() and not a getWForQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
333
diff
changeset
|
217 // b = q1 - m*w1 |
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
|
218 |
378
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
219 double q; |
334
b7c8df643dc4
Discharge table: we need a getQForW() and not a getWForQ().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
333
diff
changeset
|
220 if (w1 == w2) { |
378
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
221 q = 0.5*(q1 + q2); |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
222 if (debug) { |
1929
6b0ae0f2cae6
(Minor) cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
735
diff
changeset
|
223 log.debug("same w1 and w2: " + w1); |
378
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
224 } |
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
|
225 } |
378
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
226 else { |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
227 double m = (q2 - q1)/(w2 - w1); |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
228 double b = q1 - m*w1; |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
229 q = w*m + b; |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
230 } |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
231 if (debug) { |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
232 log.debug("Q(" + w + ") = " + q); |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
233 } |
20c3a5b36434
Repaired DischargeTables.getQForW()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
376
diff
changeset
|
234 return q; |
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
|
235 } |
146
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 } |
e8dfe6ba2000
Fetch w/q values of discharge tables for given gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |