comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 678:19a3185822a4

Added error reporting to 'Wasserspiegellage' calculation. flys-artifacts/trunk@2102 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 10 Jun 2011 15:59:47 +0000
parents a95f34f1f39a
children eab5e5089d77
comparison
equal deleted inserted replaced
677:a95f34f1f39a 678:19a3185822a4
1 package de.intevation.flys.artifacts; 1 package de.intevation.flys.artifacts;
2 2
3 import java.util.List; 3 import java.util.List;
4 import java.util.Set;
5 import java.util.HashSet;
6 import java.util.ArrayList;
7 4
8 import org.w3c.dom.Document; 5 import org.w3c.dom.Document;
9 import org.w3c.dom.Element; 6 import org.w3c.dom.Element;
10 import org.w3c.dom.Node; 7 import org.w3c.dom.Node;
11 8
30 27
31 import de.intevation.flys.artifacts.model.MainValuesFactory; 28 import de.intevation.flys.artifacts.model.MainValuesFactory;
32 import de.intevation.flys.artifacts.model.WQDay; 29 import de.intevation.flys.artifacts.model.WQDay;
33 import de.intevation.flys.artifacts.model.WQKms; 30 import de.intevation.flys.artifacts.model.WQKms;
34 import de.intevation.flys.artifacts.model.WstValueTable; 31 import de.intevation.flys.artifacts.model.WstValueTable;
35 import de.intevation.flys.artifacts.model.WstValueTable.QPosition;
36 import de.intevation.flys.artifacts.model.WstValueTableFactory; 32 import de.intevation.flys.artifacts.model.WstValueTableFactory;
33 import de.intevation.flys.artifacts.model.Calculation1;
37 import de.intevation.flys.artifacts.model.Calculation2; 34 import de.intevation.flys.artifacts.model.Calculation2;
38 import de.intevation.flys.artifacts.model.Calculation3; 35 import de.intevation.flys.artifacts.model.Calculation3;
39 import de.intevation.flys.artifacts.model.Calculation4; 36 import de.intevation.flys.artifacts.model.Calculation4;
40 import de.intevation.flys.artifacts.model.Segment; 37 import de.intevation.flys.artifacts.model.Segment;
41 38
277 WstValueTable wst = WstValueTableFactory.getTable(river); 274 WstValueTable wst = WstValueTableFactory.getTable(river);
278 if (wst == null) { 275 if (wst == null) {
279 throw new NullPointerException("No Wst found for selected river."); 276 throw new NullPointerException("No Wst found for selected river.");
280 } 277 }
281 278
282 HashSet<Integer> failed = new HashSet<Integer>();
283
284 WQKms[] results = computeWaterlevelData( 279 WQKms[] results = computeWaterlevelData(
285 kms, qs, wst, river.getKmUp(), failed); 280 kms, qs, ws, wst, river.getKmUp());
286 281
287 // TODO Introduce a caching mechanism here! 282 // TODO Introduce a caching mechanism here!
288 283
289 setWaterlevelNames(
290 results, qSel ? qs : ws, qSel ? "Q" : "W", failed);
291
292 return results; 284 return results;
293 } 285 }
294
295
296 /**
297 * Sets the name for waterlevels where each WQKms in <i>r</i> represents a
298 * column.
299 *
300 * @param r The waterlevel columns.
301 * @param v The input values of the computations.
302 * @param wq The WQ mode - can be one of "W" or "Q".
303 */
304 public static void setWaterlevelNames(
305 WQKms[] r,
306 double[] v,
307 String wq,
308 Set failed
309 ) {
310 int pos = 0;
311 for (int i = 0; i < v.length; i++) {
312 if (!failed.contains(i)) {
313 r[pos++].setName(wq + "=" + v[i]);
314 }
315 }
316 }
317
318 286
319 /** 287 /**
320 * Computes the data of a waterlevel computation based on the interpolation 288 * Computes the data of a waterlevel computation based on the interpolation
321 * in WstValueTable. 289 * in WstValueTable.
322 * 290 *
325 * @param wst The WstValueTable used for the interpolation. 293 * @param wst The WstValueTable used for the interpolation.
326 * 294 *
327 * @return an array of data triples that consist of W, Q and Kms. 295 * @return an array of data triples that consist of W, Q and Kms.
328 */ 296 */
329 public static WQKms[] computeWaterlevelData( 297 public static WQKms[] computeWaterlevelData(
330 double[] kms, 298 double [] kms,
331 double[] qs, 299 double [] qs,
300 double [] ws,
332 WstValueTable wst, 301 WstValueTable wst,
333 boolean up, 302 boolean up
334 Set<Integer> failed
335 ) { 303 ) {
336 logger.info("WINFOArtifact.computeWaterlevelData"); 304 logger.info("WINFOArtifact.computeWaterlevelData");
337 305
338 WQKms[] wqkms = new WQKms[qs.length]; 306 Calculation1 calculation = new Calculation1(kms, qs, ws, up);
339 307
340 ArrayList<WQKms> results = new ArrayList<WQKms>(); 308 WQKms[] wqkms = calculation.calculate(wst);
341 309
342 int referenceIndex = up ? 0 : kms.length-1; 310 // TODO: report problems to user
343 311
344 for (int i = 0; i < qs.length; i++) { 312 return wqkms;
345 double [] oqs = new double[kms.length];
346 double [] ows = new double[kms.length];
347 WstValueTable.QPosition qPosition =
348 wst.interpolate(qs[i], kms[referenceIndex], kms, ows, oqs);
349 if (qPosition != null) {
350 results.add(new WQKms(kms, oqs, ows));
351 }
352 else {
353 logger.warn("interpolation failed for q = " + qs[i]);
354 failed.add(i);
355 }
356 }
357
358 return results.toArray(new WQKms[results.size()]);
359 } 313 }
360 314
361 315
362 /** 316 /**
363 * Returns the data that is computed by a duration curve computation. 317 * Returns the data that is computed by a duration curve computation.

http://dive4elements.wald.intevation.org