utl_spectrum_divide_by_blackbody.c

00001 /* $Id: utl_spectrum_divide_by_blackbody.c,v 1.1 2005/10/14 16:14:46 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: 2005/10/14 16:14:46 $
00024  * $Revision: 1.1 $
00025  * $Name:  $
00026  */
00027 
00028 
00029 /*-----------------------------------------------------------------------------
00030                                 Includes
00031  -----------------------------------------------------------------------------*/
00032 
00033 
00034 #include "utl_spectrum_divide_by_blackbody.h"
00035 #include <eclipse.h>
00036 #include <spectrum_ops.h>
00037 #include "sinfoni_key_names.h"
00038 #include <sinfoni_memory.h>
00039 
00040 /*-----------------------------------------------------------------------------
00041                             Functions prototypes
00042  -----------------------------------------------------------------------------*/
00043 /*-----------------------------------------------------------------------------
00044                             Static variables
00045  -----------------------------------------------------------------------------*/
00046 
00047 
00048 /*-----------------------------------------------------------------------------
00049                                 Functions code
00050  -----------------------------------------------------------------------------*/
00051 
00052 /*----------------------------------------------------------------------------*/
00059 /*----------------------------------------------------------------------------*/
00060 int si_utl_spectrum_divide_by_blackbody(
00061         cpl_parameterlist   *   parlist, 
00062         cpl_frameset        *   framelist)
00063 {
00064     const char          *   fctid = "si_utl_spectrum_divide_by_blackbody" ;
00065     cpl_parameter       *   param =NULL;
00066     const char          *   name_i =NULL;
00067     const char          *   name_o =NULL;
00068 
00069     double                  temp=0 ;
00070 
00071     cpl_frame           *   frm_spct=NULL ;
00072 
00073     cpl_propertylist    *   plist=NULL ;
00074     cpl_image           *   image   =NULL;
00075     cpl_image           *   image_w   =NULL;
00076 
00077     cpl_frame           *   product_frame=NULL;
00078     OneImage * bb_img=NULL;
00079     OneImage * image_o=NULL;
00080     OneImage * image_i=NULL;
00081 
00082     Vector*   bb=NULL;
00083     /* double * ker=NULL; */
00084 
00085     /* HOW TO RETRIEVE INPUT PARAMETERS */
00086     /* --stropt */
00087     name_o = "out_ima.fits";
00088 
00089     /* --doubleopt */
00090     param = cpl_parameterlist_find(parlist,"sinfoni.si_utl_spectrum_divide_by_blackbody.temperature");
00091     temp = cpl_parameter_get_double(param) ;
00092 
00093    
00094     /* HOW TO ACCESS INPUT DATA */
00095     if ((frm_spct = cpl_frameset_find(framelist, SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM))==NULL) {
00096         cpl_msg_error(fctid, "SOF does not have a file tagged as %s",SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM);
00097         return -1 ;
00098     }
00099 
00100 
00101     if ((plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct), 
00102                     0)) == NULL) {
00103         cpl_msg_error(fctid, "Cannot read the FITS header") ;
00104         return -1 ;
00105     }
00106     /* Now performing the data reduction */
00107     /* Let's generate one image for the example */
00108     name_i = cpl_frame_get_filename(frm_spct);
00109     image_i= load_image ((char*)name_i);                                    
00110     bb     = blackbodySpectrum ((char*)name_i, temp);
00111     bb_img = vectorToImage(bb);
00112     image_o = divImageBySpectrum (image_i,bb_img);
00113     
00114     /* HOW TO SAVE A PRODUCT ON DISK  */
00115     /* Set the file name */
00116     image_w=cpl_image_wrap_float(image_o->lx,image_o->ly,image_o->data);
00117     image=cpl_image_duplicate(image_w);
00118     cpl_image_unwrap(image_w);
00119 
00120     /* Create product frame */
00121     product_frame = cpl_frame_new();
00122     cpl_frame_set_filename(product_frame, name_o) ;
00123     cpl_frame_set_tag(product_frame, SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_PROSPECTRUM) ;
00124     cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
00125     cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT) ;
00126     cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL) ;
00127     if (cpl_error_get_code()) {
00128         cpl_msg_error(fctid, "Error while initialising the product frame") ;
00129     cpl_propertylist_delete(plist) ;
00130         cpl_frame_delete(product_frame) ;
00131         cpl_image_delete(image) ;
00132     destroy_image(image_i);
00133     destroy_image(image_o);
00134       if(bb != NULL) {
00135         /* destroyVector(bb); */
00136       }
00137       if(bb_img != NULL) {
00138         destroy_image(bb_img);
00139       }
00140         sinfoni_memory_status();
00141         return -1 ;
00142     }
00143 
00144     /* Add DataFlow keywords */
00145     /*
00146     if (cpl_dfs_setup_product_header(plist, product_frame, framelist, parlist,
00147             "si_utl_spectrum_divide_by_blackbody", "SINFONI", KEY_VALUE_HPRO_DID) != CPL_ERROR_NONE) {
00148         cpl_msg_error(fctid, "Problem in the product DFS-compliance") ;
00149         cpl_propertylist_delete(plist) ;
00150         cpl_frame_delete(product_frame) ;
00151         cpl_image_delete(image) ;
00152         return -1 ;
00153     }
00154     */
00155    
00156     /* Save the file */
00157     if (cpl_image_save(image, name_o, CPL_BPP_DEFAULT, plist,
00158                        CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00159         cpl_msg_error(fctid, "Could not save product");
00160         cpl_propertylist_delete(plist) ;
00161         cpl_frame_delete(product_frame) ;
00162         cpl_image_delete(image) ;
00163         return -1 ;
00164     }
00165     cpl_propertylist_delete(plist) ;
00166     cpl_image_delete(image) ;
00167 
00168 
00169 
00170     /* Log the saved file in the input frameset */
00171     cpl_frameset_insert(framelist, product_frame) ;
00172 
00173     destroy_image(image_i);
00174     destroy_image(image_o);
00175 
00176        if(bb != NULL) {
00177      /* destroyVector(bb); */
00178        }
00179        if(bb_img != NULL) {
00180           destroy_image(bb_img);
00181        }
00182 
00183        sinfoni_memory_status();
00184     /* Return */
00185     if (cpl_error_get_code()) 
00186         return -1 ;
00187     else 
00188         return 0 ;
00189 }

Generated on Wed Oct 26 13:08:56 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001