comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java @ 3073:0ace00c0c12a

FixA: Improved W/Q facet code flys-artifacts/trunk@4664 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 14 Jun 2012 14:03:16 +0000
parents d87aadaa4f7e
children 6502b17931b9
comparison
equal deleted inserted replaced
3072:0d3dd8230064 3073:0ace00c0c12a
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 String[] columnNames = params.getColumnNames(); 77 String[] columnNames = params.getColumnNames();
78 for(String columnName : columnNames) { 78
79 logger.debug("FixWQCurveFacet.getData: columnName = '" + columnName + "'"); 79 String[] paramNames = ff.getParameterNames();
80
81 double [] coeffs = params.interpolate("km", km, paramNames);
82
83 if (coeffs == null) {
84 return null;
80 } 85 }
81 int row = params.binarySearch("km", km, Math.pow(10, -4));
82 if(row < 0) {
83 row = -row - 1;
84 logger.debug("getData: no direct hit in params.binarySearch");
85 }
86 String[] paramNames = ff.getParameterNames();
87 int[] paramInd = params.columnIndices(paramNames);
88 double[] coeffs = new double[paramNames.length];
89 params.get(row, paramInd, coeffs);
90 86
91 de.intevation.flys.artifacts.math.Function mf = 87 de.intevation.flys.artifacts.math.Function mf =
92 ff.instantiate(coeffs); 88 ff.instantiate(coeffs);
93 89
94 double maxQ = getMaxQ(result, km); 90 double maxQ = getMaxQ(params, km);
95 logger.debug("getData: maxQ = " + maxQ); 91 logger.debug("getData: maxQ = " + maxQ);
96 92
97 FixFunction fix = new FixFunction( 93 FixFunction fix = new FixFunction(
98 ff.getName(), 94 ff.getName(),
99 ff.getDescription(), 95 ff.getDescription(),
107 return null; 103 return null;
108 } 104 }
109 } 105 }
110 106
111 107
112 protected double getMaxQ(FixResult result, double km) { 108 protected double getMaxQ(Parameters params, double km) {
113 double maxQ = 0; 109 double [] maxQ = params.interpolate("km", km, new String[] { "max_q" });
114 110 if (maxQ == null) {
115 KMIndex<QW []> kmQWRef = result.getReferenced(); 111 return 1000;
116
117 KMIndex.Entry<QW []> qwEntry = kmQWRef.binarySearch(km);
118 if(qwEntry != null) {
119 QW[] qwRef = qwEntry.getValue();
120 if (qwRef != null) {
121 for (int i = 0; i < qwRef.length; i++) {
122 if (qwRef[i].getQ() > maxQ) {
123 maxQ = qwRef[i].getQ();
124 }
125 }
126 }
127 } else {
128 logger.debug("getMaxQ: qwEntry is null, that's odd...");
129 } 112 }
130 113 double mQ = Math.min(10000, Math.abs(maxQ[0]));
131 KMIndex<AnalysisPeriod []> kmQWDAna = result.getAnalysisPeriods(); 114 return mQ + 0.05*mQ;
132 KMIndex.Entry<AnalysisPeriod []> periodsEntry = kmQWDAna.binarySearch(km);
133
134 if(periodsEntry != null) {
135 AnalysisPeriod[] periods = kmQWDAna.binarySearch(km).getValue();
136 if(periods != null) {
137 for (int i = 0; i < periods.length; i++) {
138 QWD[] qwdAna = periods[i].getQWDs();
139 if (qwdAna != null) {
140 for (int j = 0; j < qwdAna.length; j++) {
141 if (qwdAna[j].getQ() > maxQ) {
142 maxQ = qwdAna[j].getQ();
143 }
144 }
145 }
146 }
147 }
148 } else {
149 logger.debug("getMaxQ: periodsEntry is null, that's odd...");
150 }
151 //return maxQ;
152 return 1000; //FIXME replace by parameters.interpolate("q_max")...
153 } 115 }
154 116
155 /** 117 /**
156 * Create a deep copy of this Facet. 118 * Create a deep copy of this Facet.
157 * @return a deep copy. 119 * @return a deep copy.

http://dive4elements.wald.intevation.org