Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation4.java @ 4838:ac9a3d9576b4
merged.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 23 Jan 2013 11:15:35 +0100 |
parents | 8e72777c961c |
children | 61ebb6fb2ac4 |
comparison
equal
deleted
inserted
replaced
4837:9e25c7523485 | 4838:ac9a3d9576b4 |
---|---|
1 package de.intevation.flys.artifacts.model; | 1 package de.intevation.flys.artifacts.model; |
2 | |
3 import de.intevation.flys.artifacts.access.Calculation4Access; | |
2 | 4 |
3 import de.intevation.flys.artifacts.math.BackJumpCorrector; | 5 import de.intevation.flys.artifacts.math.BackJumpCorrector; |
4 import de.intevation.flys.artifacts.math.Function; | 6 import de.intevation.flys.artifacts.math.Function; |
5 import de.intevation.flys.artifacts.math.Identity; | 7 import de.intevation.flys.artifacts.math.Identity; |
6 import de.intevation.flys.artifacts.math.Linear; | 8 import de.intevation.flys.artifacts.math.Linear; |
7 | 9 |
8 import de.intevation.flys.artifacts.model.RiverFactory; | 10 import de.intevation.flys.artifacts.model.RiverFactory; |
11 | |
9 import de.intevation.flys.artifacts.model.WstValueTable.QPosition; | 12 import de.intevation.flys.artifacts.model.WstValueTable.QPosition; |
10 | 13 |
11 import de.intevation.flys.model.River; | 14 import de.intevation.flys.model.River; |
12 | 15 |
13 import de.intevation.flys.utils.DoubleUtil; | 16 import de.intevation.flys.utils.DoubleUtil; |
14 | |
15 import de.intevation.flys.artifacts.access.Calculation4Access; | |
16 | 17 |
17 import java.util.ArrayList; | 18 import java.util.ArrayList; |
18 import java.util.Arrays; | 19 import java.util.Arrays; |
19 import java.util.List; | 20 import java.util.List; |
20 | 21 |
271 for (int i = 0; i < results.length; ++i) { | 272 for (int i = 0; i < results.length; ++i) { |
272 results[i].setName(createName(i)); | 273 results[i].setName(createName(i)); |
273 } | 274 } |
274 | 275 |
275 // Generate the "Umhuellende". | 276 // Generate the "Umhuellende". |
276 results = generateInfolding(table, results, from, to, step); | 277 ConstantWQKms [] infoldings = |
277 | 278 generateInfolding(table, results, from, to, step); |
278 return new CalculationResult(results, this); | 279 |
279 } | 280 // TODO: Use qkms in a new result type. |
280 | 281 WQKms [] newResults = new WQKms[results.length + infoldings.length]; |
281 protected WQKms [] generateInfolding( | 282 System.arraycopy( |
283 results, 0, newResults, 0, results.length); | |
284 System.arraycopy( | |
285 infoldings, 0, newResults, results.length, infoldings.length); | |
286 | |
287 return new CalculationResult(newResults, this); | |
288 } | |
289 | |
290 protected ConstantWQKms [] generateInfolding( | |
282 WstValueTable wst, | 291 WstValueTable wst, |
283 WQKms [] results, | 292 WQKms [] results, |
284 double from, | 293 double from, |
285 double to, | 294 double to, |
286 double step | 295 double step |
288 WstValueTable.Column [] columns = wst.getColumns(); | 297 WstValueTable.Column [] columns = wst.getColumns(); |
289 | 298 |
290 InfoldingColumns ic = new InfoldingColumns(columns); | 299 InfoldingColumns ic = new InfoldingColumns(columns); |
291 ic.markInfoldingColumns(results); | 300 ic.markInfoldingColumns(results); |
292 | 301 |
293 List<WQKms> infoldings = new ArrayList<WQKms>(); | 302 List<ConstantWQKms> infoldings = new ArrayList<ConstantWQKms>(); |
294 | 303 |
295 boolean [] infoldingColumns = ic.getInfoldingColumns(); | 304 boolean [] infoldingColumns = ic.getInfoldingColumns(); |
305 | |
306 double [] kms = null; | |
307 double [] ws = null; | |
308 | |
296 for (int i = 0; i < infoldingColumns.length; ++i) { | 309 for (int i = 0; i < infoldingColumns.length; ++i) { |
297 if (!infoldingColumns[i]) { | 310 if (!infoldingColumns[i]) { |
298 continue; | 311 continue; |
299 } | 312 } |
300 double q = columns[i].getQRangeTree().findQ(from); | 313 |
301 if (Double.isNaN(q)) { | 314 if (kms == null) { |
302 addProblem(from, "cannot.find.q"); | 315 kms = DoubleUtil.explode(from, to, step); |
303 continue; | 316 ws = new double[kms.length]; |
304 } | 317 } |
305 double [] kms = DoubleUtil.explode(from, to, step); | 318 |
306 double [] oqs = new double[kms.length]; | 319 QRangeTree.QuickQFinder qf = |
307 double [] ows = new double[kms.length]; | 320 columns[i].getQRangeTree().new QuickQFinder(); |
308 boolean success = | 321 |
309 wst.interpolate(q, from, kms, ows, oqs, this) != null; | 322 int numProblemsBefore = numProblems(); |
310 | 323 double [] qs = qf.findQs(kms, this); |
311 if (success) { | 324 |
312 // TODO: generate a better name. I18N. | 325 // TODO: i18n |
313 String name = "Umh\u00fcllende " + columns[i].getName(); | 326 String name = "Umh\u00fcllende " + columns[i].getName(); |
314 WQKms wqkms = new WQKms(kms, oqs, ows, name); | 327 |
315 infoldings.add(wqkms); | 328 ConstantWQKms infolding = new ConstantWQKms(kms, qs, ws, name); |
316 } | 329 |
317 } | 330 if (numProblems() > numProblemsBefore) { |
318 | 331 infolding.removeNaNs(); |
319 int N = infoldings.size(); | 332 } |
320 if (N > 0) { | 333 |
321 WQKms [] newResults = new WQKms[results.length + N]; | 334 infoldings.add(infolding); |
322 System.arraycopy(results, 0, newResults, 0, results.length); | 335 } |
323 for (int i = 0; i < N; ++i) { | 336 |
324 newResults[i+results.length] = infoldings.get(i); | 337 return infoldings.toArray(new ConstantWQKms[infoldings.size()]); |
325 } | |
326 results = newResults; | |
327 } | |
328 | |
329 return results; | |
330 } | 338 } |
331 | 339 |
332 protected String createName(int index) { | 340 protected String createName(int index) { |
333 // TODO: i18n | 341 // TODO: i18n |
334 StringBuilder sb = new StringBuilder(isQ ? "Q" : "W"); | 342 StringBuilder sb = new StringBuilder(isQ ? "Q" : "W"); |