sinfoni/sinfo_utl_spectrum_divide_by_blackbody.c

00001 /* $Id: sinfo_utl_spectrum_divide_by_blackbody.c,v 1.3 2006/12/01 12:45:36 amodigli Exp $
00002  *
00003  * This file is part of the IIINSTRUMENT Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: amodigli $
00023  * $Date: 2006/12/01 12:45:36 $
00024  * $Revision: 1.3 $
00025  * $Name:  $
00026  */
00027 
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #  include <config.h>
00031 #endif
00032 /*----------------------------------------------------------------------------
00033                                 Includes
00034  ----------------------------------------------------------------------------*/
00035 
00036 
00037 #include "sinfo_utl_spectrum_divide_by_blackbody.h"
00038 /* #include <eclipse.h> */
00039 #include <sinfo_spectrum_ops.h>
00040 #include "sinfo_key_names.h"
00041 #include "sinfo_error.h"
00042 #include "sinfo_utils_wrappers.h"
00043 #include "sinfo_msg.h"
00044 /*----------------------------------------------------------------------------
00045                             Functions prototypes
00046  ----------------------------------------------------------------------------*/
00047 /*----------------------------------------------------------------------------
00048                             Static variables
00049  ----------------------------------------------------------------------------*/
00050 
00059 /*----------------------------------------------------------------------------
00060                                 Functions code
00061  ----------------------------------------------------------------------------*/
00062 
00063 /*---------------------------------------------------------------------------*/
00070 /*---------------------------------------------------------------------------*/
00071 int sinfo_utl_spectrum_divide_by_blackbody(
00072         cpl_parameterlist   *   parlist, 
00073         cpl_frameset        *   framelist)
00074 {
00075     cpl_parameter       *   param =NULL;
00076     const char          *   name_i =NULL;
00077     const char          *   name_o =NULL;
00078 
00079     double                  temp=0 ;
00080 
00081     cpl_frame           *   frm_spct=NULL ;
00082 
00083     cpl_propertylist    *   plist=NULL ;
00084 
00085 
00086     cpl_frame           *   product_frame=NULL;
00087     cpl_image * bb_img=NULL;
00088     cpl_image * image_o=NULL;
00089     cpl_image * image_i=NULL;
00090 
00091     Vector*   bb=NULL;
00092     /* double * ker=NULL; */
00093 
00094     /* HOW TO RETRIEVE INPUT PARAMETERS */
00095     /* --stropt */
00096     name_o = "out_ima.fits";
00097 
00098     /* --doubleopt */
00099 
00100     check_nomsg(param = cpl_parameterlist_find(parlist,
00101                 "sinfoni.sinfo_utl_spectrum_divide_by_blackbody.temperature"));
00102     check_nomsg(temp = cpl_parameter_get_double(param));
00103    
00104     /* HOW TO ACCESS INPUT DATA */
00105     check(frm_spct = cpl_frameset_find(framelist, 
00106                     SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM),
00107                     "SOF does not have a file tagged as %s",
00108                     SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM);
00109 
00110     check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct), 
00111                         0),"Cannot read the FITS header") ;
00112 
00113     /* Now performing the data reduction */
00114     /* Let's generate one image for the example */
00115     check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
00116     check_nomsg(image_i= cpl_image_load((char*)name_i, CPL_TYPE_FLOAT,0,0));  
00117     cknull_nomsg(bb= sinfo_new_blackbody_spectrum ((char*)name_i, temp));
00118     cknull_nomsg(bb_img = sinfo_new_vector_to_image(bb));
00119     cknull_nomsg(image_o = sinfo_new_div_image_by_spectrum (image_i,bb_img));
00120     
00121     /* HOW TO SAVE A PRODUCT ON DISK  */
00122     /* Set the file name */
00123 
00124     /* Create product frame */
00125     check_nomsg(product_frame = cpl_frame_new());
00126     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00127     check_nomsg(cpl_frame_set_tag(product_frame, 
00128                         SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_PROSPECTRUM));
00129     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
00130     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
00131     check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL));
00132 
00133     /* Add DataFlow keywords */
00134        /*
00135     check(cpl_dfs_setup_product_header(plist, product_frame, 
00136                                              framelist, parlist,
00137             "sinfo_utl_spectrum_divide_by_blackbody", "SINFONI", 
00138                 KEY_VALUE_HPRO_DID),"Problem in the product DFS-compliance") ;
00139        */
00140  
00141     /* Save the file */
00142     check(cpl_image_save(image_o, name_o, CPL_BPP_DEFAULT, plist,
00143                    CPL_IO_DEFAULT),"Could not save product");
00144 
00145     /* Log the saved file in the input frameset */
00146     check_nomsg(cpl_frameset_insert(framelist, product_frame));
00147 
00148  cleanup:
00149 
00150        sinfo_free_propertylist(&plist) ;
00151        sinfo_free_image(&image_i);
00152        sinfo_free_image(&image_o);
00153        sinfo_free_image(&bb_img);
00154      
00155 
00156     /* Return */
00157     if (cpl_error_get_code()) 
00158         return -1 ;
00159     else 
00160         return 0 ;
00161 }

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