comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 2316:61b32380ffdb

Be more conservative about arrays and indices in "Bezugslinienverfahren". flys-artifacts/trunk@3997 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 09 Feb 2012 12:13:28 +0000
parents 4d30e38600b8
children 594885703687
comparison
equal deleted inserted replaced
2315:c0dfa36add96 2316:61b32380ffdb
938 errors.addProblem(km2, "cannot.create.index.q.relation"); 938 errors.addProblem(km2, "cannot.create.index.q.relation");
939 } 939 }
940 return new double[2][0]; 940 return new double[2][0];
941 } 941 }
942 942
943 int N = sf1.splineQs.length; 943 int N = Math.min(sf1.splineQs.length, sf2.splineQs.length);
944 double stepWidth = N/(double)numSamples; 944 double stepWidth = N/(double)numSamples;
945 945
946 PolynomialSplineFunction qW1 = sf1.spline; 946 PolynomialSplineFunction qW1 = sf1.spline;
947 PolynomialSplineFunction qW2 = sf2.spline; 947 PolynomialSplineFunction qW2 = sf2.spline;
948 948
949 double [] ws1 = new double[numSamples]; 949 TDoubleArrayList ws1 = new TDoubleArrayList(numSamples);
950 double [] ws2 = new double[numSamples]; 950 TDoubleArrayList ws2 = new TDoubleArrayList(numSamples);
951 double [] qs1 = new double[numSamples]; 951 TDoubleArrayList qs1 = new TDoubleArrayList(numSamples);
952 double [] qs2 = new double[numSamples]; 952 TDoubleArrayList qs2 = new TDoubleArrayList(numSamples);
953
954 Arrays.fill(ws1, Double.NaN);
955 Arrays.fill(ws2, Double.NaN);
956 Arrays.fill(qs1, Double.NaN);
957 Arrays.fill(qs2, Double.NaN);
958 953
959 boolean hadErrors = false; 954 boolean hadErrors = false;
960 955
961 double p = 0d; 956 int i = 0;
962 for (int i = 0; i < numSamples; ++i, p += stepWidth) { 957 for (double p = 0d; p <= N-1; p += stepWidth, ++i) {
963 try { 958 try {
964 qs1[i] = iQ1.value(p); 959 double q1 = iQ1.value(p);
965 ws1[i] = qW1.value(qs1[i]); 960 double w1 = qW1.value(q1);
966 qs2[i] = iQ2.value(p); 961 double q2 = iQ2.value(p);
967 ws2[i] = qW2.value(qs2[i]); 962 double w2 = qW2.value(q2);
963 ws1.add(w1);
964 ws2.add(w2);
965 qs1.add(q1);
966 qs2.add(q2);
968 } 967 }
969 catch (ArgumentOutsideDomainException aode) { 968 catch (ArgumentOutsideDomainException aode) {
970 if (!hadErrors) { 969 if (!hadErrors) {
971 // XXX: I'm not sure if this really can happen 970 // XXX: I'm not sure if this really can happen
972 // and if we should report this more than once. 971 // and if we should report this more than once.
977 } 976 }
978 } 977 }
979 } 978 }
980 } 979 }
981 980
982 return new double [][] { ws1, qs1, ws2, qs2 }; 981 return new double [][] {
982 ws1.toNativeArray(),
983 qs1.toNativeArray(),
984 ws2.toNativeArray(),
985 qs2.toNativeArray() };
983 } 986 }
984 987
985 public QPosition getQPosition(double km, double q) { 988 public QPosition getQPosition(double km, double q) {
986 return getQPosition(km, q, new QPosition()); 989 return getQPosition(km, q, new QPosition());
987 } 990 }

http://dive4elements.wald.intevation.org