(boolean withWeights)
| 6122 | } |
| 6123 | |
| 6124 | double fitCurve(boolean withWeights) { |
| 6125 | interp.getLeftParen(); |
| 6126 | int fit = -1; |
| 6127 | String name = null; |
| 6128 | double[] initialValues = null; |
| 6129 | if (isStringArg()) { |
| 6130 | name = getString(); |
| 6131 | if (!name.contains("Math.")) |
| 6132 | name = name.toLowerCase(Locale.US); |
| 6133 | String[] list = CurveFitter.fitList; |
| 6134 | for (int i=0; i<list.length; i++) { |
| 6135 | if (name.equals(list[i].toLowerCase(Locale.US))) { |
| 6136 | fit = i; |
| 6137 | break; |
| 6138 | } |
| 6139 | } |
| 6140 | boolean isCustom = name.indexOf("y=")!=-1 || name.indexOf("y =")!=-1; |
| 6141 | if (fit==-1&&!isCustom) |
| 6142 | interp.error("Unrecognized fit"); |
| 6143 | } else |
| 6144 | fit = (int)interp.getExpression(); |
| 6145 | double[] x = getNextArray(); |
| 6146 | interp.getComma(); |
| 6147 | double[] y = getNumericArray(); |
| 6148 | double[] weights = null; |
| 6149 | if (withWeights) { |
| 6150 | interp.getComma(); |
| 6151 | weights = getNumericArray(); |
| 6152 | } |
| 6153 | if (interp.nextToken()==',') { |
| 6154 | interp.getComma(); |
| 6155 | initialValues = getNumericArray(); |
| 6156 | } |
| 6157 | interp.getRightParen(); |
| 6158 | if (x.length!=y.length) |
| 6159 | interp.error("Arrays not same length"); |
| 6160 | if (x.length==0) |
| 6161 | interp.error("Zero length array"); |
| 6162 | fitter = new CurveFitter(x, y); |
| 6163 | if (withWeights) |
| 6164 | fitter.setWeights(weights); |
| 6165 | fitter.setStatusAndEsc(null, true); |
| 6166 | if (fit==-1 && name!=null) { |
| 6167 | Interpreter instance = Interpreter.getInstance(); |
| 6168 | int params = fitter.doCustomFit(name, initialValues, showFitDialog); |
| 6169 | Interpreter.instance = instance; |
| 6170 | if (params==0) |
| 6171 | interp.error("Invalid custom function"); |
| 6172 | } else |
| 6173 | fitter.doFit(fit, showFitDialog); |
| 6174 | if (logFitResults) { |
| 6175 | IJ.log(fitter.getResultString()); |
| 6176 | logFitResults = false; |
| 6177 | } |
| 6178 | showFitDialog = false; |
| 6179 | return Double.NaN; |
| 6180 | } |
| 6181 |
no test coverage detected