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

Generated on Fri Apr 18 14:11:42 2008 for UVES Pipeline Reference Manual by  doxygen 1.5.1