uves_mdark_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 02110-1301 USA          *
00018  */
00019  
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2011/01/03 08:39:09 $
00023  * $Revision: 1.53 $
00024  * $Name: uves-4_9_1 $
00025  * $Log: uves_mdark_impl.c,v $
00026  * Revision 1.53  2011/01/03 08:39:09  amodigli
00027  * fixed error computing QC with uves_cal_mkmaster (DFS09854)
00028  *
00029  * Revision 1.52  2010/12/16 16:57:40  amodigli
00030  * fixed compiler warnings
00031  *
00032  * Revision 1.51  2010/09/27 06:32:41  amodigli
00033  * fixed mem leaks
00034  *
00035  * Revision 1.50  2010/09/24 09:32:03  amodigli
00036  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
00037  *
00038  * Revision 1.48  2010/06/11 11:40:00  amodigli
00039  * add uves_qcdark_define_parameters_body(), uves_mdark_define_qc_parameters()
00040  *
00041  * Revision 1.47  2010/06/08 13:51:55  amodigli
00042  * cleaned output
00043  *
00044  * Revision 1.46  2010/05/14 12:47:40  amodigli
00045  * set range on several params that control QC
00046  *
00047  * Revision 1.45  2010/05/11 05:49:02  amodigli
00048  * clarified recipe help
00049  *
00050  * Revision 1.44  2010/03/24 14:56:30  amodigli
00051  * fixed compiler warning
00052  *
00053  * Revision 1.43  2010/03/22 15:57:43  amodigli
00054  * added params and possibility to compute master as mean stack
00055  *
00056  * Revision 1.42  2010/03/01 18:00:22  amodigli
00057  * fixed several bugs in computing QC parameters
00058  *
00059  * Revision 1.41  2008/11/06 14:36:27  amodigli
00060  * fixed mem leaks
00061  *
00062  * Revision 1.40  2008/09/29 06:57:03  amodigli
00063  * add #include <string.h>
00064  *
00065  * Revision 1.39  2008/03/28 08:53:50  amodigli
00066  * IRPLIB_CONCAT2X-->UVES_CONCAT2X
00067  *
00068  * Revision 1.38  2008/02/15 12:43:49  amodigli
00069  * allow lower/upper chip for parameter process_chip
00070  *
00071  * Revision 1.37  2007/10/05 16:01:45  amodigli
00072  * using proces_chip parameter to process or not a given RED chip
00073  *
00074  * Revision 1.36  2007/08/31 06:27:02  amodigli
00075  * include uves_globals.h
00076  *
00077  * Revision 1.35  2007/08/24 08:28:36  amodigli
00078  * clearer parm doc
00079  *
00080  * Revision 1.34  2007/08/24 06:55:36  amodigli
00081  * fixed parameter io for qc
00082  *
00083  * Revision 1.33  2007/08/21 13:08:26  jmlarsen
00084  * Removed irplib_access module, largely deprecated by CPL-4
00085  *
00086  * Revision 1.32  2007/08/17 10:07:02  amodigli
00087  * added QC params asked by DFS04195
00088  *
00089  * Revision 1.31  2007/06/11 13:28:26  jmlarsen
00090  * Changed recipe contact address to cpl at eso.org
00091  *
00092  * Revision 1.30  2007/06/08 13:06:16  jmlarsen
00093  * Send bug reports to Andrea
00094  *
00095  * Revision 1.29  2007/06/06 08:17:33  amodigli
00096  * replace tab with 4 spaces
00097  *
00098  * Revision 1.28  2007/05/16 09:50:40  jmlarsen
00099  * Do not threshold to zero after bias subtraction
00100  *
00101  * Revision 1.27  2007/04/24 12:50:29  jmlarsen
00102  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00103  *
00104  * Revision 1.26  2007/02/09 13:37:47  jmlarsen
00105  * Enable calling from uves_cal_mkmaster
00106  *
00107  * Revision 1.25  2007/02/09 08:57:44  jmlarsen
00108  * Include <float.h>
00109  *
00110  * Revision 1.24  2007/02/09 08:14:16  jmlarsen
00111  * Do not use CPL_PIXEL_MAXVAL which works only for integer images
00112  *
00113  * Revision 1.23  2006/12/07 08:23:23  jmlarsen
00114  * uves_load_raw_imagelist: support FLAMES
00115  *
00116  * Revision 1.22  2006/11/15 15:02:14  jmlarsen
00117  * Implemented const safe workarounds for CPL functions
00118  *
00119  * Revision 1.20  2006/11/15 14:04:08  jmlarsen
00120  * Removed non-const version of parameterlist_get_first/last/next which is
00121  * already in CPL, added const-safe wrapper, unwrapper and deallocator functions
00122  *
00123  * Revision 1.19  2006/11/06 15:19:41  jmlarsen
00124  * Removed unused include directives
00125  *
00126  * Revision 1.18  2006/10/17 12:33:02  jmlarsen
00127  * Added semicolon at UVES_RECIPE_DEFINE invocation
00128  *
00129  * Revision 1.17  2006/10/09 13:01:13  jmlarsen
00130  * Use macro to define recipe interface functions
00131  *
00132  * Revision 1.16  2006/09/19 14:31:17  jmlarsen
00133  * uves_insert_frame(): use bitmap to specify which image statistics keywords must be computed
00134  *
00135  * Revision 1.15  2006/09/19 06:55:55  jmlarsen
00136  * Changed interface of uves_frameset to optionally write image statistics kewwords
00137  *
00138  * Revision 1.14  2006/08/24 11:36:37  jmlarsen
00139  * Write recipe start/stop time to header
00140  *
00141  * Revision 1.13  2006/08/17 13:56:53  jmlarsen
00142  * Reduced max line length
00143  *
00144  * Revision 1.12  2006/08/11 14:56:05  amodigli
00145  * removed Doxygen warnings
00146  *
00147  * Revision 1.11  2006/07/14 12:19:28  jmlarsen
00148  * Support multiple QC tests per product
00149  *
00150  * Revision 1.10  2006/07/03 13:02:18  jmlarsen
00151  * Threshold to zero after bias subtraction
00152  *
00153  * Revision 1.9  2006/06/28 13:29:06  amodigli
00154  * removed TEST ID from QC log
00155  *
00156  * Revision 1.8  2006/06/16 08:25:45  jmlarsen
00157  * Manually propagate ESO.DET. keywords from 1st/2nd input header
00158  *
00159  * Revision 1.7  2006/06/13 11:57:02  jmlarsen
00160  * Check that calibration frames are from the same chip ID
00161  *
00162  * Revision 1.6  2006/06/01 14:43:17  jmlarsen
00163  * Added missing documentation
00164  *
00165  * Revision 1.5  2006/05/09 07:42:18  amodigli
00166  * added QC-LOG
00167  *
00168  * Revision 1.4  2006/04/06 12:57:22  jmlarsen
00169  * Added support for PDARK, MASTER_PDARK frames
00170  *
00171  * Revision 1.3  2006/04/06 09:48:15  amodigli
00172  * changed uves_frameset_insert interface to have QC log
00173  *
00174  * Revision 1.2  2006/04/06 08:37:33  jmlarsen
00175  * Removed memory leak
00176  *
00177  * Revision 1.1  2006/02/03 07:46:30  jmlarsen
00178  * Moved recipe implementations to ./uves directory
00179  *
00180  * Revision 1.27  2006/01/19 08:47:24  jmlarsen
00181  * Insertedv missing doxygen end tag
00182  *
00183  * Revision 1.26  2005/12/19 16:17:55  jmlarsen
00184  * Replaced bool -> int
00185  *
00186  */
00187 
00188 #ifdef HAVE_CONFIG_H
00189 #  include <config.h>
00190 #endif
00191 
00192 /*----------------------------------------------------------------------------*/
00199 /*----------------------------------------------------------------------------*/
00200 
00201 /*-----------------------------------------------------------------------------
00202                                 Includes
00203  -----------------------------------------------------------------------------*/
00204 #include <uves_mdark_impl.h>
00205 
00206 #include <uves_parameters.h>
00207 #include <uves_utils.h>
00208 #include <uves.h>
00209 #include <uves_dfs.h>
00210 #include <uves_pfits.h>
00211 #include <uves_qclog.h>
00212 #include <uves_recipe.h>
00213 #include <uves_utils_wrappers.h>
00214 #include <uves_error.h>
00215 #include <uves_globals.h>
00216 
00217 #include <cpl.h>
00218 #include <float.h>
00219 #include <string.h>
00220 /*-----------------------------------------------------------------------------
00221                             Functions prototypes
00222  -----------------------------------------------------------------------------*/
00223 /*
00224 static int
00225 uves_qcdark_define_parameters_body(cpl_parameterlist *parameters, 
00226                    const char *recipe_id);
00227 */
00228 static int
00229 uves_mdark_define_parameters(cpl_parameterlist *parameters);
00230 
00231 static void uves_mdark_region_qc(cpl_image* img, 
00232                                  const cpl_parameterlist* p,
00233                                  const cpl_imagelist* raw_images,
00234                  const char* recipe_id,
00235                                  cpl_table* qclog);
00236 static cpl_image *
00237 uves_mdark_process_chip(const cpl_imagelist *raw_images, 
00238             uves_propertylist **raw_headers,
00239             const cpl_image *master_bias,
00240             uves_propertylist *mdark_header, 
00241             const cpl_parameterlist *parameters,
00242             const char* recipe_id,
00243                         cpl_table* qclog, const int do_qc);
00244 
00245 
00246 /*-----------------------------------------------------------------------------
00247                             Recipe standard code
00248  -----------------------------------------------------------------------------*/
00249 #define cpl_plugin_get_info uves_mdark_get_info
00250 UVES_RECIPE_DEFINE(
00251     UVES_MDARK_ID, UVES_MDARK_DOM, 
00252     /* Warning: if more parameters are added to this recipe, they 
00253        need to be propagated to uves_cal_mkmaster! */
00254     uves_mdark_define_parameters,
00255     "Jonas M. Larsen", "cpl@eso.org",
00256     "Creates the master dark frame",
00257     "This recipe creates a master dark frame by taking the median of all\n"
00258     "input frames which should have identical exposure times. Symbolically,\n"
00259     "   masterdark = median( dark_i ) - masterbias\n"
00260     "\n"
00261     "The input dark frames must have same tag and size and must be either\n"
00262     "(P)DARK_BLUE or (P)DARK_RED. Also, a master bias (MASTER_BIAS_xxxx) must\n"
00263     "be provided for each chip (xxxx = BLUE, REDL, REDU).\n"
00264     "\n"
00265     "On blue input the recipe computes one master dark frame; on red input the\n"
00266     "recipe produces a master dark frame for each chip (MASTER_(P)DARK_xxxx).\n");
00267 
00269 /*-----------------------------------------------------------------------------
00270                             Functions code
00271  -----------------------------------------------------------------------------*/
00272 
00273 
00274 
00275 /*----------------------------------------------------------------------------*/
00281 /*----------------------------------------------------------------------------*/
00282 static cpl_error_code
00283 uves_extract_basic_parameters_for_qc(const cpl_parameterlist* p,
00284                                      const char* recipe_id,
00285                                      int * pr_num_x, 
00286                                      int* pr_num_y, 
00287                                      int* pr_box_sx, 
00288                                      int* pr_box_sy)
00289 {
00290 
00291   char name[MAX_NAME_SIZE];
00292   char pname[MAX_NAME_SIZE];
00293 
00294   sprintf(name,"reg.num_x");
00295   sprintf(pname,"%s.%s", UVES_QCDARK_ID, name);
00296   uves_msg("pname=%s",pname);
00297   check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,pr_num_x), 
00298     "Could not read parameter");
00299 
00300   sprintf(name,"reg.num_y");
00301   sprintf(pname,"%s.%s", UVES_QCDARK_ID, name);
00302   check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,pr_num_y), 
00303      "Could not read parameter");
00304 
00305   sprintf(name,"reg.box_sx");
00306   sprintf(pname,"%s.%s", UVES_QCDARK_ID, name);
00307   check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,pr_box_sx),
00308      "Could not read parameter");
00309 
00310   sprintf(name,"reg.box_sy");
00311   sprintf(pname,"%s.%s", UVES_QCDARK_ID, name);
00312   check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,pr_box_sy),
00313      "Could not read parameter");
00314 
00315   cleanup:
00316   return cpl_error_get_code();
00317 
00318 }
00319 
00320 
00321 
00322 
00323 
00324 
00325 /*----------------------------------------------------------------------------*/
00331 /*----------------------------------------------------------------------------*/
00332 static int
00333 uves_mdark_define_parameters(cpl_parameterlist *parameters)
00334 {
00335   if (uves_master_stack_define_parameters(parameters,
00336                                            make_str(UVES_MDARK_ID))
00337         != CPL_ERROR_NONE)
00338         {
00339             return -1;
00340         }
00341 
00342     return uves_qcdark_define_parameters_body(parameters, 
00343                          make_str(UVES_MDARK_ID));
00344 }
00345 
00346 /*----------------------------------------------------------------------------*/
00353 /*----------------------------------------------------------------------------*/
00354 int
00355 uves_qcdark_define_parameters_body(cpl_parameterlist *parameters, 
00356                   const char *recipe_id)
00357 {
00358     /*****************
00359      *    General    *
00360      *****************/
00361     if (uves_define_global_parameters(parameters) != CPL_ERROR_NONE)
00362     {
00363         return -1;
00364     }
00365 
00366     if (uves_master_stack_define_parameters(parameters,recipe_id) 
00367         != CPL_ERROR_NONE)
00368         {
00369             return -1;
00370         }
00371 
00372     
00373     /****************************
00374      *  Spline back.sub.        *
00375      ****************************/
00376     
00377     if (uves_propagate_parameters_step(UVES_QCDARK_ID, parameters, 
00378                        recipe_id, NULL) != 0)
00379     {
00380         return -1;
00381     }
00382 
00383     return (cpl_error_get_code() != CPL_ERROR_NONE);
00384 }
00385 
00386 
00387 
00388 /*----------------------------------------------------------------------------*/
00397 /*----------------------------------------------------------------------------*/
00398 cpl_error_code 
00399 uves_mdark_define_qc_parameters(cpl_parameterlist* parameters)
00400 {
00401   
00402     const char *name = "";
00403     char *full_name = NULL;
00404     cpl_parameter *p = NULL;
00405     
00406     {
00407    
00408       name = "reg.num_x";
00409       full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID, name);
00410       uves_parameter_new_range(p, full_name,
00411                    CPL_TYPE_INT,
00412                    "Number of regions along the X axis "
00413                                "(where mean/med/rms are computed). ",
00414                    UVES_QCDARK_ID,
00415                    4,0,INT_MAX);
00416 
00417       cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name );
00418       cpl_parameterlist_append(parameters, p);
00419       cpl_free(full_name);
00420 
00421 
00422 
00423       name = "reg.num_y";
00424       full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID,name);
00425       uves_parameter_new_range(p, full_name,
00426                    CPL_TYPE_INT,
00427                    "Number of regions along the Y axis"
00428                                "(where mean/med/rms are computed). ",
00429                    UVES_QCDARK_ID,
00430                    4,0,INT_MAX);
00431 
00432       cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00433       cpl_parameterlist_append(parameters, p);
00434       cpl_free(full_name);
00435 
00436 
00437 
00438       name = "reg.box_sx";
00439       full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID,name);
00440       uves_parameter_new_range(p, full_name,
00441                    CPL_TYPE_INT,
00442                    "Region X size [pix]",
00443                    UVES_QCDARK_ID,
00444                    100,0,INT_MAX);
00445       cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00446       cpl_parameterlist_append(parameters, p);
00447       cpl_free(full_name);
00448 
00449 
00450       name = "reg.box_sy";
00451       full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID,name);
00452       uves_parameter_new_range(p, full_name,
00453                    CPL_TYPE_INT,
00454                    "Region Y size [pix]",
00455                    UVES_QCDARK_ID,
00456                    100,0,INT_MAX);
00457       cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00458       cpl_parameterlist_append(parameters, p);
00459       cpl_free(full_name);
00460 
00461       name = "reg.border_x";
00462       full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID,name);
00463       uves_parameter_new_range(p, full_name,
00464                    CPL_TYPE_INT,
00465                    "X distance between the left hand side "
00466                                "of the detector and the left hand side "
00467                                "of the region [pix]",
00468                    UVES_QCDARK_ID,
00469                    100,0,INT_MAX);
00470       cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00471       cpl_parameterlist_append(parameters, p);
00472       cpl_free(full_name);
00473 
00474 
00475       name = "reg.border_y";
00476       full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID,name);
00477       uves_parameter_new_range(p, full_name,
00478                    CPL_TYPE_INT,
00479                    "X distance between the left hand side "
00480                                "of the detector and the left hand side "
00481                                "of the region [pix]",
00482                    UVES_QCDARK_ID,
00483                    100,0,INT_MAX);
00484       cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00485       cpl_parameterlist_append(parameters, p);
00486       cpl_free(full_name);
00487 
00488 
00489 
00490       name = "reg.when";
00491       full_name = uves_sprintf("%s.%s", UVES_QCDARK_ID,name);
00492       uves_parameter_new_enum(p, full_name,
00493                    CPL_TYPE_INT,
00494                    "When QC analysis is performed. "
00495                                "0: on each raw frame or "
00496                                "1: on the master frame",
00497                    UVES_QCDARK_ID,
00498                   0,2,0,1);
00499       cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name);
00500       cpl_parameterlist_append(parameters, p);
00501       cpl_free(full_name);
00502 
00503 
00504     }
00505     
00506     if (cpl_error_get_code() != CPL_ERROR_NONE)
00507     {
00508         cpl_msg_error(__func__, "Creation of mdark parameters failed: '%s'", 
00509               cpl_error_get_where());
00510         cpl_parameterlist_delete(parameters);
00511     }
00512     return cpl_error_get_code();
00513 }
00514 
00515 
00516 /*----------------------------------------------------------------------------*/
00524 /*----------------------------------------------------------------------------*/
00525 cpl_parameterlist *
00526 uves_qcdark_define_parameters(void)
00527 {
00528   
00529     cpl_parameterlist *parameters = NULL;
00530     
00531     parameters = cpl_parameterlist_new();
00532 
00533     check(uves_mdark_define_qc_parameters(parameters),
00534           "Error defining mdark qc parameters");
00535 
00536 
00537   cleanup:  
00538     if (cpl_error_get_code() != CPL_ERROR_NONE)
00539     {
00540         cpl_msg_error(__func__, "Creation of mdark parameters failed: '%s'", 
00541               cpl_error_get_where());
00542         cpl_parameterlist_delete(parameters);
00543         return NULL;
00544     } else {
00545        return parameters;
00546     }
00547 }
00548 
00549 
00550 
00551 
00552 
00553 /*----------------------------------------------------------------------------*/
00573 /*----------------------------------------------------------------------------*/
00574 static cpl_image *
00575 uves_mdark_process_chip(const cpl_imagelist *raw_images, 
00576                         uves_propertylist **raw_headers, 
00577                         const cpl_image *master_bias,
00578                 uves_propertylist *mdark_header, 
00579             const cpl_parameterlist *parameters,
00580             const char* recipe_id,
00581             cpl_table* qclog,const int do_qc)
00582 {
00583    cpl_image *master_dark        = NULL; /* Result */
00584    cpl_image *current_dark       = NULL;
00585    cpl_imagelist *preproc_images = NULL;
00586    double min_exptime = 0;
00587    double max_exptime = 0;
00588    int i;
00589    //char name[MAX_NAME_SIZE];
00590    //char pname[MAX_NAME_SIZE];
00591 
00592    int pr_num_x=4;
00593    int pr_num_y=4;
00594    int pr_box_sx=100;
00595    int pr_box_sy=100;
00596    const char* STACK_METHOD=NULL;
00597    double STACK_KLOW=0;
00598    double STACK_KHIGH=0;
00599    int STACK_NITER=0;
00600 
00601 /* check critical QC parameters to see if QC need to be computed or not */
00602 
00603    check_nomsg(uves_extract_basic_parameters_for_qc(parameters,recipe_id,
00604                                                     &pr_num_x,&pr_num_y, 
00605                                                     &pr_box_sx,&pr_box_sy));
00606 
00607 /* parameters for stacking */
00608     check( uves_get_parameter(parameters, NULL, recipe_id, "stack_method", CPL_TYPE_STRING, &STACK_METHOD),
00609                "Could not read parameter");
00610 
00611     uves_string_toupper((char*)STACK_METHOD);
00612 
00613     check( uves_get_parameter(parameters, NULL, recipe_id, "klow", CPL_TYPE_DOUBLE, &STACK_KLOW),
00614                "Could not read parameter");
00615     check( uves_get_parameter(parameters, NULL, recipe_id, "khigh", CPL_TYPE_DOUBLE, &STACK_KHIGH),
00616                "Could not read parameter");
00617     check( uves_get_parameter(parameters, NULL, recipe_id, "niter", CPL_TYPE_INT, &STACK_NITER),
00618                "Could not read parameter");
00619 
00620 
00621 
00622     /* First process each input image and store the results in a 
00623        new image list */
00624 
00625     preproc_images = cpl_imagelist_new();
00626     for (i = 0; i < cpl_imagelist_get_size(raw_images); i++)
00627     {
00628         double exposure_time = 0.0;
00629         const uves_propertylist *current_header;
00630         
00631         current_dark = cpl_image_duplicate(cpl_imagelist_get_const(raw_images, i));
00632         current_header = raw_headers[i];
00633                 
00634         /* Subtract master bias */
00635         if (master_bias != NULL)
00636         {
00637             uves_msg("Subtracting master bias");
00638             check( uves_subtract_bias(current_dark, master_bias), 
00639                "Error subtracting master bias");
00640 
00641                     if (false) {
00642             uves_msg_debug("Thresholding to non-negative values");
00643             check( cpl_image_threshold(current_dark, 
00644                            0, DBL_MAX,     /* Interval */
00645                            0, DBL_MAX),    /* New values */
00646                "Error thresholding image");
00647                     }
00648         }
00649         else
00650         {
00651             uves_msg("Skipping bias subtraction");
00652         }
00653         
00654         check( exposure_time = uves_pfits_get_exptime(current_header), 
00655            "Error reading exposure time");
00656 
00657         if(pr_num_x != 0 && pr_num_y != 0 && pr_box_sx != 0 && pr_box_sy !=0 ) {
00658         if(do_qc == 0) {
00659       uves_msg("Calculating QC parameters on raw dark frame %d",i);
00660           uves_mdark_region_qc(current_dark,parameters,raw_images,recipe_id,qclog);
00661     }
00662 
00663         }
00664         /* Initialize/update min/max exposure time*/
00665         if (i == 0 || exposure_time < min_exptime)
00666         {
00667             min_exptime = exposure_time;
00668         }
00669         if (i == 0 || exposure_time > max_exptime)
00670         {
00671             max_exptime = exposure_time;
00672         }
00673 
00674         /* Do not normalize to unit exposure time */
00675 /*        If this is uncommented, then remember to also calculate the
00676         correct master dark exposure time below.
00677             uves_msg("Normalizing from %f s to unit exposure time", exposure_time);
00678         check( cpl_image_divide_scalar(current_dark, exposure_time), 
00679         "Error normalizing dark frame");   */        
00680 
00681         /* Append to imagelist */
00682         check( cpl_imagelist_set(preproc_images,
00683                      current_dark,  
00684                      i),            /* Position (number_of_images=>append) */
00685            "Could not insert image into image list");
00686         
00687         /* Don't deallocate the image. It will be deallocated when
00688            the image list is deallocated */
00689         current_dark = NULL;
00690     }
00691 
00692     /* Check exposure times */
00693     uves_msg("Exposure times range from %e s to %e s (%e %% variation)", 
00694             min_exptime,
00695             max_exptime,
00696             100 * (max_exptime - min_exptime) / min_exptime);
00697 
00698     if ((max_exptime - min_exptime) / min_exptime > .001)
00699     {
00700         uves_msg_warning("Exposure times differ by %e %%", 
00701                  100 * (max_exptime - min_exptime) / min_exptime);
00702     }
00703     
00704     /* Get median stack of input darks */
00705     if(strcmp(STACK_METHOD,"MEDIAN")==0) {
00706        uves_msg("Calculating stack median");
00707        check( master_dark = cpl_imagelist_collapse_median_create(preproc_images), 
00708               "Error computing median");
00709     } else {
00710        uves_msg("Calculating stack mean");
00711        check( master_dark = uves_ksigma_stack(preproc_images,STACK_KLOW,
00712                                               STACK_KHIGH,STACK_NITER),
00713               "Error computing master dark");
00714 
00715     } 
00716     check( uves_pfits_set_exptime(mdark_header, (max_exptime + min_exptime)/2),
00717        "Error setting master dark exposure time");
00718     
00719   cleanup:
00720     uves_free_image(&current_dark);
00721     uves_free_imagelist(&preproc_images);
00722     if (cpl_error_get_code() != CPL_ERROR_NONE)
00723     {
00724         uves_free_image(&master_dark);
00725     }
00726     
00727     return master_dark;
00728 }
00729 
00730 
00731 /*----------------------------------------------------------------------------*/
00738 /*----------------------------------------------------------------------------*/
00739 static void
00740 UVES_CONCAT2X(UVES_MDARK_ID,exe)(cpl_frameset *frames, 
00741                    const cpl_parameterlist *parameters,
00742                    const char *starttime)
00743 {
00744     uves_mdark_exe_body(frames, parameters, starttime, make_str(UVES_MDARK_ID));
00745     return;
00746 }
00747 
00748 /*----------------------------------------------------------------------------*/
00760 /*----------------------------------------------------------------------------*/
00761 void
00762 uves_mdark_exe_body(cpl_frameset *frames, 
00763             const cpl_parameterlist *parameters,
00764             const char *starttime,
00765             const char *recipe_id)
00766 {
00767     /* Function id */
00768     /*
00769      * Variables that will contain the values of the recipe parameters 
00770      */
00771     /* None */
00772 
00773     /* CPL objects */
00774     /* Input */
00775     cpl_imagelist *raw_images[2]       = {NULL, NULL};
00776     uves_propertylist  **raw_headers[2] = {NULL, NULL};    /* Two arrays of pointers */
00777 
00778     /* Master bias */
00779     cpl_image *master_bias               = NULL;
00780     uves_propertylist *master_bias_header = NULL;
00781     
00782     /* Output */
00783     cpl_table* qclog[2] = {NULL, NULL};
00784     cpl_image *master_dark              = NULL;
00785     uves_propertylist *product_header[2] = {NULL, NULL};
00786     
00787     /* Local variables */
00788     char *product_filename = NULL;
00789     const char *product_tag[2] = {NULL, NULL};
00790     bool blue;
00791     enum uves_chip chip;
00792 
00793     const char* pname=NULL;
00794    
00795 
00796     int pr_when=0;
00797     const char* PROCESS_CHIP=NULL;
00798     int pr_num_x=0;
00799     int pr_num_y=0;
00800     int pr_box_sx=0;
00801     int pr_box_sy=0;
00802     bool dump_qc=true;
00803 
00804     /* Load and check raw dark images and headers, identify arm (blue/red) */
00805     /* On success, 'raw_headers' will be an array with the same size as 'raw_images' */
00806     if (cpl_frameset_find(frames, UVES_DARK(true )) != NULL ||
00807     cpl_frameset_find(frames, UVES_DARK(false)) != NULL)
00808     {
00809         check( uves_load_raw_imagelist(frames, 
00810                        false,    /* FLAMES format? */
00811                        UVES_DARK(true), UVES_DARK(false),
00812                        CPL_TYPE_DOUBLE,
00813                        raw_images, raw_headers, product_header, 
00814                        &blue), "Error loading raw dark frames");
00815         
00816         for (chip = uves_chip_get_first(blue); 
00817          chip != UVES_CHIP_INVALID; 
00818          chip = uves_chip_get_next(chip))
00819         {
00820             product_tag[uves_chip_get_index(chip)] = UVES_MASTER_DARK(chip);
00821         }
00822     }
00823     else if (cpl_frameset_find(frames, UVES_PDARK(true )) != NULL ||
00824          cpl_frameset_find(frames, UVES_PDARK(false)) != NULL)
00825     {
00826         check( uves_load_raw_imagelist(frames, 
00827                        false,  /* FLAMES format? */
00828                        UVES_PDARK(true), UVES_PDARK(false),
00829                        CPL_TYPE_DOUBLE,
00830                        raw_images, raw_headers, product_header, 
00831                        &blue), "Error loading raw dark frames");
00832         
00833         for (chip = uves_chip_get_first(blue);
00834          chip != UVES_CHIP_INVALID;
00835          chip = uves_chip_get_next(chip))
00836         {
00837             product_tag[uves_chip_get_index(chip)] = UVES_MASTER_PDARK(chip);
00838         }
00839     }
00840     else
00841     {
00842         assure(false, CPL_ERROR_DATA_NOT_FOUND,
00843            "Missing input dark frame: %s, %s, %s or %s expected",
00844            UVES_DARK(true) , UVES_DARK(false),
00845            UVES_PDARK(true), UVES_PDARK(false));
00846     }
00847 
00848 
00849   
00850    check_nomsg(uves_extract_basic_parameters_for_qc(parameters,recipe_id,
00851                                                     &pr_num_x,&pr_num_y, 
00852                                                     &pr_box_sx,&pr_box_sy));
00853 
00854    if(pr_num_x <=0 || pr_num_y <= 0 || pr_box_sx <=0 || pr_box_sy <= 0) {
00855       dump_qc=false;
00856    }
00857     pname = uves_sprintf("%s.%s", UVES_QCDARK_ID, "reg.when");
00858     check(uves_get_parameter(parameters,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_when), 
00859      "Could not read parameter");
00860   
00861     check( uves_get_parameter(parameters, NULL, "uves", "process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
00862                "Could not read parameter");
00863     uves_string_toupper((char*)PROCESS_CHIP);
00864 
00865 
00866     /* Loop over one or two chips */
00867     for (chip = uves_chip_get_first(blue); 
00868          chip != UVES_CHIP_INVALID; 
00869          chip = uves_chip_get_next(chip))
00870         {
00871 
00872       if(strcmp(PROCESS_CHIP,"REDU") == 0) {
00873     chip = uves_chip_get_next(chip);
00874       }
00875 
00876         const char *master_bias_filename = "";
00877         const char *chip_name = "";
00878         
00879         int raw_index = uves_chip_get_index(chip);
00880         
00881         uves_msg("Processing %s chip",
00882              uves_chip_tostring_upper(chip));
00883 
00884         /* Get chip name of first input frame */
00885         check_nomsg( chip_name = uves_pfits_get_chipid(raw_headers[raw_index][0], chip));
00886 
00887         /* Load master bias, set pointer to NULL if not present */
00888         uves_free_image(&master_bias);
00889         uves_free_propertylist(&master_bias_header);
00890         if (cpl_frameset_find(frames, UVES_MASTER_BIAS(chip)) != NULL)
00891         {
00892             check( uves_load_mbias(frames, chip_name,
00893                        &master_bias_filename, &master_bias, 
00894                        &master_bias_header, chip), 
00895                "Error loading master bias");
00896             
00897             uves_msg_low("Using master bias in '%s'", master_bias_filename);
00898         }
00899         else
00900         {
00901             uves_msg_low("No master bias in SOF. Bias subtraction not done");
00902         }
00903         
00904         /* Process chip */
00905 
00906 
00907 
00908         uves_free_image(&master_dark);
00909     uves_qclog_delete(&qclog[0]);
00910     qclog[0] = uves_qclog_init(raw_headers[raw_index][0], chip);
00911         check( master_dark = uves_mdark_process_chip(raw_images[raw_index], 
00912                              raw_headers[raw_index], 
00913                              master_bias,
00914                              product_header[raw_index],
00915                              parameters,recipe_id,
00916                                                      qclog[0],pr_when),
00917            "Error processing chip");
00918 
00919 
00920         /* Finished. Save */
00921                 /* Finished. Calculate QC parameters and save */
00922         if(pr_when==1) {
00923       uves_msg("Calculating QC parameters on master dark frame");
00924           uves_mdark_region_qc(master_dark,parameters,
00925                    raw_images[raw_index],recipe_id,qclog[0]);
00926 
00927     }
00928 
00929         /* Insert into frame set */
00930         uves_msg("Saving product");
00931         
00932         cpl_free(product_filename);
00933         check( product_filename = uves_masterdark_filename(chip), "Error getting filename");
00934 
00935   
00936         check( uves_frameset_insert(frames,
00937                     master_dark,
00938                     CPL_FRAME_GROUP_PRODUCT,
00939                     CPL_FRAME_TYPE_IMAGE,
00940                     CPL_FRAME_LEVEL_INTERMEDIATE,
00941                     product_filename,
00942                     product_tag[raw_index],
00943                     raw_headers[raw_index][0],
00944                     product_header[raw_index],
00945                     NULL,
00946                     parameters,
00947                     recipe_id,
00948                     PACKAGE "/" PACKAGE_VERSION,qclog,
00949                     starttime, dump_qc, 
00950                     UVES_ALL_STATS), 
00951            "Could not add master dark %s to frameset", product_filename);
00952         uves_msg("Master dark %s added to frameset", product_filename);
00953         uves_qclog_delete(&qclog[0]);
00954 
00955       if(strcmp(PROCESS_CHIP,"REDL") == 0) {
00956     chip = uves_chip_get_next(chip);
00957       }
00958         
00959 
00960     }/* For each chip */
00961 
00962   cleanup:
00963     /* Input */
00964     if (raw_images[0] != NULL)
00965     {
00966         int i;
00967         for (i = 0; i < cpl_imagelist_get_size(raw_images[0]); i++) 
00968         {
00969             if (raw_headers[0] != NULL) uves_free_propertylist(&raw_headers[0][i]);
00970             if (raw_headers[1] != NULL) uves_free_propertylist(&raw_headers[1][i]);
00971         }
00972 
00973         cpl_free(raw_headers[0]); raw_headers[0] = NULL;
00974         cpl_free(raw_headers[1]); raw_headers[1] = NULL;
00975     }
00976 
00977     uves_free_imagelist(&raw_images[0]);
00978     uves_free_imagelist(&raw_images[1]);
00979 
00980     /* Master bias */
00981     uves_free_image(&master_bias);
00982     uves_free_propertylist(&master_bias_header);
00983 
00984     /* Output */
00985     uves_qclog_delete(&qclog[0]);
00986     uves_free_image(&master_dark);
00987     uves_free_propertylist(&product_header[0]);
00988     uves_free_propertylist(&product_header[1]);
00989     cpl_free(product_filename);
00990     uves_free(pname);
00991     return;
00992 }
00993 
00994 
00995 static void 
00996 uves_mdark_region_qc(cpl_image* img, 
00997                      const cpl_parameterlist* p,
00998                      const cpl_imagelist* raw_images,
00999                      const char* recipe_id,
01000                      cpl_table* qclog)
01001 {
01002 
01003   int pr_num_x=4;
01004   int pr_num_y=4;
01005   int pr_box_sx=100;
01006   int pr_box_sy=100;
01007   int pr_border_x=100;
01008   int pr_border_y=100;
01009 
01010 
01011   int i=0;
01012   int j=0;
01013   int llx=0;
01014   int lly=0;
01015   int urx=0;
01016   int ury=0;
01017   int space_x=0;
01018   int space_y=0;
01019   int sx=0;
01020   int sy=0;
01021   int nraw=0;
01022   int raw=0;
01023   char name[MAX_NAME_SIZE];
01024   char pname[MAX_NAME_SIZE];
01025   char qc_key[MAX_NAME_SIZE];
01026   char qc_com[MAX_NAME_SIZE];
01027   double qc_avg=0;
01028   double qc_med=0;
01029   double qc_rms=0;
01030   double qc_min=0;
01031   double qc_max=0;
01032   cpl_table* qc_sto=NULL;
01033  
01034   check_nomsg(uves_extract_basic_parameters_for_qc(p,recipe_id,
01035                                                     &pr_num_x,&pr_num_y, 
01036                                                     &pr_box_sx,&pr_box_sy));
01037 
01038   uves_msg("pr_num_x=%d pr_num_y=%d pr_box_sx=%d pr_box_sy=%d",
01039           pr_num_x,pr_num_y,pr_box_sx,pr_box_sy);
01040 
01041   if(pr_num_x <= 0 || pr_num_y <= 0 || pr_box_sx <= 0 || pr_box_sy <= 0) {
01042      return; 
01043   }
01044  
01045   sprintf(name,"reg.border_x");
01046   sprintf(pname,"%s.%s", UVES_QCDARK_ID, name);
01047   check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_border_x),
01048      "Could not read parameter");
01049 
01050   sprintf(name,"reg.border_y");
01051   sprintf(pname,"%s.%s", UVES_QCDARK_ID, name);
01052   check(uves_get_parameter(p,NULL,recipe_id,pname,CPL_TYPE_INT,&pr_border_y),
01053      "Could not read parameter");
01054 
01055 
01056   check_nomsg(nraw=cpl_imagelist_get_size(raw_images));
01057   check_nomsg(uves_qclog_add_int(qclog,
01058                         "PRO DATANCOM",
01059                         nraw,
01060                         "Number of frames combined",
01061                         "%d"));
01062 
01063   sx=cpl_image_get_size_x(img);
01064   sy=cpl_image_get_size_y(img);
01065   space_x=(int)((sx-2*pr_border_x)/pr_num_x);
01066   space_y=(int)((sy-2*pr_border_y)/pr_num_y);
01067   qc_sto=cpl_table_new(pr_num_x*pr_num_y);
01068   cpl_table_new_column(qc_sto,"MIN",CPL_TYPE_DOUBLE);
01069   cpl_table_new_column(qc_sto,"MAX",CPL_TYPE_DOUBLE);
01070   cpl_table_new_column(qc_sto,"AVG",CPL_TYPE_DOUBLE);
01071   cpl_table_new_column(qc_sto,"MED",CPL_TYPE_DOUBLE);
01072   cpl_table_new_column(qc_sto,"RMS",CPL_TYPE_DOUBLE);
01073 
01074   for(i=0;i<pr_num_x;i++) {
01075     llx=pr_border_x+i*space_x;
01076     urx=llx+pr_box_sx;
01077 
01078     llx=(llx>0) ? llx:1;
01079     urx=(urx<=sx) ? urx:sx;
01080 
01081     for(j=0;j<pr_num_y;j++) {
01082       lly=pr_border_y+j*space_y;
01083       ury=lly+pr_box_sy;
01084 
01085       lly=(lly>0) ? lly:1;
01086       ury=(ury<=sy) ? ury:sy;
01087 
01088       raw=i*pr_num_y+j;
01089       check_nomsg(qc_min=cpl_image_get_min_window(img,llx,lly,urx,ury));
01090       qc_max=cpl_image_get_min_window(img,llx,lly,urx,ury);
01091       qc_avg=cpl_image_get_mean_window(img,llx,lly,urx,ury);
01092       qc_med=cpl_image_get_median_window(img,llx,lly,urx,ury);
01093       qc_rms=cpl_image_get_stdev_window(img,llx,lly,urx,ury);
01094       uves_msg_debug("QC on area [%d,%d:%d,%d]. Min %g Max %g Avg %g Med %g Rms %g",
01095            llx,lly,urx,ury,qc_min,qc_max,qc_avg,qc_med,qc_rms);
01096 
01097       sprintf(qc_key,"%s%d%d%s","QC REG",i,j," MIN");
01098       sprintf(qc_com,"%s%d%d","Min of region [%d,%d]",i,j);
01099       check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
01100       check_nomsg(cpl_table_set_double(qc_sto,"MIN",raw,qc_min));
01101 
01102       sprintf(qc_key,"%s%d%d%s","QC REG",i,j," MAX");
01103       sprintf(qc_com,"%s%d%d","Max of region [%d,%d]",i,j);
01104       check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
01105       check_nomsg(cpl_table_set_double(qc_sto,"MAX",raw,qc_max));
01106 
01107       sprintf(qc_key,"%s%d%d%s","QC REG",i,j," AVG");
01108       sprintf(qc_com,"%s%d%d","Mean of region [%d,%d]",i,j);
01109       check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
01110       check_nomsg(cpl_table_set_double(qc_sto,"AVG",raw,qc_avg));
01111 
01112       sprintf(qc_key,"%s%d%d%s","QC REG",i,j," MED");
01113       sprintf(qc_com,"%s%d%d","Median of region [%d,%d]",i,j);
01114       check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
01115       check_nomsg(cpl_table_set_double(qc_sto,"MED",raw,qc_med));
01116 
01117       sprintf(qc_key,"%s%d%d%s","QC REG",i,j," RMS");
01118       sprintf(qc_com,"%s%d%d","Rms of region [%d,%d]",i,j);
01119       check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
01120       check_nomsg(cpl_table_set_double(qc_sto,"RMS",raw,qc_rms));
01121 
01122 
01123     }
01124   }
01125 
01126 
01127   check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"MIN"));
01128   check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"MIN"));
01129   check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"MIN"));
01130   check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"MIN"));
01131   check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"MIN"));
01132 
01133   sprintf(qc_key,"%s","QC REG MIN MIN");
01134   sprintf(qc_com,"%s","Min of all Mins");
01135   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
01136 
01137   sprintf(qc_key,"%s","QC REG MIN MAX");
01138   sprintf(qc_com,"%s","Max of all Mins");
01139   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
01140 
01141   sprintf(qc_key,"%s","QC REG MIN AVG");
01142   sprintf(qc_com,"%s","Mean of all Mins");
01143   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
01144 
01145   sprintf(qc_key,"%s","QC REG MIN MED");
01146   sprintf(qc_com,"%s","Median of all Mins");
01147   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
01148 
01149   sprintf(qc_key,"%s","QC REG MIN RMS");
01150   sprintf(qc_com,"%s","Rms of all Mins");
01151   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
01152 
01153 
01154 
01155   check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"MAX"));
01156   check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"MAX"));
01157   check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"MAX"));
01158   check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"MAX"));
01159   check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"MAX"));
01160 
01161   sprintf(qc_key,"%s","QC REG MAX MIN");
01162   sprintf(qc_com,"%s","Min of all Maxs");
01163   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
01164 
01165   sprintf(qc_key,"%s","QC REG MAX MAX");
01166   sprintf(qc_com,"%s","Max of all Maxs");
01167   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
01168 
01169   sprintf(qc_key,"%s","QC REG MAX AVG");
01170   sprintf(qc_com,"%s","Mean of all Maxs");
01171   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
01172 
01173   sprintf(qc_key,"%s","QC REG MAX MED");
01174   sprintf(qc_com,"%s","Median of all Maxs");
01175   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
01176 
01177   sprintf(qc_key,"%s","QC REG MAX RMS");
01178   sprintf(qc_com,"%s","Rms of all Maxs");
01179   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
01180 
01181 
01182   check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"AVG"));
01183   check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"AVG"));
01184   check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"AVG"));
01185   check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"AVG"));
01186   check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"AVG"));
01187 
01188   sprintf(qc_key,"%s","QC REG AVG MIN");
01189   sprintf(qc_com,"%s","Min of all Means");
01190   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
01191 
01192   sprintf(qc_key,"%s","QC REG AVG MAX");
01193   sprintf(qc_com,"%s","Max of all Means");
01194   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
01195 
01196   sprintf(qc_key,"%s","QC REG AVG AVG");
01197   sprintf(qc_com,"%s","Mean of all Means");
01198   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
01199 
01200   sprintf(qc_key,"%s","QC REG AVG MED");
01201   sprintf(qc_com,"%s","Median of all Means");
01202   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
01203 
01204   sprintf(qc_key,"%s","QC REG AVG RMS");
01205   sprintf(qc_com,"%s","Rms of all Means");
01206   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
01207 
01208 
01209   check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"MED"));
01210   check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"MED"));
01211   check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"MED"));
01212   check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"MED"));
01213   check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"MED"));
01214 
01215   sprintf(qc_key,"%s","QC REG MED MIN");
01216   sprintf(qc_com,"%s","Min of all Medians");
01217   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
01218 
01219   sprintf(qc_key,"%s","QC REG MED MAX");
01220   sprintf(qc_com,"%s","Max of all Medians");
01221   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
01222 
01223   sprintf(qc_key,"%s","QC REG MED AVG");
01224   sprintf(qc_com,"%s","Mean of all Medians");
01225   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
01226 
01227   sprintf(qc_key,"%s","QC REG MED MED");
01228   sprintf(qc_com,"%s","Median of all Medians");
01229   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
01230 
01231   sprintf(qc_key,"%s","QC REG MED RMS");
01232   sprintf(qc_com,"%s","Rms of all Medians");
01233   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
01234 
01235 
01236   check_nomsg(qc_min=cpl_table_get_column_min(qc_sto,"RMS"));
01237   check_nomsg(qc_max=cpl_table_get_column_max(qc_sto,"RMS"));
01238   check_nomsg(qc_avg=cpl_table_get_column_mean(qc_sto,"RMS"));
01239   check_nomsg(qc_med=cpl_table_get_column_median(qc_sto,"RMS"));
01240   check_nomsg(qc_rms=cpl_table_get_column_stdev(qc_sto,"RMS"));
01241 
01242 
01243   sprintf(qc_key,"%s","QC REG RMS MIN");
01244   sprintf(qc_com,"%s","Min of all Rms");
01245   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_min,qc_com,"%g"));
01246 
01247   sprintf(qc_key,"%s","QC REG RMS MAX");
01248   sprintf(qc_com,"%s","Max of all Rms");
01249   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_max,qc_com,"%g"));
01250 
01251   sprintf(qc_key,"%s","QC REG RMS AVG");
01252   sprintf(qc_com,"%s","Mean of all Rms");
01253   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_avg,qc_com,"%g"));
01254 
01255   sprintf(qc_key,"%s","QC REG RMS MED");
01256   sprintf(qc_com,"%s","Median of all Rms");
01257   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_med,qc_com,"%g"));
01258 
01259   sprintf(qc_key,"%s","QC REG RMS RMS");
01260   sprintf(qc_com,"%s","Rms of all Rms");
01261   check_nomsg(uves_qclog_add_double(qclog,qc_key,qc_rms,qc_com,"%g"));
01262 
01263 
01264 
01265 
01266  cleanup:
01267   uves_free_table(&qc_sto);
01268 
01269   return;
01270 
01271 }
01272 
01273 

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