comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 676:c501f27c1f71

Added error reporting to 'Dauerzahlen' calculation. flys-artifacts/trunk@2100 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 10 Jun 2011 12:38:08 +0000
parents 913b52064449
children a95f34f1f39a
comparison
equal deleted inserted replaced
675:8b0152363bdb 676:c501f27c1f71
105 public void interpolateW( 105 public void interpolateW(
106 Row other, 106 Row other,
107 double km, 107 double km,
108 double [] iqs, 108 double [] iqs,
109 double [] ows, 109 double [] ows,
110 WstValueTable table 110 WstValueTable table,
111 Calculation errors
111 ) { 112 ) {
112 double kmWeight = Linear.factor(km, this.km, other.km); 113 double kmWeight = Linear.factor(km, this.km, other.km);
113 114
114 QPosition qPosition = new QPosition(); 115 QPosition qPosition = new QPosition();
115 116
116 for (int i = 0; i < iqs.length; ++i) { 117 for (int i = 0; i < iqs.length; ++i) {
117 if (table.getQPosition(km, iqs[i], qPosition) != null) { 118 if (table.getQPosition(km, iqs[i], qPosition) != null) {
118 double wt = getW(qPosition); 119 double wt = getW(qPosition);
119 double wo = other.getW(qPosition); 120 double wo = other.getW(qPosition);
120 ows[i] = Linear.weight(kmWeight, wt, wo); 121 if (Double.isNaN(wt) || Double.isNaN(wo)) {
122 if (errors != null) {
123 // TODO: I18N
124 errors.addProblem(
125 km, "cannot find w for q = " + iqs[i]);
126 }
127 ows[i] = Double.NaN;
128 }
129 else {
130 ows[i] = Linear.weight(kmWeight, wt, wo);
131 }
121 } 132 }
122 else { 133 else {
134 if (errors != null) {
135 // TODO: I18N
136 errors.addProblem(km, "cannot find q = " + iqs[i]);
137 }
123 ows[i] = Double.NaN; 138 ows[i] = Double.NaN;
124 } 139 }
125 } 140 }
126 } 141 }
127 142
280 public void sortRows() { 295 public void sortRows() {
281 Collections.sort(rows); 296 Collections.sort(rows);
282 } 297 }
283 298
284 public double [] interpolateW(double km, double [] qs, double [] ws) { 299 public double [] interpolateW(double km, double [] qs, double [] ws) {
285 300 return interpolateW(km, qs, ws, null);
301 }
302
303 public double [] interpolateW(
304 double km,
305 double [] qs,
306 double [] ws,
307 Calculation errors
308 ) {
286 int rowIndex = Collections.binarySearch(rows, new Row(km)); 309 int rowIndex = Collections.binarySearch(rows, new Row(km));
287 310
288 QPosition qPosition = new QPosition(); 311 QPosition qPosition = new QPosition();
289 312
290 if (rowIndex >= 0) { // direct row match 313 if (rowIndex >= 0) { // direct row match
291 Row row = rows.get(rowIndex); 314 Row row = rows.get(rowIndex);
292 for (int i = 0; i < qs.length; ++i) { 315 for (int i = 0; i < qs.length; ++i) {
293 ws[i] = getQPosition(km, qs[i], qPosition) != null 316 if (getQPosition(km, qs[i], qPosition) == null) {
294 ? row.getW(qPosition) 317 if (errors != null) {
295 : Double.NaN; 318 // TODO: I18N
319 errors.addProblem(km, "cannot find q = " + qs[i]);
320 }
321 ws[i] = Double.NaN;
322 }
323 else {
324 if (Double.isNaN(ws[i] = row.getW(qPosition))
325 && errors != null) {
326 // TODO: I18N
327 errors.addProblem(
328 km, "cannot find w for q = " + qs[i]);
329 }
330 }
296 } 331 }
297 } 332 }
298 else { // needs bilinear interpolation 333 else { // needs bilinear interpolation
299 rowIndex = -rowIndex -1; 334 rowIndex = -rowIndex -1;
300 335
301 if (rowIndex < 1 || rowIndex >= rows.size()) { 336 if (rowIndex < 1 || rowIndex >= rows.size()) {
302 // do not extrapolate 337 // do not extrapolate
303 Arrays.fill(ws, Double.NaN); 338 Arrays.fill(ws, Double.NaN);
339 if (errors != null) {
340 errors.addProblem(km, "km not found");
341 }
304 } 342 }
305 else { 343 else {
306 Row r1 = rows.get(rowIndex-1); 344 Row r1 = rows.get(rowIndex-1);
307 Row r2 = rows.get(rowIndex); 345 Row r2 = rows.get(rowIndex);
308 r1.interpolateW(r2, km, qs, ws, this); 346 r1.interpolateW(r2, km, qs, ws, this, errors);
309 } 347 }
310 } 348 }
311 349
312 return ws; 350 return ws;
313 } 351 }

http://dive4elements.wald.intevation.org