Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/Calculation2.java @ 6434:898afcce1d0a
Partial fix for flys/1303
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 26 Jun 2013 13:33:15 +0200 |
parents | af13ceeba52a |
children | e4606eae8ea5 |
comparison
equal
deleted
inserted
replaced
6433:2874e16c2cc6 | 6434:898afcce1d0a |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.model; | 9 package org.dive4elements.river.artifacts.model; |
10 | 10 |
11 import java.io.FileWriter; | |
12 import java.io.IOException; | |
13 import java.io.PrintWriter; | |
11 import java.util.Arrays; | 14 import java.util.Arrays; |
12 | 15 |
13 import org.apache.log4j.Logger; | 16 import org.apache.log4j.Logger; |
14 | 17 |
15 | 18 |
26 | 29 |
27 public Calculation2(double km) { | 30 public Calculation2(double km) { |
28 this.km = km; | 31 this.km = km; |
29 } | 32 } |
30 | 33 |
34 private void dump(double [][] wqs) { | |
35 double [] ws = wqs[0]; | |
36 double [] qs = wqs[1]; | |
37 | |
38 String filename = "/tmp/computed-discharge-curve-" + km + "-" + | |
39 System.currentTimeMillis() + ".txt"; | |
40 | |
41 PrintWriter pw = null; | |
42 try { | |
43 pw = | |
44 new PrintWriter( | |
45 new FileWriter(filename)); | |
46 | |
47 for (int i = 0; i < ws.length; ++i) { | |
48 pw.println(ws[i] + " " + qs[i]); | |
49 } | |
50 | |
51 pw.flush(); | |
52 } | |
53 catch (IOException ioe) { | |
54 logger.error(ioe); | |
55 } | |
56 finally { | |
57 if (pw != null) { | |
58 pw.close(); | |
59 } | |
60 } | |
61 } | |
62 | |
31 public CalculationResult calculate(WstValueTable wst) { | 63 public CalculationResult calculate(WstValueTable wst) { |
32 | 64 |
33 logger.debug("Calculation2.calculate"); | 65 boolean debug = logger.isDebugEnabled(); |
66 | |
67 if (debug) { | |
68 logger.debug("Calculation2.calculate: km " + km); | |
69 } | |
34 | 70 |
35 double [][] wqs = wst.interpolateWQ(km, this); | 71 double [][] wqs = wst.interpolateWQ(km, this); |
72 | |
73 if (debug) { | |
74 if (hasProblems()) { | |
75 logger.debug("problems: " + problemsToString()); | |
76 } | |
77 logger.debug("wqs: " + wqs); | |
78 if (wqs != null && wqs[0] != null) { | |
79 logger.debug("wqs length: " + wqs[0].length); | |
80 // TODO: Uncomment to see the data externally. | |
81 //dump(wqs); | |
82 } | |
83 } | |
36 | 84 |
37 if (wqs == null || wqs[0].length == 0) { | 85 if (wqs == null || wqs[0].length == 0) { |
38 addProblem("cannot.compute.discharge.curve"); | 86 addProblem("cannot.compute.discharge.curve"); |
39 return new CalculationResult(new WQKms[0], this); | 87 return new CalculationResult(new WQKms[0], this); |
40 } | 88 } |