uves_physmod_qc1pmtbl.c

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.6 $
00024  * $Name: uves-3_3_1 $
00025  * $Log: uves_physmod_qc1pmtbl.c,v $
00026  * Revision 1.6  2007/06/06 08:17:33  amodigli
00027  * replace tab with 4 spaces
00028  *
00029  * Revision 1.5  2006/11/06 15:19:41  jmlarsen
00030  * Removed unused include directives
00031  *
00032  * Revision 1.4  2006/10/05 11:17:49  jmlarsen
00033  * Removed debugging call of uves_error_dump
00034  *
00035  * Revision 1.3  2006/06/20 10:56:56  amodigli
00036  * cleaned output, added units
00037  *
00038  * Revision 1.2  2006/03/08 08:55:37  amodigli
00039  * fixed garbage in SELPLOT column of line table
00040  *
00041  * Revision 1.1  2006/02/03 07:46:30  jmlarsen
00042  * Moved recipe implementations to ./uves directory
00043  *
00044  * Revision 1.7  2006/01/19 08:47:24  jmlarsen
00045  * Inserted missing doxygen end tag
00046  *
00047  * Revision 1.6  2006/01/16 08:01:57  amodigli
00048  *
00049  * Added stability check
00050  *
00051  * Revision 1.5  2006/01/05 14:29:59  jmlarsen
00052  * Removed newline characters from output strings
00053  *
00054  * Revision 1.4  2006/01/05 09:30:48  amodigli
00055  * Col SELPLOT initialized to NULL
00056  *
00057  * Revision 1.3  2005/12/19 16:17:55  jmlarsen
00058  * Replaced bool -> int
00059  *
00060  */
00061 
00062 /*----------------------------------------------------------------------------*/
00066 /*----------------------------------------------------------------------------*/
00069 #ifdef HAVE_CONFIG_H
00070 #  include <config.h>
00071 #endif
00072 
00073 /*-----------------------------------------------------------------------------
00074                                 Includes
00075  -----------------------------------------------------------------------------*/
00076 #include <uves_physmod_qc1pmtbl.h>
00077 
00078 #include <uves_error.h>
00079 #include <uves_msg.h>
00080 
00081 /*-----------------------------------------------------------------------------
00082                                 Defines
00083  -----------------------------------------------------------------------------*/
00084 #define FILESIZE 200
00085 /*-----------------------------------------------------------------------------
00086                             Functions prototypes
00087  ----------------------------------------------------------------------------*/
00088 /*-----------------------------------------------------------------------------
00089                             Static variables
00090  -----------------------------------------------------------------------------*/
00091 
00092 /*-----------------------------------------------------------------------------
00093                             Functions code
00094  -----------------------------------------------------------------------------*/
00095 
00096 /*----------------------------------------------------------------------------*/
00105 /*----------------------------------------------------------------------------*/
00106 int uves_physmod_qc1pmtbl(cpl_table** rline_tbl,cpl_table** lin_tbl)
00107 {
00108 
00109   int nCol   = 0;            /* No of columns in tbl */
00110   int rlineRowNumber=0;      /* number of rows in rline table */
00111   int lineRowNo=0;           /* number of Rows in line table */
00112   int null=0;                /* number of null values in keyword */
00113   int i=0;                   /* loop variable */
00114   int l=0;                   /* loop variable */
00115 
00116 
00117   int    selIdx=0;           /* actual value */
00118   
00119   char   lineTbl[FILESIZE];  /* buffer for data values */
00120   char   rLineTbl[FILESIZE]; /* buffer for data values */
00121   char   aHeading[FILESIZE]; /* column reference */
00122   char   tmps[FILESIZE];     /* for messout */
00123    
00124   
00125   
00126   double  xDif=0.0;          /* actual value */
00127   double  yDif=0.0;          /* actual value */
00128   double  xModReg=0.0;       /* actual value */
00129   double  yModReg=0.0;       /* actual value */
00130   double  xPred=0.0;         /* actual value */
00131   double  yPred=0.0;         /* actual value */
00132   double  x=0.0;             /* actual value */
00133   double  yNew=0.0;          /* actual value */
00134   double  diffX=0.0;         /* difference between x and y */
00135   double  diffY=0.0;         /* difference between x and y */
00136                              /* (rounding error threshold) */
00137   
00138 /* initializes chars */
00139   memset(lineTbl,  0, FILESIZE);    
00140   memset(rLineTbl, 0, FILESIZE);    
00141   memset(aHeading, 0, FILESIZE);    
00142   memset(tmps,     0, FILESIZE);        
00143 
00144 
00145   uves_msg_debug("start %s",__func__);
00146 
00147   check(nCol=cpl_table_get_ncol(*rline_tbl),"Error getting ncol");
00148   rlineRowNumber=cpl_table_get_nrow(*rline_tbl);
00149   uves_msg_debug("Opened table %s nCol=%d nrow=%d",
00150                      "rline.tbl" ,nCol,rlineRowNumber);
00151 
00152   nCol=cpl_table_get_ncol(*lin_tbl);
00153   lineRowNo=cpl_table_get_nrow(*lin_tbl);
00154   
00155   uves_msg_debug("Opened table %s nCol=%d nrow=%d",
00156                       lineTbl ,nCol,lineRowNo); 
00157 
00158 
00159   if(cpl_table_has_column(*lin_tbl,"XDIF")){
00160     cpl_table_erase_column(*lin_tbl,"XDIF"); 
00161     uves_msg_debug("removed column XDIF");
00162   }
00163 
00164   if(cpl_table_has_column(*lin_tbl,"YDIF")){
00165     cpl_table_erase_column(*lin_tbl,"YDIF"); 
00166     uves_msg_debug("removed column YDIF");
00167   }
00168 
00169   if(cpl_table_has_column(*lin_tbl,"SELPLOT")){
00170     cpl_table_erase_column(*lin_tbl,"SELPLOT"); 
00171     uves_msg_debug("removed column SELPLOT");
00172   }
00173 
00174 
00175   if(cpl_table_has_column(*lin_tbl,"XPRED")){
00176     cpl_table_erase_column(*lin_tbl,"XPRED"); 
00177     uves_msg_debug("removed column XPRED");
00178   }
00179 
00180   if(cpl_table_has_column(*lin_tbl,"YPRED")){
00181     cpl_table_erase_column(*lin_tbl,"YPRED"); 
00182     uves_msg_debug("removed column YPRED");
00183   }
00184 
00185   /* Then add those columns */
00186 
00187   cpl_table_new_column(*lin_tbl,"XPRED",CPL_TYPE_DOUBLE);
00188   cpl_table_new_column(*lin_tbl,"YPRED",CPL_TYPE_DOUBLE);
00189   cpl_table_new_column(*lin_tbl,"XDIF",CPL_TYPE_DOUBLE);
00190   cpl_table_new_column(*lin_tbl,"YDIF",CPL_TYPE_DOUBLE);
00191   cpl_table_new_column(*lin_tbl,"SELPLOT",CPL_TYPE_INT);
00192 
00193 
00194 /*
00195  ***************************************************************************
00196  * Now does the actual ordering of the elements writing in the right place *
00197  ***************************************************************************
00198  */
00199  
00200   cpl_table_set_column_invalid(*lin_tbl,"SELPLOT",0,
00201                                cpl_table_get_nrow(*lin_tbl));
00202   for (l=0; l< rlineRowNumber; l++) {
00203 
00204 
00205     xModReg=cpl_table_get_double(*rline_tbl,"XMODREG",l,&null);
00206     yModReg=cpl_table_get_double(*rline_tbl,"YMODREG",l,&null);
00207     xDif=cpl_table_get_double(*rline_tbl,"XDIF",l,&null);
00208     yDif=cpl_table_get_double(*rline_tbl,"YDIF",l,&null);
00209     xPred=cpl_table_get_double(*rline_tbl,"XMOD",l,&null);
00210     yPred=cpl_table_get_double(*rline_tbl,"YMOD",l,&null);
00211 
00212     selIdx = 1;
00213     for (i=0; i< lineRowNo; i++) {
00214      
00215         x=cpl_table_get_double(*lin_tbl,"X",i,&null);
00216         yNew=cpl_table_get_double(*lin_tbl,"YNEW",i,&null);
00217 
00218         diffX=fabs(x-xModReg);
00219         diffY=fabs(yNew-yModReg);
00220     
00221     
00222         if ((diffX <= 0.001) && (diffY <= 0.001)) {
00223       /*
00224         uves_msg("x=%f,xModReg=%f,diffX=%f,yNew=%f,yModReg=%f,diffY=%f",
00225            x,xModReg,diffX,yNew,yModReg,diffY);
00226       */
00227 
00228           cpl_table_set_double(*lin_tbl,"XPRED",i,xPred);
00229           cpl_table_set_double(*lin_tbl,"YPRED",i,yPred);
00230           cpl_table_set_double(*lin_tbl,"XDIF",i,xDif);
00231           cpl_table_set_double(*lin_tbl,"YDIF",i,yDif);
00232           cpl_table_set_int(*lin_tbl,"SELPLOT",i,selIdx);
00233 
00234            break;   
00235         }
00236     }
00237   }
00238   /*
00239   cpl_table_dump(*lin_tbl,0,20,stdout);
00240   */
00241   uves_msg_debug("end %s",__func__);
00242   cpl_table_fill_invalid_int(*lin_tbl,"SELPLOT",-1);
00243 
00244   cleanup:
00245   return 0;
00246 
00247 }

Generated on Tue Jun 19 14:39:16 2007 for UVES Pipeline Reference Manual by  doxygen 1.4.6