sinfo_utl_spectrum_divide_by_blackbody.c

00001 /* $Id: sinfo_utl_spectrum_divide_by_blackbody.c,v 1.7 2007/06/06 07:10:45 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: 2007/06/06 07:10:45 $
00024  * $Revision: 1.7 $
00025  * $Name: sinfo-2_2_5 $
00026  */
00027 
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #  include <config.h>
00031 #endif
00032 /*----------------------------------------------------------------------------
00033                                 Includes
00034  ----------------------------------------------------------------------------*/
00035 
00036 #include <string.h>
00037 #include "sinfo_utl_spectrum_divide_by_blackbody.h"
00038 #include <sinfo_spectrum_ops.h>
00039 #include "sinfo_key_names.h"
00040 #include "sinfo_error.h"
00041 #include "sinfo_utils_wrappers.h"
00042 #include "sinfo_msg.h"
00043 /*----------------------------------------------------------------------------
00044                             Functions prototypes
00045  ----------------------------------------------------------------------------*/
00046 /*----------------------------------------------------------------------------
00047                             Static variables
00048  ----------------------------------------------------------------------------*/
00049 
00058 /*----------------------------------------------------------------------------
00059                                 Functions code
00060  ----------------------------------------------------------------------------*/
00061 
00062 /*---------------------------------------------------------------------------*/
00069 /*---------------------------------------------------------------------------*/
00070 int sinfo_utl_spectrum_divide_by_blackbody(
00071         cpl_parameterlist   *   parlist, 
00072         cpl_frameset        *   framelist)
00073 {
00074     cpl_parameter       *   param =NULL;
00075     const char          *   name_i =NULL;
00076     const char          *   name_o =NULL;
00077 
00078     double                  temp=0 ;
00079 
00080     cpl_frame           *   frm_spct=NULL ;
00081 
00082     cpl_propertylist    *   plist=NULL ;
00083 
00084 
00085     cpl_frame           *   product_frame=NULL;
00086     cpl_image * bb_img=NULL;
00087     cpl_image * image_o=NULL;
00088     cpl_image * image_i=NULL;
00089 
00090     Vector*   bb=NULL;
00091     /* double * ker=NULL; */
00092 
00093     /* HOW TO RETRIEVE INPUT PARAMETERS */
00094     /* --stropt */
00095     name_o = "out_ima.fits";
00096 
00097     /* --doubleopt */
00098 
00099     check_nomsg(param = cpl_parameterlist_find(parlist,
00100                 "sinfoni.sinfo_utl_spectrum_divide_by_blackbody.temperature"));
00101     check_nomsg(temp = cpl_parameter_get_double(param));
00102    
00103     /* HOW TO ACCESS INPUT DATA */
00104     check(frm_spct = cpl_frameset_find(framelist, 
00105                     SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM),
00106                     "SOF does not have a file tagged as %s",
00107                     SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM);
00108 
00109     check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct), 
00110                         0),"Cannot read the FITS header") ;
00111 
00112     /* Now performing the data reduction */
00113     /* Let's generate one image for the example */
00114     check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
00115     check_nomsg(image_i= cpl_image_load((char*)name_i, CPL_TYPE_FLOAT,0,0));  
00116     cknull_nomsg(bb= sinfo_new_blackbody_spectrum ((char*)name_i, temp));
00117     cknull_nomsg(bb_img = sinfo_new_vector_to_image(bb));
00118     cknull_nomsg(image_o = sinfo_new_div_image_by_spectrum (image_i,bb_img));
00119     
00120     /* HOW TO SAVE A PRODUCT ON DISK  */
00121     /* Set the file name */
00122 
00123     /* Create product frame */
00124     check_nomsg(product_frame = cpl_frame_new());
00125     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00126     check_nomsg(cpl_frame_set_tag(product_frame, 
00127                         SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_PROSPECTRUM));
00128     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
00129     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
00130     check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL));
00131 
00132     /* Add DataFlow keywords */
00133        /*
00134     check(cpl_dfs_setup_product_header(plist, product_frame, 
00135                                              framelist, parlist,
00136             "sinfo_utl_spectrum_divide_by_blackbody", "SINFONI", 
00137                 KEY_VALUE_HPRO_DID),"Problem in the product DFS-compliance") ;
00138        */
00139  
00140     /* Save the file */
00141     check(cpl_image_save(image_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
00142                    CPL_IO_DEFAULT),"Could not save product");
00143 
00144     /* Log the saved file in the input frameset */
00145     check_nomsg(cpl_frameset_insert(framelist, product_frame));
00146 
00147  cleanup:
00148 
00149        sinfo_free_propertylist(&plist) ;
00150        sinfo_free_image(&image_i);
00151        sinfo_free_image(&image_o);
00152        sinfo_free_image(&bb_img);
00153      
00154 
00155     /* Return */
00156     if (cpl_error_get_code()) 
00157         return -1 ;
00158     else 
00159         return 0 ;
00160 }

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