comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 2423:ac528b883b47

Picked rev 4070,4074,4076,4080 from trunk. flys-artifacts/tags/2.6.1@4083 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 17 Feb 2012 12:59:56 +0000
parents 750cdcccb39c
children 8490faba00e7
comparison
equal deleted inserted replaced
2422:44dc117aa2b7 2423:ac528b883b47
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(double [] result) {
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 result[0] = minW;
509 result[1] = maxW;
510 return result;
511 }
512
513 public double [] getMinMaxW(Row other, double km, double [] result) {
514 double [] m1 = this .getMinMaxW(new double [2]);
515 double [] m2 = other.getMinMaxW(new double [2]);
516 double factor = Linear.factor(km, this.km, other.km);
517 result[0] = Linear.weight(factor, m1[0], m2[0]);
518 result[1] = Linear.weight(factor, m1[1], m2[1]);
519 return result;
520 }
499 } // class Row 521 } // class Row
500 522
501 /** Rows in table. */ 523 /** Rows in table. */
502 protected List<Row> rows; 524 protected List<Row> rows;
503 525
581 r1.interpolateW(r2, km, qs, ws, this, errors); 603 r1.interpolateW(r2, km, qs, ws, this, errors);
582 } 604 }
583 } 605 }
584 606
585 return ws; 607 return ws;
608 }
609
610 public double [] getMinMaxW(double km) {
611 return getMinMaxW(km, new double [2]);
612
613 }
614 public double [] getMinMaxW(double km, double [] result) {
615 int rowIndex = Collections.binarySearch(rows, new Row(km));
616
617 if (rowIndex >= 0) {
618 return rows.get(rowIndex).getMinMaxW(result);
619 }
620
621 rowIndex = -rowIndex -1;
622
623 if (rowIndex < 1 || rowIndex >= rows.size()) {
624 // do not extrapolate
625 return null;
626 }
627
628 Row r1 = rows.get(rowIndex-1);
629 Row r2 = rows.get(rowIndex);
630
631 return r1.getMinMaxW(r2, km, result);
632 }
633
634 public double [] getMinMaxW(double from, double to, double step) {
635 double [] result = new double[2];
636
637 double minW = Double.MAX_VALUE;
638 double maxW = -Double.MAX_VALUE;
639
640 if (from > to) {
641 double tmp = from;
642 from = to;
643 to = tmp;
644 }
645
646 step = Math.max(Math.abs(step), 0.0001);
647
648 double d = from;
649 for (; d <= to; d += step) {
650 if (getMinMaxW(d, result) != null) {
651 if (result[0] < minW) minW = result[0];
652 if (result[1] > maxW) maxW = result[1];
653 }
654 }
655
656 if (d != to) {
657 if (getMinMaxW(to, result) != null) {
658 if (result[0] < minW) minW = result[0];
659 if (result[1] > maxW) maxW = result[1];
660 }
661 }
662
663 return minW < Double.MAX_VALUE
664 ? new double [] { minW, maxW }
665 : null;
586 } 666 }
587 667
588 /** 668 /**
589 * Interpolate W and Q values at a given km. 669 * Interpolate W and Q values at a given km.
590 */ 670 */

http://dive4elements.wald.intevation.org