00001 /* * 00002 * This file is part of the ESO UVES Pipeline * 00003 * Copyright (C) 2004,2005 European Southern Observatory * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the Free Software * 00017 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA * 00018 * */ 00019 00020 /* 00021 * $Author: amodigli $ 00022 * $Date: 2007/06/06 08:17:33 $ 00023 * $Revision: 1.5 $ 00024 * $Name: uves-3_4_5 $ 00025 * $Log: uves_physmod_necregr.c,v $ 00026 * Revision 1.5 2007/06/06 08:17:33 amodigli 00027 * replace tab with 4 spaces 00028 * 00029 * Revision 1.4 2006/11/06 15:19:41 jmlarsen 00030 * Removed unused include directives 00031 * 00032 * Revision 1.3 2006/08/23 09:33:03 jmlarsen 00033 * Renamed local variables shadowing POSIX reserved names 00034 * 00035 * Revision 1.2 2006/06/20 10:56:56 amodigli 00036 * cleaned output, added units 00037 * 00038 * Revision 1.1 2006/02/03 07:46:30 jmlarsen 00039 * Moved recipe implementations to ./uves directory 00040 * 00041 * Revision 1.8 2006/01/20 10:05:49 jmlarsen 00042 * Inserted missing doxygen end tag 00043 * 00044 * Revision 1.7 2006/01/16 08:01:57 amodigli 00045 * 00046 * Added stability check 00047 * 00048 * Revision 1.6 2006/01/05 14:29:59 jmlarsen 00049 * Removed newline characters from output strings 00050 * 00051 * Revision 1.5 2005/12/20 08:11:44 jmlarsen 00052 * Added CVS entry 00053 * 00054 */ 00055 00056 /*----------------------------------------------------------------------------*/ 00060 /*----------------------------------------------------------------------------*/ 00063 #ifdef HAVE_CONFIG_H 00064 # include <config.h> 00065 #endif 00066 00067 /*----------------------------------------------------------------------------- 00068 Includes 00069 -----------------------------------------------------------------------------*/ 00070 #include <uves_physmod_necregr.h> 00071 00072 #include <uves_error.h> 00073 #include <uves_msg.h> 00074 00075 /*----------------------------------------------------------------------------- 00076 Defines 00077 -----------------------------------------------------------------------------*/ 00078 /*----------------------------------------------------------------------------- 00079 Functions prototypes 00080 ----------------------------------------------------------------------------*/ 00081 /*----------------------------------------------------------------------------- 00082 Static variables 00083 -----------------------------------------------------------------------------*/ 00084 00085 /*----------------------------------------------------------------------------- 00086 Functions code 00087 -----------------------------------------------------------------------------*/ 00088 00089 /*----------------------------------------------------------------------------*/ 00102 /*----------------------------------------------------------------------------*/ 00103 00104 int 00105 uves_physmod_necregr(cpl_table** ord_tbl, cpl_table** reg_tbl) 00106 00107 { 00108 00109 int order=0; 00110 int nb_order=0; 00111 int present_order=0; 00112 int order_nb=0; 00113 int row=0; 00114 int ncol=0; 00115 int nrow=0; 00116 00117 int selected=0; 00118 int null=0; 00119 int ord_min=0; 00120 int ord_max=0; 00121 00122 double x=0., y=0., cnt=0., sx=0., sy=0., sx2=0., sxy=0., sy2=0.; 00123 double det=0., a=0., b=0., rms=0.; 00124 00125 uves_msg_debug("start %s",__func__); 00126 nrow=cpl_table_get_nrow(*ord_tbl); 00127 ncol=cpl_table_get_ncol(*ord_tbl); 00128 00129 uves_msg_debug("nrow=%d ncol=%d",nrow,ncol); 00130 ord_min=cpl_table_get_column_min(*ord_tbl,"ORDER"); 00131 ord_max=cpl_table_get_column_max(*ord_tbl,"ORDER"); 00132 nb_order=ord_max-ord_min+1; 00133 *reg_tbl=cpl_table_new(100); 00134 cpl_table_new_column(*reg_tbl,"ORDER",CPL_TYPE_INT); 00135 cpl_table_new_column(*reg_tbl,"RMS",CPL_TYPE_DOUBLE); 00136 00137 row = 0; 00138 selected=1; 00139 00140 for (order=0; order<nb_order; order++) { 00141 00142 cnt=0., sx=0., sy=0., sx2=0., sxy=0., sy2 = 0.; 00143 order_nb=cpl_table_get_int(*ord_tbl,"ORDER",row,&null); 00144 00145 present_order = order_nb; 00146 00147 while (present_order == order_nb) { 00148 00149 if (selected) { 00150 00151 x=cpl_table_get_double(*ord_tbl,"X",row,&null); 00152 y=cpl_table_get_double(*ord_tbl,"Y",row,&null); 00153 00154 cnt += 1., sx += x, sy += y, sx2 += x*x, sy2 += y*y, sxy += x*y; 00155 } 00156 00157 if (row >= (nrow-1)) break; 00158 row++; 00159 present_order=cpl_table_get_int(*ord_tbl,"ORDER",row,&null); 00160 00161 } 00162 00163 00164 if (cnt >= 3) { 00165 det = cnt*sx2 - sx*sx; 00166 a = (sy*sx2 - sx*sxy)/det; 00167 b = (cnt*sxy - sx*sy)/det; 00168 rms = (sy2 - a*a*cnt - 2.*b*a*sx - b*b*sx2)/cnt; 00169 if (rms < 0. && rms > -0.05) rms = 0.; 00170 rms = sqrt(rms); 00171 } 00172 else rms = 99999.; 00173 00174 cpl_table_set_int(*reg_tbl,"ORDER",order,order_nb); 00175 cpl_table_set_double(*reg_tbl,"RMS",order,rms); 00176 00177 } 00178 cpl_table_erase_invalid_rows(*reg_tbl); 00179 uves_msg_debug("end %s",__func__); 00180 return 0; 00181 }
1.5.1