annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java @ 5133:8e52b4829cd1

Fix flys/issue1228: Units in tabular calculation output.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 28 Feb 2013 12:37:07 +0100
parents 842026a5a12c
children 345f3bba6f15
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
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3776
diff changeset
56 /** Checks whether given km lies inside the to/from bounds of this segment. */
3449
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
57 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
58 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
59 ? 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
60 : 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
61 }
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
62
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
63 @Override
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 public String toString() {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 StringBuilder sb = new StringBuilder("Segment: [");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 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
67 .append(to)
8124ca1ecaaa Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 655
diff changeset
68 .append("; ref: ").append(referencePoint)
8124ca1ecaaa Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 655
diff changeset
69 .append("; values: (");
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 for (int i = 0; i < values.length; ++i) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 if (i > 0) sb.append(", ");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 sb.append(values[i]);
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 sb.append(")]");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 return sb.toString();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
78 public void setFrom(double from) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
79 this.from = from;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
82 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
83 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
84 ? (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
85 : null;
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
86 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
87
3449
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
88 public double [] getBackup() {
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
89 return backup;
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
90 }
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
91
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
92 public double getFrom() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
93 return from;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
96 public void setTo(double to) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
97 this.to = to;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
100 public double getTo() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
101 return to;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
104 public void setValues(double [] values) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
105 this.values = values;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
108 public double [] getValues() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
109 return values;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
110 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
111
3449
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
112 public int numValues() {
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
113 return values.length;
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
114 }
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
115
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
116 public void setReferencePoint(double referencePoint) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
117 this.referencePoint = referencePoint;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
120 public double getReferencePoint() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
121 return referencePoint;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
122 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
123
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3776
diff changeset
124 /** Use DoubleUtil to parse Segments. */
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 public static List<Segment> parseSegments(String input) {
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 final List<Segment> segments = new ArrayList<Segment>();
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
129 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
130 @Override
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
131 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
132 segments.add(new Segment(from, to, values));
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 }
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
134 });
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 return segments;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 }
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
138
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
139 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
140 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
141 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
142 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
143 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
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 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
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 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
148
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
149 // 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
150 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
151 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
152
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
153 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
154 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
155 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
156 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
157 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
158 else {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
159 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
160 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
161 "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
162 " (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
163 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
164 }
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 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
167
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
168 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
169 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 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
171 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
172 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
173 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
174 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
175
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
176 // 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
177 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
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 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
180
5117
842026a5a12c Fixed 'W fuer ungleichwertige AbflussLaengsschnitte'. See TODO!!!
Raimund Renkert <rrenkert@intevation.de>
parents: 5107
diff changeset
181 //TODO: Change scale from 100 to 1 immediately after
842026a5a12c Fixed 'W fuer ungleichwertige AbflussLaengsschnitte'. See TODO!!!
Raimund Renkert <rrenkert@intevation.de>
parents: 5107
diff changeset
182 // discharge table import changed to cm!
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
183 double [][] table =
5117
842026a5a12c Fixed 'W fuer ungleichwertige AbflussLaengsschnitte'. See TODO!!!
Raimund Renkert <rrenkert@intevation.de>
parents: 5107
diff changeset
184 DischargeTables.loadDischargeTableValues(dt, 100);
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
185
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
186 // 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
187 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
188
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
189 for (int i = 0; i < values.length; ++i) {
5117
842026a5a12c Fixed 'W fuer ungleichwertige AbflussLaengsschnitte'. See TODO!!!
Raimund Renkert <rrenkert@intevation.de>
parents: 5107
diff changeset
190 //TODO: s.o.
842026a5a12c Fixed 'W fuer ungleichwertige AbflussLaengsschnitte'. See TODO!!!
Raimund Renkert <rrenkert@intevation.de>
parents: 5107
diff changeset
191 double w = values[i]; /* / 100.0; */
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
192 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
193 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
194 log.warn("No Qs found for W = " + values[i]);
5117
842026a5a12c Fixed 'W fuer ungleichwertige AbflussLaengsschnitte'. See TODO!!!
Raimund Renkert <rrenkert@intevation.de>
parents: 5107
diff changeset
195 report.addProblem("cannot.find.q.for.w", values[i]);
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
196 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
197 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
198 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
199 else {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
200 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
201 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
202 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
203 "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
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 }
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 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
208 } // 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
209
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
210 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
211
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
212 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
213 }
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org