Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java @ 5037:2837b11cdb13 dami
SCHEMA Change: Make hws_lines a 3d geom
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 20 Feb 2013 10:43:00 +0100 |
parents | 1ddbf66a2b0a |
children | a929d9a9fa1e |
rev | line source |
---|---|
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
3441
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
3 import de.intevation.flys.model.DischargeTable; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
4 import de.intevation.flys.model.Gauge; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
5 import de.intevation.flys.model.River; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
6 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
7 import de.intevation.flys.utils.DoubleUtil; |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
8 |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import java.io.Serializable; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
11 import java.util.ArrayList; |
3441
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
12 import java.util.Collections; |
3439
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
13 import java.util.Comparator; |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
14 import java.util.List; |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
16 import org.apache.log4j.Logger; |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
17 |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 public class Segment |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 implements Serializable |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 { |
3441
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
21 private static Logger log = Logger.getLogger(Segment.class); |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
3439
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
23 public static final Comparator<Segment> REF_CMP = |
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
24 new Comparator<Segment>() { |
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
25 @Override |
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
26 public int compare(Segment a, Segment b) { |
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
27 double d = a.referencePoint - b.referencePoint; |
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
28 if (d < 0d) return -1; |
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
29 return d > 0d ? +1 : 0; |
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
30 } |
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
31 }; |
cb11919cccf9
FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3419
diff
changeset
|
32 |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 protected double from; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 protected double to; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 protected double [] values; |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
36 protected double [] backup; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
37 protected double referencePoint; |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 public Segment() { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
42 public Segment(double referencePoint) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
43 this.referencePoint = referencePoint; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
44 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
45 |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 public Segment(double from, double to, double [] values) { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 this.from = from; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 this.to = to; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 this.values = values; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 public boolean isUp() { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 return from < to; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
3449
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
56 public boolean inside(double km) { |
3552
1df6984628c3
S/Q: Extented the result data model of the S/Q calculation to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3449
diff
changeset
|
57 return from < to |
3449
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
58 ? km >= from && km <= to |
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
59 : km >= to && km <= from; |
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
60 } |
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
61 |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
62 @Override |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 public String toString() { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 StringBuilder sb = new StringBuilder("Segment: ["); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 sb.append("from: ").append(from).append("; to: ") |
670
8124ca1ecaaa
Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
655
diff
changeset
|
66 .append(to) |
8124ca1ecaaa
Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
655
diff
changeset
|
67 .append("; ref: ").append(referencePoint) |
8124ca1ecaaa
Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
655
diff
changeset
|
68 .append("; values: ("); |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 for (int i = 0; i < values.length; ++i) { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 if (i > 0) sb.append(", "); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 sb.append(values[i]); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 sb.append(")]"); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 return sb.toString(); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
77 public void setFrom(double from) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
78 this.from = from; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
79 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
80 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
81 public void backup() { |
3419
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
82 backup = values != null |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
83 ? (double [])values.clone() |
da7cf0e3ccaa
FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
670
diff
changeset
|
84 : null; |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
85 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
86 |
3449
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
87 public double [] getBackup() { |
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
88 return backup; |
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
89 } |
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
90 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
91 public double getFrom() { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
92 return from; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
93 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
94 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
95 public void setTo(double to) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
96 this.to = to; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
97 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
98 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
99 public double getTo() { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
100 return to; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
101 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
102 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
103 public void setValues(double [] values) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
104 this.values = values; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
105 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
106 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
107 public double [] getValues() { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
108 return values; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
109 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
110 |
3449
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
111 public int numValues() { |
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
112 return values.length; |
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
113 } |
fc351f12b906
FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3441
diff
changeset
|
114 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
115 public void setReferencePoint(double referencePoint) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
116 this.referencePoint = referencePoint; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
117 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
118 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
119 public double getReferencePoint() { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
120 return referencePoint; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
121 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
650
diff
changeset
|
122 |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 public static List<Segment> parseSegments(String input) { |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 |
3776
1ddbf66a2b0a
Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
125 final List<Segment> segments = new ArrayList<Segment>(); |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 |
3776
1ddbf66a2b0a
Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
127 DoubleUtil.parseSegments(input, new DoubleUtil.SegmentCallback() { |
1ddbf66a2b0a
Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
128 @Override |
1ddbf66a2b0a
Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
129 public void newSegment(double from, double to, double [] values) { |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 segments.add(new Segment(from, to, values)); |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 } |
3776
1ddbf66a2b0a
Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3552
diff
changeset
|
132 }); |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 return segments; |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 } |
3441
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
136 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
137 public static boolean setReferencePointConvertQ( |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
138 List<Segment> segments, |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
139 River river, |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
140 boolean isQ, |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
141 Calculation report |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
142 ) { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
143 int numResults = -1; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
144 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
145 boolean success = true; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
146 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
147 // assign reference points |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
148 for (Segment segment: segments) { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
149 Gauge gauge = river.maxOverlap(segment.getFrom(), segment.getTo()); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
150 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
151 if (gauge == null) { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
152 log.warn("no gauge found. Defaults to mid point."); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
153 segment.setReferencePoint( |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
154 0.5*(segment.getFrom()+segment.getTo())); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
155 } |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
156 else { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
157 double ref = gauge.getStation().doubleValue(); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
158 log.debug( |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
159 "reference gauge: " + gauge.getName() + |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
160 " (km " + ref + ")"); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
161 segment.setReferencePoint(ref); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
162 } |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
163 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
164 double [] values = segment.values; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
165 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
166 if (numResults == -1) { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
167 numResults = values.length; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
168 } |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
169 else if (numResults != values.length) { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
170 log.warn("wrong length of values"); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
171 return false; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
172 } |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
173 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
174 // convert to Q if needed |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
175 if (!isQ && gauge != null) { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
176 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
177 DischargeTable dt = gauge.fetchMasterDischargeTable(); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
178 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
179 double [][] table = |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
180 DischargeTables.loadDischargeTableValues(dt, 1); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
181 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
182 // need the original values for naming |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
183 segment.backup(); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
184 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
185 for (int i = 0; i < values.length; ++i) { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
186 double w = values[i] / 100.0; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
187 double [] qs = DischargeTables.getQsForW(table, w); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
188 if (qs.length == 0) { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
189 log.warn("No Qs found for W = " + values[i]); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
190 report.addProblem("cannot.find.w.for.q", values[i]); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
191 values[i] = Double.NaN; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
192 success = false; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
193 } |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
194 else { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
195 values[i] = qs[0]; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
196 if (qs.length > 1) { |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
197 log.warn( |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
198 "More than one Q found for W = " + values[i]); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
199 } |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
200 } |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
201 } |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
202 } |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
203 } // for all segments |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
204 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
205 Collections.sort(segments, Segment.REF_CMP); |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
206 |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
207 return success; |
bfbd478bd607
FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3439
diff
changeset
|
208 } |
650
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 } |
6695e03e9b82
Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |