SINFONI Pipeline Reference Manual  2.6.0
sinfoni/sinfo_utl_spectrum_wavelength_shift.c
1 /* $Id: sinfo_utl_spectrum_wavelength_shift.c,v 1.8 2012-03-03 10:17:31 amodigli Exp $
2  *
3  * This file is part of the IIINSTRUMENT Pipeline
4  * Copyright (C) 2002,2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: amodigli $
23  * $Date: 2012-03-03 10:17:31 $
24  * $Revision: 1.8 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include <string.h>
37 
38 #include "sinfo_utl_spectrum_wavelength_shift.h"
39 #include "sinfo_spectrum_ops.h"
40 #include "sinfo_shift_images.h"
41 #include "sinfo_key_names.h"
42 #include "sinfo_error.h"
43 #include "sinfo_utils_wrappers.h"
44 #include "sinfo_msg.h"
45 /*-----------------------------------------------------------------------------
46  Functions prototypes
47  -----------------------------------------------------------------------------*/
48 /*-----------------------------------------------------------------------------
49  Static variables
50  -----------------------------------------------------------------------------*/
51 
60 /*-----------------------------------------------------------------------------
61  Functions code
62  -----------------------------------------------------------------------------*/
63 
64 /*----------------------------------------------------------------------------*/
71 /*----------------------------------------------------------------------------*/
72 int
73 sinfo_utl_spectrum_wavelength_shift(cpl_parameterlist * parlist,
74  cpl_frameset * framelist)
75 {
76  cpl_parameter * param = NULL;
77  const char * method = NULL;
78  const char * name_i = NULL;
79  const char * name_o = NULL;
80 
81  double shift = 0;
82 
83  cpl_frame * frm_spct = NULL;
84 
85  cpl_propertylist * plist = NULL;
86 
87  cpl_frame * product_frame = NULL;
88  cpl_image * image_o = NULL;
89  cpl_image * image_i = NULL;
90  cpl_image * image_s = NULL;
91 
92  double* sub_shift = NULL;
93  /* double * ker=NULL; */
94 
95  /* HOW TO RETRIEVE INPUT PARAMETERS */
96  /* --stropt */
97  name_o = "out_ima.fits";
98 
99  /* --doubleopt */
100  check_nomsg(
101  param = cpl_parameterlist_find(parlist,
102  "sinfoni.sinfo_utl_spectrum_arith.method"));
103  check_nomsg(method = cpl_parameter_get_string(param));
104 
105  check_nomsg(
106  param =
107  cpl_parameterlist_find(parlist,
108  "sinfoni.sinfo_utl_spectrum_wavelength_shift.shift"));
109  check_nomsg(shift = cpl_parameter_get_double(param));
110 
111  /* HOW TO ACCESS INPUT DATA */
112  check(
113  frm_spct = cpl_frameset_find(framelist, SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM),
114  "SOF does not have a file tagged as %s",
115  SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM);
116 
117  check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct),
118  0),"Cannot read the FITS header");
119  /* Now performing the data reduction */
120  /* Let's generate one image for the example */
121  check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
122  check_nomsg(image_i = cpl_image_load((char* )name_i, CPL_TYPE_FLOAT, 0, 0));
123  sub_shift = sinfo_new_doublearray(1);
124  sinfo_new_doublearray_set_value(sub_shift, 0., 0);
125  cknull(image_s = sinfo_new_shift_image_in_spec(image_i, shift, sub_shift),
126  "error in sinfo_new_shift_image_in_spec()");
127 
128  shift = sinfo_new_doublearray_get_value(sub_shift, 0);
129 
130  if (strcmp(method, "S") == 0) {
131 
132  cknull(
133  image_o = sinfo_new_fine_shift_image_in_spec_cubic_spline(
134  image_s, shift),
135  "error in fine_shift_image_in_spec_cubic_spline()");
136 
137  }
138  else if (strcmp(method, "P") == 0) {
139  cknull(image_o = sinfo_new_fine_shift_image_in_spec_poly(image_s, shift, 2),
140  "error in sinfo_fineShiftImageInSpecPoly()");
141  /*
142  } else if (strcmp (method, "T")==0) {
143  ker = sinfo_new_generate_interpolation_kernel("tanh");
144  cknull(image_o = sinfo_new_shift_image ( image_s, 0, shift, ker ),
145  "error in sinfo_new_fine_shift_image_in_spec_poly()");
146  */
147  /* sinfo_new_destroy_doublearray(ker); */
148  }
149  else {
150  sinfo_msg_error("wrong method %s", method);
151  goto cleanup;
152  }
153 
154  /* HOW TO SAVE A PRODUCT ON DISK */
155  /* Set the file name */
156 
157  /* Create product frame */
158  check_nomsg(product_frame = cpl_frame_new());
159  check_nomsg(cpl_frame_set_filename(product_frame, name_o));
160  check_nomsg(cpl_frame_set_tag(product_frame,
161  SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_PROSPECTRUM));
162  check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
163  check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
164  check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL));
165 
166  /* Add DataFlow keywords */
167  /*
168  check(cpl_dfs_setup_product_header(plist, product_frame,
169  framelist, parlist,
170  "si_sinfo_utl_spectrum_wavelength_shift",
171  "SINFONI", KEY_VALUE_HPRO_DID),
172  "Problem in the product DFS-compliance") ;
173  */
174 
175  /* Save the file */
176  check(cpl_image_save(image_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
177  CPL_IO_DEFAULT),"Could not save product");
178  check_nomsg(cpl_frameset_insert(framelist, product_frame));
179  cleanup: sinfo_free_image(&image_i);
180  sinfo_free_image(&image_o);
181  sinfo_free_image(&image_s);
182  if (sub_shift != NULL )
183  sinfo_new_destroy_doublearray(sub_shift);
184  sinfo_free_propertylist(&plist);
185 
186  if (cpl_error_get_code())
187  return -1;
188  else
189  return 0;
190 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69