sinfo_utl_spectrum_wavelength_shift.c

00001 /* $Id: sinfo_utl_spectrum_wavelength_shift.c,v 1.8 2012/03/03 10:17:31 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: 2012/03/03 10:17:31 $
00024  * $Revision: 1.8 $
00025  * $Name: HEAD $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <string.h>
00037 
00038 #include "sinfo_utl_spectrum_wavelength_shift.h"
00039 #include "sinfo_spectrum_ops.h"
00040 #include "sinfo_shift_images.h"
00041 #include "sinfo_key_names.h"
00042 #include "sinfo_error.h"
00043 #include "sinfo_utils_wrappers.h"
00044 #include "sinfo_msg.h"
00045 /*-----------------------------------------------------------------------------
00046                             Functions prototypes
00047  -----------------------------------------------------------------------------*/
00048 /*-----------------------------------------------------------------------------
00049                             Static variables
00050  -----------------------------------------------------------------------------*/
00051 
00060 /*-----------------------------------------------------------------------------
00061                                 Functions code
00062  -----------------------------------------------------------------------------*/
00063 
00064 /*----------------------------------------------------------------------------*/
00071 /*----------------------------------------------------------------------------*/
00072 int sinfo_utl_spectrum_wavelength_shift(
00073         cpl_parameterlist   *   parlist, 
00074         cpl_frameset        *   framelist)
00075 {
00076     cpl_parameter       *   param =NULL;
00077     const char          *   method =NULL;
00078     const char          *   name_i =NULL;
00079     const char          *   name_o =NULL;
00080 
00081     double                  shift=0 ;
00082 
00083     cpl_frame           *   frm_spct=NULL ;
00084 
00085     cpl_propertylist    *   plist=NULL ;
00086 
00087     cpl_frame           *   product_frame=NULL;
00088     cpl_image * image_o=NULL;
00089     cpl_image * image_i=NULL;
00090     cpl_image * image_s=NULL;
00091 
00092     double* sub_shift=NULL;
00093     /* double * ker=NULL; */
00094 
00095     /* HOW TO RETRIEVE INPUT PARAMETERS */
00096     /* --stropt */
00097     name_o = "out_ima.fits";
00098  
00099     /* --doubleopt */
00100     check_nomsg(param = cpl_parameterlist_find(parlist, 
00101                                   "sinfoni.sinfo_utl_spectrum_arith.method"));
00102     check_nomsg(method = cpl_parameter_get_string(param));
00103 
00104 
00105     check_nomsg(param = cpl_parameterlist_find(parlist,
00106                          "sinfoni.sinfo_utl_spectrum_wavelength_shift.shift"));
00107     check_nomsg(shift = cpl_parameter_get_double(param));
00108   
00109    
00110     /* HOW TO ACCESS INPUT DATA */
00111     check(frm_spct = cpl_frameset_find(framelist, 
00112                                    SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM),
00113                                    "SOF does not have a file tagged as %s",
00114                                    SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM);
00115 
00116     check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct), 
00117                         0),"Cannot read the FITS header") ;
00118    /* Now performing the data reduction */
00119     /* Let's generate one image for the example */
00120     check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
00121     check_nomsg(image_i= cpl_image_load ((char*)name_i,CPL_TYPE_FLOAT,0,0));  
00122     sub_shift = sinfo_new_doublearray(1);
00123     sinfo_new_doublearray_set_value(sub_shift, 0., 0);
00124     cknull(image_s = sinfo_new_shift_image_in_spec (image_i, shift, sub_shift),
00125          "error in sinfo_new_shift_image_in_spec()");
00126 
00127     shift = sinfo_new_doublearray_get_value(sub_shift, 0);
00128  
00129     if (strcmp(method,"S")==0) {
00130 
00131        cknull(image_o = sinfo_new_fine_shift_image_in_spec_cubic_spline (
00132                        image_s, shift ),
00133                        "error in fine_shift_image_in_spec_cubic_spline()");
00134 
00135        } else if (strcmp(method,"P")==0) {
00136      cknull(image_o = sinfo_new_fine_shift_image_in_spec_poly(
00137                             image_s,shift,2),
00138                             "error in sinfo_fineShiftImageInSpecPoly()");
00139       /*
00140        } else if (strcmp (method, "T")==0) {
00141       ker = sinfo_new_generate_interpolation_kernel("tanh");
00142           cknull(image_o = sinfo_new_shift_image ( image_s, 0, shift, ker ),
00143               "error in sinfo_new_fine_shift_image_in_spec_poly()");
00144       */
00145           /* sinfo_new_destroy_doublearray(ker); */
00146        }  else {
00147           sinfo_msg_error("wrong method %s",method);
00148           goto cleanup;
00149        }
00150     
00151     /* HOW TO SAVE A PRODUCT ON DISK  */
00152     /* Set the file name */
00153 
00154     /* Create product frame */
00155     check_nomsg(product_frame = cpl_frame_new());
00156     check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00157     check_nomsg(cpl_frame_set_tag(product_frame, 
00158                                 SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_PROSPECTRUM)) ;
00159     check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
00160     check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00161     check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL)) ;
00162 
00163     /* Add DataFlow keywords */
00164     /*
00165     check(cpl_dfs_setup_product_header(plist, product_frame, 
00166                                       framelist, parlist,
00167                                       "si_sinfo_utl_spectrum_wavelength_shift", 
00168                                       "SINFONI", KEY_VALUE_HPRO_DID),
00169         "Problem in the product DFS-compliance") ;
00170     */
00171    
00172    
00173     /* Save the file */
00174     check(cpl_image_save(image_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
00175              CPL_IO_DEFAULT),"Could not save product");
00176     check_nomsg(cpl_frameset_insert(framelist, product_frame));
00177  cleanup:
00178     sinfo_free_image(&image_i);
00179     sinfo_free_image(&image_o);
00180     sinfo_free_image(&image_s);
00181     if(sub_shift != NULL) sinfo_new_destroy_doublearray(sub_shift);
00182     sinfo_free_propertylist(&plist);
00183 
00184     if (cpl_error_get_code()) 
00185         return -1 ;
00186     else 
00187         return 0 ;
00188 }

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1