UVES Pipeline Reference Manual  5.5.4
uves_physmod_necregr.c
1 /* *
2  * This file is part of the ESO UVES Pipeline *
3  * Copyright (C) 2004,2005 European Southern Observatory *
4  * *
5  * This library is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18  * */
19 
20 /*
21  * $Author: amodigli $
22  * $Date: 2010-09-24 09:32:07 $
23  * $Revision: 1.7 $
24  * $Name: not supported by cvs2svn $
25  *
26  */
27 
28 /*----------------------------------------------------------------------------*/
32 /*----------------------------------------------------------------------------*/
35 #ifdef HAVE_CONFIG_H
36 # include <config.h>
37 #endif
38 
39 /*-----------------------------------------------------------------------------
40  Includes
41  -----------------------------------------------------------------------------*/
42 #include <uves_physmod_necregr.h>
43 
44 #include <uves_error.h>
45 #include <uves_msg.h>
46 
47 /*-----------------------------------------------------------------------------
48  Defines
49  -----------------------------------------------------------------------------*/
50 /*-----------------------------------------------------------------------------
51  Functions prototypes
52  ----------------------------------------------------------------------------*/
53 /*-----------------------------------------------------------------------------
54  Static variables
55  -----------------------------------------------------------------------------*/
56 
57 /*-----------------------------------------------------------------------------
58  Functions code
59  -----------------------------------------------------------------------------*/
60 
61 /*----------------------------------------------------------------------------*/
74 /*----------------------------------------------------------------------------*/
75 
76 int
77 uves_physmod_necregr(cpl_table** ord_tbl, cpl_table** reg_tbl)
78 
79 {
80 
81  int order=0;
82  int nb_order=0;
83 
84  int order_nb=0;
85  int row=0;
86  int ncol=0;
87  int nrow=0;
88 
89  int selected=0;
90  int null=0;
91  int ord_min=0;
92  int ord_max=0;
93 
94  double x=0., y=0.;
95  double det=0., a=0., b=0., rms=0.;
96 
97  uves_msg_debug("start %s",__func__);
98  nrow=cpl_table_get_nrow(*ord_tbl);
99  ncol=cpl_table_get_ncol(*ord_tbl);
100 
101  uves_msg_debug("nrow=%d ncol=%d",nrow,ncol);
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);
108 
109  row = 0;
110  selected=1;
111 
112  for (order=0; order<nb_order; order++) {
113 
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);
116 
117  int present_order = order_nb;
118 
119  while (present_order == order_nb) {
120 
121  if (selected) {
122 
123  x=cpl_table_get_double(*ord_tbl,"X",row,&null);
124  y=cpl_table_get_double(*ord_tbl,"Y",row,&null);
125 
126  cnt += 1., sx += x, sy += y, sx2 += x*x, sy2 += y*y, sxy += x*y;
127  }
128 
129  if (row >= (nrow-1)) break;
130  row++;
131  present_order=cpl_table_get_int(*ord_tbl,"ORDER",row,&null);
132 
133  }
134 
135 
136  if (cnt >= 3) {
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.;
142  rms = sqrt(rms);
143  }
144  else rms = 99999.;
145 
146  cpl_table_set_int(*reg_tbl,"ORDER",order,order_nb);
147  cpl_table_set_double(*reg_tbl,"RMS",order,rms);
148 
149  }
150  cpl_table_erase_invalid_rows(*reg_tbl);
151  uves_msg_debug("end %s",__func__);
152  return 0;
153 }
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.
Definition: uves_msg.h:97