50 cpl_table *spec, cpl_table *lines,
51 const cpl_parameterlist *parlist)
95 cpl_error_code err_code = CPL_ERROR_NONE;
97 cpl_array *fwhm_arr = cpl_array_new(0, CPL_TYPE_DOUBLE),
98 *iso_arr = cpl_array_new(0, CPL_TYPE_DOUBLE);
100 const cpl_parameter *p;
124 p = cpl_parameterlist_find_const(parlist,
"varfwhm");
125 varfwhm = cpl_parameter_get_int(p);
128 p = cpl_parameterlist_find_const(parlist,
"meanlam");
129 meanlam = cpl_parameter_get_double(p);
132 data.x = cpl_array_new(0, CPL_TYPE_DOUBLE);
133 data.y = cpl_array_new(0, CPL_TYPE_DOUBLE);
134 data.y_err = cpl_array_new(0, CPL_TYPE_DOUBLE);
137 n_lines = cpl_table_get_nrow(lines);
141 for (i = 0; i < n_lines; i++) {
144 if (cpl_table_get_int(lines,
"isol_flag", i, NULL) == 1) {
146 i_start = cpl_table_get_int(lines,
"line_px_start", i, NULL);
147 i_end = cpl_table_get_int(lines,
"line_px_end", i, NULL);
150 nline = i_end - i_start;
153 cpl_array_set_size(data.x, nline);
154 cpl_array_set_size(data.y_err, nline);
155 cpl_array_set_size(data.y, nline);
158 cpl_array_copy_data_double(data.y,
159 cpl_table_get_data_double(spec,
"lflux")+i_start);
160 for (j = 0, total = 0; j < nline; j++) {
161 cpl_array_set_double(data.x, j, (
double) (i_start + j));
162 cpl_array_set_double(data.y_err, j, 1.);
163 total += cpl_array_get_double(data.y, j, NULL);
167 width = cpl_table_get_double(lines,
"fwhm", i, NULL);
170 width = (double) cpl_table_get_int(lines,
"width", i, NULL);
174 width *= cpl_table_get_double(lines,
"peak_lam", i,
181 pars[1] = cpl_table_get_int(lines,
"peak_loc", i, NULL);
182 pars[2] = width / CPL_MATH_FWHM_SIG;
186 sc_basic_status2txt(msg, status);
192 if (status == MP_OK_CHI ||
193 status == MP_OK_PAR ||
194 status == MP_OK_BOTH ||
195 status == MP_OK_DIR) {
196 width = pars[2] * CPL_MATH_FWHM_SIG;
204 width *= meanlam / cpl_table_get_double(lines,
"peak_lam", i,
209 cpl_table_set_double(lines,
"fwhm", i, width);
212 cpl_array_set_size(fwhm_arr, niso);
213 cpl_array_set_double(fwhm_arr, niso-1, width);
216 cpl_array_set_size(iso_arr, niso);
217 cpl_array_set_double(iso_arr, niso-1, width);
231 *fwhm = cpl_array_get_double(iso_arr, 0, NULL);
235 *fwhm = cpl_array_get_min(iso_arr);
239 *fwhm = cpl_array_get_median(iso_arr);
243 cpl_array_get_maxpos(iso_arr, &maxpos);
244 cpl_array_set_invalid(iso_arr, maxpos);
245 *fwhm = cpl_array_get_median(iso_arr);
255 cpl_array_delete(fwhm_arr);
256 cpl_array_delete(iso_arr);
257 cpl_array_delete(data.x);
258 cpl_array_delete(data.y);
259 cpl_array_delete(data.y_err);
266 double **derivs,
void *pdata)
295 fgauss = (
double *) malloc(n_data *
sizeof(
double));
299 for (i = 0; i < n_data; i++) {
300 deviates[i] = (cpl_array_get_double(data->y, i, NULL) - fgauss[i]) /
301 cpl_array_get_double(data->y_err, i, NULL);
int sc_basic_gaussfunc(double *fgauss, const double *xgauss, const int n_data, const double *par)
cpl_error_code sc_basic_clipmean(double *mean, double *rms, cpl_array *arr, const cpl_boolean clip)
cpl_error_code sc_fwhmest(double *fwhm, double *rms, cpl_table *spec, cpl_table *lines, const cpl_parameterlist *parlist)
int sc_fwhmest_gaussfunc(int n_data, int n_pars, double *p, double *deviates, double **derivs, void *pdata)