comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.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
492 492
493 return !Double.isNaN(out[0]); 493 return !Double.isNaN(out[0]);
494 } 494 }
495 495
496 public QPosition interpolate( 496 public QPosition interpolate(
497 double q, 497 double q,
498 double referenceKm, 498 double referenceKm,
499 double [] kms, 499 double [] kms,
500 double [] ws, 500 double [] ws,
501 double [] qs 501 double [] qs,
502 Calculation errors
502 ) { 503 ) {
503 return interpolate(q, referenceKm, kms, ws, qs, 0, kms.length); 504 return interpolate(
505 q, referenceKm, kms, ws, qs, 0, kms.length, errors);
504 } 506 }
505 507
506 public QPosition interpolate( 508 public QPosition interpolate(
507 double q, 509 double q,
508 double referenceKm, 510 double referenceKm,
509 double [] kms, 511 double [] kms,
510 double [] ws, 512 double [] ws,
511 double [] qs, 513 double [] qs,
512 int startIndex, 514 int startIndex,
513 int length 515 int length,
516 Calculation errors
514 ) { 517 ) {
515 QPosition qPosition = getQPosition(referenceKm, q); 518 QPosition qPosition = getQPosition(referenceKm, q);
516 519
517 if (qPosition == null) { 520 if (qPosition == null) {
518 // we cannot locate q at km 521 // we cannot locate q at km
522 Arrays.fill(ws, Double.NaN);
523 Arrays.fill(qs, Double.NaN);
524 if (errors != null) {
525 errors.addProblem(referenceKm, "cannot find q");
526 }
519 return null; 527 return null;
520 } 528 }
521 529
522 Row kmKey = new Row(); 530 Row kmKey = new Row();
523 531
524 int R1 = rows.size()-1; 532 int R1 = rows.size()-1;
525 533
526 for (int i = startIndex, end = startIndex+length; i < end; ++i) { 534 for (int i = startIndex, end = startIndex+length; i < end; ++i) {
535
536 if (Double.isNaN(qs[i] = getQ(qPosition, kms[i]))) {
537 if (errors != null) {
538 errors.addProblem(kms[i], "cannot find q");
539 }
540 ws[i] = Double.NaN;
541 continue;
542 }
543
527 kmKey.km = kms[i]; 544 kmKey.km = kms[i];
528
529 int rowIndex = Collections.binarySearch(rows, kmKey); 545 int rowIndex = Collections.binarySearch(rows, kmKey);
530
531 qs[i] = getQ(qPosition, kms[i]);
532 546
533 if (rowIndex >= 0) { 547 if (rowIndex >= 0) {
534 // direct row match 548 // direct row match
535 ws[i] = rows.get(rowIndex).getW(qPosition); 549 if (Double.isNaN(ws[i] = rows.get(rowIndex).getW(qPosition))
550 && errors != null) {
551 errors.addProblem(kms[i], "cannot find w");
552 }
536 continue; 553 continue;
537 } 554 }
538 555
539 rowIndex = -rowIndex -1; 556 rowIndex = -rowIndex -1;
540 557
541 if (rowIndex < 1 || rowIndex >= R1) { 558 if (rowIndex < 1 || rowIndex >= R1) {
542 // do not extrapolate 559 // do not extrapolate
560 if (errors != null) {
561 errors.addProblem(kms[i], "cannot find km");
562 }
543 ws[i] = Double.NaN; 563 ws[i] = Double.NaN;
544 continue; 564 continue;
545 } 565 }
546 Row r1 = rows.get(rowIndex-1); 566 Row r1 = rows.get(rowIndex-1);
547 Row r2 = rows.get(rowIndex); 567 Row r2 = rows.get(rowIndex);
548 568
549 ws[i] = r1.getW(r2, kms[i], qPosition); 569 if (Double.isNaN(ws[i] = r1.getW(r2, kms[i], qPosition))
570 && errors != null) {
571 errors.addProblem(kms[i], "cannot find w");
572 }
550 } 573 }
551 574
552 return qPosition; 575 return qPosition;
553 } 576 }
554 577

http://dive4elements.wald.intevation.org