annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Segment.java @ 5242:88e3473a3846 2.9.12

Add kind handling for floodplains and crossectiontracks getFloodplain / getCrossection now return only the "current" one 1 is current 0 is misc
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 12 Mar 2013 11:29:10 +0100
parents 345f3bba6f15
children
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
5150
345f3bba6f15 Doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5117
diff changeset
18 /** A Range with values and a reference point. */
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 public class Segment
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 implements Serializable
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 {
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
22 private static Logger log = Logger.getLogger(Segment.class);
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
3439
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
24 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
25 new Comparator<Segment>() {
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
26 @Override
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
27 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
28 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
29 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
30 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
31 }
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
32 };
cb11919cccf9 FixA 'ausgelagerte Wasserspiegellagen' move comparator code into segment class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3419
diff changeset
33
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 protected double from;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 protected double to;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 protected double [] values;
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
37 protected double [] backup;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
38 protected double referencePoint;
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 public Segment() {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
43 public Segment(double referencePoint) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
44 this.referencePoint = referencePoint;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
45 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
46
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 public Segment(double from, double to, double [] values) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 this.from = from;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 this.to = to;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 this.values = values;
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
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 public boolean isUp() {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 return from < to;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3776
diff changeset
57 /** 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
58 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
59 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
60 ? 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
61 : 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
62 }
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
63
3419
da7cf0e3ccaa FixA: Created a common base class for the fixing related calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
64 @Override
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 public String toString() {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 StringBuilder sb = new StringBuilder("Segment: [");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 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
68 .append(to)
8124ca1ecaaa Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 655
diff changeset
69 .append("; ref: ").append(referencePoint)
8124ca1ecaaa Berechnung 4: Added more debug output
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 655
diff changeset
70 .append("; values: (");
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 for (int i = 0; i < values.length; ++i) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 if (i > 0) sb.append(", ");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 sb.append(values[i]);
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 sb.append(")]");
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 return sb.toString();
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
79 public void setFrom(double from) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
80 this.from = from;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
83 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
84 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
85 ? (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
86 : null;
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
87 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
88
3449
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
89 public double [] getBackup() {
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
90 return backup;
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
91 }
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
92
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
93 public double getFrom() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
94 return from;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
97 public void setTo(double to) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
98 this.to = to;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
101 public double getTo() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
102 return to;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
105 public void setValues(double [] values) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
106 this.values = values;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
109 public double [] getValues() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
110 return values;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
111 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
112
3449
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
113 public int numValues() {
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
114 return values.length;
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
115 }
fc351f12b906 FixA: Vollmer. Calculated the Q -> Ws. TODO: Produce result.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3441
diff changeset
116
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
117 public void setReferencePoint(double referencePoint) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
118 this.referencePoint = referencePoint;
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
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
121 public double getReferencePoint() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
122 return referencePoint;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
123 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 650
diff changeset
124
5107
a929d9a9fa1e Picky doc and whitespace fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3776
diff changeset
125 /** Use DoubleUtil to parse Segments. */
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 public static List<Segment> parseSegments(String input) {
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
128 final List<Segment> segments = new ArrayList<Segment>();
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
130 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
131 @Override
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
132 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
133 segments.add(new Segment(from, to, values));
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 }
3776
1ddbf66a2b0a Implemented the access for 'Auslagerung extremer Wasserspiegellagen'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3552
diff changeset
135 });
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 return segments;
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 }
3441
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
139
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
140 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
141 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
142 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
143 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
144 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
145 ) {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
146 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
147
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
148 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
149
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
150 // 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
151 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
152 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
153
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
154 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
155 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
156 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
157 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
158 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
159 else {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
160 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
161 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
162 "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
163 " (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
164 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
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
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
167 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
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 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
170 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
171 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
172 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
173 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
174 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
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
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
177 // 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
178 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
179
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
180 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
181
5117
842026a5a12c Fixed 'W fuer ungleichwertige AbflussLaengsschnitte'. See TODO!!!
Raimund Renkert <rrenkert@intevation.de>
parents: 5107
diff changeset
182 //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
183 // 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
184 double [][] table =
5117
842026a5a12c Fixed 'W fuer ungleichwertige AbflussLaengsschnitte'. See TODO!!!
Raimund Renkert <rrenkert@intevation.de>
parents: 5107
diff changeset
185 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
186
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
187 // 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
188 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
189
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
190 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
191 //TODO: s.o.
842026a5a12c Fixed 'W fuer ungleichwertige AbflussLaengsschnitte'. See TODO!!!
Raimund Renkert <rrenkert@intevation.de>
parents: 5107
diff changeset
192 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
193 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
194 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
195 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
196 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
197 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
198 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
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 else {
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
201 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
202 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
203 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
204 "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
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 }
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
209 } // 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
210
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
211 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
212
bfbd478bd607 FixA: Moved Q -> W conversion code into segments to be reusable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3439
diff changeset
213 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
214 }
650
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215 }
6695e03e9b82 Added parser for segments
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
216 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org