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: 2010/09/24 09:32:07 $ 00023 * $Revision: 1.7 $ 00024 * $Name: uves-5_0_0 $ 00025 * $Log: uves_physmod_necregr.c,v $ 00026 * Revision 1.7 2010/09/24 09:32:07 amodigli 00027 * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data 00028 * 00029 * Revision 1.5 2007/06/06 08:17:33 amodigli 00030 * replace tab with 4 spaces 00031 * 00032 * Revision 1.4 2006/11/06 15:19:41 jmlarsen 00033 * Removed unused include directives 00034 * 00035 * Revision 1.3 2006/08/23 09:33:03 jmlarsen 00036 * Renamed local variables shadowing POSIX reserved names 00037 * 00038 * Revision 1.2 2006/06/20 10:56:56 amodigli 00039 * cleaned output, added units 00040 * 00041 * Revision 1.1 2006/02/03 07:46:30 jmlarsen 00042 * Moved recipe implementations to ./uves directory 00043 * 00044 * Revision 1.8 2006/01/20 10:05:49 jmlarsen 00045 * Inserted missing doxygen end tag 00046 * 00047 * Revision 1.7 2006/01/16 08:01:57 amodigli 00048 * 00049 * Added stability check 00050 * 00051 * Revision 1.6 2006/01/05 14:29:59 jmlarsen 00052 * Removed newline characters from output strings 00053 * 00054 * Revision 1.5 2005/12/20 08:11:44 jmlarsen 00055 * Added CVS entry 00056 * 00057 */ 00058 00059 /*----------------------------------------------------------------------------*/ 00063 /*----------------------------------------------------------------------------*/ 00066 #ifdef HAVE_CONFIG_H 00067 # include <config.h> 00068 #endif 00069 00070 /*----------------------------------------------------------------------------- 00071 Includes 00072 -----------------------------------------------------------------------------*/ 00073 #include <uves_physmod_necregr.h> 00074 00075 #include <uves_error.h> 00076 #include <uves_msg.h> 00077 00078 /*----------------------------------------------------------------------------- 00079 Defines 00080 -----------------------------------------------------------------------------*/ 00081 /*----------------------------------------------------------------------------- 00082 Functions prototypes 00083 ----------------------------------------------------------------------------*/ 00084 /*----------------------------------------------------------------------------- 00085 Static variables 00086 -----------------------------------------------------------------------------*/ 00087 00088 /*----------------------------------------------------------------------------- 00089 Functions code 00090 -----------------------------------------------------------------------------*/ 00091 00092 /*----------------------------------------------------------------------------*/ 00105 /*----------------------------------------------------------------------------*/ 00106 00107 int 00108 uves_physmod_necregr(cpl_table** ord_tbl, cpl_table** reg_tbl) 00109 00110 { 00111 00112 int order=0; 00113 int nb_order=0; 00114 int present_order=0; 00115 int order_nb=0; 00116 int row=0; 00117 int ncol=0; 00118 int nrow=0; 00119 00120 int selected=0; 00121 int null=0; 00122 int ord_min=0; 00123 int ord_max=0; 00124 00125 double x=0., y=0., cnt=0., sx=0., sy=0., sx2=0., sxy=0., sy2=0.; 00126 double det=0., a=0., b=0., rms=0.; 00127 00128 uves_msg_debug("start %s",__func__); 00129 nrow=cpl_table_get_nrow(*ord_tbl); 00130 ncol=cpl_table_get_ncol(*ord_tbl); 00131 00132 uves_msg_debug("nrow=%d ncol=%d",nrow,ncol); 00133 ord_min=cpl_table_get_column_min(*ord_tbl,"ORDER"); 00134 ord_max=cpl_table_get_column_max(*ord_tbl,"ORDER"); 00135 nb_order=ord_max-ord_min+1; 00136 *reg_tbl=cpl_table_new(100); 00137 cpl_table_new_column(*reg_tbl,"ORDER",CPL_TYPE_INT); 00138 cpl_table_new_column(*reg_tbl,"RMS",CPL_TYPE_DOUBLE); 00139 00140 row = 0; 00141 selected=1; 00142 00143 for (order=0; order<nb_order; order++) { 00144 00145 cnt=0., sx=0., sy=0., sx2=0., sxy=0., sy2 = 0.; 00146 order_nb=cpl_table_get_int(*ord_tbl,"ORDER",row,&null); 00147 00148 present_order = order_nb; 00149 00150 while (present_order == order_nb) { 00151 00152 if (selected) { 00153 00154 x=cpl_table_get_double(*ord_tbl,"X",row,&null); 00155 y=cpl_table_get_double(*ord_tbl,"Y",row,&null); 00156 00157 cnt += 1., sx += x, sy += y, sx2 += x*x, sy2 += y*y, sxy += x*y; 00158 } 00159 00160 if (row >= (nrow-1)) break; 00161 row++; 00162 present_order=cpl_table_get_int(*ord_tbl,"ORDER",row,&null); 00163 00164 } 00165 00166 00167 if (cnt >= 3) { 00168 det = cnt*sx2 - sx*sx; 00169 a = (sy*sx2 - sx*sxy)/det; 00170 b = (cnt*sxy - sx*sy)/det; 00171 rms = (sy2 - a*a*cnt - 2.*b*a*sx - b*b*sx2)/cnt; 00172 if (rms < 0. && rms > -0.05) rms = 0.; 00173 rms = sqrt(rms); 00174 } 00175 else rms = 99999.; 00176 00177 cpl_table_set_int(*reg_tbl,"ORDER",order,order_nb); 00178 cpl_table_set_double(*reg_tbl,"RMS",order,rms); 00179 00180 } 00181 cpl_table_erase_invalid_rows(*reg_tbl); 00182 uves_msg_debug("end %s",__func__); 00183 return 0; 00184 }