comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 2165:637dd38d0e2f

Handle the case in "W auf freier Strecke" where more than ne Q is related to a W. flys-artifacts/trunk@3753 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 23 Jan 2012 17:39:51 +0000
parents d548e2e13524
children 2898b1ff6013
comparison
equal deleted inserted replaced
2164:d548e2e13524 2165:637dd38d0e2f
362 362
363 if (qs == null) { 363 if (qs == null) {
364 logger.debug("Determine Q values based on a set of W values."); 364 logger.debug("Determine Q values based on a set of W values.");
365 qSel = false; 365 qSel = false;
366 ws = getWs(); 366 ws = getWs();
367 qs = getQsForWs(ws); 367 double [][] qws = getQsForWs(ws);
368 if (qs == null) { 368 if (qws == null) {
369 return error(new WQKms[0], "conversion ws to qs failed."); 369 return error(new WQKms[0], "conversion ws to qs failed.");
370 }
371 qs = qws[0];
372
373 if (qws[1] != null) { // If new ws where generated.
374 // TODO: Inform user!
375 ws = qws[1];
370 } 376 }
371 } 377 }
372 378
373 WstValueTable wst = WstValueTableFactory.getTable(river); 379 WstValueTable wst = WstValueTableFactory.getTable(river);
374 if (wst == null) { 380 if (wst == null) {
712 * 718 *
713 * @param ws An array of W values. 719 * @param ws An array of W values.
714 * 720 *
715 * @return an array of Q values. 721 * @return an array of Q values.
716 */ 722 */
717 public double[] getQsForWs(double[] ws) { 723 public double [][] getQsForWs(double[] ws) {
718 724
719 boolean debug = logger.isDebugEnabled(); 725 boolean debug = logger.isDebugEnabled();
720 726
721 if (debug) { 727 if (debug) {
722 logger.debug("FLYSArtifact.getQsForWs"); 728 logger.debug("FLYSArtifact.getQsForWs");
733 logger.warn("no ranges found"); 739 logger.warn("no ranges found");
734 return null; 740 return null;
735 } 741 }
736 742
737 if (isFreeW()) { 743 if (isFreeW()) {
744 // The simple case of the "Bezugslinienverfahren"
745 // "W auf freier Strecke".
738 WstValueTable wst = WstValueTableFactory.getTable(r); 746 WstValueTable wst = WstValueTableFactory.getTable(r);
739 if (wst == null) { 747 if (wst == null) {
740 logger.warn("no wst value table found"); 748 logger.warn("no wst value table found");
741 return null; 749 return null;
742 } 750 }
743 double km = range[0]; 751 double km = range[0];
744 752
745 double [] outQs = new double[ws.length]; 753 TDoubleArrayList outQs = new TDoubleArrayList(ws.length);
754 TDoubleArrayList outWs = new TDoubleArrayList(ws.length);
755
756 boolean generatedWs = false;
746 757
747 for (int i = 0; i < ws.length; ++i) { 758 for (int i = 0; i < ws.length; ++i) {
759 // There could bemore than one Q per W.
748 double [] qs = wst.findQsForW(km, ws[i]); 760 double [] qs = wst.findQsForW(km, ws[i]);
749 if (qs.length < 1) { 761 for (int j = 0; j < qs.length; ++j) {
750 logger.warn("no q found for w = " + ws[i]); 762 outWs.add(ws[i]);
751 outQs[i] = Double.NaN; 763 outQs.add(qs[j]);
752 } 764 }
753 if (qs.length > 1) { 765 generatedWs |= qs.length != 1;
754 // TODO: Generate more than w/q line! 766 }
755 logger.warn("more than one q found for w = " + ws[i]); 767
756 } 768 return new double [][] {
757 outQs[i] = qs[0]; 769 outQs.toNativeArray(),
758 } 770 generatedWs ? outWs.toNativeArray() : null };
759
760 return outQs;
761 } 771 }
762 772
763 if (debug) { 773 if (debug) {
764 logger.debug("range: " + Arrays.toString(range)); 774 logger.debug("range: " + Arrays.toString(range));
765 } 775 }
785 if (debug) { 795 if (debug) {
786 logger.debug("w: " + ws[i] + " -> q: " + qs[i]); 796 logger.debug("w: " + ws[i] + " -> q: " + qs[i]);
787 } 797 }
788 } 798 }
789 799
790 return qs; 800 return new double [][] { qs, null };
791 } 801 }
792 802
793 803
794 /** 804 /**
795 * Determines the selected mode of distance/range input. 805 * Determines the selected mode of distance/range input.

http://dive4elements.wald.intevation.org