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: 2010/09/24 09:32:07 $
00023  * $Revision: 1.13 $
00024  * $Name: uves-4_9_1 $
00025  * $Log: uves_physmod_qc1pmtbl.c,v $
00026  * Revision 1.13  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.11  2010/06/08 09:45:58  amodigli
00030  * removed XMODREG_X_RES YMODREG_YNEW_RES columns from result of selplot=1 selection
00031  *
00032  * Revision 1.10  2010/06/07 16:49:56  amodigli
00033  * added columns XMODREG_X_RES,YMODREG_YNEW_RES and now the XDIF,YDIF are computed for any of the points that do not satisfy the SELPLOT=1 condition
00034  *
00035  * Revision 1.9  2010/06/02 15:04:10  amodigli
00036  * fixed bug in cross correlating line and model predicted tables
00037  *
00038  * Revision 1.8  2010/06/01 13:28:57  amodigli
00039  * added column units to line table columns
00040  *
00041  * Revision 1.7  2008/09/29 06:55:33  amodigli
00042  * add #include <string.h>
00043  *
00044  * Revision 1.6  2007/06/06 08:17:33  amodigli
00045  * replace tab with 4 spaces
00046  *
00047  * Revision 1.5  2006/11/06 15:19:41  jmlarsen
00048  * Removed unused include directives
00049  *
00050  * Revision 1.4  2006/10/05 11:17:49  jmlarsen
00051  * Removed debugging call of uves_error_dump
00052  *
00053  * Revision 1.3  2006/06/20 10:56:56  amodigli
00054  * cleaned output, added units
00055  *
00056  * Revision 1.2  2006/03/08 08:55:37  amodigli
00057  * fixed garbage in SELPLOT column of line table
00058  *
00059  * Revision 1.1  2006/02/03 07:46:30  jmlarsen
00060  * Moved recipe implementations to ./uves directory
00061  *
00062  * Revision 1.7  2006/01/19 08:47:24  jmlarsen
00063  * Inserted missing doxygen end tag
00064  *
00065  * Revision 1.6  2006/01/16 08:01:57  amodigli
00066  *
00067  * Added stability check
00068  *
00069  * Revision 1.5  2006/01/05 14:29:59  jmlarsen
00070  * Removed newline characters from output strings
00071  *
00072  * Revision 1.4  2006/01/05 09:30:48  amodigli
00073  * Col SELPLOT initialized to NULL
00074  *
00075  * Revision 1.3  2005/12/19 16:17:55  jmlarsen
00076  * Replaced bool -> int
00077  *
00078  */
00079 
00080 /*----------------------------------------------------------------------------*/
00084 /*----------------------------------------------------------------------------*/
00087 #ifdef HAVE_CONFIG_H
00088 #  include <config.h>
00089 #endif
00090 
00091 /*-----------------------------------------------------------------------------
00092                                 Includes
00093  -----------------------------------------------------------------------------*/
00094 #include <uves_physmod_qc1pmtbl.h>
00095 
00096 #include <uves_error.h>
00097 #include <uves_msg.h>
00098 #include <string.h>
00099 /*-----------------------------------------------------------------------------
00100                                 Defines
00101  -----------------------------------------------------------------------------*/
00102 #define FILESIZE 200
00103 /*-----------------------------------------------------------------------------
00104                             Functions prototypes
00105  ----------------------------------------------------------------------------*/
00106 /*-----------------------------------------------------------------------------
00107                             Static variables
00108  -----------------------------------------------------------------------------*/
00109 
00110 /*-----------------------------------------------------------------------------
00111                             Functions code
00112  -----------------------------------------------------------------------------*/
00113 
00114 /*----------------------------------------------------------------------------*/
00123 /*----------------------------------------------------------------------------*/
00124 int uves_physmod_qc1pmtbl(cpl_table** rline_tbl,cpl_table** lin_tbl)
00125 {
00126 
00127   int nCol   = 0;            /* No of columns in tbl */
00128   int rlineRowNumber=0;      /* number of rows in rline table */
00129   int lineRowNo=0;           /* number of Rows in line table */
00130   int null=0;                /* number of null values in keyword */
00131   int i=0;                   /* loop variable */
00132   int l=0;                   /* loop variable */
00133 
00134 
00135   int    selIdx=0;           /* actual value */
00136   
00137   char   lineTbl[FILESIZE];  /* buffer for data values */
00138   char   rLineTbl[FILESIZE]; /* buffer for data values */
00139   char   aHeading[FILESIZE]; /* column reference */
00140   char   tmps[FILESIZE];     /* for messout */
00141    
00142   
00143   
00144   double  xDif=0.0;          /* actual value */
00145   double  yDif=0.0;          /* actual value */
00146   double  xModReg=0.0;       /* actual value */
00147   double  yModReg=0.0;       /* actual value */
00148   double  xPred=0.0;         /* actual value */
00149   double  yPred=0.0;         /* actual value */
00150   double  x=0.0;             /* actual value */
00151   double  yNew=0.0;          /* actual value */
00152   double  diffX=0.0;         /* difference between x and y */
00153   double  diffY=0.0;         /* difference between x and y */
00154                              /* (rounding error threshold) */
00155   double waveReg=0.0;
00156   double wavec=0.0;
00157   int match=1;
00158   int order=0;
00159   int orderReg=0;
00160 
00161 
00162 /* initializes chars */
00163   memset(lineTbl,  0, FILESIZE);    
00164   memset(rLineTbl, 0, FILESIZE);    
00165   memset(aHeading, 0, FILESIZE);    
00166   memset(tmps,     0, FILESIZE);        
00167 
00168 
00169   uves_msg_debug("start %s",__func__);
00170 
00171   check(nCol=cpl_table_get_ncol(*rline_tbl),"Error getting ncol");
00172   rlineRowNumber=cpl_table_get_nrow(*rline_tbl);
00173   uves_msg_debug("Opened table %s nCol=%d nrow=%d",
00174                      "rline.tbl" ,nCol,rlineRowNumber);
00175 
00176   nCol=cpl_table_get_ncol(*lin_tbl);
00177   lineRowNo=cpl_table_get_nrow(*lin_tbl);
00178   
00179   uves_msg_debug("Opened table %s nCol=%d nrow=%d",
00180                       lineTbl ,nCol,lineRowNo); 
00181 
00182  
00183   if(cpl_table_has_column(*lin_tbl,"XDIF")){
00184     cpl_table_erase_column(*lin_tbl,"XDIF"); 
00185     uves_msg_debug("removed column XDIF");
00186   }
00187 
00188   if(cpl_table_has_column(*lin_tbl,"YDIF")){
00189     cpl_table_erase_column(*lin_tbl,"YDIF"); 
00190     uves_msg_debug("removed column YDIF");
00191   }
00192 
00193   if(cpl_table_has_column(*lin_tbl,"SELPLOT")){
00194     cpl_table_erase_column(*lin_tbl,"SELPLOT"); 
00195     uves_msg_debug("removed column SELPLOT");
00196   }
00197 
00198   if(cpl_table_has_column(*lin_tbl,"XPRED")){
00199     cpl_table_erase_column(*lin_tbl,"XPRED"); 
00200     uves_msg_debug("removed column XPRED");
00201   }
00202 
00203   if(cpl_table_has_column(*lin_tbl,"YPRED")){
00204     cpl_table_erase_column(*lin_tbl,"YPRED"); 
00205     uves_msg_debug("removed column YPRED");
00206   }
00207 
00208   /* Then add those columns */
00209 
00210   cpl_table_new_column(*lin_tbl,"XPRED",CPL_TYPE_DOUBLE);
00211   cpl_table_set_column_unit(*lin_tbl,"XPRED","pix");
00212 
00213   cpl_table_new_column(*lin_tbl,"YPRED",CPL_TYPE_DOUBLE);
00214   cpl_table_set_column_unit(*lin_tbl,"YPRED","pix");
00215 
00216   cpl_table_new_column(*lin_tbl,"XDIF",CPL_TYPE_DOUBLE);
00217   cpl_table_set_column_unit(*lin_tbl,"XDIF","pix");
00218 
00219   cpl_table_new_column(*lin_tbl,"YDIF",CPL_TYPE_DOUBLE);
00220   cpl_table_set_column_unit(*lin_tbl,"YDIF","pix");
00221 
00222   cpl_table_new_column(*lin_tbl,"SELPLOT",CPL_TYPE_INT);
00223   cpl_table_set_column_unit(*lin_tbl,"YDIF","pix");
00224 
00225 
00226 /*
00227  ***************************************************************************
00228  * Now does the actual ordering of the elements writing in the right place *
00229  ***************************************************************************
00230  */
00231  
00232   cpl_table_set_column_invalid(*lin_tbl,"SELPLOT",0,
00233                                cpl_table_get_nrow(*lin_tbl));
00234 
00235 
00236 /*
00237   uves_msg("rlineRowNumber=%d",rlineRowNumber);
00238   cpl_table_dump(*rline_tbl,1,2,stdout);
00239   cpl_table_dump(*lin_tbl,1,2,stdout);
00240 */
00241   for (l=0; l< rlineRowNumber; l++) {
00242 
00243  
00244     xModReg=cpl_table_get_double(*rline_tbl,"XMODREG",l,&null);
00245     yModReg=cpl_table_get_double(*rline_tbl,"YMODREG",l,&null);
00246     xDif=cpl_table_get_double(*rline_tbl,"XDIF",l,&null);
00247     yDif=cpl_table_get_double(*rline_tbl,"YDIF",l,&null);
00248     xPred=cpl_table_get_double(*rline_tbl,"XMOD",l,&null);
00249     yPred=cpl_table_get_double(*rline_tbl,"YMOD",l,&null);
00250     waveReg=cpl_table_get_double(*rline_tbl,"WAVE",l,&null);
00251     check_nomsg(orderReg=cpl_table_get_int(*rline_tbl,"ORDER",l,&null));
00252     //uves_msg("i=%d xDif=%f yDif=%f lineRowNo=%d",i,xDif,yDif,lineRowNo);
00253 
00254     selIdx = 1;
00255     match=0;
00256     for (i=0; i< lineRowNo; i++) {
00257        //uves_msg("i=%d",i);
00258         x=cpl_table_get_double(*lin_tbl,"X",i,&null);
00259         yNew=cpl_table_get_double(*lin_tbl,"YNEW",i,&null);
00260         wavec=cpl_table_get_double(*lin_tbl,"WAVEC",i,&null);
00261         check_nomsg(order=cpl_table_get_int(*lin_tbl,"Order",i,&null));
00262         diffX=fabs(x-xModReg);
00263         diffY=fabs(yNew-yModReg);
00264 /*
00265         uves_msg("waveReg=%f wavec=%f diff=%f",
00266                  10.*waveReg, wavec, fabs(waveReg - wavec));
00267 */  
00268         if ( (fabs(10.*waveReg - wavec)  <= 0.01) && 
00269               match == 0 && 
00270              (fabs(orderReg-order)<0.1) ) {
00271            //uves_msg("match wave l=%d i=%d order=%d",l,i,order);
00272           cpl_table_set_double(*lin_tbl,"XPRED",i,xPred);
00273           cpl_table_set_double(*lin_tbl,"YPRED",i,yPred);
00274           cpl_table_set_double(*lin_tbl,"XDIF",i,xDif);
00275           cpl_table_set_double(*lin_tbl,"YDIF",i,yDif);
00276         }    
00277         if ((diffX <= 0.001) && (diffY <= 0.001)) {
00278            match=1;
00279           cpl_table_set_double(*lin_tbl,"XPRED",i,xPred);
00280           cpl_table_set_double(*lin_tbl,"YPRED",i,yPred);
00281           cpl_table_set_double(*lin_tbl,"XDIF",i,xDif);
00282           cpl_table_set_double(*lin_tbl,"YDIF",i,yDif);
00283 
00284           cpl_table_set_int(*lin_tbl,"SELPLOT",i,selIdx);
00285 
00286            break;   
00287         }
00288     }
00289   }
00290 
00291 
00292   /* second check to add only those lines that are not matching selplot=1
00293      criterium */
00294 
00295   for (l=0; l< rlineRowNumber; l++) { 
00296     xModReg=cpl_table_get_double(*rline_tbl,"XMODREG",l,&null);
00297     yModReg=cpl_table_get_double(*rline_tbl,"YMODREG",l,&null);
00298     xDif=cpl_table_get_double(*rline_tbl,"XDIF",l,&null);
00299     yDif=cpl_table_get_double(*rline_tbl,"YDIF",l,&null);
00300     xPred=cpl_table_get_double(*rline_tbl,"XMOD",l,&null);
00301     yPred=cpl_table_get_double(*rline_tbl,"YMOD",l,&null);
00302     waveReg=cpl_table_get_double(*rline_tbl,"WAVE",l,&null);
00303     check_nomsg(orderReg=cpl_table_get_int(*rline_tbl,"ORDER",l,&null));
00304     //uves_msg("i=%d xDif=%f yDif=%f lineRowNo=%d",i,xDif,yDif,lineRowNo);
00305     
00306     for (i=0; i< lineRowNo; i++) {
00307        //uves_msg("i=%d",i);
00308         x=cpl_table_get_double(*lin_tbl,"X",i,&null);
00309         yNew=cpl_table_get_double(*lin_tbl,"YNEW",i,&null);
00310         wavec=cpl_table_get_double(*lin_tbl,"WAVEC",i,&null);
00311         check_nomsg(order=cpl_table_get_int(*lin_tbl,"Order",i,&null));
00312         check_nomsg(selIdx=cpl_table_get_int(*lin_tbl,"SELPLOT",i,&null));
00313         diffX=fabs(x-xModReg);
00314         diffY=fabs(yNew-yModReg);
00315 
00316         if ( selIdx != 1 && 
00317              (fabs(orderReg-order)<0.1) ) {
00318           cpl_table_set_double(*lin_tbl,"XPRED",i,xPred);
00319           cpl_table_set_double(*lin_tbl,"YPRED",i,yPred);
00320           cpl_table_set_double(*lin_tbl,"XDIF",i,xDif);
00321           cpl_table_set_double(*lin_tbl,"YDIF",i,yDif);
00322            break;   
00323         }    
00324     }
00325   }
00326 
00327 
00328 
00329 
00330   /*
00331   cpl_table_dump(*lin_tbl,0,20,stdout);
00332   */
00333   uves_msg_debug("end %s",__func__);
00334   cpl_table_fill_invalid_int(*lin_tbl,"SELPLOT",-1);
00335 
00336   cleanup:
00337   return 0;
00338 
00339 }

Generated on 8 Mar 2011 for UVES Pipeline Reference Manual by  doxygen 1.6.1