comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 2557:adb8641f5b5d

WstValueTable: Added method to find the w extent for a given km. flys-artifacts/trunk@4076 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 17 Feb 2012 11:29:14 +0000
parents 750cdcccb39c
children 33e4481933e2
comparison
equal deleted inserted replaced
2556:efb2038783f9 2557:adb8641f5b5d
494 qs.add(q); 494 qs.add(q);
495 } 495 }
496 496
497 return qs.toNativeArray(); 497 return qs.toNativeArray();
498 } 498 }
499
500 public double [] getMinMaxW() {
501 double minW = Double.MAX_VALUE;
502 double maxW = -Double.MAX_VALUE;
503 for (int i = 0; i < ws.length; ++i) {
504 double w = ws[i];
505 if (w < minW) minW = w;
506 if (w > maxW) maxW = w;
507 }
508 return new double [] { minW, maxW };
509 }
510
511 public double [] getMinMaxW(Row other, double km) {
512 double [] m1 = this .getMinMaxW();
513 double [] m2 = other.getMinMaxW();
514 double factor = Linear.factor(km, this.km, other.km);
515 return new double [] {
516 Linear.weight(factor, m1[0], m2[0]),
517 Linear.weight(factor, m1[1], m2[1])
518 };
519 }
499 } // class Row 520 } // class Row
500 521
501 /** Rows in table. */ 522 /** Rows in table. */
502 protected List<Row> rows; 523 protected List<Row> rows;
503 524
582 } 603 }
583 } 604 }
584 605
585 return ws; 606 return ws;
586 } 607 }
608
609 public double [] getMinMaxW(double km) {
610 int rowIndex = Collections.binarySearch(rows, new Row(km));
611
612 if (rowIndex >= 0) {
613 return rows.get(rowIndex).getMinMaxW();
614 }
615
616 rowIndex = -rowIndex -1;
617
618 if (rowIndex < 1 || rowIndex >= rows.size()) {
619 // do not extrapolate
620 return null;
621 }
622
623 Row r1 = rows.get(rowIndex-1);
624 Row r2 = rows.get(rowIndex);
625
626 return r1.getMinMaxW(r2, km);
627 }
628
587 629
588 /** 630 /**
589 * Interpolate W and Q values at a given km. 631 * Interpolate W and Q values at a given km.
590 */ 632 */
591 public double [][] interpolateWQ(double km) { 633 public double [][] interpolateWQ(double km) {

http://dive4elements.wald.intevation.org