sinfo_new_dark.c

00001 /*
00002  * This file is part of the ESO SINFONI Pipeline
00003  * Copyright (C) 2004,2005 European Southern Observatory
00004  *
00005  * This program 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    File name    :       sinfo_new_dark.c
00022    Author       :   A. Modigliani
00023    Created on   :   Sep 17, 2003
00024    Description  :   Master sinfo_dark creation 
00025 
00026  ---------------------------------------------------------------------------*/
00027 #ifdef HAVE_CONFIG_H
00028 #  include <config.h>
00029 #endif
00030 
00031 /*----------------------------------------------------------------------------
00032                                 Includes
00033  ---------------------------------------------------------------------------*/
00034 #include "sinfo_new_dark.h"
00035 #include "sinfo_utilities.h"
00036 #include "sinfo_pro_save.h"
00037 #include "sinfo_dark_ini_by_cpl.h"
00038 #include "sinfo_dfs.h"
00039 #include "sinfo_pfits.h"
00040 #include "sinfo_error.h"
00041 #include "sinfo_utils_wrappers.h"
00042 /*----------------------------------------------------------------------------
00043                                 Defines
00044  ---------------------------------------------------------------------------*/
00045 static int sinfo_dark_ron_reduce(cpl_frameset * framelist,
00046                             dark_config* cfg,
00047                             cpl_table* qclog);
00048 
00049 
00050 static int sinfo_dark_compare(cpl_frame   *   frame1,cpl_frame   *   frame2);
00051 
00061 /*----------------------------------------------------------------------------
00062                              Function Definitions
00063  ---------------------------------------------------------------------------*/
00064 
00065 /*----------------------------------------------------------------------------
00066    @name  sinfo_new_dark()
00067    @param  plugin_id recipe id
00068    @param  config input parameterlist
00069    @param  sof    input set of frames
00070    @return integer (0 if it worked, -1 if it doesn't) 
00071    @doc 
00072                   1) Sorts frames according to integration time
00073                   2) Take the clean mean of a stack of frames with the 
00074                   same integration time
00075 
00076  ---------------------------------------------------------------------------*/
00077 
00078 int sinfo_new_dark (const char* plugin_id, cpl_parameterlist* config, 
00079           cpl_frameset* sof, char* dark_name)
00080 {
00081     
00082     dark_config * cfg=NULL ;
00083     cpl_imagelist * image_list=NULL ;
00084     cpl_imagelist * object_list=NULL ;
00085 
00086    
00087     cpl_image * image=NULL ;
00088     cpl_image * eclipse_image=NULL ;
00089 
00090     cpl_image* dark_img=NULL;
00091     cpl_frame* first_frame=NULL;
00092     cpl_vector* qc_dark_median=NULL;
00093     cpl_frameset* raw=NULL;
00094     cpl_table* qclog_tbl=NULL;
00095     cpl_propertylist* rplist=NULL;
00096     cpl_frameset* f_one=NULL;
00097     int no=0;
00098     float lo_cut=0.;
00099     float hi_cut=0.;
00100 
00101     int i = 0;
00102     int j = 0;
00103     int n = 0;
00104     int count = 0;
00105     int* n_times=NULL;
00106     double exp_time = 0.;    
00107     float* int_time=NULL;   
00108     float time_val = 0.; 
00109 
00110     char   ref_file[MAX_NAME_SIZE];
00111     int zone_def[4];
00112     double qc_ron_val=0;
00113     double qc_ron_err=0;
00114     double qc_darkmed_ave=0;
00115     double qc_darkmed_stdev=0;
00116     double fpn=0;
00117     int zone[4];
00118     int naxis1=0;
00119     int naxis2=0;
00120 
00121     int* selection=NULL;
00122     int nsets=0;
00123     /* 
00124        -----------------------------------------------------------------
00125        1) parse the file names and parameters to the dark_config data 
00126           structure cfg 
00127        -----------------------------------------------------------------
00128      */
00129  
00130     check_nomsg(raw=cpl_frameset_new());
00131     cknull(cfg = sinfo_parse_cpl_input_dark(config,sof,&raw),
00132            "could not parse cpl input!") ;
00133 
00134     /* 
00135        -----------------------------------------------------------------
00136        2) GET FRAMES AND SORT ACCORDING TO EXPOSURE TIME 
00137        -----------------------------------------------------------------
00138      */
00139      
00140     /* 
00141        2.1) get the total integration time from the fits header and 
00142             store it in an array
00143      */
00144 
00145     /* 2.1.1) get a data cube to stack darks */
00146     sinfo_msg("Build data cube");
00147     /* take a clean mean of the frames */
00148     check_nomsg(image_list = cpl_imagelist_new());
00149     int_time = (float*) cpl_calloc(cfg -> nframes, sizeof(float)) ;
00150     sinfo_check_rec_status(0);
00151  
00152     for ( i = 0 ; i < cfg->nframes ; i++ )
00153     {
00154         if (sinfo_is_fits_file (cfg->inFrameList[i]) != 1) {
00155        sinfo_msg_error("Input file %s is not FITS",cfg->inFrameList[i]);
00156            goto cleanup;
00157         }
00158 
00159     check_nomsg(cpl_imagelist_set(image_list,
00160                     cpl_image_load(cfg->inFrameList[i],CPL_TYPE_FLOAT,0,0),i));
00161 
00162         exp_time = sinfo_pfits_get_exptime(cfg->inFrameList[i]);
00163     if(cpl_error_get_code() != CPL_ERROR_NONE) {
00164        sinfo_msg_error("could not get exposure time from fits header!\n");
00165            goto cleanup;
00166     }
00167         sinfo_new_array_set_value(int_time, (float)exp_time, i);
00168     }
00169     no=cfg->nframes;
00170 
00171 
00172     /*
00173        2.2) find the number of frames with the same integration time
00174      */
00175     sinfo_msg("Find frames with same tint");
00176     n = 0;
00177 
00178     n_times = (int*) cpl_calloc(cfg -> nframes, sizeof(int));
00179     sinfo_msg("Sort frames with same tint");
00180 
00181     for ( i = 0 ; i < cfg->nframes-1 ; i++ )
00182     {
00183          if ( sinfo_new_array_get_value(int_time, i+1) != 
00184               sinfo_new_array_get_value(int_time, i)
00185         ) {
00186 
00187     n_times[n] = i+1;
00188         n = n+1;
00189     }
00190     
00191     }
00192 
00193     /* 
00194        2.3) store the images with the same tint in data cubes and take 
00195             clean means
00196      */
00197     sinfo_msg("Do clean mean");
00198     if ( n == 0 ) {
00199 
00200       sinfo_msg("n == 0 ");
00201        time_val = sinfo_new_array_get_value(int_time, 0);
00202 
00203       cknull(object_list = cpl_imagelist_new(),
00204          "could not allocate memory for object_list");
00205 
00206        /* here we have a leak of 80 bytes */
00207 
00208 
00209        count = 0;
00210        /* do also QC log */
00211        check_nomsg(qc_dark_median=cpl_vector_new(cfg->nframes));
00212 
00213        /* AMo here there is a leak */
00214        for ( j = 0 ; j < cfg->nframes ; j++ ) {
00215      check_nomsg(cpl_imagelist_set(object_list,
00216                      cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00217                      count));
00218      check_nomsg(cpl_vector_set(qc_dark_median,j,
00219                      cpl_image_get_median(cpl_imagelist_get(image_list,j))));
00220          count = count + 1;
00221        }
00222 
00223 
00224  
00225        check_nomsg(qc_darkmed_ave=cpl_vector_get_mean(qc_dark_median));
00226        if (cfg->nframes > 1) {
00227           check_nomsg(qc_darkmed_stdev=cpl_vector_get_stdev(qc_dark_median));
00228        }
00229        /* 
00230         rms   = stdev * sqrt(1-1/(double)cpl_vector_get_size(myvector)); 
00231        qc_darkmed_stdev = qc_darkmed_stdev * 
00232                        sqrt(1-1/(double)cpl_vector_get_size(qc_dark_median));
00233         */  
00234 
00235        check_nomsg(no=cpl_imagelist_get_size(object_list));
00236        lo_cut=(floor)(cfg->lo_reject*no+0.5);
00237        hi_cut=(floor)(cfg->hi_reject*no+0.5);
00238 
00239  
00240   
00241        cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
00242                                                          lo_cut,hi_cut),
00243           "sinfo_average_with_rejection failed");
00244 
00245        sinfo_free_imagelist(&object_list);
00246 
00247        sinfo_msg("dark_name=%s\n",dark_name);
00248        
00249        check_nomsg(first_frame = cpl_frameset_get_frame(raw, 0)) ;
00250    
00251        strcpy(ref_file,cpl_frame_get_filename(first_frame)) ;
00252        cknull_nomsg(rplist = cpl_propertylist_load(ref_file, 0));
00253 
00254        check_nomsg(naxis1=cpl_propertylist_get_int(rplist,"NAXIS1"));
00255        check_nomsg(naxis2=cpl_propertylist_get_int(rplist,"NAXIS1"));
00256        sinfo_free_propertylist(&rplist);
00257 
00258        if(cfg->qc_ron_xmin < 1) {
00259      sinfo_msg_error("qc_ron_xmin %d < 1",cfg->qc_ron_xmin);
00260          goto cleanup;
00261        }
00262 
00263        if(cfg->qc_ron_xmax > naxis1) {
00264      sinfo_msg_error("qc_ron_xmax %d > %d",cfg->qc_ron_xmax,naxis1);
00265          goto cleanup;
00266        }
00267 
00268        if(cfg->qc_ron_ymin < 1) {
00269      sinfo_msg_error("qc_ron_ymin %d < 1",cfg->qc_ron_ymin);
00270          goto cleanup;
00271        }
00272 
00273        if(cfg->qc_ron_ymax > naxis2) {
00274      sinfo_msg_error("qc_ron_ymax %d > %d",cfg->qc_ron_ymax,naxis2);
00275          goto cleanup;
00276        }
00277 
00278        zone_def[0]=cfg->qc_ron_xmin;
00279        zone_def[1]=cfg->qc_ron_xmax;
00280        zone_def[2]=cfg->qc_ron_ymin;
00281        zone_def[3]=cfg->qc_ron_ymax;
00282 
00283 
00284 
00285        check(cpl_flux_get_noise_window(image,
00286                        zone_def,
00287                        cfg->qc_ron_hsize,
00288                        cfg->qc_ron_nsamp,
00289                        &qc_ron_val,
00290                        &qc_ron_err),
00291          "In computation RON on image %s",dark_name);
00292       
00293  
00294 
00295        if(cfg->qc_fpn_xmin < 1) {
00296      sinfo_msg_error("qc_fpn_xmin %d < 1",cfg->qc_fpn_xmin);
00297          goto cleanup;
00298        }
00299 
00300        if(cfg->qc_fpn_xmax > naxis1) {
00301      sinfo_msg_error("qc_fpn_xmax %d > %d",cfg->qc_fpn_xmax,naxis1);
00302          goto cleanup;
00303        }
00304 
00305        if(cfg->qc_fpn_ymin < 1) {
00306      sinfo_msg_error("qc_fpn_ymin %d < 1",cfg->qc_fpn_ymin);
00307          goto cleanup;
00308        }
00309 
00310        if(cfg->qc_fpn_ymax > naxis2) {
00311      sinfo_msg_error("qc_fpn_ymax %d > %d",cfg->qc_fpn_ymax,naxis2);
00312          goto cleanup;
00313        }
00314 
00315        zone[0]=cfg->qc_fpn_xmin;
00316        zone[1]=cfg->qc_fpn_xmax;
00317        zone[2]=cfg->qc_fpn_ymin;
00318        zone[3]=cfg->qc_fpn_ymax;
00319        check(cpl_flux_get_noise_window(image, zone, cfg->qc_fpn_hsize,
00320                        cfg->qc_fpn_nsamp, &fpn, NULL),
00321          "Error computing noise in a window");
00322 
00323        /* QC LOG */
00324        cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00325 
00326        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED AVE",
00327              qc_darkmed_ave,"Average of raw darks medians","%f"));
00328 
00329        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED STDEV",
00330                      qc_darkmed_stdev,"STDEV of raw darks medians","%f"));
00331 
00332        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RON",
00333                      qc_ron_val,"Read Out Noise","%f"));
00334        
00335        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RONRMS",
00336                      qc_ron_err,"RMS on Read Out Noise","%f"));
00337 
00338        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKFPN",
00339                      fpn,"Fixed Pattern Noise of combined frames","%g"));
00340 
00341  
00342        /* special way to calculate RON: for each couple */
00343        
00344        check(selection = cpl_frameset_labelise(raw,sinfo_dark_compare,&nsets),
00345          "Error labelizing");
00346 
00347 
00348 
00349        for ( i = 0 ; i < nsets ; i++ ) {
00350          sinfo_msg("Reduce data set no %d out of %d", i+1, nsets);
00351          cpl_msg_indent_more();
00352      check_nomsg(f_one = cpl_frameset_extract(raw,selection,i));
00353          if (cpl_frameset_get_size(f_one) < 2) {
00354            sinfo_msg_warning("Skip %d set. One frame, not enough "
00355                              "to get ron",i+1);
00356      } else {
00357            if (sinfo_dark_ron_reduce(f_one,cfg,qclog_tbl) ) {
00358          sinfo_msg_warning( "Cannot reduce set number %d", i+1) ;
00359        }
00360      }
00361          sinfo_free_frameset(&f_one);
00362          cpl_msg_indent_less();
00363 
00364        }
00365        sinfo_free_int(&selection);
00366 
00367 
00368        /* generate a dummy_set with the master dark and a dummy 
00369               dark=2*master_dark */
00370 
00371        ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00372                  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00373                            "cannot save ima %s", dark_name);
00374        sinfo_free_table(&qclog_tbl);
00375        sinfo_free_image(&image);
00376  
00377     } else if (n == 1) {
00378 
00379        sinfo_msg("n == 1");
00380        time_val = sinfo_new_array_get_value(int_time, 0);
00381        cknull(object_list = cpl_imagelist_new(),
00382            "could not allocate memory");
00383 
00384        count = 0;
00385 
00386        for (j =0; j < n_times[0]; j++) {
00387 
00388      check_nomsg(cpl_imagelist_set(object_list,
00389                      cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00390                      count));
00391      count = count + 1;
00392        }
00393 
00394 
00395        check_nomsg(no=cpl_imagelist_get_size(object_list));
00396        lo_cut=(floor)(cfg->lo_reject*no+0.5);
00397        hi_cut=(floor)(cfg->hi_reject*no+0.5);
00398        check(image=cpl_imagelist_collapse_minmax_create(object_list,
00399                                                         lo_cut,hi_cut),
00400                                  "sinfo_average_with_rejection failed!");
00401 
00402        sinfo_free_imagelist(&object_list);
00403 
00404        cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00405        ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00406                                      "A description","%d"));
00407 
00408        ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00409                   PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00410                           "cannot save ima %s", dark_name);
00411 
00412 
00413        sinfo_free_image(&image);
00414        sinfo_free_table(&qclog_tbl);
00415 
00416        time_val = sinfo_new_array_get_value(int_time, n_times[0]);
00417        cknull(object_list = cpl_imagelist_new(),
00418           "could not allocate memory");
00419        count = 0;
00420 
00421 
00422        for (j = n_times[0]; j < cfg->nframes; j++) {
00423 
00424      check_nomsg(cpl_imagelist_set(object_list,
00425                      cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00426                      count));
00427          count = count + 1;
00428        }
00429 
00430 
00431        check_nomsg(no=cpl_imagelist_get_size(object_list));
00432        lo_cut=(floor)(cfg->lo_reject*no+0.5);
00433        hi_cut=(floor)(cfg->hi_reject*no+0.5);
00434        cknull(eclipse_image=cpl_imagelist_collapse_minmax_create(object_list,
00435                                                                  lo_cut,hi_cut),
00436           "sinfo_average_with_rejection failed!");
00437 
00438        sinfo_free_imagelist(&object_list);
00439 
00440 
00441        cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00442        ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00443                                      "A description","%d"));
00444 
00445        ck0(sinfo_pro_save_ima(eclipse_image,raw,sof,dark_name,
00446                   PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00447                           "cannot save ima %s", dark_name);
00448 
00449        sinfo_free_image(&eclipse_image);
00450        sinfo_free_table(&qclog_tbl);
00451 
00452     } else {
00453 
00454        sinfo_msg("n==else\n");
00455 
00456        for (i= 0; i < n+1; i++) {
00457          if ( i == 0 ) {
00458         time_val = sinfo_new_array_get_value(int_time, 0);
00459         check(object_list = cpl_imagelist_new(),
00460               "could not allocate memory");
00461 
00462             count = 0;
00463             for (j = 0; j < n_times[0]; j++) {
00464           check_nomsg(cpl_imagelist_set(object_list,
00465                           cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00466                           count));
00467           count = count + 1;
00468         }
00469         check_nomsg(no=cpl_imagelist_get_size(object_list));
00470         lo_cut=(floor)(cfg->lo_reject*no+0.5);
00471         hi_cut=(floor)(cfg->hi_reject*no+0.5);
00472             check(image=cpl_imagelist_collapse_minmax_create(object_list,
00473                                                              lo_cut,hi_cut),
00474                                     "Error computing average with rejection");
00475             sinfo_free_imagelist(&object_list);
00476 
00477             sinfo_msg("dark_name-%s\n",dark_name);
00478             cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00479             ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00480                                           "A description","%d"));
00481 
00482             ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00483                    PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00484               "cannot save ima %s", dark_name);
00485 
00486 
00487             sinfo_free_table(&qclog_tbl);
00488             sinfo_free_image(&image);
00489      } else if ( i == n ) {
00490             time_val = sinfo_new_array_get_value(int_time, n_times[n-1]);
00491             cknull(object_list = cpl_imagelist_new(), 
00492                "could not allocate memory");
00493 
00494             count = 0;
00495             for (j = n_times[n-1]; j < cfg->nframes; j++) {
00496           check_nomsg(cpl_imagelist_set(object_list,
00497                           cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00498                           count));
00499           count = count + 1;
00500         }
00501         check_nomsg(no=cpl_imagelist_get_size(object_list));
00502         lo_cut=(floor)(cfg->lo_reject*no+0.5);
00503         hi_cut=(floor)(cfg->hi_reject*no+0.5);
00504             check(image=cpl_imagelist_collapse_minmax_create(object_list,
00505                                                              lo_cut,hi_cut),
00506                   "Error computing average with rejection");
00507 
00508             sinfo_free_imagelist(&object_list);
00509 
00510             cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00511             ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00512                                           "A description","%d"));
00513 
00514             ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00515                    PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00516         "cannot save ima %s", dark_name);
00517             sinfo_free_table(&qclog_tbl);
00518             sinfo_free_image(&image);
00519     } else {
00520         time_val = sinfo_new_array_get_value(int_time, n_times[i-1]);
00521         cknull(object_list = cpl_imagelist_new(), 
00522                    "could not allocate memory");
00523 
00524             count = 0;
00525             for (j = n_times[i-1]; j < n_times[i]; j++) {
00526           check_nomsg(cpl_imagelist_set(object_list,
00527                           cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00528                           count));
00529           count = count + 1;
00530         }
00531         check_nomsg(no=cpl_imagelist_get_size(object_list));
00532         lo_cut=(floor)(cfg->lo_reject*no+0.5);
00533         hi_cut=(floor)(cfg->hi_reject*no+0.5);
00534             cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
00535                                                               lo_cut,hi_cut),
00536                                      "Error computing average with rejection");
00537 
00538             sinfo_free_imagelist(&object_list);
00539 
00540             cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00541             ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00542                                           "A description","%d"));
00543 
00544             ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00545                    PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00546                                    "cannot save ima %s", dark_name);
00547 
00548             sinfo_free_image(&image);
00549             sinfo_free_table(&qclog_tbl);
00550     }
00551        
00552        } /* end for loop */
00553     } /* end else over n */
00554 
00555  
00556 
00557        sinfo_free_imagelist(&image_list);
00558        sinfoni_free_vector(&qc_dark_median);
00559        sinfo_free_int(&n_times);
00560        sinfo_free_float(&int_time);
00561        sinfo_dark_free(&cfg);
00562        sinfo_free_frameset(&raw);
00563 
00564       return 0;
00565 
00566  cleanup:
00567        sinfo_free_frameset(&f_one);
00568        sinfo_free_int(&selection);
00569        sinfo_free_image(&eclipse_image);
00570        sinfo_free_table(&qclog_tbl);
00571        sinfo_free_image(&dark_img);
00572        sinfo_free_image(&image);
00573        sinfo_free_propertylist(&rplist);
00574        sinfoni_free_vector(&qc_dark_median);
00575        sinfo_free_imagelist(&object_list);
00576        sinfo_free_int(&n_times);
00577        sinfo_free_float(&int_time);
00578        sinfo_free_imagelist(&image_list);
00579        sinfo_dark_free(&cfg);
00580        sinfo_free_frameset(&raw);
00581 
00582        return -1;
00583 
00584 }
00585 
00586 
00587 
00588 
00589 
00590 
00591 /*--------------------------------------------------------------------*/
00598 /*--------------------------------------------------------------------*/
00599  static int 
00600 sinfo_dark_ron_reduce(cpl_frameset    *   framelist,
00601               dark_config     *   cfg,
00602               cpl_table       *   qclog_tbl)
00603 {
00604   cpl_imagelist   *   iset =NULL;
00605   int                 i =0;
00606   double* ron=NULL;
00607   int nraw=0;
00608   int niset=0;
00609   char key_name[MAX_NAME_SIZE];
00610   /* Test entries */
00611 
00612   cknull_nomsg(framelist);
00613 
00614   /* Load the current set */
00615   if ((iset = sinfo_new_frameset_to_iset(framelist)) == NULL) {
00616     sinfo_msg_error( "Cannot load the data") ;
00617     return -1 ;
00618   }
00619   /* Loop on all pairs */
00620   nraw = cpl_table_get_nrow(qclog_tbl);
00621   niset=cpl_imagelist_get_size(iset);
00622 
00623   ron = cpl_calloc(niset,sizeof(double));
00624 
00625   sinfo_get_ron(framelist,
00626                 cfg->qc_ron_xmin,cfg->qc_ron_xmax,
00627                 cfg->qc_ron_ymin,cfg->qc_ron_ymax,
00628                 cfg->qc_ron_hsize,cfg->qc_ron_nsamp,
00629                 &ron);
00630 
00631   for (i=0 ; i<niset-1 ; i++) {
00632 
00633     /* Write the paf file on disk */
00634     /* Write QC LOG */
00635 
00636     snprintf(key_name,MAX_NAME_SIZE-1,"%s%d","QC RON",i+1);
00637     sinfo_qclog_add_double(qclog_tbl,key_name,ron[i],
00638                "Read Out Noise","%f");
00639 
00640   }
00641 
00642   cpl_free(ron);
00643   sinfo_free_imagelist(&iset) ;
00644 
00645   return 0 ;
00646  cleanup:
00647   cpl_free(ron);
00648   ron=NULL;
00649   sinfo_free_imagelist(&iset) ;
00650 
00651   return -1;
00652 
00653 }
00654 
00655 
00656 /*---------------------------------------------------------------------------*/
00663 /*---------------------------------------------------------------------------*/
00664 static int sinfo_dark_compare(
00665         cpl_frame   *   frame1,
00666         cpl_frame   *   frame2)
00667 {
00668     int                 comparison=0 ;
00669     cpl_propertylist *  plist1=NULL;
00670     cpl_propertylist *  plist2=NULL;
00671 
00672     char            *   sval ;
00673     char                mode1[512] ;
00674     char                mode2[512] ;
00675     double              dval1=0;
00676     double              dval2=0;
00677     int                 ival1=0;
00678     int                 ival2=0;
00679 
00680     /* Test entries */
00681     if (frame1==NULL || frame2==NULL) return -1 ;
00682 
00683     /* Get property lists */
00684     cknull(plist1=cpl_propertylist_load(cpl_frame_get_filename(frame1),0),
00685         "getting header from reference frame");
00686 
00687     cknull(plist2=cpl_propertylist_load(cpl_frame_get_filename(frame2),0),
00688         "getting header from reference frame");
00689      
00690     /* Compare exposure time */
00691     comparison = 1 ;
00692     check(dval1=sinfo_pfits_get_exp_time(plist1),"To get exptime");
00693     check(dval2=sinfo_pfits_get_exp_time(plist2),"To get exptime");
00694 
00695     if (fabs(dval1-dval2) > 1e-5) comparison = 0 ;
00696 
00697     /* Compare the readout mode */
00698     check(ival1=sinfo_pfits_get_rom(plist1),"to get read out mode");
00699     check(ival2=sinfo_pfits_get_rom(plist2),"to get read out mode");
00700     if (ival1 != ival2) comparison = 0 ;
00701 
00702 
00703     /* Compare the detector mode */
00704     cknull(sval=sinfo_pfits_get_mode(plist1),"to get detector mode");
00705     strcpy(mode1, sval) ;
00706 
00707     cknull(sval=sinfo_pfits_get_mode(plist2),"to get detector mode");
00708     strcpy(mode2, sval) ;
00709 
00710 
00711     if (strcmp(mode1, mode2)) comparison = 0 ;
00712 
00713     /* Files have to be consequtive */
00714     /*
00715     check(ival1 = sinfo_pfits_get_expno(plist1),"to get exposure number");
00716     check(ival2 = sinfo_pfits_get_expno(plist1),"to get exposure number");
00717     if (ival1 != ival2) comparison = 0 ;
00718     */
00719     sinfo_free_propertylist(&plist1);
00720     sinfo_free_propertylist(&plist2);
00721 
00722     return comparison ;
00723  cleanup:
00724     sinfo_free_propertylist(&plist1);
00725     sinfo_free_propertylist(&plist2);
00726     return -1 ;
00727 
00728 
00729 }

Generated on Wed Jan 17 08:33:43 2007 for SINFONI Pipeline Reference Manual by  doxygen 1.4.4