comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 2418:899ca89f497e

Another partial fix for flys/issue499: Do the W to Q conversions needed for 'W am Pegel' correctly. flys-artifacts/trunk@4052 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 14 Feb 2012 16:48:13 +0000
parents 64dd65aa620d
children 44dc117aa2b7
comparison
equal deleted inserted replaced
2417:e5fa3cbbe3ae 2418:899ca89f497e
46 import de.intevation.flys.geom.Lines; 46 import de.intevation.flys.geom.Lines;
47 47
48 import de.intevation.flys.model.FastCrossSectionLine; 48 import de.intevation.flys.model.FastCrossSectionLine;
49 import de.intevation.flys.model.Gauge; 49 import de.intevation.flys.model.Gauge;
50 import de.intevation.flys.model.River; 50 import de.intevation.flys.model.River;
51 import de.intevation.flys.model.DischargeTable;
51 52
52 import de.intevation.flys.utils.DoubleUtil; 53 import de.intevation.flys.utils.DoubleUtil;
53 import de.intevation.flys.utils.FLYSUtils; 54 import de.intevation.flys.utils.FLYSUtils;
54 55
55 import gnu.trove.TDoubleArrayList; 56 import gnu.trove.TDoubleArrayList;
923 924
924 if (debug) { 925 if (debug) {
925 logger.debug("convert w->q with gauge '" + g.getName() + "'"); 926 logger.debug("convert w->q with gauge '" + g.getName() + "'");
926 } 927 }
927 928
928 DischargeTables dt = new DischargeTables(r.getName(), g.getName()); 929 DischargeTable dt = g.fetchMasterDischargeTable();
929 Map<String, double [][]> tmp = dt.getValues(); 930
930 931 if (dt == null) {
931 double[][] values = tmp.get(g.getName()); 932 logger.warn("No master discharge table found for gauge '"
932 double[] qs = new double[ws.length]; 933 + g.getName() + "'");
934 return null;
935 }
936
937 double [][] values = DischargeTables.loadDischargeTableValues(dt, 1);
933 938
934 TDoubleArrayList wsOut = new TDoubleArrayList(ws.length); 939 TDoubleArrayList wsOut = new TDoubleArrayList(ws.length);
935 TDoubleArrayList qsOut = new TDoubleArrayList(ws.length); 940 TDoubleArrayList qsOut = new TDoubleArrayList(ws.length);
941
942 boolean generatedWs = false;
936 943
937 for (int i = 0; i < ws.length; i++) { 944 for (int i = 0; i < ws.length; i++) {
938 if (Double.isNaN(ws[i])) { 945 if (Double.isNaN(ws[i])) {
939 logger.warn("W is NaN: ignored"); 946 logger.warn("W is NaN: ignored");
940 continue; 947 continue;
941 } 948 }
942 double w = ws[i] / 100.0; 949 double w = ws[i] / 100d;
943 double q = dt.getQForW(values, w); 950 double [] qs = DischargeTables.getQsForW(values, w);
944 if (Double.isNaN(q)) { 951
945 logger.warn("No Q found for W = " + ws[i]); 952 if (qs.length == 0) {
946 continue; 953 logger.warn("No Qs found for W = " + ws[i]);
947 } 954 }
948 wsOut.add(w); 955 else {
949 qsOut.add(q); 956 for (double q: qs) {
950 if (debug) { 957 wsOut.add(ws[i]);
951 logger.debug("w: " + w + " -> q: " + q); 958 qsOut.add(q);
952 } 959 }
960 }
961 generatedWs |= qs.length != 1;
953 } 962 }
954 963
955 return new double [][] { 964 return new double [][] {
956 qsOut.toNativeArray(), 965 qsOut.toNativeArray(),
957 wsOut.toNativeArray() 966 generatedWs ? wsOut.toNativeArray() : null
958 }; 967 };
959 } 968 }
960 969
961 970
962 /** 971 /**

http://dive4elements.wald.intevation.org