Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 2330:594885703687
Picked changes r4015:4026 from trunk.
flys-artifacts/tags/2.6@4028 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 10 Feb 2012 11:18:27 +0000 |
parents | 61b32380ffdb |
children | 177b0c91928d |
comparison
equal
deleted
inserted
replaced
2329:d999062c20e6 | 2330:594885703687 |
---|---|
901 Calculation errors | 901 Calculation errors |
902 ) { | 902 ) { |
903 return relateWs(km1, km2, RELATE_WS_SAMPLES, errors); | 903 return relateWs(km1, km2, RELATE_WS_SAMPLES, errors); |
904 } | 904 } |
905 | 905 |
906 private static class ErrorHandler { | |
907 | |
908 boolean hasErrors; | |
909 Calculation errors; | |
910 | |
911 ErrorHandler(Calculation errors) { | |
912 this.errors = errors; | |
913 } | |
914 | |
915 void error(double km, String key, Object ... args) { | |
916 if (errors != null && !hasErrors) { | |
917 hasErrors = true; | |
918 errors.addProblem(km, key, args); | |
919 } | |
920 } | |
921 } // class ErrorHandler | |
922 | |
923 | |
906 /* TODO: Add optimized methods of relateWs to relate one | 924 /* TODO: Add optimized methods of relateWs to relate one |
907 * start km to many end kms. The index generation/spline stuff for | 925 * start km to many end kms. The index generation/spline stuff for |
908 * the start km is always the same. | 926 * the start km is always the same. |
909 */ | 927 */ |
910 | |
911 public double [][] relateWs( | 928 public double [][] relateWs( |
912 double km1, | 929 double km1, |
913 double km2, | 930 double km2, |
914 int numSamples, | 931 int numSamples, |
915 Calculation errors | 932 Calculation errors |
949 TDoubleArrayList ws1 = new TDoubleArrayList(numSamples); | 966 TDoubleArrayList ws1 = new TDoubleArrayList(numSamples); |
950 TDoubleArrayList ws2 = new TDoubleArrayList(numSamples); | 967 TDoubleArrayList ws2 = new TDoubleArrayList(numSamples); |
951 TDoubleArrayList qs1 = new TDoubleArrayList(numSamples); | 968 TDoubleArrayList qs1 = new TDoubleArrayList(numSamples); |
952 TDoubleArrayList qs2 = new TDoubleArrayList(numSamples); | 969 TDoubleArrayList qs2 = new TDoubleArrayList(numSamples); |
953 | 970 |
954 boolean hadErrors = false; | 971 ErrorHandler err = new ErrorHandler(errors); |
955 | 972 |
956 int i = 0; | 973 int i = 0; |
957 for (double p = 0d; p <= N-1; p += stepWidth, ++i) { | 974 for (double p = 0d; p <= N-1; p += stepWidth, ++i) { |
975 | |
976 double q1; | |
958 try { | 977 try { |
959 double q1 = iQ1.value(p); | 978 q1 = iQ1.value(p); |
960 double w1 = qW1.value(q1); | |
961 double q2 = iQ2.value(p); | |
962 double w2 = qW2.value(q2); | |
963 ws1.add(w1); | |
964 ws2.add(w2); | |
965 qs1.add(q1); | |
966 qs2.add(q2); | |
967 } | 979 } |
968 catch (ArgumentOutsideDomainException aode) { | 980 catch (ArgumentOutsideDomainException aode) { |
969 if (!hadErrors) { | 981 err.error(km1, "w.w.qkm1.failed", p); |
970 // XXX: I'm not sure if this really can happen | 982 continue; |
971 // and if we should report this more than once. | 983 } |
972 hadErrors = true; | 984 |
973 if (errors != null) { | 985 double w1; |
974 errors.addProblem("relating.w.w.failed"); | 986 try { |
975 log.warn("W~W failed", aode); | 987 w1 = qW1.value(q1); |
976 } | 988 } |
977 } | 989 catch (ArgumentOutsideDomainException aode) { |
978 } | 990 err.error(km1, "w.w.wkm1.failed", p); |
991 continue; | |
992 } | |
993 | |
994 double q2; | |
995 try { | |
996 q2 = iQ2.value(p); | |
997 } | |
998 catch (ArgumentOutsideDomainException aode) { | |
999 err.error(km2, "w.w.qkm2.failed", p); | |
1000 continue; | |
1001 } | |
1002 | |
1003 double w2; | |
1004 try { | |
1005 w2 = qW2.value(q2); | |
1006 } | |
1007 catch (ArgumentOutsideDomainException aode) { | |
1008 err.error(km2, "w.w.wkm2.failed", p); | |
1009 continue; | |
1010 } | |
1011 | |
1012 ws1.add(w1); | |
1013 ws2.add(w2); | |
1014 qs1.add(q1); | |
1015 qs2.add(q2); | |
979 } | 1016 } |
980 | 1017 |
981 return new double [][] { | 1018 return new double [][] { |
982 ws1.toNativeArray(), | 1019 ws1.toNativeArray(), |
983 qs1.toNativeArray(), | 1020 qs1.toNativeArray(), |