70 #include <uves_physmod_necregr.h>
72 #include <uves_error.h>
122 double x=0., y=0., cnt=0., sx=0., sy=0., sx2=0., sxy=0., sy2=0.;
123 double det=0., a=0., b=0., rms=0.;
126 nrow=cpl_table_get_nrow(*ord_tbl);
127 ncol=cpl_table_get_ncol(*ord_tbl);
130 ord_min=cpl_table_get_column_min(*ord_tbl,
"ORDER");
131 ord_max=cpl_table_get_column_max(*ord_tbl,
"ORDER");
132 nb_order=ord_max-ord_min+1;
133 *reg_tbl=cpl_table_new(100);
134 cpl_table_new_column(*reg_tbl,
"ORDER",CPL_TYPE_INT);
135 cpl_table_new_column(*reg_tbl,
"RMS",CPL_TYPE_DOUBLE);
140 for (order=0; order<nb_order; order++) {
142 cnt=0., sx=0., sy=0., sx2=0., sxy=0., sy2 = 0.;
143 order_nb=cpl_table_get_int(*ord_tbl,
"ORDER",row,&null);
145 present_order = order_nb;
147 while (present_order == order_nb) {
151 x=cpl_table_get_double(*ord_tbl,
"X",row,&null);
152 y=cpl_table_get_double(*ord_tbl,
"Y",row,&null);
154 cnt += 1., sx += x, sy += y, sx2 += x*x, sy2 += y*y, sxy += x*y;
157 if (row >= (nrow-1))
break;
159 present_order=cpl_table_get_int(*ord_tbl,
"ORDER",row,&null);
165 det = cnt*sx2 - sx*sx;
166 a = (sy*sx2 - sx*sxy)/det;
167 b = (cnt*sxy - sx*sy)/det;
168 rms = (sy2 - a*a*cnt - 2.*b*a*sx - b*b*sx2)/cnt;
169 if (rms < 0. && rms > -0.05) rms = 0.;
174 cpl_table_set_int(*reg_tbl,
"ORDER",order,order_nb);
175 cpl_table_set_double(*reg_tbl,
"RMS",order,rms);
178 cpl_table_erase_invalid_rows(*reg_tbl);
int uves_physmod_necregr(cpl_table **ord_tbl, cpl_table **reg_tbl)
This procedure does a linear fit of independent orders.
#define uves_msg_debug(...)
Print a debug message.