annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Calculation1.java @ 735:db68806e6563

Fixed "W am Pegel" calculations. flys-artifacts/trunk@2230 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 25 Jun 2011 17:35:50 +0000
parents 3b7e9ddf6bb1
children 5abdb2fa8eb1
rev   line source
678
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.ArrayList;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import org.apache.log4j.Logger;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 public class Calculation1
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 extends Calculation
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 {
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 private static Logger logger = Logger.getLogger(Calculation1.class);
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 protected double [] kms;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 protected double [] qs;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 protected double [] ws;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 protected boolean up;
708
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
16 protected double refKm;
678
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 public Calculation1() {
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 }
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 public Calculation1(
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 double [] kms,
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 double [] qs,
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 double [] ws,
708
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
25 double refKm,
678
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 boolean up
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 ) {
708
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
28 this.kms = kms;
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
29 this.qs = qs;
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
30 this.ws = ws;
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
31 this.refKm = refKm;
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
32 this.up = up;
678
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 }
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
709
3b7e9ddf6bb1 New model to transport data and error reports of calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 708
diff changeset
35 public CalculationResult calculate(WstValueTable wst) {
678
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 ArrayList<WQKms> results = new ArrayList<WQKms>();
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
708
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
39 double ref = Double.isNaN(refKm)
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
40 ? kms[up ? 0 : kms.length-1]
757ff56b43b3 Added calculation "am Pegel" version to the "Wasserspiegellage" calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 678
diff changeset
41 : refKm;
678
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 String prefix;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 double [] origData;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 if (ws != null) { prefix = "W="; origData = ws; }
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 else { prefix = "Q="; origData = qs; }
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 int oldNumProblems = numProblems();
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 for (int i = 0; i < qs.length; i++) {
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 double [] oqs = new double[kms.length];
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 double [] ows = new double[kms.length];
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 boolean success =
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 wst.interpolate(qs[i], ref, kms, ows, oqs, this) != null;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 int newNumProblems = numProblems();
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 if (success) {
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 WQKms result = new WQKms(kms, oqs, ows, prefix + origData[i]);
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 if (oldNumProblems != newNumProblems) {
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 logger.debug(
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 qs[i] + " caused " + (newNumProblems-oldNumProblems) +
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 " new problem(s).");
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 result.removeNaNs();
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 }
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 results.add(result);
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 }
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 oldNumProblems = newNumProblems;
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 }
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
709
3b7e9ddf6bb1 New model to transport data and error reports of calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 708
diff changeset
75 return new CalculationResult(
3b7e9ddf6bb1 New model to transport data and error reports of calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 708
diff changeset
76 results.toArray(new WQKms[results.size()]),
3b7e9ddf6bb1 New model to transport data and error reports of calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 708
diff changeset
77 this);
678
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 }
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 }
19a3185822a4 Added error reporting to 'Wasserspiegellage' calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org