Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java @ 3056:0b5a7a2c3724
Try to workaround some exception in FixWQCurveFacet and FixWQCurveGenerator
flys-artifacts/trunk@4632 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Sun, 10 Jun 2012 11:12:38 +0000 |
parents | 1fbf8462f808 |
children | 7660cfe5e8f6 |
comparison
equal
deleted
inserted
replaced
3055:1fbf8462f808 | 3056:0b5a7a2c3724 |
---|---|
17 | 17 |
18 import de.intevation.flys.artifacts.math.fitting.FunctionFactory; | 18 import de.intevation.flys.artifacts.math.fitting.FunctionFactory; |
19 import de.intevation.flys.artifacts.math.fitting.Function; | 19 import de.intevation.flys.artifacts.math.fitting.Function; |
20 | 20 |
21 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; | 21 import de.intevation.flys.artifacts.states.DefaultState.ComputeType; |
22 | |
23 | 22 |
24 /** | 23 /** |
25 * Facet to show the W|Q values. | 24 * Facet to show the W|Q values. |
26 * | 25 * |
27 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
67 false); | 66 false); |
68 | 67 |
69 FixResult result = (FixResult) res.getData(); | 68 FixResult result = (FixResult) res.getData(); |
70 | 69 |
71 double km = access.getCurrentKm(); | 70 double km = access.getCurrentKm(); |
71 logger.debug("FixWQCurveFacet.getData: km = " + km); | |
72 | 72 |
73 String function = access.getFunction(); | 73 String function = access.getFunction(); |
74 Function ff = FunctionFactory.getInstance().getFunction(function); | 74 Function ff = FunctionFactory.getInstance().getFunction(function); |
75 | 75 |
76 Parameters params = result.getParameters(); | 76 Parameters params = result.getParameters(); |
77 int row = 0; //params.binarySearch("km", km, Math.pow(10, -4)); //FIXME: search failes as access.getCurrentKm() always returns 13.37... | 77 String[] columnNames = params.getColumnNames(); |
78 for(String columnName : columnNames) { | |
79 logger.debug("FixWQCurveFacet.getData: columnName = '" + columnName + "'"); | |
80 } | |
81 int row = params.binarySearch("km", km /*, Math.pow(10, -4)*/); //FIXME Use epsilon as soon access.getCurrentKm() is fixed | |
82 if(row < 0) { | |
83 row = -row - 1; | |
84 logger.debug("getData: no direct hit in params.binarySearch"); | |
85 } | |
78 String[] paramNames = ff.getParameterNames(); | 86 String[] paramNames = ff.getParameterNames(); |
79 int[] paramInd = params.columnIndices(paramNames); | 87 int[] paramInd = params.columnIndices(paramNames); |
80 double[] coeffs = new double[paramNames.length]; | 88 double[] coeffs = new double[paramNames.length]; |
81 params.get(row, paramInd, coeffs); | 89 params.get(row, paramInd, coeffs); |
82 | 90 |
83 de.intevation.flys.artifacts.math.Function mf = | 91 de.intevation.flys.artifacts.math.Function mf = |
84 ff.instantiate(coeffs); | 92 ff.instantiate(coeffs); |
85 | 93 |
86 double maxQ = 100; //getMaxQ(result, km); //FIXME | 94 double maxQ = getMaxQ(result, km); |
95 logger.debug("getData: maxQ = " + maxQ); | |
87 | 96 |
88 FixFunction fix = new FixFunction( | 97 FixFunction fix = new FixFunction( |
89 ff.getName(), | 98 ff.getName(), |
90 ff.getDescription(), | 99 ff.getDescription(), |
91 mf, | 100 mf, |
103 protected double getMaxQ(FixResult result, double km) { | 112 protected double getMaxQ(FixResult result, double km) { |
104 double maxQ = 0; | 113 double maxQ = 0; |
105 | 114 |
106 KMIndex<QW []> kmQWRef = result.getReferenced(); | 115 KMIndex<QW []> kmQWRef = result.getReferenced(); |
107 | 116 |
108 QW[] qwRef = kmQWRef.binarySearch(km).getValue(); | 117 KMIndex.Entry<QW []> qwEntry = kmQWRef.binarySearch(km); |
109 if (qwRef != null) { | 118 if(qwEntry != null) { |
110 for (int i = 0; i < qwRef.length; i++) { | 119 QW[] qwRef = qwEntry.getValue(); |
111 if (qwRef[i].getQ() > maxQ) { | 120 if (qwRef != null) { |
112 maxQ = qwRef[i].getQ(); | 121 for (int i = 0; i < qwRef.length; i++) { |
122 if (qwRef[i].getQ() > maxQ) { | |
123 maxQ = qwRef[i].getQ(); | |
124 } | |
113 } | 125 } |
114 } | 126 } |
127 } else { | |
128 logger.debug("getMaxQ: qwEntry is null, that's odd..."); | |
115 } | 129 } |
116 | 130 |
117 KMIndex<AnalysisPeriod []> kmQWDAna = result.getAnalysisPeriods(); | 131 KMIndex<AnalysisPeriod []> kmQWDAna = result.getAnalysisPeriods(); |
118 AnalysisPeriod[] periods = kmQWDAna.binarySearch(km).getValue(); | 132 KMIndex.Entry<AnalysisPeriod []> periodsEntry = kmQWDAna.binarySearch(km); |
119 | 133 |
120 if(periods != null) { | 134 if(periodsEntry != null) { |
121 for (int i = 0; i < periods.length; i++) { | 135 AnalysisPeriod[] periods = kmQWDAna.binarySearch(km).getValue(); |
122 QWD[] qwdAna = periods[i].getQWDs(); | 136 if(periods != null) { |
123 if (qwdAna != null) { | 137 for (int i = 0; i < periods.length; i++) { |
124 for (int j = 0; j < qwdAna.length; j++) { | 138 QWD[] qwdAna = periods[i].getQWDs(); |
125 if (qwdAna[j].getQ() > maxQ) { | 139 if (qwdAna != null) { |
126 maxQ = qwdAna[j].getQ(); | 140 for (int j = 0; j < qwdAna.length; j++) { |
141 if (qwdAna[j].getQ() > maxQ) { | |
142 maxQ = qwdAna[j].getQ(); | |
143 } | |
127 } | 144 } |
128 } | 145 } |
129 } | 146 } |
130 } | 147 } |
148 } else { | |
149 logger.debug("getMaxQ: periodsEntry is null, that's odd..."); | |
131 } | 150 } |
132 return maxQ; | 151 return maxQ; |
133 } | 152 } |
134 | 153 |
135 /** | 154 /** |