SINFONI Pipeline Reference Manual  2.6.0
sinfoni/sinfo_utl_spectrum_divide_by_blackbody.c
1 /* $Id: sinfo_utl_spectrum_divide_by_blackbody.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  Includes
33  ----------------------------------------------------------------------------*/
34 
35 #include <string.h>
36 #include "sinfo_utl_spectrum_divide_by_blackbody.h"
37 #include <sinfo_spectrum_ops.h>
38 #include "sinfo_key_names.h"
39 #include "sinfo_error.h"
40 #include "sinfo_utils_wrappers.h"
41 #include "sinfo_msg.h"
42 /*----------------------------------------------------------------------------
43  Functions prototypes
44  ----------------------------------------------------------------------------*/
45 /*----------------------------------------------------------------------------
46  Static variables
47  ----------------------------------------------------------------------------*/
48 
57 /*----------------------------------------------------------------------------
58  Functions code
59  ----------------------------------------------------------------------------*/
60 
61 /*---------------------------------------------------------------------------*/
68 /*---------------------------------------------------------------------------*/
69 int
70 sinfo_utl_spectrum_divide_by_blackbody(cpl_parameterlist * parlist,
71  cpl_frameset * framelist)
72 {
73  cpl_parameter * param = NULL;
74  const char * name_i = NULL;
75  const char * name_o = NULL;
76 
77  double temp = 0;
78 
79  cpl_frame * frm_spct = NULL;
80 
81  cpl_propertylist * plist = NULL;
82 
83  cpl_frame * product_frame = NULL;
84  cpl_image * bb_img = NULL;
85  cpl_image * image_o = NULL;
86  cpl_image * image_i = NULL;
87 
88  Vector* bb = NULL;
89  /* double * ker=NULL; */
90 
91  /* HOW TO RETRIEVE INPUT PARAMETERS */
92  /* --stropt */
93  name_o = "out_ima.fits";
94 
95  /* --doubleopt */
96 
97  check_nomsg(
98  param =
99  cpl_parameterlist_find(parlist,
100  "sinfoni.sinfo_utl_spectrum_divide_by_blackbody.temperature"));
101  check_nomsg(temp = cpl_parameter_get_double(param));
102 
103  /* HOW TO ACCESS INPUT DATA */
104  check(
105  frm_spct = cpl_frameset_find(framelist, SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM),
106  "SOF does not have a file tagged as %s",
107  SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_SPECTRUM);
108 
109  check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct),
110  0),"Cannot read the FITS header");
111 
112 /* Now performing the data reduction */
113 /* Let's generate one image for the example */
114 check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
115 check_nomsg(image_i = cpl_image_load((char* )name_i, CPL_TYPE_FLOAT, 0, 0));
116 cknull_nomsg(bb = sinfo_new_blackbody_spectrum((char* )name_i, temp));
117 cknull_nomsg(bb_img = sinfo_new_vector_to_image(bb));
118 cknull_nomsg(image_o = sinfo_new_div_image_by_spectrum(image_i, bb_img));
119 
120 /* HOW TO SAVE A PRODUCT ON DISK */
121 /* Set the file name */
122 
123 /* Create product frame */
124 check_nomsg(product_frame = cpl_frame_new());
125 check_nomsg(cpl_frame_set_filename(product_frame, name_o));
126 check_nomsg(
127  cpl_frame_set_tag(product_frame, SI_UTL_SPECTRUM_DIVIDE_BY_BLACKBODY_PROSPECTRUM));
128 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
129 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
130 check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL));
131 
132 /* Add DataFlow keywords */
133 /*
134  check(cpl_dfs_setup_product_header(plist, product_frame,
135  framelist, parlist,
136  "sinfo_utl_spectrum_divide_by_blackbody", "SINFONI",
137  KEY_VALUE_HPRO_DID),"Problem in the product DFS-compliance") ;
138  */
139 
140 /* Save the file */
141 check(
142  cpl_image_save(image_o, name_o, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT),
143  "Could not save product");
144 
145 /* Log the saved file in the input frameset */
146 check_nomsg(cpl_frameset_insert(framelist, product_frame));
147 
148 cleanup:
149 
150 sinfo_free_propertylist(&plist);
151 sinfo_free_image(&image_i);
152 sinfo_free_image(&image_o);
153 sinfo_free_image(&bb_img);
154 
155 /* Return */
156 if (cpl_error_get_code())
157  return -1;
158 else
159  return 0;
160 }