uves_response_impl.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/11/26 11:07:14 $
00023  * $Revision: 1.83 $
00024  * $Name: uves-5_0_0 $
00025  *
00026  */
00027 #ifdef HAVE_CONFIG_H
00028 #  include <config.h>
00029 #endif
00030 
00031 /*----------------------------------------------------------------------------*/
00039 /*----------------------------------------------------------------------------*/
00040 
00041 /*-----------------------------------------------------------------------------
00042                                 Includes
00043  -----------------------------------------------------------------------------*/
00044 
00045 /* Definitions */
00046 #include <uves.h>
00047 
00048 /* Macro steps */
00049 #include <uves_reduce.h>
00050 #include <uves_reduce_utils.h>
00051 #include <uves_response_efficiency.h>
00052 #include <uves_response_utils.h>
00053 
00054 /* Utility functions */
00055 #include <uves_extract.h>
00056 #include <uves_plot.h>
00057 #include <uves_dfs.h>
00058 #include <uves_pfits.h>
00059 #include <uves_parameters.h>
00060 #include <uves_utils.h>
00061 #include <uves_utils_wrappers.h>
00062 #include <uves_utils_cpl.h>
00063 #include <uves_qclog.h>
00064 #include <uves_recipe.h>
00065 #include <uves_error.h>
00066 #include <uves_msg.h>
00067 #include <uves_merge.h>
00068 
00069 /* Library */
00070 #include <cpl.h>
00071 #include <stdbool.h>
00072 #include <string.h>
00073 
00074 /*-----------------------------------------------------------------------------
00075                             Functions prototypes
00076  -----------------------------------------------------------------------------*/
00077 static void uves_efficiency_qclog(cpl_table* table,
00078                   uves_propertylist* raw_header, 
00079                   enum uves_chip chip,
00080                   cpl_table* qclog,
00081                   const char *ref_obj_name);
00082 
00083 static int
00084 uves_response_define_parameters(cpl_parameterlist *parameters);
00085 
00086 /*-----------------------------------------------------------------------------
00087                             Recipe standard code
00088  -----------------------------------------------------------------------------*/
00089 #define cpl_plugin_get_info uves_response_get_info
00090 UVES_RECIPE_DEFINE(
00091     UVES_RESPONSE_ID, UVES_RESPONSE_DOM, uves_response_define_parameters,
00092     "Jonas M. Larsen", "cpl@eso.org",
00093     "Determines response function and quantum efficiency",
00094 "This recipe reduces a standard star frame (STANDARD_xxx or STANDARD_xxx,\n"
00095 "where xxx = BLUE, RED) using a combination (depending on recipe parameters\n"
00096 "and provided input frames) of the steps:\n"
00097 "  - bias subtraction,\n"
00098 "  - dark subtraction,\n"
00099 "  - background subtraction,\n"
00100 "  - extraction/cosmic ray removal,\n"
00101 "  - flat-field correction,\n"
00102 "  - wavelength rebinning,\n"
00103 "  - sky subtraction,\n"
00104 "  - order merging.\n"
00105 "\n"
00106 " Expected input for this recipe is an raw std star frame, STANDARD_xxx or \n"
00107 "order table(s) for each chip, ORDER_TABLE_xxxx (where xxxx=BLUE, REDL, REDU),\n"
00108 "line table(s) for each chip, LINE_TABLE_xxxx, a master bias frame,\n"
00109 "MASTER_BIAS_xxxx, a master flat, MASTER_FLAT_xxxx, a reference standard star\n"
00110 "flux table, FLUX_STD_TABLE, a table describing the atmospheric extintion,\n"
00111 "EXTCOEFF_TABLE. \n"
00112 
00113 "Two reductions are performed, the first using optimal extraction (used to\n"
00114 "compute the instrument response function), the second using linear extraction\n"
00115 "(used to get the Quantum Detection Efficiency)\n"
00116 "\n"
00117 "For each chip (xxxx = BLUE, REDL, REDU) the recipe produces\n"
00118 "  INSTR_RESPONSE_xxxx          Response curve\n"
00119 "  WCALIB_FF_RESPONSE_xxxx      Response curve in (lambda,order) space before\n"
00120 "                               correcting for exposure time, gain, binning and\n"
00121 "                               atmospheric absorption\n"
00122 "  RED_STD_xxxx                 Reduced spectrum\n"
00123 "  EFFICIENCY_TABLE_xxxx        Efficiency table\n"
00124     "  BKG_STD_xxxx                 The subtracted background\n");
00125 
00127 /*----------------------------------------------------------------------------*/
00133 /*----------------------------------------------------------------------------*/
00134 static int
00135 uves_response_define_parameters(cpl_parameterlist *parameters)
00136 {
00137     /*****************
00138      *    General    *
00139      *****************/
00140 
00141     if (uves_define_global_parameters(parameters) != CPL_ERROR_NONE)
00142     {
00143         return -1;
00144     }
00145     
00146     /*******************
00147      *    Reduce       *
00148      ******************/
00149     /* Get reduce parameters for the top level and also for 'efficiency' substep */
00150     if (uves_propagate_parameters_step(
00151         UVES_REDUCE_ID, parameters, make_str(UVES_RESPONSE_ID), NULL) != 0)
00152     {
00153         return -1;
00154     }
00155 
00156 
00157     check(uves_define_efficiency_parameters(parameters),
00158           "Defining efficiency parameters");
00159 
00160 
00161   cleanup:
00162     return (cpl_error_get_code() != CPL_ERROR_NONE);
00163 }
00164 
00165 /*----------------------------------------------------------------------------*/
00219 /*----------------------------------------------------------------------------*/
00220 
00221 static cpl_error_code
00222 uves_response_process_chip(const cpl_image *raw_image, 
00223                            const uves_propertylist *raw_header, 
00224                            const uves_propertylist *rotated_header,
00225                const cpl_image *master_bias,
00226                const cpl_image *master_dark, 
00227                            const uves_propertylist *mdark_header, 
00228                const cpl_image *master_flat, 
00229                            const uves_propertylist *mflat_header,
00230                const cpl_table *ordertable, 
00231                            const polynomial *order_locations,
00232                const cpl_table *linetable[3], 
00233                            const uves_propertylist *linetable_header[3], 
00234                            const polynomial *dispersion_relation[3],
00235                const cpl_table *flux_table,
00236                const cpl_table *atm_extinction,
00237                enum uves_chip chip,
00238                /* General */
00239                bool   DEBUG,
00240                /* Backsub */
00241                /* Flat fielding */
00242                /* Extraction */
00243                /* Rebinning  */
00244                const cpl_parameterlist *parameters,
00245                bool calc_response,
00246                /* Identification */
00247                double PACCURACY,
00248                /* Output */
00249                char **ref_obj_id,
00250                cpl_image **reduced_spectrum, 
00251                            uves_propertylist **reduced_header, 
00252                            cpl_image **background,
00253                cpl_image **response_orders, 
00254                            uves_propertylist **response_header_2d,
00255                cpl_image **response_curve,  
00256                            uves_propertylist **response_header,
00257                cpl_table **efficiency, 
00258                            cpl_table** blaze_efficiency,
00259                            cpl_table** info_tbl,
00260                double *extraction_slit)
00261 {
00262     cpl_image        *rebinned_spectrum = NULL;
00263     cpl_image        *rebinned_noise    = NULL;
00264     uves_propertylist *rebinned_header   = NULL;
00265     cpl_image        *reduced_rebinned = NULL;
00266     cpl_image        *reduced_rebinned_noise = NULL;
00267 
00268     cpl_image        *reduced_noise    = NULL;
00269 
00270     cpl_table *cosmic_mask     = NULL;   /* Cosmic ray table  (not a product of this recipe) */
00271     cpl_table *order_trace     = NULL;   /* Order trace table (not a product of this recipe) */
00272     cpl_image *merged_spectrum = NULL;   /* Not sky-subtracted (if simple extraction)        */
00273     cpl_image *wave_map      = NULL;
00274     cpl_image *merged_sky      = NULL;
00275     cpl_image *merged_noise    = NULL;
00276     cpl_image *reduced_scaled  = NULL;   /* Merged, sky-subtracted and normalized 
00277                         (exposure time, gain...) */
00278 
00279     cpl_table *catalogue_flux = NULL;    /* Std star catalogue flux */
00280  
00281     /* Do the science reduction. Produces wave.cal. spectra. */
00282     uves_msg("Reducing standard star");
00283 
00284     check( uves_reduce(raw_image, 
00285                        raw_header, 
00286                        rotated_header,
00287                master_bias,
00288                master_dark, 
00289                        mdark_header,
00290                master_flat, 
00291                        mflat_header,
00292                ordertable, 
00293                        order_locations,
00294                linetable, 
00295                        linetable_header, 
00296                        dispersion_relation,
00297                chip,
00298                DEBUG, 
00299                parameters, 
00300                        make_str(UVES_RESPONSE_ID),
00301                "",
00302                /* Output */
00303                NULL, 
00304                        NULL, 
00305                        NULL,                   /* 2d products */
00306                &cosmic_mask,
00307                &wave_map,
00308                background,
00309                NULL, 
00310                        NULL,                          /* Variance of flat-fielded */
00311                NULL, 
00312                        NULL,                         /* Don't need these 
00313                                   intermediate products */
00314                &merged_sky,
00315                &rebinned_spectrum, 
00316                        &rebinned_noise, 
00317                        &rebinned_header,
00318                &merged_spectrum,   
00319                        &merged_noise, 
00320                        reduced_header,
00321                &reduced_rebinned,  
00322                        &reduced_rebinned_noise,
00323                reduced_spectrum,   
00324                        &reduced_noise,
00325                        info_tbl,
00326                extraction_slit,
00327                        &order_trace),
00328        "Could not reduce frame");
00329 
00330 
00331     check( uves_plot_image_rows(*reduced_spectrum, 1, 1, 1,
00332                 "Wavelength (arbitrary units)", NULL,
00333                 "Reduced spectrum (%s chip)", 
00334                 uves_chip_tostring_upper(chip)),
00335        "Plotting failed");
00336 
00337     if (calc_response)
00338     {
00339         /* Calculate 2d response curve  (but don't scale to unit exposure time, ...) */
00340         uves_msg("Filtering rebinned spectrum");
00341         check( uves_filter_image_median(&reduced_rebinned, 10, 0, false), 
00342            "Could not smooth spectrum");
00343         check( uves_filter_image_average(reduced_rebinned, 10, 0), 
00344            "Could not smooth spectrum");    
00345         
00346         uves_msg("Calculating 2d response curve");
00347         
00348         check( *response_orders = uves_calculate_response(reduced_rebinned, 
00349                                   rebinned_header,
00350                                   flux_table,
00351                                   raw_header, 
00352                                   PACCURACY,
00353                                   true,     
00354                                   /*  std_flux / flux  */
00355                                   ref_obj_id),
00356            "Could not calculate response curve");
00357         
00358         check( *response_header_2d = uves_propertylist_duplicate(rebinned_header),
00359            "Error creating FITS header for 2d response curve");
00360         
00361         check( uves_pfits_set_bunit(*response_header_2d, "FLUX_CAT / FLUX_STD"),
00362            "Error writing BUNIT keyword");
00363         
00364         /*
00365          *  Calculate 1d response curve
00366          */
00367         
00368         uves_msg("Normalizing reduced spectrum");
00369         
00370         {
00371         int n_traces = cpl_image_get_size_y(*reduced_spectrum);
00372         assure( n_traces == 1, CPL_ERROR_ILLEGAL_INPUT,
00373             "2d extraction/reduction not supported");
00374         
00375         check( reduced_scaled = uves_normalize_spectrum(*reduced_spectrum, 
00376                                 reduced_noise, 
00377                                 *reduced_header,
00378                                 raw_header,
00379                                 n_traces,
00380                                 chip,
00381                                 atm_extinction,
00382                                 true,  /* Yes, divide by binning */
00383                                 NULL), /* Noise spectrum         */
00384                "Error normalizing reduced spectrum");
00385         }
00386         
00387         uves_msg("Filtering reduced spectrum");
00388         check( uves_filter_image_median(&reduced_scaled, 10, 0, false), 
00389            "Could not smooth spectrum");
00390         check( uves_filter_image_average(reduced_scaled, 10, 0), 
00391            "Could not smooth spectrum");
00392         
00393         uves_msg("Calculating response curve from scaled spectrum");
00394         
00395         cpl_free(*ref_obj_id); *ref_obj_id = NULL;
00396         check( *response_curve = uves_calculate_response(reduced_scaled, 
00397                                  *reduced_header,
00398                                  flux_table,
00399                                  raw_header, 
00400                                  PACCURACY, 
00401                                  true, /*  catalogue_flux / flux  */
00402                                  ref_obj_id),
00403            "Could not calculate response curve");
00404         
00405         check( *response_header = uves_propertylist_duplicate(*reduced_header),
00406            "Error creating FITS header for response curve");
00407         
00408         check( uves_pfits_set_bunit(*response_header, "FLUX_CAT / FLUX_STD"),
00409            "Error writing BUNIT keyword");
00410         
00411         if (DEBUG)
00412         {
00413             check( uves_save_image_local("Pre-smoothed response curve", "raw_response", 
00414                          *response_curve, chip, -1, -1, *response_header, true), 
00415                "Error saving image");
00416         }
00417         
00418         check( uves_plot_image_rows(*response_curve, 1, 1, 1, "Wavelength (arbitrary units)", 
00419                     NULL,
00420                     "Raw response (%s chip)", uves_chip_tostring_upper(chip)),
00421            "Plotting failed");
00422         
00423         
00424         /* Rebin the response curve to 50 wlu:
00425            1) smooth it using a radius of    25 wlu,
00426            2) then extract every n'th pixel where n = 50/step */
00427         uves_msg("Rebinning response curve to step size = 50 w.l.u.");
00428         {
00429         double dlambda, lambda_start;
00430         int n, bin, newbin;
00431     
00432         check( lambda_start = uves_pfits_get_crval1(*response_header),
00433                "Error reading start wavelength from header");
00434         check( dlambda = uves_pfits_get_cdelt1(*response_header),
00435                "Error reading wavelength step from header");
00436         
00437         n = uves_round_double(50.0/dlambda);
00438         
00439         assure( n >= 1, CPL_ERROR_ILLEGAL_OUTPUT,
00440             "Cannot rebin to 50 w.l.u. Current step is only %f w.l.u.", dlambda);
00441         
00442         /* Filter radius = 25 wlu, 0    (It's a 1d image) */
00443         check( uves_filter_image_average(*response_curve, n/2, 0),
00444                "Error filtering response curve");
00445         
00446         newbin = 1;
00447         for (bin = 1+n/2; bin <= cpl_image_get_size_x(*response_curve); bin += n)
00448             {
00449             int pis_rejected;
00450             
00451             /* Write to the same image buffer */
00452             cpl_image_set(*response_curve, 
00453                       newbin, 1,
00454                       cpl_image_get(*response_curve, bin, 1, &pis_rejected)
00455                 );
00456             newbin++;
00457             }
00458         
00459         
00460         /* Extract image, update start+step wavelengths */
00461         uves_crop_image(response_curve, 1, 1, newbin-1, 1);
00462         
00463         lambda_start = lambda_start + dlambda * ((1+n/2) - 1);  /* Center of first bin */
00464         dlambda      = n * dlambda;
00465         
00466         check( uves_pfits_set_crval1(*response_header, lambda_start),
00467                "Error updating start wavelength");
00468         check( uves_pfits_set_cdelt1(*response_header, dlambda),
00469                "Error updating wavelength step");
00470         
00471         }
00472         
00473         check( uves_plot_image_rows(*response_curve, 1, 1, 1, "Wavelength (arbitrary units)", 
00474                     NULL,
00475                     "Response curve (%s chip)", 
00476                     uves_chip_tostring_upper(chip)),
00477            "Plotting failed");
00478         
00479         /* Calculate efficiency table */
00480         uves_msg("Calculating efficiency curve");
00481         
00482         check( uves_response_efficiency(raw_image, 
00483                         raw_header, 
00484                         rotated_header,
00485                         master_bias,
00486                         master_dark, 
00487                         mdark_header, 
00488                         ordertable, 
00489                         order_locations,
00490                         linetable, 
00491                         linetable_header, 
00492                         dispersion_relation,
00493                         flux_table,
00494                         atm_extinction,
00495                         chip,
00496                         DEBUG,
00497                         parameters,
00498                         PACCURACY,
00499                         efficiency, 
00500                         blaze_efficiency),
00501            "Efficiency calculation failed");
00502         
00503         check( uves_plot_table(*efficiency, "Wave", "Eff",
00504                    "Detection Quantum Efficiency (%s chip)", 
00505                    uves_chip_tostring_upper(chip)), 
00506            "Plotting failed");
00507         
00508         /* Save blaze function efficiency (efficiency at center of order) */
00509         if (DEBUG) check( uves_save_table_local("Blaze efficiency table",
00510                             "blaze_efficiency", 
00511                             *blaze_efficiency, chip, -1, -1, rotated_header, NULL),
00512                   "Error saving blaze efficiency table");
00513     }
00514     else
00515     {
00516         uves_msg("Skipping response/efficiency computation");
00517     }
00518 
00519   cleanup:
00520     uves_free_propertylist(&rebinned_header);
00521     uves_free_image(&rebinned_noise);
00522     uves_free_image(&rebinned_spectrum);
00523     uves_free_table(&cosmic_mask);
00524     uves_free_table(&order_trace);
00525     uves_free_image(&merged_spectrum);
00526     uves_free_image(&merged_noise);
00527     uves_free_image(&merged_sky);
00528     uves_free_image(&reduced_rebinned);
00529     uves_free_image(&reduced_rebinned_noise);
00530     uves_free_image(&reduced_noise);
00531     uves_free_image(&reduced_scaled);
00532     uves_free_table(&catalogue_flux);
00533 
00534     if (cpl_error_get_code() != CPL_ERROR_NONE)
00535     {
00536         /* Output */
00537         uves_free_image(reduced_spectrum);
00538         uves_free_image(background);
00539         uves_free_image(response_orders);
00540         uves_free_image(response_curve);
00541         uves_free_propertylist(reduced_header);
00542         uves_free_propertylist(response_header);
00543         uves_free_propertylist(response_header_2d);
00544         uves_free_table(efficiency);
00545     }
00546     
00547     return cpl_error_get_code();
00548 }
00549 
00550 /*----------------------------------------------------------------------------*/
00557 /*----------------------------------------------------------------------------*/
00558 static void
00559 UVES_CONCAT2X(UVES_RESPONSE_ID,exe)(cpl_frameset *frames,
00560           const cpl_parameterlist *parameters,
00561           const char *starttime)
00562 {
00563     /*
00564      * Variables containg the values of recipe parameters 
00565      */
00566 
00567     /* General */
00568     bool DEBUG;
00569 
00570     /* Background subtraction */
00571     /* Implicitly passed */
00572 
00573     /* Flat-fielding */
00574 
00575     /* Extraction */
00576     /* Implicitly passed */
00577     
00578     /* Rebinning */
00579     /* Implicitly passed */
00580 
00581     /* Efficiency */
00582     double PACCURACY;
00583 
00584     /* CPL objects */
00585     /* Input, raw */
00586     cpl_image        *raw_image[2]      = {NULL, NULL};
00587     uves_propertylist *raw_header[2]     = {NULL, NULL};
00588     uves_propertylist *rotated_header[2] = {NULL, NULL};
00589 
00590     /* Input, calib */
00591     cpl_image        *master_bias        = NULL;
00592     uves_propertylist *master_bias_header = NULL;
00593 
00594     cpl_image        *master_dark        = NULL;
00595     uves_propertylist *master_dark_header = NULL;
00596 
00597     cpl_image        *master_flat        = NULL;
00598     uves_propertylist *master_flat_header = NULL;
00599 
00600     cpl_table        *ordertable       = NULL;
00601     uves_propertylist *ordertable_header= NULL;
00602     polynomial       *order_locations  = NULL;
00603     cpl_table        *traces           = NULL;
00604 
00605     cpl_table        *flux_table       = NULL;
00606 
00607     cpl_table        *atm_extinction   = NULL;
00608 
00609     /* Line tables for sky, object, sky (UVES specific) */
00610     const cpl_table        *linetable[3]           = {NULL, NULL, NULL};
00611     const uves_propertylist *linetable_header[3]    = {NULL, NULL, NULL};
00612     const polynomial       *dispersion_relation[3] = {NULL, NULL, NULL};
00613 
00614     /* Output */
00615     cpl_image        *background         = NULL;
00616     cpl_image        *reduced_spectrum   = NULL;
00617     uves_propertylist *spectrum_header    = NULL;
00618     cpl_image        *response_orders    = NULL;
00619     uves_propertylist *response_header_2d = NULL;
00620     cpl_image        *response_curve     = NULL;
00621     uves_propertylist *response_header    = NULL;
00622     cpl_table        *efficiency         = NULL;
00623     cpl_table        *blaze_efficiency   = NULL;
00624     uves_propertylist *efficiency_header  = NULL;
00625     cpl_table* info_tbl=NULL;
00626 
00627     /* Local variables */
00628     cpl_table *qclog[2] = {NULL, NULL};
00629     cpl_table *qclog_optext[2] = {NULL, NULL};
00630     cpl_table *catalogue_flux = NULL;
00631     const char *raw_filename = "";        /* Static */
00632     const char *flux_table_filename = ""; /* Static */
00633     const char *atm_ext_filename = "";    /* Static */
00634     char *product_filename = NULL;        /* Dynamically allocated */
00635     char *prod_catg = NULL; 
00636     char *ref_obj_name = NULL;            /* Reference object id */
00637     bool calc_response = false;           /* Calculate instr response? */
00638     double extraction_slit;
00639 
00640     bool blue  = false;
00641     enum uves_chip chip;
00642     int binx = 0;
00643     int biny = 0;
00644     const char* PROCESS_CHIP=NULL;
00645 
00646     const char *ordertable_filename = "";
00647     const char *linetable_filename = "";
00648     const char *master_bias_filename = "";
00649     const char *master_dark_filename = "";
00650     const char *master_flat_filename = "";
00651     const char *chip_name = "";
00652     int tracerow=0;                  /* Index of table row */
00653         
00654     int raw_index = 0;
00655 
00656 
00657     double trace_offset=0;
00658     int trace_number=0;
00659     int trace_enabled=0;
00660     int window=0;          /* window number */
00661     merge_method m_method;
00662 
00663     /* Read recipe parameters */
00664     {
00665     /* General */
00666     check( uves_get_parameter(parameters, NULL, "uves", "debug", 
00667                   CPL_TYPE_BOOL  , &DEBUG      ), "Could not read parameter");
00668 
00669     check( uves_get_parameter(parameters, NULL, "uves", "process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
00670                "Could not read parameter");
00671     uves_string_toupper((char*)PROCESS_CHIP);
00672 
00673     /* Background subtraction, Flat-fielding, Rebinning */
00674     /* The input parameter list is passed */
00675     
00676     /* For both response curve and efficiency step:
00677        Allow only extraction methods average/linear/optimal */
00678     {
00679         extract_method em;
00680 
00681         /* Validate uves_response.reduce.extract.method */
00682         check( em = uves_get_extract_method(
00683                parameters, NULL,
00684                make_str(UVES_RESPONSE_ID) "." UVES_REDUCE_ID "." UVES_EXTRACT_ID),
00685            "Could not read extraction method");
00686         
00687         assure( em == EXTRACT_LINEAR || em == EXTRACT_AVERAGE || em == EXTRACT_OPTIMAL,
00688             CPL_ERROR_UNSUPPORTED_MODE, 
00689             "Use linear/average/optimal extraction method to calculate response curve");
00690         
00691         /* Validate uves_response.efficiency.reduce.extract.method */
00692         check( em = uves_get_extract_method(
00693                parameters, NULL,
00694                make_str(UVES_RESPONSE_ID) ".efficiency." UVES_REDUCE_ID "." UVES_EXTRACT_ID),
00695            "Could not read extraction method");
00696         
00697         assure( em == EXTRACT_LINEAR || em == EXTRACT_AVERAGE || em == EXTRACT_OPTIMAL,
00698             CPL_ERROR_UNSUPPORTED_MODE, 
00699             "Use linear/average/optimal extraction "
00700             "method to calculate quantum efficiency");
00701     }
00702     
00703     /* Identification */
00704     check( uves_get_parameter(parameters, NULL, 
00705                   make_str(UVES_RESPONSE_ID) ".efficiency", "paccuracy", 
00706                   CPL_TYPE_DOUBLE, &PACCURACY), 
00707            "Could not read parameter");
00708     }
00709     
00710     /* Load raw image and header, and identify input frame as red or blue */
00711     check( uves_load_standard(frames,
00712                   &raw_filename, raw_image, raw_header, rotated_header, 
00713                   &blue), 
00714        "Error loading raw frame");
00715 
00716     /* Load flux table */
00717     check( uves_load_flux_table(frames, &flux_table_filename, &flux_table),
00718        "Error loading standard flux table");
00719 
00720     uves_msg_low("Using standard star flux table in '%s'", flux_table_filename);
00721 
00722     /* Before doing the reduction, find out if the standard star is in the table.
00723      * If not, still do the science reduction, but skip the instr.response part
00724      */
00725     catalogue_flux = uves_align(raw_header[0], flux_table, PACCURACY, &ref_obj_name);
00726 
00727     calc_response = true;
00728     if (cpl_error_get_code() == CPL_ERROR_INCOMPATIBLE_INPUT)
00729     {
00730         uves_error_reset();
00731 
00732         uves_msg_warning("No catalogue object found within %.2f arcsecs. "
00733                  "Instrument response curve will not be computed",
00734                  PACCURACY);
00735 
00736         calc_response = false;
00737     }
00738 
00739     /* Load atmospheric extinction table */
00740     check( uves_load_atmo_ext(frames, &atm_ext_filename, &atm_extinction), 
00741        "Error loading extinction coefficients");
00742     
00743     uves_msg_low("Using atmospheric extinction table in '%s'", atm_ext_filename);
00744 
00745     //cpl_parameterlist_dump(parameters,stdout);
00746     //uves_msg("recipe=%s",UVES_RESPONSE_ID);
00747    check( m_method = uves_get_merge_method(parameters, "uves_cal_response", "reduce"),
00748            "Could not get merging method");
00749     /* Adjust parameters according to binning 
00750      */
00751     check (binx = uves_pfits_get_binx(raw_header[0]), 
00752        "Could not read x binning factor from input header");
00753     check (biny = uves_pfits_get_biny(raw_header[0]),
00754        "Could not read y binning factor from input header");
00755 
00756     /* Loop over one or two chips, over traces and
00757        over extraction windows */
00758     for (chip = uves_chip_get_first(blue);
00759      chip != UVES_CHIP_INVALID;
00760      chip = uves_chip_get_next(chip))
00761     {
00762 
00763 
00764       if(strcmp(PROCESS_CHIP,"REDU") == 0) {
00765     chip = uves_chip_get_next(chip);
00766       }
00767 
00768 
00769         /* const char *drs_filename        = "";    not used */
00770         raw_index = uves_chip_get_index(chip);
00771         uves_msg("Processing %s chip in '%s'",
00772              uves_chip_tostring_upper(chip), raw_filename);
00773         
00774         check_nomsg( chip_name = uves_pfits_get_chipid(raw_header[raw_index], chip));
00775 
00776         uves_msg_debug("Binning = %dx%d", binx, biny);
00777         
00778         /* Load master bias, set pointer to NULL if not present */
00779         uves_free_image(&master_bias);
00780         uves_free_propertylist(&master_bias_header);
00781         if (cpl_frameset_find(frames, UVES_MASTER_BIAS(chip)) != NULL)
00782         {
00783             check( uves_load_mbias(frames, chip_name, 
00784                        &master_bias_filename,
00785                        &master_bias,
00786                        &master_bias_header, chip), 
00787                "Error loading master bias");
00788             
00789             uves_msg_low("Using master bias in '%s'", master_bias_filename);
00790         }
00791         else
00792         {
00793             uves_msg_low("No master bias in SOF. Bias subtraction not done");
00794         }
00795         
00796         
00797         /* Load master dark, set pointer to NULL if not present */
00798         uves_free_image(&master_dark);
00799         uves_free_propertylist(&master_dark_header);
00800         if (cpl_frameset_find(frames, UVES_MASTER_DARK(chip)) != NULL)
00801         {
00802             check( uves_load_mdark(frames, chip_name,
00803                        &master_dark_filename,
00804                        &master_dark,
00805                        &master_dark_header, chip),
00806                "Error loading master dark");
00807             
00808             uves_msg_low("Using master dark in '%s'", master_dark_filename);
00809         }
00810         else
00811         {
00812             uves_msg_low("No master dark in SOF. Dark subtraction not done");
00813         }
00814         
00815         /* Load master flat */
00816         uves_free_image(&master_flat);
00817         uves_free_propertylist(&master_flat_header);
00818         check( uves_load_mflat_const(frames, chip_name, 
00819                      &master_flat_filename,
00820                      &master_flat, 
00821                      &master_flat_header, 
00822                      chip, NULL), "Error loading master flat");
00823         
00824         uves_msg_low("Using master flat in '%s'", master_flat_filename);
00825         
00826         
00827         /* Load the order table for this chip */
00828         uves_free_table       (&ordertable);
00829         uves_free_propertylist(&ordertable_header);
00830         uves_polynomial_delete(&order_locations);
00831         uves_free_table       (&traces);
00832     
00833         check( uves_load_ordertable(frames, 
00834                     false,  /* FLAMES? */
00835                     chip_name,
00836                     &ordertable_filename, 
00837                     &ordertable, 
00838                     &ordertable_header,
00839                                         NULL,
00840                     &order_locations, &traces, 
00841                     NULL, NULL,
00842                                        NULL, NULL, /* fibre_pos,fibre_mask */
00843                     chip, false),
00844            "Could not load order table");
00845         uves_msg_low("Using order table in '%s'", ordertable_filename);
00846         
00847         
00848         /* Loop over all traces (1 trace for UVES) */
00849         for(tracerow = 0; tracerow < cpl_table_get_nrow(traces); tracerow++)
00850         {
00851 
00852             
00853             trace_offset  = cpl_table_get_double(traces, "Offset"    , tracerow, NULL);
00854             trace_number  = cpl_table_get_int   (traces, "TraceID"   , tracerow, NULL);
00855             trace_enabled = cpl_table_get_int   (traces, "Tracemask" , tracerow, NULL);
00856             
00857             if (trace_enabled != 0)
00858             {
00859                 
00860                             if (cpl_table_get_nrow(traces) > 1) {
00861                                 uves_msg("Processing trace %d", trace_number);
00862                             }
00863                 
00864                 /* This is UVES specific. Load linetable for the 
00865                    two sky windows (number 1, 3) and for the object
00866                    window (number 2) */
00867                 
00868                 for (window = 1; window <= 3; window ++)
00869                 {
00870                     uves_free_table_const ( &(linetable[window-1]) );
00871                     uves_free_propertylist_const( &(linetable_header[window-1]) );
00872                     uves_polynomial_delete_const( &(dispersion_relation[window-1]) );
00873                     check( uves_load_linetable_const(
00874                            frames, 
00875                            false,  /* FLAMES? */
00876                            chip_name,
00877                            order_locations,
00878                            cpl_table_get_column_min(ordertable, "Order"),
00879                            cpl_table_get_column_max(ordertable, "Order"),
00880                            &linetable_filename,
00881                            &(linetable          [window-1]),
00882                            &(linetable_header   [window-1]),
00883                            &(dispersion_relation[window-1]),
00884                            NULL,
00885                            chip,
00886                            trace_number,
00887                            window),
00888                        "Could not load line table, window #%d", window);
00889                 }
00890                 
00891                 uves_msg_low("Using line tables in '%s'", linetable_filename);
00892                 /* end, UVES specific */
00893                 
00894                 /* Do the reduction + response calculation */
00895                 cpl_free(ref_obj_name); ref_obj_name = NULL;
00896                 uves_free_image(&reduced_spectrum);
00897                 uves_free_image(&background);
00898                 uves_free_image(&response_orders);
00899                 uves_free_image(&response_curve);
00900                 uves_free_propertylist(&response_header);
00901                 uves_free_propertylist(&spectrum_header);
00902                 uves_free_propertylist(&response_header_2d);
00903                 uves_free_table(&efficiency);
00904                 uves_free_table(&blaze_efficiency);
00905                 uves_free_table(&info_tbl);
00906                 
00907                 check( uves_response_process_chip(
00908                        raw_image[raw_index],   /* Raw         */
00909                                        raw_header[raw_index],  
00910                        rotated_header[raw_index],
00911                        master_bias,            /* Calibration */
00912                        master_dark, 
00913                                        master_dark_header,
00914                        master_flat, 
00915                                        master_flat_header,
00916                        ordertable, 
00917                                        order_locations,
00918                        linetable, 
00919                                        linetable_header, 
00920                                        dispersion_relation,
00921                        flux_table,
00922                        atm_extinction,
00923                        chip,                  /* Parameters  */
00924                        DEBUG, 
00925                        parameters,
00926                        calc_response,
00927                        PACCURACY,             /* Identification */
00928                        &ref_obj_name,
00929                        &reduced_spectrum, 
00930                                        &spectrum_header, 
00931                                        &background,
00932                        &response_orders, 
00933                                        &response_header_2d,
00934                        &response_curve,  
00935                                        &response_header,
00936                        &efficiency, 
00937                                        &blaze_efficiency,
00938                                        &info_tbl,
00939                        &extraction_slit),
00940                    "Response computation failed");
00941                 
00942                 uves_msg("Saving products...");
00943                 
00944                 /* Calculate QC (two tables) */
00945                 
00946                 if (calc_response)
00947                 {
00948                     uves_qclog_delete(&qclog[0]);
00949                     qclog[0] = uves_qclog_init(raw_header[raw_index], chip);
00950 
00951                     check( uves_efficiency_qclog(blaze_efficiency,
00952                                  raw_header[raw_index],
00953                                  chip,
00954                                  qclog[0],
00955                                  ref_obj_name), 
00956                        "Error generating efficiency QC log");
00957                 }
00958                 
00959                 uves_qclog_delete(&qclog_optext[0]);
00960                         qclog_optext[0] = cpl_table_new(0);
00961                 /* Do not:  
00962                    qclog_optext[0] = uves_qclog_init(raw_header[raw_index], chip);
00963                    because we don't want QC.DID for this
00964                 */
00965                 cpl_table_new_column(qclog_optext[0],"key_name", CPL_TYPE_STRING);
00966                 cpl_table_new_column(qclog_optext[0],"key_type", CPL_TYPE_STRING);
00967                 cpl_table_new_column(qclog_optext[0],"key_value",CPL_TYPE_STRING);
00968                 cpl_table_new_column(qclog_optext[0],"key_help", CPL_TYPE_STRING);
00969                 
00970                 check( uves_qclog_add_sci(qclog_optext[0],
00971                               raw_header[raw_index],
00972                               raw_image[raw_index],
00973                               extraction_slit,
00974                               info_tbl),
00975                    "Error generating extraction QC log");
00976 
00977                 if (calc_response)
00978                 {
00979                     /* Save response curve */
00980                     cpl_free(product_filename);
00981                     check( product_filename = uves_response_curve_filename(chip),
00982                        "Error getting filename");    
00983                     check( uves_frameset_insert(
00984                            frames,
00985                            response_curve,
00986                            CPL_FRAME_GROUP_PRODUCT,
00987                            CPL_FRAME_TYPE_IMAGE,
00988                            CPL_FRAME_LEVEL_INTERMEDIATE,
00989                            product_filename,
00990                            UVES_INSTR_RESPONSE(chip),
00991                            raw_header[raw_index],
00992                            response_header,
00993                            NULL,
00994                            parameters,
00995                            make_str(UVES_RESPONSE_ID),
00996                            PACKAGE "/" PACKAGE_VERSION, 
00997                            qclog_optext,
00998                            starttime, false, 
00999                            UVES_ALL_STATS),
01000                        "Could not add response curve '%s' (%s) to frameset", 
01001                        product_filename, UVES_INSTR_RESPONSE(chip));
01002                     
01003                     uves_msg("Response curve '%s' (%s) added to frameset",
01004                          product_filename, UVES_INSTR_RESPONSE(chip));
01005                     
01006                     /* Save response curve (2d) */
01007                     cpl_free(product_filename);
01008                     check( product_filename = 
01009                        uves_response_curve_2d_filename(chip), 
01010                        "Error getting filename");    
01011                     check( uves_frameset_insert(
01012                            frames,
01013                            response_orders,
01014                            CPL_FRAME_GROUP_PRODUCT,
01015                            CPL_FRAME_TYPE_IMAGE,
01016                            CPL_FRAME_LEVEL_INTERMEDIATE,
01017                            product_filename,
01018                            UVES_WCALIB_FF_RESPONSE(chip),
01019                            raw_header[raw_index],
01020                            response_header_2d,
01021                            NULL,
01022                            parameters,
01023                            make_str(UVES_RESPONSE_ID),
01024                            PACKAGE "/" PACKAGE_VERSION,
01025                            qclog_optext,
01026                            starttime, false, 
01027                            UVES_ALL_STATS),
01028                        "Could not add response curve (2d) "
01029                        "'%s' (%s) to frameset",
01030                        product_filename, UVES_WCALIB_FF_RESPONSE(chip));
01031             
01032                     uves_msg("Response curve (2d) '%s' (%s) added to frameset", 
01033                          product_filename, UVES_WCALIB_FF_RESPONSE(chip));
01034                 }
01035 
01036                 /* Save reduced spectrum */
01037                 cpl_free(product_filename);
01038                 if (m_method == MERGE_NOAPPEND) {
01039                check( product_filename = uves_response_red_noappend_standard_filename(chip),
01040                    "Error getting filename");    
01041                    prod_catg=UVES_RED_NOAPPEND_STD(chip);
01042                 } else {
01043 
01044                 check( product_filename = uves_response_red_standard_filename(chip),
01045                    "Error getting filename");    
01046                    prod_catg=UVES_RED_STD(chip);
01047 
01048                 }
01049                 check( uves_frameset_insert(frames,
01050                             reduced_spectrum,
01051                             CPL_FRAME_GROUP_PRODUCT,
01052                             CPL_FRAME_TYPE_IMAGE,
01053                             CPL_FRAME_LEVEL_INTERMEDIATE,
01054                             product_filename,
01055                             prod_catg,
01056                             raw_header[raw_index],
01057                             spectrum_header,
01058                             NULL,
01059                             parameters,
01060                             make_str(UVES_RESPONSE_ID),
01061                             PACKAGE "/" PACKAGE_VERSION,
01062                             qclog_optext,
01063                             starttime, false, 
01064                             UVES_ALL_STATS),
01065                    "Could not add reduced spectrum '%s' (%s) to frameset",
01066                    product_filename, UVES_RED_STD(chip));
01067                 
01068                 uves_msg("Reduced spectrum '%s' (%s) added to frameset", 
01069                      product_filename, UVES_RED_STD(chip));
01070 
01071                 if (calc_response)
01072                 {
01073                     /* Save efficiency table */
01074                     uves_free_propertylist(&efficiency_header);
01075                     efficiency_header = uves_propertylist_new();
01076                     
01077                     cpl_free(product_filename);
01078                     check( product_filename = 
01079                        uves_response_efficiency_filename(chip),
01080                        "Error getting filename");
01081                     
01082                     check( uves_frameset_insert(
01083                            frames,
01084                            efficiency,
01085                            CPL_FRAME_GROUP_PRODUCT,
01086                            CPL_FRAME_TYPE_TABLE,
01087                            CPL_FRAME_LEVEL_INTERMEDIATE,
01088                            product_filename,
01089                            UVES_EFFICIENCY_TABLE(chip),
01090                            raw_header[raw_index],
01091                            efficiency_header,
01092                            NULL,
01093                            parameters,
01094                            make_str(UVES_RESPONSE_ID),
01095                            PACKAGE "/" PACKAGE_VERSION,
01096                            qclog,
01097                            starttime, true, 0),
01098                        "Could not add background image '%s' (%s) to frameset",
01099                        product_filename, UVES_EFFICIENCY_TABLE(chip));
01100                     
01101                     uves_msg("Efficiency table '%s' (%s) added to frameset", 
01102                          product_filename, UVES_EFFICIENCY_TABLE(chip));
01103                 } /* end if calc_response */
01104                 
01105                 /* Save background image */
01106                 cpl_free(product_filename);
01107                 check( product_filename = 
01108                    uves_response_bkg_standard_filename(chip), 
01109                    "Error getting filename");
01110                 check( uves_frameset_insert(frames,
01111                             background,
01112                             CPL_FRAME_GROUP_PRODUCT,
01113                             CPL_FRAME_TYPE_IMAGE,
01114                             CPL_FRAME_LEVEL_INTERMEDIATE,
01115                             product_filename,
01116                             UVES_BKG_STD(chip),
01117                             raw_header[raw_index],
01118                             rotated_header[raw_index],
01119                             NULL,
01120                             parameters,
01121                             make_str(UVES_RESPONSE_ID),
01122                             PACKAGE "/" PACKAGE_VERSION, NULL,
01123                             starttime, false, 
01124                             CPL_STATS_MIN | CPL_STATS_MAX),
01125                    "Could not add background image '%s' (%s) to frameset",
01126                    product_filename, UVES_BKG_STD(chip));
01127 
01128                 uves_msg("Background image '%s' (%s) added to frameset",
01129                      product_filename, UVES_BKG_STD(chip));
01130                 
01131 
01132                 /* Save info table */
01133                cpl_free(product_filename);
01134                 check( product_filename = 
01135                    uves_order_extract_qc_standard_filename(chip), 
01136                    "Error getting filename");
01137                 check( uves_frameset_insert(frames,
01138                             info_tbl,
01139                             CPL_FRAME_GROUP_PRODUCT,
01140                             CPL_FRAME_TYPE_TABLE,
01141                             CPL_FRAME_LEVEL_INTERMEDIATE,
01142                             product_filename,
01143                             UVES_ORDER_EXTRACT_QC(chip),
01144                             raw_header[raw_index],
01145                             rotated_header[raw_index],
01146                             NULL,
01147                             parameters,
01148                             make_str(UVES_RESPONSE_ID),
01149                             PACKAGE "/" PACKAGE_VERSION, NULL,
01150                             starttime, true, 
01151                             0),
01152                    "Could not add extraction quality table '%s' (%s) to frameset",
01153                    product_filename, UVES_ORDER_EXTRACT_QC(chip));
01154 
01155                 uves_msg("Extraction quality table '%s' (%s) added to frameset",
01156                      product_filename, UVES_ORDER_EXTRACT_QC(chip));
01157                 
01158 
01159 
01160             }/* ... if trace is enabled */
01161             else
01162             {
01163                 uves_msg_low("Skipping trace number %d", trace_number);
01164             }
01165         
01166         }/* For each trace */
01167     
01168 
01169       if(strcmp(PROCESS_CHIP,"REDL") == 0) {
01170     chip = uves_chip_get_next(chip);
01171       }
01172 
01173 
01174 
01175 
01176     } /* For each chip */
01177     
01178   cleanup:
01179     /* Input */
01180     uves_free_image(&raw_image[0]);
01181     uves_free_image(&raw_image[1]);
01182     uves_free_propertylist(&raw_header[0]);
01183     uves_free_propertylist(&raw_header[1]);
01184     uves_free_propertylist(&rotated_header[0]);
01185     uves_free_propertylist(&rotated_header[1]);
01186     
01187     /* Input, calib */
01188     uves_free_image(&master_bias);
01189     uves_free_propertylist(&master_bias_header);
01190     
01191     uves_free_image(&master_dark);
01192     uves_free_propertylist(&master_dark_header);
01193 
01194     uves_free_image(&master_flat);
01195     uves_free_propertylist(&master_flat_header);
01196     
01197     uves_free_table(&ordertable);
01198     uves_free_propertylist(&ordertable_header);
01199     uves_polynomial_delete(&order_locations);
01200     uves_free_table(&traces);
01201     
01202     uves_free_table_const( &(linetable[0]) );
01203     uves_free_table_const( &(linetable[1]) );
01204     uves_free_table_const( &(linetable[2]) );
01205     uves_free_propertylist_const( &(linetable_header[0]) );
01206     uves_free_propertylist_const( &(linetable_header[1]) );
01207     uves_free_propertylist_const( &(linetable_header[2]) );
01208     uves_polynomial_delete_const( &(dispersion_relation[0]) );
01209     uves_polynomial_delete_const( &(dispersion_relation[1]) );
01210     uves_polynomial_delete_const( &(dispersion_relation[2]) );
01211     uves_free_table( &flux_table );
01212     uves_free_table( &atm_extinction );
01213     
01214     /* Output */
01215     uves_qclog_delete(&qclog[0]);
01216     uves_qclog_delete(&qclog_optext[0]);
01217     uves_free_image(&background);
01218     uves_free_image(&reduced_spectrum);
01219     uves_free_propertylist(&spectrum_header);
01220     uves_free_propertylist(&response_header_2d);
01221     uves_free_propertylist(&response_header);
01222     uves_free_propertylist(&efficiency_header);
01223     uves_free_image(&response_orders);
01224     uves_free_image(&response_curve);
01225     uves_free_table(&efficiency);
01226     uves_free_table(&blaze_efficiency);
01227     uves_free_table(&info_tbl);
01228     
01229     /* Local */
01230     uves_free_table(&catalogue_flux);    
01231     cpl_free(product_filename);
01232     cpl_free(ref_obj_name);
01233     
01234     return;
01235 }
01236 
01246 static void uves_efficiency_qclog(cpl_table* table,
01247                   uves_propertylist* raw_header, 
01248                   enum uves_chip chip,
01249                   cpl_table* qclog,
01250                   const char *ref_obj_name)
01251 {
01252   int i=0;
01253   bool new_format;
01254   
01255   check( new_format = uves_format_is_new(raw_header),
01256      "Error determining FITS header format");
01257 
01258   check_nomsg(uves_qclog_add_string(qclog,
01259                         "QC TEST1 ID",
01260                         "Efficiency-Test-Results",
01261                         "Name of QC test",
01262                     "%s"));
01263 
01264   check_nomsg(uves_qclog_add_string(qclog,
01265                         uves_remove_string_prefix(UVES_INSPATH,"ESO "),
01266                          uves_pfits_get_inspath(raw_header),
01267                         "Optical path used.",
01268                    "%s"));
01269 
01270   check_nomsg(uves_qclog_add_string(qclog,
01271                         uves_remove_string_prefix(UVES_INSMODE,"ESO "),
01272                          uves_pfits_get_insmode(raw_header),
01273                         "Instrument mode used.",
01274                    "%s"));
01275 
01276   check_nomsg(uves_qclog_add_string(qclog,
01277                     uves_remove_string_prefix(UVES_GRATNAME(chip),"ESO "),
01278                     uves_pfits_get_gratname(raw_header,chip),
01279                     "Cross disperser ID",
01280                     "%s"));
01281 
01282   check_nomsg(uves_qclog_add_common_wave(raw_header,
01283                                          chip, qclog));
01284 
01285   check_nomsg(
01286       uves_qclog_add_string(qclog,
01287                 uves_remove_string_prefix(UVES_CHIP_NAME(chip),"ESO "),
01288                 /* UVES_QC_CHIP_VAL(chip), */
01289                 uves_pfits_get_chip_name(raw_header, chip),
01290                 "Detector chip name",
01291                 "%s"));
01292   
01293   check_nomsg(
01294       uves_qclog_add_double(qclog,
01295                 uves_remove_string_prefix(UVES_GRATWLEN(chip),"ESO "),
01296                 uves_pfits_get_gratwlen(raw_header,chip),
01297                 "Grating central wavelength [nm] (hs).",
01298                 "%.1f"));
01299   
01300   check_nomsg(
01301       uves_qclog_add_double(qclog,
01302                 uves_remove_string_prefix(UVES_CONAD(new_format, chip),"ESO "),
01303                 uves_pfits_get_conad(raw_header, chip),
01304                 "Conversion from ADUs to electrons",
01305                 "%8.2f"));
01306   
01307  
01308   check_nomsg(
01309       uves_qclog_add_double(qclog,
01310                 uves_remove_string_prefix(UVES_QC_UIT(new_format, chip), "ESO "),
01311                 uves_pfits_get_uit(raw_header),
01312                 "user defined subintegration time",
01313                 "%8.0f"));
01314   
01315   check_nomsg(
01316       uves_qclog_add_double(qclog,
01317                 "AIRMASS",
01318                 (uves_pfits_get_airmass_start(raw_header) +
01319                  uves_pfits_get_airmass_end(raw_header))/2.0,
01320                 "Averaged airmass",
01321                 "%8.4f"));
01322 
01323   check_nomsg(
01324       uves_qclog_add_string(qclog,
01325                 uves_remove_string_prefix(UVES_TARG_NAME, "ESO "),
01326                 ref_obj_name,
01327                 "OB target name",
01328                 "%s"));
01329   
01330  
01331   for(i = 0; i < cpl_table_get_nrow(table); i++) 
01332       {
01333       char key_name[25];
01334 
01335       int order = cpl_table_get_int(table, "Order", i, NULL);
01336 
01337       sprintf(key_name,"QC BLAZEFF%d", order);
01338 
01339       check_nomsg(uves_qclog_add_double(qclog,
01340                         key_name,
01341                         cpl_table_get_double(table, "Eff", i, NULL),
01342                         "Blaze Efficiency",
01343                         "%13.6f"));
01344       /*
01345         uves_msg("QC-LOG: Wlen =%g Eff=%g", 
01346         cpl_table_get_double(table,"Wave",i,NULL),
01347         cpl_table_get_double(table,"Eff",i,NULL));
01348       */
01349 
01350       sprintf(key_name,"QC BLAZWLEN%d", order);
01351       check_nomsg(uves_qclog_add_double(qclog,
01352                         key_name,
01353                         cpl_table_get_double(table, "Wave", i, NULL)/10.,
01354                         "Blaze wavelength",  /* nm */
01355                         "%13.6f"));
01356       }
01357 
01358   /* Are these QC parameters needed anywhere? */
01359 #if 0
01360   for(i = 0; i < cpl_table_get_nrow(info_tbl); i++) 
01361       {
01362       char key_name[25];
01363 
01364       int order = cpl_table_get_int(info_tbl, "Order", i, NULL);
01365 
01366       sprintf(key_name,"QC ORDER NUM%d", order);
01367       check_nomsg(uves_qclog_add_int(qclog,
01368                      key_name,
01369                      order,
01370                      "Order Number",
01371                      "%d"));
01372       /*
01373         uves_msg("QC-LOG: Order =%d S/N=%g", 
01374         cpl_table_get_int(info_tbl,"Order",i,NULL),
01375         cpl_table_get_double(info_tbl,"S/N",i,NULL));
01376       */
01377 
01378       sprintf(key_name,"QC OBJ SN%d", order);
01379       check_nomsg(uves_qclog_add_double(qclog,
01380                         key_name,
01381                         cpl_table_get_double(info_tbl,"S/N",i,NULL),
01382                         "Order S/N",
01383                         "%f13.6"));
01384       }
01385 #endif
01386 
01387  cleanup:
01388   return;
01389 }
01390 

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