Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixATWriter.java @ 4571:95e23bcf6a50
Fix FLYS logo URL for printing.
Remove obsolete code from MapPanel.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Tue, 20 Nov 2012 15:28:07 +0100 |
parents | 8bbb9e173297 |
children |
rev | line source |
---|---|
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.exports.fixings; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import de.intevation.artifacts.CallMeta; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import de.intevation.flys.artifacts.math.fitting.Function; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import de.intevation.flys.artifacts.model.Parameters; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.flys.artifacts.resources.Resources; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.flys.exports.ATWriter; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import java.io.IOException; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import java.io.PrintWriter; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import java.io.Writer; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import java.util.Locale; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import org.apache.log4j.Logger; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
3905
8bbb9e173297
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3643
diff
changeset
|
21 /** Export Fixation Analysis Results to AT. */ |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 public class FixATWriter |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 { |
3905
8bbb9e173297
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3643
diff
changeset
|
24 /** Private logger. */ |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 private static Logger log = Logger.getLogger(FixATWriter.class); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 public static final String I18N_HEADER_KEY = |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 "fix.export.at.header"; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public static final String I18N_HEADER_DEFAULT = |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 "Exported fixings discharge curve for {0} {0}-km: {1}"; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 public static final String [] Q_MAX_COLUMN = new String [] { "max_q" }; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
3641
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
35 private static final int MAX_ITERATIONS = 10000; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
36 private static final double EPSILON = 1e-8; |
3643
171db4d5d3cb
FixA: AT export: prevent some numerical problems with steep functions around zero.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3642
diff
changeset
|
37 private static final double MIN_Q = 1e-4; |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 protected Function function; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 protected Parameters parameters; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 public FixATWriter() { |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 } |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 public FixATWriter(Function function, Parameters parameters) { |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 this.function = function; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 this.parameters = parameters; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 public void write( |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 Writer writer, |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 CallMeta meta, |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 String river, |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 double km |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 ) |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 throws IOException { |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 PrintWriter out = new PrintWriter(writer); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 printHeader(out, meta, river, km); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 double [] coeffs = parameters.interpolate( |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 "km", km, function.getParameterNames()); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 double [] qMax = parameters.interpolate( |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 "km", km, Q_MAX_COLUMN); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 if (coeffs == null || qMax == null) { |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 log.debug("No data found at km " + km + "."); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 return; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 } |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 de.intevation.flys.artifacts.math.Function funcInst = |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 function.instantiate(coeffs); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
3642
83c0735092a3
FixA: Increase Q max about 5% if storing as AT file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3641
diff
changeset
|
74 // Increase Q max about 5%. |
83c0735092a3
FixA: Increase Q max about 5% if storing as AT file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3641
diff
changeset
|
75 qMax[0] += Math.abs(qMax[0])*0.05; |
83c0735092a3
FixA: Increase Q max about 5% if storing as AT file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3641
diff
changeset
|
76 |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 double wMax = funcInst.value(qMax[0]); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 if (Double.isNaN(wMax) || wMax < 0d) { |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 log.debug("function '" + function.getName() + |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 "' eval failed at " + wMax); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 return; |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 } |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 Function inverse = function.getInverse(); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 de.intevation.flys.artifacts.math.Function invInst = |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 inverse.instantiate(coeffs); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 |
3641
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
90 double wMin = minW(invInst, wMax, qMax[0]); |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
3641
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
92 double wMinCM = wMin * 100d; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
93 double wMaxCM = wMax * 100d; |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 |
3641
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
95 int wRow = ((int)wMinCM / 10) * 10; |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 |
3641
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
97 if ((wMinCM - (int)wMinCM) > 0d) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
98 wMinCM = (int)wMinCM + 1d; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
99 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
100 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
101 double w = wMinCM / 100.0; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
102 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
103 int wcm = ((int)wMinCM) % 10; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
104 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
105 if (log.isDebugEnabled()) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
106 log.debug("wMinCM: " + wMinCM); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
107 log.debug("wMaxCM: " + wMaxCM); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
108 log.debug("wcm: " + wcm); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
109 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
110 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
111 out.printf(Locale.US, "%8d", wRow); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
112 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
113 if (wcm > 0) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
114 int rest = 10 - wcm; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
115 while (rest-- > 0) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
116 out.print(ATWriter.EMPTY); |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 } |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
3641
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
120 for (;;) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
121 while (wcm++ < 10) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
122 if (w > wMax) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
123 break; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
124 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
125 double q = invInst.value(w); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
126 if (Double.isNaN(w)) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
127 out.print(ATWriter.EMPTY); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
128 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
129 else { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
130 ATWriter.printQ(out, q); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
131 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
132 w += 0.01d; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
133 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
134 out.println(); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
135 if (w > wMax) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
136 break; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
137 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
138 out.printf(Locale.US, "%8d", wRow += 10); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
139 wcm = 0; |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 } |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 out.flush(); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 } |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 protected void printHeader( |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 PrintWriter out, |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 CallMeta meta, |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 String river, |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 double km |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 ) { |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 out.println(Resources.format( |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 meta, |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 I18N_HEADER_KEY, |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 I18N_HEADER_DEFAULT, |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 river, km)); |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 } |
3641
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
157 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
158 private static double minW( |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
159 de.intevation.flys.artifacts.math.Function function, |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
160 double maxW, |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
161 double maxQ |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
162 ) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
163 double stepWidth = 10d; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
164 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
165 double lastW = maxW; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
166 double lastQ = maxQ; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
167 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
168 for (int i = 0; i < MAX_ITERATIONS; ++i) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
169 double w = lastW - stepWidth; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
170 double q = function.value(w); |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
171 |
3643
171db4d5d3cb
FixA: AT export: prevent some numerical problems with steep functions around zero.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3642
diff
changeset
|
172 if (Double.isNaN(q) || q > lastQ || q < MIN_Q) { |
3641
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
173 if (stepWidth < EPSILON) { |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
174 break; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
175 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
176 stepWidth *= 0.5d; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
177 continue; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
178 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
179 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
180 lastW = w; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
181 lastQ = q; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
182 } |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
183 |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
184 return lastW; |
1dc904370a64
Fixed issue687: Rewrote AT export in FixA
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3220
diff
changeset
|
185 } |
3220
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 } |
0c8a6145098b
FixA: Added AT writer for fitted functions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |