sinfo_new_cubes_build.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_cubes_build.c
00022    Author       :   J. Schreiber
00023    Created on   :   December 3, 2003
00024    Description  :   Creates data cubes or merges data cubes 
00025                         out of jittered object-sky
00026                         nodding observations 
00027  ---------------------------------------------------------------------------*/
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 /*----------------------------------------------------------------------------
00033                                 Includes
00034  ---------------------------------------------------------------------------*/
00035 #include "sinfo_new_cubes_build.h"
00036 #include "sinfo_pfits.h"
00037 #include "sinfo_pro_save.h"
00038 #include "sinfo_objnod_ini_by_cpl.h"
00039 #include "sinfo_functions.h"
00040 #include "sinfo_hidden.h"
00041 #include "sinfo_utilities_scired.h" 
00042 #include "sinfo_wave_calibration.h"
00043 #include "sinfo_cube_construct.h"
00044 #include "sinfo_skycor.h"
00045 #include "sinfo_product_config.h"
00046 #include "sinfo_error.h"
00047 #include "sinfo_utils_wrappers.h"
00048 
00049 /*----------------------------------------------------------------------------
00050                                 Defines
00051  ---------------------------------------------------------------------------*/
00052 #define PI_NUMB        (3.1415926535897932384626433832795) /* pi */
00053 
00054 
00055 /*----------------------------------------------------------------------------
00056                              Function Definitions
00057  ---------------------------------------------------------------------------*/
00058 
00059 
00068 /*----------------------------------------------------------------------------
00069    Function     : sinfo_new_cubes_build()
00070    In           : ini_file: file name of according .ini file
00071    Out          : integer (0 if it worked, -1 if it doesn't) 
00072    Job          : this routine carries through the data cube creation of an 
00073                   object science observation using object-sky nodding
00074                   and jittering. This script expects jittered frames that
00075           were already sky-subtracted
00076                   averaged, flatfielded, spectral tilt corrected and 
00077         interleaved if necessary
00078  ---------------------------------------------------------------------------*/
00079 int sinfo_new_cubes_build (const char* plugin_id,cpl_parameterlist* config, 
00080             cpl_frameset* sof, const char* procatg, const int frame_index)
00081 {
00082 
00083     object_config * cfg=NULL ;
00084     cpl_image * im=NULL ;
00085     cpl_image * wavemapim=NULL ;
00086     cpl_image * wim=NULL ;
00087     cpl_image * res_obj=NULL ;
00088     cpl_image * calim=NULL ;
00089     cpl_image * halospec=NULL ;
00090     cpl_image * sky_im=NULL;
00091     cpl_image* res_flat=NULL;
00092     cpl_image* res_sky=NULL;
00093     cpl_image* flat_im=NULL;
00094     cpl_image* eima_avg=NULL;
00095     cpl_image* eima_med=NULL;
00096     cpl_imagelist  * cube=NULL ;
00097     cpl_imagelist  * outcube=NULL ;
00098     cpl_imagelist  * outcube2=NULL ;
00099     cpl_imagelist* cflat=NULL;
00100     cpl_imagelist* cflat2=NULL;
00101     cpl_imagelist* csky=NULL;
00102     cpl_imagelist* csky2=NULL;
00103     cpl_propertylist* plist=NULL;
00104     cpl_frame* obj_frm=NULL;
00105     cpl_frame* sky_frm=NULL;
00106     cpl_imagelist* obj_cor=NULL;
00107 
00108     int sky_cor=0;
00109 
00110     int n=0 ;
00111     int cpix=0 ;
00112     float ref_offx=0;
00113     float ref_offy=0;
00114     float mi=0 ;
00115     float ma=0 ;
00116     float fcol=0 ;
00117     float center_x=0;
00118     float center_y=0;
00119     float cd1_1=0;
00120     float cd1_2=0;
00121     float cd2_1=0;
00122     float cd2_2=0;
00123     double pixelscale=0;
00124     double angle=0;
00125     float radangle=0;
00126     double exptime=0;
00127 
00128     float *  correct_dist=NULL ;
00129     float * distances=NULL ;
00130     double * times=NULL ;
00131     float * offsetx=NULL;
00132     float * offsety=NULL;
00133     float ** slit_edges=NULL ;
00134 
00135     double dis=0 ;
00136     double cwav=0 ;
00137 
00138     char name_jitter[FILE_NAME_SZ] ;
00139     char pro_mjit[MAX_NAME_SIZE];
00140     char pro_obs[MAX_NAME_SIZE];
00141     char pro_med[MAX_NAME_SIZE];
00142 
00143 
00144     char * name=NULL ;
00145     char file_name[FILE_NAME_SZ];
00146 
00147     cpl_table* qclog_tbl=NULL;
00148     cpl_frameset* stk=NULL;
00149     cpl_parameter* p=NULL;
00150     int pdensity=0;
00151     sinfo_skycor_qc* sqc=NULL;
00152     cpl_table* int_obj=NULL;
00153 
00154     check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density"));
00155     check_nomsg(pdensity=cpl_parameter_get_int(p));
00156 
00157      if (strcmp(procatg,PRO_COADD_STD) == 0) {
00158     strcpy(pro_mjit,PRO_MASK_COADD_STD);
00159     strcpy(pro_obs,PRO_OBS_STD);
00160     strcpy(pro_med,PRO_MED_COADD_STD);
00161 
00162     } else if (strcmp(procatg,PRO_COADD_PSF) == 0) {
00163     strcpy(pro_mjit,PRO_MASK_COADD_PSF);
00164     strcpy(pro_obs,PRO_OBS_PSF);
00165     strcpy(pro_med,PRO_MED_COADD_PSF);
00166     } else {
00167     strcpy(pro_mjit,PRO_MASK_COADD_OBJ);
00168     strcpy(pro_obs,PRO_OBS_OBJ);
00169     strcpy(pro_med,PRO_MED_COADD_OBJ);
00170     }
00171 
00172 
00173     /*----parse input data and parameters to set cube_config cfg---*/
00174     check_nomsg(stk = cpl_frameset_new());
00175 
00176     cknull(cfg = sinfo_parse_cpl_input_objnod(config,sof,&stk),
00177        "Error setting parameter configuration");
00178  
00179     ck0(sinfo_check_input_data(cfg),"error checking input");
00180 
00181     if ( cfg->jitterind == 1 )
00182     {
00183         cknull(times = (double*) cpl_calloc (cfg->nframes, sizeof (double)), 
00184            " could not allocate memory!") ;
00185  
00186         cknull(offsetx = (float*) cpl_calloc (cfg->nframes, sizeof(float)),
00187            " could not allocate memory!") ;
00188 
00189         cknull(offsety = (float*) cpl_calloc (cfg->nframes, sizeof(float)),
00190            " could not allocate memory!") ;
00191     }
00192 
00193 
00194     ck0(sinfo_auto_size_cube2(cfg,&ref_offx,&ref_offy),"Error resizing cube");
00195 
00196  
00197     check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.objnod.fcol"));
00198     check_nomsg(fcol=(float)cpl_parameter_get_double(p));
00199 
00200      for ( n = 0 ; n < cfg->nframes ; n++ )
00201      {
00202 
00203         sinfo_msg_debug("Read FITS information");
00204         name = cfg->framelist[n] ;    
00205         if (n == 0)
00206     {
00207         strcpy (name_jitter, name) ;
00208     }   
00209         if( sinfo_is_fits_file(name) != 1) {
00210           sinfo_msg_error("Input file %s is not FITS",name);
00211           goto cleanup;
00212     }
00213 
00214     
00215     /* get some header values and compute the CD-sinfo_matrix */
00216     plist=cpl_propertylist_load(name,0);
00217     // FIXME: sometime OPTI1 duplicated??
00218     check_nomsg(pixelscale = sinfo_pfits_get_pixscale(plist) /2);
00219     // PUPIL OBJECT has no POSANGLE INFO
00220     angle = sinfo_pfits_get_posangle(plist) ;
00221         sinfo_free_propertylist(&plist);
00222         if(cpl_error_get_code() != CPL_ERROR_NONE) {
00223       cpl_error_reset();
00224         }
00225 
00226 
00227     radangle = angle * PI_NUMB / 180. ;
00228     cd1_1 = cos(radangle) ;
00229     cd1_2 = sin(radangle) ;
00230     cd2_1 = -sin(radangle) ;
00231     cd2_2 = cos(radangle) ;
00232     
00233     sinfo_msg_debug("frame no.: %d, name: %s\n", n, name) ;
00234     cknull(im = cpl_image_load(name,CPL_TYPE_FLOAT,0,0),
00235            " could not load frame %s!",name) ;
00236 
00237     if (cfg->jitterind == 1)
00238     {
00239       exptime = sinfo_pfits_get_ditndit(name) ;
00240 
00241       if (exptime == FLAG)
00242         {
00243           sinfo_msg_error("could not read fits header keyword exptime!");
00244           goto cleanup;
00245         }
00246       times[n] = exptime ;
00247 
00248           ck0(sinfo_new_assign_offset(n,name,offsetx,
00249                                       offsety,ref_offx,ref_offy),
00250                                       "Error assigning offsets");
00251 
00252     }
00253 
00254         /*
00255          *--------------------------------------------------------------    
00256          *---------------------RESAMPLING-------------------------------
00257      *--------------------------------------------------------------
00258          */
00259         sinfo_msg("Resampling object");
00260     cknull(wavemapim = cpl_image_load(cfg->wavemap,CPL_TYPE_FLOAT,0,0),
00261            "could not load wavemap");
00262         check_nomsg(wim=cpl_image_duplicate(wavemapim));
00263         cknull(res_obj = sinfo_new_defined_resampling(im, 
00264                               wim, 
00265                               cfg->ncoeffs,
00266                               &cfg->nrows,
00267                               &dis,
00268                               &mi,
00269                               &ma,
00270                               &cwav,
00271                               &cpix),
00272            " sinfo_definedResampling() failed" ) ;
00273     sinfo_free_image(&wim);
00274         if((pdensity == 2) || (pdensity == 1 && frame_index == 0)) {
00275           snprintf(file_name,MAX_NAME_SIZE-1,"%s%d%s",RESAMPLED_OUT_OBJ_FILENAME,
00276                   frame_index,".fits");
00277           ck0(sinfo_pro_save_ima(res_obj,sof,sof,file_name,
00278                    PRO_RESAMPLED_OBJ,
00279                                qclog_tbl,plugin_id,config),
00280           "cannot save image %s", file_name);
00281     }
00282 
00283 
00284     if(strcmp(cfg->sky_dist,"no_sky")!=0) {
00285       sinfo_msg("Resampling sky");
00286       check_nomsg(sky_im=cpl_image_load(cfg->sky_dist,CPL_TYPE_FLOAT,0,0));
00287           check_nomsg(wim=cpl_image_duplicate(wavemapim));
00288       cknull(res_sky = sinfo_new_defined_resampling(sky_im,
00289                                     wim,
00290                             cfg->ncoeffs,
00291                             &cfg->nrows,
00292                             &dis,
00293                             &mi,
00294                             &ma,
00295                             &cwav,
00296                             &cpix),
00297          " sinfo_definedResampling() failed" );
00298       sinfo_free_image(&wim);
00299       sinfo_free_image(&sky_im) ;
00300       if((pdensity == 2) || (pdensity == 1 && frame_index == 0)){
00301 
00302             snprintf(file_name,MAX_NAME_SIZE-1,"%s%d%s",
00303                     RESAMPLED_OUT_SKY_FILENAME,frame_index,".fits");
00304             ck0(sinfo_pro_save_ima(res_sky,sof,sof,file_name,
00305                        PRO_RESAMPLED_SKY,
00306                                    qclog_tbl,plugin_id,config),
00307         "cannot save image %s", file_name);
00308       }
00309 
00310 
00311        
00312     }
00313 
00314 
00315     if(n ==0) {
00316           if(strcmp(cfg->mflat_dist,"not_found") != 0) {
00317         sinfo_msg("Resampling master flat");
00318         cknull(flat_im=cpl_image_load(cfg->mflat_dist,CPL_TYPE_FLOAT,0,0),
00319                    "Distorted master flat field not found\n"
00320                    "You may have set --stack-flat_ind=FALSE\n"
00321                    "Flat field resampling skipped");
00322             check_nomsg(wim=cpl_image_duplicate(wavemapim));
00323             cknull(res_flat = sinfo_new_defined_resampling(flat_im, 
00324                                wim,
00325                                cfg->ncoeffs,
00326                                &cfg->nrows,
00327                                &dis,
00328                                &mi,
00329                                &ma,
00330                                &cwav,
00331                                &cpix),
00332            " sinfo_definedResampling() failed" ) ;
00333         sinfo_free_image(&wim);
00334         sinfo_free_image(&flat_im) ;
00335         if((pdensity == 2) || (pdensity == 1 && frame_index == 0)) {
00336               snprintf(file_name,MAX_NAME_SIZE-1,"%s%d%s",
00337               RESAMPLED_OUT_FLAT_FILENAME,frame_index,".fits");
00338           ck0(sinfo_pro_save_ima(res_flat,sof,sof,file_name,
00339                      PRO_RESAMPLED_FLAT_LAMP,
00340                      qclog_tbl,plugin_id,config),
00341           "cannot save image %s", file_name);
00342         }
00343 
00344 
00345       }
00346      
00347     }
00348         sinfo_msg("wmin %f wmax %f wcent %f wstep %f cpix %d",
00349                   mi,ma,cwav,dis,cpix); 
00350 
00351         sinfo_free_image(&im) ;
00352         sinfo_free_image(&wavemapim) ;
00353 
00354     /*
00355          *-------------------------------------------------------------------
00356          *----------------Calibration----------------------------------------
00357          *-------------------------------------------------------------------
00358     */
00359         /*----Multiply with calibrated halogen lamp spectrum----*/ 
00360         if (cfg->halocorrectInd == 1)
00361         {     
00362       sinfo_msg("Calibration");
00363       check_nomsg(halospec = cpl_image_load(cfg->halospectrum,
00364                                                 CPL_TYPE_FLOAT,0,0)) ;
00365 
00366       cknull(calim = sinfo_new_multiply_image_with_spectrum(res_obj,
00367                                                                 halospec),
00368                       " sinfo_new_multiply_image_with_spectrum() failed" ) ;
00369 
00370       sinfo_free_image(&halospec) ;
00371       sinfo_free_image(&res_obj) ;
00372       res_obj = cpl_image_duplicate(calim) ;
00373       sinfo_free_image(&calim);
00374         }
00375     
00376         /*
00377          *-------------------------------------------------------------------
00378          *------------------CUBECREATION-------------------------------------
00379          *-------------------------------------------------------------------
00380      */
00381     sinfo_msg("Cube creation");
00382     /*---select north-south-test or fitting of slitlet edges--*/
00383     if (cfg->northsouthInd == 0) {
00384       sinfo_msg("cfg->northsouthInd == 0");
00385       cknull(slit_edges = sinfo_read_slitlets_edges(cfg),
00386          "error reading slitlets edges");
00387     } else {
00388       sinfo_msg("cfg->northsouthInd != 0");
00389       cknull(distances = sinfo_read_distances(cfg),
00390          "error reading distances");
00391     }
00392  
00393     cknull(correct_dist = (float*) cpl_calloc(cfg->nslits, sizeof (float)),
00394            " could not allocate memory!") ;
00395 
00396     sinfo_msg("Create cube object");
00397     if (cfg->northsouthInd ==0 ) {
00398 
00399         cknull(cube = sinfo_new_make_cube_spi(res_obj,slit_edges,
00400                                                   correct_dist),
00401                                              "could not construct data cube!") ;
00402 
00403     }  else {
00404        cknull(cube = sinfo_new_make_cube_dist(res_obj,fcol,distances,
00405                                                   correct_dist),
00406                                           "could not construct a data cube!") ;
00407     }
00408     sinfo_free_image(&res_obj);
00409 
00410 
00411       if(strcmp(cfg->sky_dist,"no_sky")!=0) {
00412 
00413         sinfo_msg("Create cube sky");
00414         if (cfg->northsouthInd ==0 ) {
00415           cknull(csky = sinfo_new_make_cube_spi(res_sky,slit_edges,
00416                                                     correct_dist),
00417                                             "could not construct data cube!") ;
00418         }  else {
00419           cknull(csky = sinfo_new_make_cube_dist(res_sky,fcol,distances,
00420                                                      correct_dist),
00421                                           "could not construct a data cube!") ;
00422         }
00423         sinfo_free_image(&res_sky);
00424       }
00425 
00426     if(n==0) {
00427       if(strcmp(cfg->mflat_dist,"not_found")!=0) {
00428         sinfo_msg("Create cube master flat");
00429         if (cfg->northsouthInd ==0 ) {
00430           cknull(cflat=sinfo_new_make_cube_spi(res_flat,slit_edges,
00431                                                    correct_dist),
00432                                              "could not construct data cube!") ;
00433         }  else {
00434           cknull(cflat = sinfo_new_make_cube_dist(res_flat,fcol,distances,
00435                                                       correct_dist),
00436                                           "could not construct a data cube!") ;
00437         }
00438         sinfo_free_image(&res_flat);
00439       }
00440     }
00441 
00442         if (cfg->northsouthInd ==0 )
00443      {
00444        sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
00445      }
00446     else
00447       {
00448             sinfo_new_destroy_array(&distances);
00449       }
00450 
00451         /*
00452          *--------------------------------------------------------------------
00453          *------------------------FINETUNING----------------------------------
00454          *--------------------------------------------------------------------
00455          * shift the rows of the reconstructed images of the data cube to the 
00456          * correct sub pixel position select the shift method: polynomial 
00457          * interpolation, FFT or cubic spline interpolation
00458          *--------------------------------------------------------------------
00459          */
00460 
00461       if(strcmp(cfg->sky_dist,"no_sky")!=0) {
00462          cknull(csky2=sinfo_new_fine_tune(csky,
00463                                              correct_dist,
00464                                              cfg->method,
00465                                              cfg->order,
00466                           cfg->nslits),
00467             " could not fine tune the data cube") ;
00468 
00469          sinfo_free_imagelist(&csky);
00470          sinfo_msg("Stretch output cube along Y direction");
00471  
00472          cknull(csky = sinfo_new_bin_cube(csky2,1,2,0,63,0,63),
00473             "error rebinning sky cube");
00474          sinfo_free_imagelist(&csky2);
00475 
00476        
00477      
00478              snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_sky_cube",frame_index,".fits");
00479          ck0(sinfo_pro_save_ims(csky,sof,sof,file_name,
00480                     PRO_OBS_SKY,NULL,plugin_id,config),
00481          "cannot dump cube %s", file_name);
00482  
00483          cknull(eima_med=sinfo_new_median_cube(csky),
00484                 "Creating an average image");
00485          check_nomsg(center_x = cpl_image_get_size_x(eima_med)/ 2. + 0.5);
00486          check_nomsg(center_y = cpl_image_get_size_y(eima_med)/ 2. + 0.5);
00487 
00488          sinfo_new_set_wcs_cube(csky,file_name, cwav, 
00489                           dis, cpix, center_x, center_y);
00490 
00491          sinfo_free_imagelist(&csky) ;
00492 
00493              snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_sky_med",frame_index,".fits");
00494          ck0(sinfo_pro_save_ima(eima_med,sof,sof,file_name,
00495                     PRO_SKY_MED,NULL,plugin_id,config),
00496          "cannot save ima %s",file_name);
00497 
00498          sinfo_new_set_wcs_image(eima_med,file_name, center_x, center_y);
00499          sinfo_free_image(&eima_med);
00500       }
00501 
00502 
00503  
00504     if(n==0) {
00505       if(strcmp(cfg->mflat_dist,"not_found")!=0) {
00506 
00507         cknull(cflat2=sinfo_new_fine_tune(cflat,
00508                                               correct_dist,
00509                                               cfg->method,
00510                                               cfg->order,
00511                                               cfg->nslits),
00512                                     " could not fine tune the data cube") ;
00513 
00514         sinfo_free_imagelist(&cflat);
00515         sinfo_msg("Stretch output cube along Y direction");
00516  
00517         cknull(cflat = sinfo_new_bin_cube(cflat2,1,2,0,63,0,63),
00518            "Error binning flat cube");
00519         sinfo_free_imagelist(&cflat2);
00520 
00521         ck0(sinfo_pro_save_ims(cflat,sof,sof,"out_mflat_cube.fits",
00522                    "MFLAT_CUBE",NULL,plugin_id,config),
00523         "cannot save cube %s", "out_mflat_cube.fits");
00524 
00525     sinfo_new_set_wcs_cube(cflat,"out_mflat_cube.fits",cwav, dis, 
00526                      cpix, center_x, center_y);
00527 
00528         cknull(eima_avg=sinfo_new_average_cube_to_image(cflat),
00529                "Creating an average image");
00530 
00531         ck0(sinfo_pro_save_ima(eima_avg,sof,sof,"out_mflat_avg.fits",
00532                    "MFLAT_AVG",NULL,plugin_id,config),
00533         "cannot save ima %s", "out_mflat_avg.fits");
00534 
00535         sinfo_free_image(&eima_avg);
00536 
00537         cknull(eima_med=sinfo_new_median_cube(cflat),
00538            "Error computing median on cube flat");
00539 
00540         ck0(sinfo_pro_save_ima(eima_med,sof,sof,"out_mflat_med.fits",
00541                    "MFLAT_MED",NULL,plugin_id,config),
00542         "cannot save ima %s", "out_mflat_med.fits");
00543 
00544         sinfo_free_imagelist(&cflat); 
00545         sinfo_free_image(&eima_med);
00546       }
00547     }
00548 
00549         cknull(outcube2=sinfo_new_fine_tune(cube,
00550                                             correct_dist,
00551                                             cfg->method,
00552                                             cfg->order,
00553                                             cfg->nslits),
00554                                         " could not fine tune the data cube") ;
00555 
00556         sinfo_msg("Stretch output cube along Y direction");
00557         cknull(outcube = sinfo_new_bin_cube(outcube2,1,2,0,63,0,63),
00558            "Error binning cube");
00559         sinfo_free_imagelist(&cube);
00560         cknull_nomsg(qclog_tbl=sinfo_qclog_init());
00561         sinfo_get_pupil_shift(outcube,n,&qclog_tbl);
00562         snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_cube_obj",frame_index,".fits");
00563         ck0(sinfo_pro_save_ims(outcube,sof,sof,file_name,
00564                    pro_obs,qclog_tbl,plugin_id,config),
00565         "cannot save cube %s", file_name);
00566 
00567     check_nomsg(center_x = cpl_image_get_size_x(
00568                                cpl_imagelist_get(outcube,0))/2.+0.5) ;
00569     check_nomsg(center_y = cpl_image_get_size_y(
00570                                cpl_imagelist_get(outcube,0))/2.+0.5 );
00571    
00572 
00573     sinfo_new_set_wcs_cube(outcube, file_name, cwav, dis, 
00574                      cpix, center_x, center_y);
00575 
00576     /* free memory */
00577         /* to prevent error message comment next line */
00578 
00579         check_nomsg(p=cpl_parameterlist_find(config,
00580                     "sinfoni.sinfo_utl_skycor.rot_cor"));
00581         check_nomsg(sky_cor=cpl_parameter_get_bool(p));
00582       
00583         if(sky_cor == 1 && pdensity == 2) {
00584       obj_frm=cpl_frameset_find(sof,pro_obs);
00585       sky_frm=cpl_frameset_find(sof,PRO_OBS_SKY);
00586           sqc=sinfo_skycor_qc_new();
00587       ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
00588           "determining sky residuals corrected object");
00589           cpl_frameset_erase(sof,pro_obs);
00590           snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_cube_obj_cor",
00591           frame_index,".fits");
00592           ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC SKYCOR THBKGFIT",
00593              sqc->th_fit,"Thermal background fit success","%d"));
00594 
00595           ck0(sinfo_pro_save_ims(obj_cor,sof,sof,file_name,
00596                    pro_obs,qclog_tbl,plugin_id,config),
00597           "cannot save cube %s", file_name);
00598           sinfo_skycor_qc_delete(&sqc);
00599 
00600       sinfo_free_imagelist(&obj_cor) ;
00601       snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_int_obj",
00602            frame_index,".fits");
00603           
00604           ck0(sinfo_pro_save_tbl(int_obj,sof,sof,file_name,
00605                    PRO_SPECTRA_QC,qclog_tbl,plugin_id,config),
00606           "cannot save cube %s", file_name);
00607 
00608 
00609       sinfo_free_table(&int_obj) ;
00610 
00611 
00612     }
00613         sinfo_free_table(&qclog_tbl);
00614         sinfo_free_imagelist(&outcube2);
00615         sinfo_free_imagelist(&outcube) ;
00616     sinfo_free_float(&correct_dist) ;
00617 
00618      } /* end loop over n (nframes) */
00619 
00620  /* free memory */
00621     sinfo_free_double(&times);
00622     sinfo_free_float(&offsety);
00623     sinfo_free_float(&offsetx);
00624     sinfo_objnod_free(&cfg);
00625     sinfo_free_frameset(&stk);
00626 
00627 
00628     return 0;   
00629 
00630  cleanup:
00631     sinfo_skycor_qc_delete(&sqc);
00632     sinfo_free_imagelist(&obj_cor) ;
00633     sinfo_free_propertylist(&plist);
00634     sinfo_free_imagelist(&outcube2) ;
00635     sinfo_free_imagelist(&outcube) ;
00636     sinfo_free_table(&qclog_tbl);
00637     sinfo_free_image(&eima_avg);
00638     sinfo_free_image(&eima_med);
00639     sinfo_free_imagelist(&cflat) ;
00640     sinfo_free_imagelist(&cflat2) ;
00641     sinfo_free_imagelist(&cube) ;
00642     sinfo_free_imagelist(&csky) ;
00643     sinfo_free_imagelist(&csky2) ;
00644 
00645     if(cfg!=NULL) {
00646       if (cfg->northsouthInd ==0 ) {
00647     if(slit_edges != NULL) {
00648        sinfo_new_destroy_2Dfloatarray(&slit_edges,cfg->nslits);
00649     }
00650       } else {
00651     if (distances != NULL ) {
00652             sinfo_new_destroy_array(&distances);
00653     }
00654       }
00655     }
00656 
00657     sinfo_free_float(&correct_dist);
00658     sinfo_free_image(&res_flat);
00659     sinfo_free_image(&res_sky);
00660     sinfo_free_image(&calim);
00661     sinfo_free_image(&halospec) ;
00662     sinfo_free_image(&sky_im) ;
00663     sinfo_free_image(&res_obj);
00664     sinfo_free_image(&flat_im) ;
00665     sinfo_free_image(&wavemapim);
00666     sinfo_free_image(&wim);
00667     sinfo_free_image(&im);
00668     sinfo_free_float(&offsety);
00669     sinfo_free_float(&offsetx);
00670     sinfo_free_double(&times);
00671     sinfo_objnod_free(&cfg);
00672     sinfo_free_frameset(&stk);
00673 
00674     return -1;   
00675 
00676 
00677 
00678 }
00679 

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