comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java @ 674:d5f9ba1d055f

Added calculation base class to collect the problems during the calculations. Adjusted calculation 4 to use the mechanism. flys-artifacts/trunk@2098 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 10 Jun 2011 09:19:27 +0000
parents e0e39a0eb3fe
children eab5e5089d77
comparison
equal deleted inserted replaced
673:b22f21b173a7 674:d5f9ba1d055f
18 import de.intevation.flys.artifacts.math.BackJumpCorrector; 18 import de.intevation.flys.artifacts.math.BackJumpCorrector;
19 19
20 import org.apache.log4j.Logger; 20 import org.apache.log4j.Logger;
21 21
22 public class Calculation4 22 public class Calculation4
23 extends Calculation
23 { 24 {
24 private static Logger logger = Logger.getLogger(Calculation4.class); 25 private static Logger logger = Logger.getLogger(Calculation4.class);
25 26
26 public static final double MINIMAL_STEP_WIDTH = 1e-5; 27 public static final double MINIMAL_STEP_WIDTH = 1e-5;
27 28
98 } 99 }
99 } 100 }
100 101
101 if (segments.isEmpty()) { 102 if (segments.isEmpty()) {
102 logger.debug("no segments found"); 103 logger.debug("no segments found");
104 // TODO: I18N
105 addProblem("no segments found");
103 return new WQKms[0]; 106 return new WQKms[0];
104 } 107 }
105 108
106 int numResults = segments.get(0).values.length; 109 int numResults = segments.get(0).values.length;
107 110
108 if (numResults < 1) { 111 if (numResults < 1) {
109 logger.debug("no values given"); 112 logger.debug("no values given");
113 // TODO: I18N
114 addProblem("no values given");
110 return new WQKms[0]; 115 return new WQKms[0];
111 } 116 }
112 117
113 118
114 WQKms [] results = new WQKms[numResults]; 119 WQKms [] results = new WQKms[numResults];
211 QPosition qi = table.getQPosition( 216 QPosition qi = table.getQPosition(
212 anchor.referencePoint, 217 anchor.referencePoint,
213 anchor.values[i]); 218 anchor.values[i]);
214 219
215 if ((qPositions[i] = qi) == null) { 220 if ((qPositions[i] = qi) == null) {
216 // TODO: error report 221 // TODO: I18N
222 addProblem(pos, "cannot find q = " + anchor.values[i]);
217 functions[i] = Identity.IDENTITY; 223 functions[i] = Identity.IDENTITY;
218 } 224 }
219 else { 225 else {
220 double qA = table.getQ(qi, anchor.referencePoint); 226 double qA = table.getQ(qi, anchor.referencePoint);
221 double qF = table.getQ(qi, free .referencePoint); 227 double qF = table.getQ(qi, free .referencePoint);
247 253
248 if (table.interpolate(pos, out, qPosition, functions[i])) { 254 if (table.interpolate(pos, out, qPosition, functions[i])) {
249 results[i].add(out[0], out[1], pos); 255 results[i].add(out[0], out[1], pos);
250 } 256 }
251 else { 257 else {
252 // TODO: error report 258 // TODO: I18N
259 addProblem(pos, "cannot interpolate w/q");
253 } 260 }
254 } 261 }
255 } 262 }
256 263
257 // Backjump correction 264 // Backjump correction
259 BackJumpCorrector bjc = new BackJumpCorrector(); 266 BackJumpCorrector bjc = new BackJumpCorrector();
260 267
261 double [] ws = results[i].getWs(); 268 double [] ws = results[i].getWs();
262 double [] kms = results[i].getKms(); 269 double [] kms = results[i].getKms();
263 270
264 if (bjc.doCorrection(kms, ws)) { 271 if (bjc.doCorrection(kms, ws, this)) {
265 results[i] = new WQCKms(results[i], bjc.getCorrected()); 272 results[i] = new WQCKms(results[i], bjc.getCorrected());
266 } 273 }
267 // TODO: error report
268 } 274 }
269 275
270 // name the curves 276 // name the curves
271 for (int i = 0; i < results.length; ++i) { 277 for (int i = 0; i < results.length; ++i) {
272 results[i].setName(createName(i)); 278 results[i].setName(createName(i));
274 280
275 return results; 281 return results;
276 } 282 }
277 283
278 protected String createName(int index) { 284 protected String createName(int index) {
279 // TODO: i18n 285 // TODO: I18N
280 StringBuilder sb = new StringBuilder(isQ ? "Q" : "W"); 286 StringBuilder sb = new StringBuilder(isQ ? "Q" : "W");
281 sb.append(" benutzerdefiniert ("); 287 sb.append(" benutzerdefiniert (");
282 for (int i = 0, N = segments.size(); i < N; ++i) { 288 for (int i = 0, N = segments.size(); i < N; ++i) {
283 if (i > 0) { 289 if (i > 0) {
284 sb.append("; "); 290 sb.append("; ");

http://dive4elements.wald.intevation.org