sinfoni/sinfo_utl_spectrum_wavelength_shift.c

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

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