comparison artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java @ 6524:641ec405c4ac

MainValuesArtifact: Added method to determine whether at gauge or not.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 02 Jul 2013 07:10:25 +0200
parents 5afb1cda5885
children cf3065a17057
comparison
equal deleted inserted replaced
6523:5afb1cda5885 6524:641ec405c4ac
314 return state; 314 return state;
315 else 315 else
316 return spawnState(); 316 return spawnState();
317 } 317 }
318 318
319 /**
320 * Access the Gauge that the mainvalues are taken from.
321 * @return Gauge that main values are taken from or null in case of
322 * invalid parameterization.
323 */
324 protected Gauge getGauge(double km) {
325 River river = RiverUtils.getRiver(this);
326
327 if (river == null) {
328 logger.error("River is null");
329 return null;
330 }
331
332 return river.determineGaugeByPosition(km);
333 }
319 334
320 /** 335 /**
321 * Access the Gauge that the mainvalues are taken from. 336 * Access the Gauge that the mainvalues are taken from.
322 * @return Gauge that main values are taken from or null in case of 337 * @return Gauge that main values are taken from or null in case of
323 * invalid parameterization. 338 * invalid parameterization.
387 } 402 }
388 return filteredList; 403 return filteredList;
389 } 404 }
390 405
391 406
392 /** 407 /** Get main values of km. */
393 * Get a list of "W" main values. 408 public List<NamedDouble> getMainValuesW(double[] kms) {
394 * @param atGauge if true, do not interpolate 409 List<NamedDouble> filteredList = new ArrayList<NamedDouble>();
395 * @return list of W main values. 410 boolean atGauge = false;
396 */ 411 double gaugeDatum = 0d;
397 public List<NamedDouble> getMainValuesW(boolean atGauge) { 412 Gauge gauge = getGauge(kms[0]);
413 if (gauge == null) {
414 return filteredList;
415 }
416 else if (Math.abs(kms[0] - gauge.getStation().doubleValue()) < 1e-4) {
417 atGauge = true;
418 gaugeDatum = gauge.getDatum().doubleValue();
419 }
420
421 WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this));
422 Calculation c = new Calculation();
423
424 double gaugeStation = gauge.getStation().doubleValue();
425 double w_out[] = {0.0f};
426 double q_out[] = {0.0f};
427 if (gauge != null) {
428 List<MainValue> orig = gauge.getMainValues();
429 for (MainValue mv : orig) {
430 if (atGauge) {
431 if (mv.getMainValue().getType().getName().equals("W")) {
432 filteredList.add(new NamedDouble(mv.getMainValue().getName(),
433 mv.getValue().doubleValue()));
434 }
435 } else
436 // We cannot interpolate the W values, so derive them
437 // from given Q values.
438 if (mv.getMainValue().getType().getName().equals("Q")) {
439 interpolator.interpolate(mv.getValue().doubleValue(),
440 gaugeStation, kms, w_out, q_out, c);
441
442 filteredList.add(new NamedDouble(
443 "W(" + mv.getMainValue().getName() +")",
444 w_out[0]
445 ));
446 }
447 }
448 }
449 return filteredList;
450 }
451
452
453 public List<NamedDouble> getMainValuesW(boolean atGauge, double[] kms) {
398 List<NamedDouble> filteredList = new ArrayList<NamedDouble>(); 454 List<NamedDouble> filteredList = new ArrayList<NamedDouble>();
399 Gauge gauge = getGauge(); 455 Gauge gauge = getGauge();
400 WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this)); 456 WstValueTable interpolator = WstValueTableFactory.getTable(RiverUtils.getRiver(this));
401 Calculation c = new Calculation(); 457 Calculation c = new Calculation();
402 458

http://dive4elements.wald.intevation.org