uves_physmod_chop_otab.c

00001 
00002 /*                                                                              *
00003  *   This file is part of the ESO UVES Pipeline                                 *
00004  *   Copyright (C) 2004,2005 European Southern Observatory                      *
00005  *                                                                              *
00006  *   This library is free software; you can redistribute it and/or modify       *
00007  *   it under the terms of the GNU General Public License as published by       *
00008  *   the Free Software Foundation; either version 2 of the License, or          *
00009  *   (at your option) any later version.                                        *
00010  *                                                                              *
00011  *   This program is distributed in the hope that it will be useful,            *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
00014  *   GNU General Public License for more details.                               *
00015  *                                                                              *
00016  *   You should have received a copy of the GNU General Public License          *
00017  *   along with this program; if not, write to the Free Software                *
00018  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA       *
00019  *                                                                              */
00020 
00021 /*
00022  * $Author: amodigli $
00023  * $Date: 2010/09/24 09:32:07 $
00024  * $Revision: 1.14 $
00025  * $Name: uves-5_0_0 $
00026  * $Log: uves_physmod_chop_otab.c,v $
00027  * Revision 1.14  2010/09/24 09:32:07  amodigli
00028  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
00029  *
00030  * Revision 1.12  2008/11/06 14:36:27  amodigli
00031  * fixed mem leaks
00032  *
00033  * Revision 1.11  2008/05/13 08:44:32  amodigli
00034  * added check on guess order table spectral format size
00035  *
00036  * Revision 1.10  2008/05/01 09:44:10  amodigli
00037  * modify table after chop
00038  *
00039  * Revision 1.9  2007/06/06 08:17:33  amodigli
00040  * replace tab with 4 spaces
00041  *
00042  * Revision 1.8  2007/05/16 16:32:55  amodigli
00043  * changed factor from 0.05to 0.075
00044  *
00045  * Revision 1.7  2007/04/24 12:50:29  jmlarsen
00046  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00047  *
00048  * Revision 1.6  2006/11/06 15:19:41  jmlarsen
00049  * Removed unused include directives
00050  *
00051  * Revision 1.5  2006/07/28 14:51:26  amodigli
00052  * fixed some bugs on improper table selection
00053  *
00054  * Revision 1.4  2006/06/05 08:51:55  amodigli
00055  * cleaned some warnings from static checks
00056  *
00057  * Revision 1.3  2006/05/09 15:42:48  amodigli
00058  * safer way to do selection
00059  *
00060  * Revision 1.2  2006/05/08 15:42:16  amodigli
00061  * allow to specify order column label
00062  *
00063  * Revision 1.1  2006/02/03 07:46:30  jmlarsen
00064  * Moved recipe implementations to ./uves directory
00065  *
00066  * Revision 1.5  2006/01/19 08:47:24  jmlarsen
00067  * Inserted missing doxygen end tag
00068  *
00069  * Revision 1.4  2006/01/16 08:01:57  amodigli
00070  *
00071  * Added stability check
00072  *
00073  * Revision 1.3  2006/01/09 14:05:42  amodigli
00074  * Fixed doxigen warnings
00075  *
00076  * Revision 1.2  2006/01/03 16:57:13  amodigli
00077  * Fixed bug
00078  *
00079  * Revision 1.1  2006/01/03 14:47:53  amodigli
00080  *
00081  * Added uves_physmod_chop_otab.h .c to match MIDAS
00082  *
00083  * Revision 1.3  2005/12/19 16:17:55  jmlarsen
00084  * Replaced bool -> int
00085  *
00086  */
00087 
00088 /*----------------------------------------------------------------------------*/
00092 /*----------------------------------------------------------------------------*/
00095 #ifdef HAVE_CONFIG_H
00096 #  include <config.h>
00097 #endif
00098 
00099 /*-----------------------------------------------------------------------------
00100                                 Includes
00101  -----------------------------------------------------------------------------*/
00102 #include <uves_physmod_chop_otab.h>
00103 
00104 #include <uves_utils_wrappers.h>
00105 #include <uves_pfits.h>
00106 #include <uves_error.h>
00107 
00108 /*-----------------------------------------------------------------------------
00109                                 Defines
00110  -----------------------------------------------------------------------------*/
00111 /*-----------------------------------------------------------------------------
00112                             Functions prototypes
00113  ----------------------------------------------------------------------------*/
00114 /*-----------------------------------------------------------------------------
00115                             Static variables
00116  -----------------------------------------------------------------------------*/
00117 
00118 /*-----------------------------------------------------------------------------
00119                             Functions code
00120  -----------------------------------------------------------------------------*/
00121 
00122 /*----------------------------------------------------------------------------*/
00137 /*----------------------------------------------------------------------------*/
00138 
00139 int  uves_physmod_chop_otab(const uves_propertylist * raw_header,
00140                             enum uves_chip  chip,
00141                             cpl_table** ord_tbl,
00142                             const char* col_name,
00143                             int * ord_min,
00144                             int * ord_max)
00145 {
00146 
00147   int nx=0;
00148   int ny=0;
00149 
00150   double xbox[2]={0,0};
00151   double ybox[2]={0,0};
00152   const double fct=0.075;
00153   const double add=50.;
00154   cpl_table* tmp_tbl1=NULL;
00155   cpl_table* tmp_tbl2=NULL;
00156 
00157   /* note those are swapped */
00158   check (ny = uves_pfits_get_nx(raw_header,chip),
00159      "Could not read nx from input header");
00160   check (nx = uves_pfits_get_ny(raw_header,chip),
00161      "Could not read ny from input header");
00162 
00163   xbox[0]=(double)(nx/2-nx*fct);
00164   xbox[1]=(double)(nx/2+nx*fct);
00165   ybox[0]=add;
00166   ybox[1]=(double)(ny-add);
00167 
00168   uves_msg_debug("NX=%d NY=%d",nx,ny);
00169   uves_msg_debug("xbox=%f,%f ybox=%f,%f",xbox[0],xbox[1],ybox[0],ybox[1]);
00170 
00171   check(tmp_tbl1=uves_extract_table_rows(*ord_tbl,"X",CPL_GREATER_THAN,xbox[0]),
00172           "Error selecting X");
00173 
00174   check(tmp_tbl2=uves_extract_table_rows(tmp_tbl1,"X",CPL_LESS_THAN,xbox[1]),
00175           "Error selecting X");
00176   uves_free_table(&tmp_tbl1);
00177 
00178   check_nomsg(*ord_min=(int)cpl_table_get_column_min(tmp_tbl2,col_name));
00179   check_nomsg(*ord_max=(int)cpl_table_get_column_max(tmp_tbl2,col_name));
00180   uves_free_table(&tmp_tbl2);
00181   uves_msg_debug("ord_min=%d ord_max=%d",*ord_min,*ord_max);
00182 
00183   check(tmp_tbl1=uves_extract_table_rows(*ord_tbl,col_name,
00184                      CPL_NOT_GREATER_THAN,*ord_max),
00185     "Error selecting Order");
00186   uves_free_table(ord_tbl);
00187   check(*ord_tbl=uves_extract_table_rows(tmp_tbl1,col_name,
00188                      CPL_NOT_LESS_THAN,*ord_min),
00189     "Error selecting Order");
00190 
00191 
00192   cleanup:
00193   uves_free_table(&tmp_tbl1);
00194   uves_free_table(&tmp_tbl2);
00195 
00196   return 0;
00197 
00198 }

Generated on 9 Mar 2012 for UVES Pipeline Reference Manual by  doxygen 1.6.1