uves_physmod_create_table.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.18 $
00024  * $Name: uves-3_3_1 $
00025  * $Log: uves_physmod_create_table.c,v $
00026  * Revision 1.18  2007/06/06 08:17:33  amodigli
00027  * replace tab with 4 spaces
00028  *
00029  * Revision 1.17  2007/04/24 12:50:29  jmlarsen
00030  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00031  *
00032  * Revision 1.16  2007/01/15 14:26:11  jmlarsen
00033  * Read plate id only in FLAMES mode
00034  *
00035  * Revision 1.15  2007/01/10 14:16:46  jmlarsen
00036  * Unified two get_plate_id functions
00037  *
00038  * Revision 1.14  2007/01/08 16:59:28  amodigli
00039  * changes to make flames-uves iterations to recover physical model
00040  *
00041  * Revision 1.13  2006/12/27 13:54:44  amodigli
00042  * added flames_get_trans for FIBER mode
00043  *
00044  * Revision 1.12  2006/11/06 15:19:41  jmlarsen
00045  * Removed unused include directives
00046  *
00047  * Revision 1.11  2006/10/24 14:12:16  jmlarsen
00048  * Parametrized recipe id to support FLAMES recipe
00049  *
00050  * Revision 1.10  2006/10/05 11:16:41  jmlarsen
00051  * Declared parameter list const
00052  *
00053  * Revision 1.9  2006/08/23 15:41:06  amodigli
00054  * removed warning from checks on line length
00055  *
00056  * Revision 1.8  2006/07/14 12:53:41  jmlarsen
00057  * Change message
00058  *
00059  * Revision 1.7  2006/06/29 07:57:22  amodigli
00060  * fixed warning messages from make html
00061  *
00062  * Revision 1.6  2006/06/28 13:28:29  amodigli
00063  * improved output
00064  *
00065  * Revision 1.5  2006/06/20 10:56:56  amodigli
00066  * cleaned output, added units
00067  *
00068  * Revision 1.4  2006/06/14 16:07:54  amodigli
00069  * fixed bug with selection of new spectral format offsets
00070  *
00071  * Revision 1.3  2006/06/08 11:01:50  amodigli
00072  * fixed some warnings
00073  *
00074  * Revision 1.2  2006/02/15 13:19:15  jmlarsen
00075  * Reduced source code max. line length
00076  *
00077  * Revision 1.1  2006/02/03 07:46:30  jmlarsen
00078  * Moved recipe implementations to ./uves directory
00079  *
00080  * Revision 1.13  2006/01/19 08:47:24  jmlarsen
00081  * Inserted missing doxygen end tag
00082  *
00083  * Revision 1.12  2006/01/16 08:01:57  amodigli
00084  *
00085  * Added stability check
00086  *
00087  * Revision 1.11  2006/01/09 14:05:42  amodigli
00088  * Fixed doxigen warnings
00089  *
00090  * Revision 1.10  2006/01/05 14:29:59  jmlarsen
00091  * Removed newline characters from output strings
00092  *
00093  * Revision 1.9  2006/01/05 09:30:07  amodigli
00094  * uves_msg-->uves_msg_debug
00095  *
00096  * Revision 1.8  2006/01/04 15:13:01  amodigli
00097  * Fixed typo
00098  *
00099  * Revision 1.6  2005/12/20 08:11:44  jmlarsen
00100  * Added CVS  entry
00101  *
00102  */
00103 
00104 /*---------------------------------------------------------------------------*/
00108 /*---------------------------------------------------------------------------*/
00111 #ifdef HAVE_CONFIG_H
00112 #  include <config.h>
00113 #endif
00114 /*----------------------------------------------------------------------------
00115                                 Includes
00116  ----------------------------------------------------------------------------*/
00117 #include <uves_physmod_create_table.h>
00118 
00119 #include <uves_physmod_utils.h>
00120 #include <uves_utils_wrappers.h>
00121 #include <uves_pfits.h>
00122 #include <uves_msg.h>
00123 #include <uves_error.h>
00124 
00125 /*-----------------------------------------------------------------------------
00126                                 Defines
00127  ----------------------------------------------------------------------------*/
00128 /*-----------------------------------------------------------------------------
00129                             Functions prototypes
00130  ----------------------------------------------------------------------------*/
00131 
00132 static int
00133 flames_get_trans(const int plt_no,
00134                  enum uves_chip chip, 
00135                  const double wlen, 
00136                  double * TX,
00137                  double * TY);
00138 
00139 /*-----------------------------------------------------------------------------
00140                             Static variables
00141  ----------------------------------------------------------------------------*/
00142 
00143 /*-----------------------------------------------------------------------------
00144                             Functions code
00145  ----------------------------------------------------------------------------*/
00146 
00147 /*---------------------------------------------------------------------------*/
00170 /*---------------------------------------------------------------------------*/
00171 
00172 
00173 
00174 
00175 int 
00176 uves_physmod_create_table(const uves_propertylist *raw_header, 
00177                           enum uves_chip chip, 
00178               const char *recipe_id,
00179                           const cpl_parameterlist* parameters, 
00180                           cpl_table* line_refer,
00181                           const double physmod_shift_x,
00182                           const double physmod_shift_y,
00183                           cpl_table** mod_tbl,
00184                           cpl_table** fsr_tbl)
00185 
00186 {
00187 
00188   /* General */
00189   int      MBOX_X=0;
00190   int      MBOX_Y=0;
00191   double   TRANS_X=0;
00192   double   TRANS_Y=0;
00193 
00194   double      ECH_ANG_OFF=0;
00195   double      CD_ANG_OFF=0;
00196   double      CCD_ANG_OFF=0;
00197 
00198 
00199 
00200   int      CMP_REG_SW=0;
00201 
00202   double binx=0;
00203   double biny=0;
00204 
00205   double pressure=0;
00206   double temp_cam=0;
00207   double slit_width=0;
00208   double slit_length=0;
00209   double humidity=0;
00210 
00211 
00212   double wcent=0;
00213   double xtrans=0;
00214   double ytrans=0;
00215   double echoff=0;
00216   double CDoff=0;
00217   double ccdrotoff=0;
00218   double ccd_rot[2];
00219   double offset_x[6];
00220   double offset_y[6];
00221 
00222   const char*   cd_id;
00223   int     CDID=0;
00224   int status=0;
00225 
00226 
00227   int aRowNumber=0;
00228   int xpix=0;
00229   int ypix=0;
00230   int i=0;
00231   int mm=0;
00232   double xmod=0;
00233   double ymod=0;
00234   double blaze=0;
00235   double binsize=0;
00236   double pixscale=0;
00237   double pixscalCD=0;
00238   double linelenpx=0;
00239   double linewidth=0;
00240   double linewidpx=0;
00241   double resol=0;
00242   double xreg=0;
00243   double yreg=0;
00244   double fsr_min=0;
00245   double fsr_max=0;
00246   double xfsr_min=0;
00247   double xfsr_max=0;
00248   double yfsr_min=0;
00249   double yfsr_max=0;
00250   int m_min=0;
00251   int m_max=0;
00252   double lmin=0;
00253   double lmax=0;
00254   double dxpix=0;
00255   double dypix=0;
00256   double dblwav=0;
00257   int imod=0;
00258   double dl=0;
00259   int mmin=0;
00260   int mmax=0;
00261   int ncol=0;
00262   int order=0;
00263   double xr=0;
00264   double yr=0;
00265   double lcent=0;
00266 
00267   double mbox_x=0;
00268   double mbox_y=0;
00269 
00270   /* variables which were globals in physmodel */
00271   double uves_beta_ech=0;
00272   double uves_beta_cd=0 ;
00273   double uves_physmod_rcd=0;
00274   double uves_physmod_rech=0;
00275   double uves_physmod_x_off=0;
00276   double uves_physmod_y_off=0;
00277   double x=0;
00278   double y=0;
00279   double fc=0;
00280   double l=0;
00281   int m=0;
00282   int plate_no=0;
00283 
00284  
00285  
00286   
00287   enum uves_arm_ident {UVES_ARM_UNDEF,UVES_ARM_BLUE,UVES_ARM_RED};
00288   enum uves_arm_ident uves_arm_ident = UVES_ARM_UNDEF;
00289   int upper;
00290 
00291   const char* ccd_id="";
00292   const char* dpr_tech="";
00293   /* initialize the configuration */
00294 
00295 
00296     /* Read recipe parameters */
00297   {
00298     check( uves_get_parameter(parameters, NULL, recipe_id, 
00299            "mbox_x", CPL_TYPE_INT, &MBOX_X )  , 
00300        "Could not read parameter");
00301 
00302     check( uves_get_parameter(parameters, NULL, recipe_id, 
00303            "mbox_y", CPL_TYPE_INT, &MBOX_Y )  , 
00304        "Could not read parameter");
00305 
00306     check( uves_get_parameter(parameters, NULL, recipe_id, 
00307            "trans_x", CPL_TYPE_DOUBLE, &TRANS_X )  , 
00308        "Could not read parameter");
00309 
00310     check( uves_get_parameter(parameters, NULL, recipe_id, 
00311            "trans_y", CPL_TYPE_DOUBLE, &TRANS_Y )  ,
00312        "Could not read parameter");
00313     xtrans=TRANS_X;
00314     ytrans=TRANS_Y;
00315 
00316     /*
00317 AMo 02/04/2004
00318 We noticed that the physical model has in some way shifted on MIT, thus we apply corrections
00319     */
00320 
00321 if ((xtrans == 0.) && (ytrans == 0.)) {
00322   /*
00323    If the user has not set its own defaults which we assume as the right ones
00324    In case of MIT chip we apply a shift
00325   */
00326      if (chip == UVES_CHIP_REDU) {
00327        ytrans = 6.7;
00328      }
00329 }
00330 
00331  uves_msg_debug("xtrans=%f ytrans=%f",xtrans,ytrans);
00332     check( uves_get_parameter(parameters, NULL, recipe_id, 
00333            "ech_angle_off", CPL_TYPE_DOUBLE, &ECH_ANG_OFF )  , 
00334        "Could not read parameter");
00335 
00336     check( uves_get_parameter(parameters, NULL, recipe_id, 
00337            "cd_angle_off", CPL_TYPE_DOUBLE, &CD_ANG_OFF )  , 
00338        "Could not read parameter");
00339 
00340     check( uves_get_parameter(parameters, NULL, recipe_id, 
00341            "ccd_rot_angle_off", CPL_TYPE_DOUBLE, &CCD_ANG_OFF )  , 
00342        "Could not read parameter");
00343 
00344     check( uves_get_parameter(parameters, NULL, recipe_id, 
00345           "compute_regression_sw", CPL_TYPE_BOOL, &CMP_REG_SW )  , 
00346           "Could not read parameter");
00347 
00348 
00349 
00350     /* check parameters */
00351   }
00352     
00353 
00354 
00355   /* get instrument configuration setting keywords */
00356   check (ccd_id = uves_pfits_get_chipid(raw_header,chip), 
00357      "Could not read CCD ID from input header");
00358   check (dpr_tech = uves_pfits_get_dpr_tech(raw_header), 
00359      "Could not read DPR TECH from input header");
00360   uves_msg("DPR TECH=%s<",dpr_tech);
00361   if(strstr(dpr_tech,"MOS")!=NULL) {
00362       check_nomsg( plate_no = uves_flames_pfits_get_plateid(raw_header) );
00363       uves_msg("PLATE NO=%d",plate_no);
00364   }
00365 
00366   if(strcmp(ccd_id,"CCD-44b") == 0) {
00367     uves_msg("New Spectral Format");
00368     offset_x[0]=1355.0;
00369     offset_x[1]=1350.0;
00370     offset_x[2]=1852.0;
00371     offset_x[3]=1835.0;
00372     offset_x[4]=1852.0;
00373     offset_x[5]=1834.0;
00374 
00375     offset_y[0]=1030.0;
00376     offset_y[1]=1023.0;
00377     offset_y[2]=2098.0;
00378     offset_y[3]=2104.0;
00379     offset_y[4]=-52.0;
00380     offset_y[5]=-49.0;
00381     ccd_rot[0]=0.3;
00382     ccd_rot[1]=-0.10;
00383 
00384   } else {
00385     uves_msg("Old Spectral Format");
00386 
00387     offset_x[0]=1391.0;
00388     offset_x[1]=1385.0;
00389     offset_x[2]=1852.0;
00390     offset_x[3]=1835.0;
00391     offset_x[4]=1852.0;
00392     offset_x[5]=1834.0;
00393 
00394     offset_y[0]=1030.0;
00395     offset_y[1]=1025.0;
00396     offset_y[2]=2098.0;
00397     offset_y[3]=2104.0;
00398     offset_y[4]=-52.0;
00399     offset_y[5]=-49.0;
00400 
00401     ccd_rot[0]=0.3;
00402     ccd_rot[1]=-0.55;
00403   }
00404 
00405 
00406   check (biny = uves_pfits_get_binx(raw_header),
00407      "Could not read x binning factor from input header");
00408 
00409   check (binx = uves_pfits_get_biny(raw_header), 
00410      "Could not read x binning factor from input header");
00411 
00412   check (pressure = uves_pfits_get_pressure(raw_header), 
00413      "Could not read pressure from input header");
00414 
00415   /*
00416     check (humidity = uves_pfits_get_humidity(raw_header), 
00417            "Could not read humidity from input header");
00418   */
00419   humidity=3.;
00420 
00421 
00422 /* New code */
00423   check (slit_width = uves_pfits_get_slitwidth(raw_header, chip), 
00424      "Could not read slit width input header");
00425   
00426   check (slit_length = uves_pfits_get_slitlength(raw_header, chip), 
00427      "Could not read slit length input header");
00428   
00429   check (wcent = uves_pfits_get_gratwlen(raw_header, chip), 
00430      "Could not read central wavelength setting from input header");
00431   
00432   check (cd_id =  uves_pfits_get_gratid(raw_header, chip), 
00433      "Could not read central CD ID setting from input header");
00434 
00435   check (temp_cam = uves_pfits_get_tempcam(raw_header,chip), 
00436      "Could not read camera's temperature from input header");
00437 
00438   if (chip == UVES_CHIP_BLUE)
00439       {
00440       uves_arm_id='b';
00441       uves_arm_ident=UVES_ARM_BLUE;
00442 
00443       }
00444   else
00445       {
00446       uves_arm_id='r';
00447       uves_arm_ident=UVES_ARM_RED;
00448       }
00449   upper = (chip == UVES_CHIP_REDU);
00450 
00451 
00452 
00453 
00454          if(strstr(cd_id,"CD#1") != NULL) {
00455        CDID=1;
00456   } else if(strstr(cd_id,"CD#2") != NULL) {
00457        CDID=2;
00458   } else if(strstr(cd_id,"CD#3") != NULL) {
00459        CDID=3;
00460   } else if(strstr(cd_id,"CD#4") != NULL) {
00461        CDID=4;
00462   } else {
00463            CDID=0;
00464   }
00465     
00466      mbox_x=MBOX_X/binx;
00467      mbox_y=MBOX_Y/biny;
00468      uves_msg("UVES configuration:");
00469          uves_msg("Optical path: %s (%s)",
00470                             UVES_ARM(chip),UVES_ARMID(chip));
00471        
00472          uves_msg("Detector: %s Binning: %1.1f, %1.1f pix/bin",
00473                       UVES_DETECTOR(chip),binx,biny);
00474          uves_msg("Cross disperser ID, number: %s %d",cd_id,CDID);
00475          uves_msg("Central wavelength: %4.1f nm",wcent);
00476          uves_msg("Slit width: %3.1f (arcsecs)",slit_width);
00477          uves_msg("Slit length: %3.1f (arcsecs)",slit_length);
00478      uves_msg("Temperature: %3.1f C",temp_cam);
00479      uves_msg("Air pressure: %4.1f mmHg/cm^2",pressure);
00480      uves_msg("Humidity: %2.1f %%",humidity);
00481 
00482   uves_msg_debug("chip    =%s", uves_chip_tostring_upper(chip));
00483 
00484 
00485   /* read input frame (line table) */
00486   ncol=cpl_table_get_ncol(line_refer);
00487  
00488   aRowNumber = cpl_table_get_nrow(line_refer);
00489   
00490   uves_msg_debug("Opened table %s ncol=%d nrow=%d","line_ref_table" ,ncol,aRowNumber);
00491 
00492   uves_air_config(pressure/1.33322, temp_cam, humidity);
00493   uves_msg("Air Index = %g",uves_air_index(wcent));
00494   if(strstr(dpr_tech,"MOS")!=NULL) {
00495     uves_msg("uves chip=%d REDL%d REDU%d",chip,UVES_CHIP_REDL,UVES_CHIP_REDU);
00496      flames_get_trans(plate_no,chip,wcent,&TRANS_X,&TRANS_Y);
00497      xtrans=TRANS_X+physmod_shift_x;
00498      ytrans=TRANS_Y+physmod_shift_y;
00499   }
00500   uves_msg("Shift in x = %6.3f pix, shift in y = %6.3f pix",TRANS_X,TRANS_Y);
00501   uves_msg("Offset angle of echelle, CD, CCD rotation (deg): "
00502        "%4.3f, %4.3f, %4.3f",ECH_ANG_OFF,CD_ANG_OFF,CCD_ANG_OFF);
00503   
00504   uves_set_ccd_rot(ccd_rot,ccdrotoff, ccdrotoff);
00505   uves_physmod_set_incidence(echoff, echoff, CDoff, CDoff);
00506   uves_msg_debug("ccdbin=%f,%f",binx,biny);
00507   uves_msg_debug("offset x=%f %f %f %f %f %f",
00508    offset_x[0],offset_x[1],offset_x[2],offset_x[3],offset_x[4],offset_x[5]);
00509 
00510   uves_msg_debug("offset y=%f %f %f %f %f %f",
00511    offset_y[0],offset_y[1],offset_y[2],offset_y[3],offset_y[4],offset_y[5]);
00512 
00513   uves_msg("Central wavelength: %4.2f nm",wcent);
00514   uves_msg_debug("chip    =%s", uves_chip_tostring_upper(chip));
00515   /* uves_msg("uves_arm=%c",ArmId); */      /* b/r */
00516   uves_msg_debug("uves_arm_ident=%d",uves_arm_ident);       /* b/r */
00517 
00518   /* uves_msg("chipid=%s",CHIP[0]); */ /* upper/lower chip */
00519   /* uves_msg("cdid=%s",CDID); */       /* 1-4 for CD#1-4 */
00520   /* uves_cfg_indx = uves_config(ArmId[0],CHIP[0],CDID,wcent,binx,biny); */
00521   uves_cfg_indx = uves_config_cpl_new(uves_arm_ident,upper,CDID,wcent,binx,biny);
00522   uves_msg_debug("uves_cfg_indx=%d",uves_cfg_indx);
00523 
00524   uves_physmod_set_offset(offset_x[uves_cfg_indx-1],offset_y[uves_cfg_indx-1],
00525                           uves_physmod_x_off,uves_physmod_y_off);
00526 
00527 /* =========================================================================
00528  * Computation of the true pixel-scale along echelle dispersion 
00529  * scale = (K*FocalRatioNasmyth*PixelSize*ApertureCamera*1e-3)/FocalNasmyth
00530  * K = 206265 : conversion radian to arcsec (1 radian = 206265 arcsec)
00531  * scale = (206265.0*15.0*0.015*200*1e-3*CCDBIN[0])/120000; 
00532  * =========================================================================
00533  */
00534 
00535 /* Creation of modtbl */
00536   
00537   *mod_tbl= cpl_table_new(3*aRowNumber);
00538  
00539   uves_msg_debug("table created: %s ncol=%d, nrow=%d","mod_tbl",10,3*aRowNumber);  
00540   cpl_table_new_column(*mod_tbl,"WAVE",CPL_TYPE_DOUBLE);
00541   cpl_table_new_column(*mod_tbl,"ORDER",CPL_TYPE_INT);
00542   cpl_table_new_column(*mod_tbl,"XMOD",CPL_TYPE_DOUBLE);
00543   cpl_table_new_column(*mod_tbl,"YMOD",CPL_TYPE_DOUBLE);
00544   cpl_table_new_column(*mod_tbl,"BIN_SIZE",CPL_TYPE_DOUBLE);
00545   cpl_table_new_column(*mod_tbl,"LINEWIDPX",CPL_TYPE_DOUBLE);
00546   cpl_table_new_column(*mod_tbl,"LINEWIDTH",CPL_TYPE_DOUBLE);
00547   cpl_table_new_column(*mod_tbl,"RESOL",CPL_TYPE_DOUBLE);
00548   cpl_table_new_column(*mod_tbl,"LINELENPX",CPL_TYPE_DOUBLE);
00549   cpl_table_new_column(*mod_tbl,"BLAZE",CPL_TYPE_DOUBLE);
00550   
00551   uves_ccd_size(&xpix,&ypix); 
00552   uves_msg_debug("CCDsize: %d %d",xpix,ypix);
00553 
00554   
00555   for (i=0; i<aRowNumber; i++) {
00556     /*
00557   for (i=450; i<455; i++) {
00558     */
00559   
00560    
00561   
00562     /* why we do access line i+1? */
00563       dblwav=cpl_table_get_double(line_refer, "Wave",i,&status);
00564       uves_msg_debug(" i: %d Line: %f",i,dblwav); 
00565      
00566       dblwav /= 10.0;     /* (10.0: conversion factor from nm to A)*/
00567       order = uves_physmod_find_order(dblwav);
00568       uves_msg_debug("order=%d",order); 
00569       
00570       order++;  
00571 
00572 /* Computes the positions xmod and ymod for the order-1, order, order+1 */
00573 /* and adds a row to the modtbl only if the position are insight the CCD */
00574  
00575       for (mm=0; mm<3; mm++){
00576         /*uves_physmod_xy_model(dblwav, order, &xmod, &ymod);
00577         blaze = blz; */
00578         /* The next line fails */
00579         uves_physmod_lambda_order2beta(dblwav, order, &uves_beta_ech, &uves_beta_cd, &fc);
00580     
00581         uves_msg_debug("uves_beta_ech %f, uves_beta_cd %f, fc %f",
00582                         uves_beta_ech,    uves_beta_cd,    fc);
00583         
00584         uves_beta2xy(uves_beta_cd, uves_beta_ech, fc, &xmod, &ymod);
00585         uves_msg_debug("xmod=%f ymod=%f",xmod,ymod);
00586     /* Computes the anamorphic magnification and the blaze function  */    
00587         uves_physmod_photo_beta(dblwav, uves_beta_ech, uves_beta_cd, 
00588                       &uves_physmod_rech, &uves_physmod_rcd, &blaze);
00589     
00590         uves_msg_debug("uves_physmod_rech %f, uves_physmod_rcd %f, blaze %f",
00591                         uves_physmod_rech,    uves_physmod_rcd,    blaze); 
00592     
00593 /* Translation */
00594         
00595         uves_msg_debug("Before translation: xmod %f, ymod %f",xmod, ymod); 
00596         
00597         xmod += xtrans;
00598         ymod += ytrans;
00599         uves_msg_debug("xtrans=%f ytrans=%f xmod=%f ymod=%f",
00600                         xtrans,   ytrans,   xmod,   ymod);
00601     
00602         uves_msg_debug("After translation: xmod %f, ymod %f",xmod, ymod); 
00603     uves_msg_debug("xpix=%d ypix=%d",xpix,ypix);
00604     
00605     uves_msg_debug("binx=%f biny=%f",binx,biny); 
00606     
00607         if (xmod > 0 && xmod < xpix && ymod > 0 && ymod < ypix) {     
00608 
00609 /* Computes the width (in pixel and A) and resolution lines */
00610       uves_physmod_pixscl(dblwav, order, uves_physmod_rech, uves_physmod_rcd, 
00611                  binx, biny, fc, slit_width, slit_length, 
00612          &binsize, &pixscale, &pixscalCD, &linewidpx, 
00613                  &linelenpx, &linewidth, &resol);
00614       
00615           uves_msg_debug("binsize %f, pixscale %f, pixscalCD %f",
00616           binsize,pixscale,pixscalCD);
00617           uves_msg_debug("linewidpx %f, linelenpx %f, linewidth %f, resol %f",
00618           linewidpx,linelenpx,linewidth,resol);
00619       
00620 /* Compute/regress */
00621       if (CMP_REG_SW) {
00622         uves_physmod_xy_regres(xmod,ymod,&xreg,&yreg);
00623       } else {
00624         xreg = xmod;
00625         yreg = ymod;
00626       }
00627 
00628      
00629           uves_msg_debug("Fill tab: i=%d wave=%f order=%d xmod=%f ymod=%f",
00630              i,dblwav,order,xmod,ymod);
00631 
00632           uves_msg_debug("Fill tab: bin_sixe=%f xreg=%f yreg=%f ",
00633              binsize,xreg,yreg);
00634 
00635           uves_msg_debug("Fill tab: linewidpx=%f linewidth=%f resol=%f linelenpx=%f blaze=%f",
00636 linewidpx,linewidth,resol,linelenpx,blaze);
00637       
00638       
00639       cpl_table_set_double(*mod_tbl, "WAVE"     ,imod, dblwav);
00640       cpl_table_set_int   (*mod_tbl, "ORDER"    ,imod, order);
00641       cpl_table_set_double(*mod_tbl, "XMOD"     ,imod, xreg);
00642       cpl_table_set_double(*mod_tbl, "YMOD"     ,imod, yreg);
00643       cpl_table_set_double(*mod_tbl, "BIN_SIZE" ,imod, binsize);
00644       cpl_table_set_double(*mod_tbl, "LINEWIDPX",imod, linewidpx);
00645       cpl_table_set_double(*mod_tbl, "LINEWIDTH",imod, linewidth);
00646       cpl_table_set_double(*mod_tbl, "RESOL"    ,imod, resol);
00647       cpl_table_set_double(*mod_tbl, "LINELENPX",imod, linelenpx);
00648       cpl_table_set_double(*mod_tbl, "BLAZE"    ,imod, blaze);
00649           ++imod;
00650 
00651     }
00652     order--;
00653       } /* end loop over mm */
00654     } /* end loop over i */
00655  
00656   cpl_table_duplicate_column(*mod_tbl,"IDENT",*mod_tbl,"WAVE");
00657   cpl_table_multiply_scalar(*mod_tbl,"IDENT",10.);
00658   cpl_table_duplicate_column(*mod_tbl,"XSTART",*mod_tbl,"XMOD");
00659   cpl_table_add_scalar(*mod_tbl,"XSTART",-mbox_x/2.);
00660   cpl_table_duplicate_column(*mod_tbl,"YSTART",*mod_tbl,"YMOD");
00661   cpl_table_add_scalar(*mod_tbl,"YSTART",-mbox_y/2.);
00662   cpl_table_duplicate_column(*mod_tbl,"XEND",*mod_tbl,"XMOD");
00663   cpl_table_add_scalar(*mod_tbl,"XEND",mbox_x/2.);
00664   cpl_table_duplicate_column(*mod_tbl,"YEND",*mod_tbl,"YMOD");
00665   cpl_table_add_scalar(*mod_tbl,"YEND",mbox_y/2.);
00666 
00667 
00668 /* close everything */
00669 
00670 
00671 
00672     uves_msg("Predicted number of lines: %d",imod);
00673 
00674 /* Compute the free spectral range */
00675 
00676     uves_msg("Determine the Free Spectral Range");
00677  
00678     dxpix = (double) xpix;
00679     dypix = (double) ypix;
00680 
00681     m_min = -1;
00682     m_max = -1;
00683 /*
00684    uves_physmod_lambda_order_model(&l,&m_max,dxpix/2,1.0);
00685    uves_physmod_lambda_order_model(&l,&m_min,dxpix/2,dypix);
00686 */
00687     uves_physmod_lambda_order_model(&lmax,&m_min,1.0,dypix);
00688     uves_physmod_lambda_order_model(&lmin,&m_max,dxpix,1.0);
00689 
00690     uves_physmod_lambda_order_model(&lmax,&m_min,dxpix,dypix);
00691     uves_physmod_lambda_order_model(&lmin,&m_max,1.0,1.0);
00692 
00693    
00694    uves_msg_debug("m_min= %d,m_max= %d",m_min,m_max);
00695 
00696    
00697 /* Creation of the modfree_sp_rg.tbl table */
00698 
00699     *fsr_tbl=cpl_table_new(m_max-m_min+1);
00700   
00701     uves_msg_debug("FSR tbl created: %s. No of columns: %d, No of rows: %d","free_spectral_range",
00702              20,m_max-m_min+1);
00703   cpl_table_new_column(*fsr_tbl,"ORDER",CPL_TYPE_INT);
00704   cpl_table_new_column(*fsr_tbl,"WVCENTCOL",CPL_TYPE_DOUBLE);
00705   cpl_table_new_column(*fsr_tbl,"YCENTCOL",CPL_TYPE_DOUBLE);
00706   cpl_table_new_column(*fsr_tbl,"START",CPL_TYPE_DOUBLE);
00707   cpl_table_new_column(*fsr_tbl,"END",CPL_TYPE_DOUBLE);
00708   cpl_table_new_column(*fsr_tbl,"WAVECENT",CPL_TYPE_DOUBLE);
00709   cpl_table_new_column(*fsr_tbl,"YCENT",CPL_TYPE_DOUBLE);
00710   cpl_table_new_column(*fsr_tbl,"FSRMIN",CPL_TYPE_DOUBLE);
00711   cpl_table_new_column(*fsr_tbl,"FSRMAX",CPL_TYPE_DOUBLE);
00712   cpl_table_new_column(*fsr_tbl,"XFSR_MIN",CPL_TYPE_DOUBLE);
00713   cpl_table_new_column(*fsr_tbl,"XFSR_MAX",CPL_TYPE_DOUBLE);
00714   cpl_table_new_column(*fsr_tbl,"YFSR_MIN",CPL_TYPE_DOUBLE);
00715   cpl_table_new_column(*fsr_tbl,"YFSR_MAX",CPL_TYPE_DOUBLE);
00716   cpl_table_new_column(*fsr_tbl,"PIXSCALE",CPL_TYPE_DOUBLE);
00717   cpl_table_new_column(*fsr_tbl,"PIXSCALCD",CPL_TYPE_DOUBLE);
00718   cpl_table_new_column(*fsr_tbl,"BIN_SIZE",CPL_TYPE_DOUBLE);
00719   cpl_table_new_column(*fsr_tbl,"LINEWIDPX",CPL_TYPE_DOUBLE);
00720   cpl_table_new_column(*fsr_tbl,"LINEWIDTH",CPL_TYPE_DOUBLE);
00721   cpl_table_new_column(*fsr_tbl,"RESOL",CPL_TYPE_DOUBLE);
00722   cpl_table_new_column(*fsr_tbl,"LINELENPX",CPL_TYPE_DOUBLE);
00723 
00724 
00725   imod = 0;
00726   uves_msg_debug("m, waveCentcol,   Start,     End,       yCent,    FSRmin,   FSRmax,  bin (mA)");
00727 
00728   for (m=m_max; m>=m_min; m--) {
00729      uves_msg_debug("%d ",m);
00730      uves_physmod_find_FSR(m,&l, &fsr_min, &fsr_max);
00731      
00732      uves_physmod_xy_model(l,m,&x,&y);
00733 
00734 /* Translation */
00735       x += xtrans;
00736       y += ytrans;
00737      
00738      uves_physmod_xy_model(fsr_min,m,&xfsr_min,&yfsr_min);
00739      
00740 /* Translation */
00741       xfsr_min += xtrans;
00742       yfsr_min += ytrans;
00743 
00744      uves_physmod_xy_model(fsr_max,m,&xfsr_max,&yfsr_max);
00745      
00746 /* Translation */
00747       xfsr_max += xtrans;
00748       yfsr_max += ytrans;
00749 
00750 /* Computes the anamorphic magnification and the blaze function */      
00751      uves_physmod_lambda_order2beta(l,m, &uves_beta_ech, &uves_beta_cd, &fc);
00752      uves_physmod_photo_beta(l, uves_beta_ech, uves_beta_cd, 
00753                              &uves_physmod_rech, &uves_physmod_rcd, &blaze); 
00754      
00755 
00756 
00757 /* Computes the width (in pixel and A) and resolution lines */  
00758      uves_physmod_pixscl(l, m, uves_physmod_rech, uves_physmod_rcd, 
00759                          binx, biny, fc, slit_width, slit_length, 
00760                          &dl, &pixscale, &pixscalCD, 
00761                      &linewidpx, &linelenpx, &linewidth, &resol);
00762 
00763      mmin  = m;
00764      mmax = m;
00765 
00766   
00767 
00768 /* WARNING! The central column doesn't correspond to the central wavelength position */     
00769      uves_physmod_lambda_order_model(&lcent,&m,dxpix/2,y);
00770      uves_physmod_xy_model(lcent,m,&xr,&yr);
00771      
00772      uves_physmod_lambda_order_model(&lmax,&mmax,dxpix,y);
00773      uves_physmod_lambda_order_model(&lmin,&mmin,1.0,y); 
00774 
00775 /*     if (y>=0. && y <=dypix) {*/
00776 
00777        uves_msg_debug("m=%d, waveCent (nm)=%f, Start=%f, End=%f",m,l,lmin,lmax);
00778        uves_msg_debug("yCent=%f,FSRmin=%f,FSRmax=%f,bin (mA)=%f",y,fsr_min,fsr_max,dl);
00779 
00780 
00781        uves_msg_debug("%d %f %f %f %f %f %f %f",m,lcent,lmin,lmax,yr,fsr_min,fsr_max,dl);
00782 
00783 
00784        uves_msg_debug("pixel-scale = %f, anamorphic corrections = %f, %f", 
00785                       pixscale, uves_physmod_rech, uves_physmod_rcd);
00786 
00787 
00788        cpl_table_set_int(*fsr_tbl, "ORDER",imod,m);
00789        cpl_table_set_double(*fsr_tbl, "WVCENTCOL",imod,lcent);
00790        cpl_table_set_double(*fsr_tbl, "YCENTCOL",imod,yr);
00791        cpl_table_set_double(*fsr_tbl, "START",imod,lmin);
00792        cpl_table_set_double(*fsr_tbl, "END",imod,lmax);
00793        cpl_table_set_double(*fsr_tbl, "WAVECENT",imod,l);
00794        cpl_table_set_double(*fsr_tbl, "YCENT",imod,y);
00795        cpl_table_set_double(*fsr_tbl, "FSRMIN",imod,fsr_min);
00796        cpl_table_set_double(*fsr_tbl, "FSRMAX",imod,fsr_max);
00797        cpl_table_set_double(*fsr_tbl, "XFSR_MIN",imod,xfsr_min);
00798        cpl_table_set_double(*fsr_tbl, "XFSR_MAX",imod,xfsr_max);
00799        cpl_table_set_double(*fsr_tbl, "YFSR_MIN",imod,yfsr_min);
00800        cpl_table_set_double(*fsr_tbl, "YFSR_MAX",imod,yfsr_max);
00801        cpl_table_set_double(*fsr_tbl, "PIXSCALE",imod,pixscale);
00802        cpl_table_set_double(*fsr_tbl, "PIXSCALCD",imod,pixscalCD);
00803        cpl_table_set_double(*fsr_tbl, "BIN_SIZE",imod,dl);
00804        cpl_table_set_double(*fsr_tbl, "LINEWIDPX",imod,linewidpx);
00805        cpl_table_set_double(*fsr_tbl, "LINEWIDTH",imod,linewidth);
00806        cpl_table_set_double(*fsr_tbl, "RESOL",imod,resol);
00807        cpl_table_set_double(*fsr_tbl, "LINELENPX",imod,linelenpx);
00808          ++imod;
00809 
00810 /*     }*/
00811   }
00812 
00813   /* To remove possible NULL entries */
00814   cpl_table_erase_invalid_rows(*mod_tbl);
00815 
00816   /* Now we do the polynomial fit */
00817   uves_msg_debug("End determination fsr range");
00818 
00819 
00820    cleanup:
00821 
00822   return 0;
00823 }
00824 
00825 
00826 static int
00827 flames_get_trans(const int plt_no,
00828                  enum uves_chip chip, 
00829                  const double wlen, 
00830                  double * TX,
00831                  double * TY)
00832 {
00833 
00834 
00835   if(plt_no==1) {
00836     if( chip==UVES_CHIP_REDL) {
00837       if(wlen==520) {
00838         *TX = -15.330;
00839         *TY = -40.461; 
00840       } else if (wlen == 580) {
00841     *TX = -17.972;
00842         *TY = -39.200;    
00843       } else if (wlen == 860) {
00844         *TX= -12.212;
00845         *TY= -49.370;
00846       }
00847     } else {
00848       if(wlen==520) {
00849         *TX = -14.237;
00850         *TY = -40.337;
00851       } else if (wlen == 580) {
00852         *TX= -14.738;
00853         *TY= -38.831;  
00854       } else if (wlen == 860) {
00855 
00856         *TX = -08.253;
00857         *TY = -45.385;
00858       }
00859     }
00860   } else if (plt_no==2) {
00861     if( chip==UVES_CHIP_REDL) {
00862       if(wlen==520) {
00863         *TX = +10.136;
00864         *TY = -41.420;
00865       } else if (wlen == 580) {
00866         *TX = +09.000;
00867         *TY = -38.289;  
00868       } else if (wlen == 860) {
00869         *TX = +16.386;
00870         *TY = -47.519;
00871       }
00872     } else {
00873       if(wlen==520) {
00874         *TX = +12.244;
00875         *TY = -41.970;
00876       } else if (wlen == 580) {
00877         *TX = +12.023;
00878         *TY = -38.165;
00879       } else if (wlen == 860) {
00880         *TX = +18.241;
00881         *TY = -43.889; 
00882       }
00883     }
00884 
00885   } else {
00886     uves_msg_warning("plt_no=%d chip=%d Wlen %g is not standard setting setting defaults",plt_no,chip,wlen); 
00887     *TX = 0;
00888     *TY = 0;
00889   }
00890   return 0;
00891 
00892 }
00893 

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