42 #include <uves_physmod_necregr.h>
44 #include <uves_error.h>
95 double det=0., a=0., b=0., rms=0.;
98 nrow=cpl_table_get_nrow(*ord_tbl);
99 ncol=cpl_table_get_ncol(*ord_tbl);
102 ord_min=cpl_table_get_column_min(*ord_tbl,
"ORDER");
103 ord_max=cpl_table_get_column_max(*ord_tbl,
"ORDER");
104 nb_order=ord_max-ord_min+1;
105 *reg_tbl=cpl_table_new(100);
106 cpl_table_new_column(*reg_tbl,
"ORDER",CPL_TYPE_INT);
107 cpl_table_new_column(*reg_tbl,
"RMS",CPL_TYPE_DOUBLE);
112 for (order=0; order<nb_order; order++) {
114 double cnt=0., sx=0., sy=0., sx2=0., sxy=0., sy2 = 0.;
115 order_nb=cpl_table_get_int(*ord_tbl,
"ORDER",row,&null);
117 int present_order = order_nb;
119 while (present_order == order_nb) {
123 x=cpl_table_get_double(*ord_tbl,
"X",row,&null);
124 y=cpl_table_get_double(*ord_tbl,
"Y",row,&null);
126 cnt += 1., sx += x, sy += y, sx2 += x*x, sy2 += y*y, sxy += x*y;
129 if (row >= (nrow-1))
break;
131 present_order=cpl_table_get_int(*ord_tbl,
"ORDER",row,&null);
137 det = cnt*sx2 - sx*sx;
138 a = (sy*sx2 - sx*sxy)/det;
139 b = (cnt*sxy - sx*sy)/det;
140 rms = (sy2 - a*a*cnt - 2.*b*a*sx - b*b*sx2)/cnt;
141 if (rms < 0. && rms > -0.05) rms = 0.;
146 cpl_table_set_int(*reg_tbl,
"ORDER",order,order_nb);
147 cpl_table_set_double(*reg_tbl,
"RMS",order,rms);
150 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.