SINFONI Pipeline Reference Manual  2.6.0
sinfo_utl_line_oh_select.c
1 /* $Id: sinfo_utl_line_oh_select.c,v 1.3 2013-07-15 08:14:38 amodigli Exp $
2  *
3  * This file is part of the SINFONI 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: 2013-07-15 08:14:38 $
24  * $Revision: 1.3 $
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 <math.h>
37 #include <cpl.h>
38 
39 #include "irplib_utils.h"
40 #include <sinfo_utils_wrappers.h>
41 #include <sinfo_msg.h>
42 
43 #include "sinfo_raw_types.h"
44 #include "sinfo_pro_types.h"
45 #include "sinfo_tpl_utils.h"
46 #include "sinfo_tpl_dfs.h"
47 #include "sinfo_globals.h"
48 
49 /*-----------------------------------------------------------------------------
50  Functions prototypes
51  -----------------------------------------------------------------------------*/
52 
53 static int sinfo_utl_line_oh_select_create(cpl_plugin *) ;
54 static int sinfo_utl_line_oh_select_exec(cpl_plugin *) ;
55 static int sinfo_utl_line_oh_select_destroy(cpl_plugin *) ;
56 static int sinfo_utl_line_oh_select(cpl_parameterlist *, cpl_frameset *) ;
57 
58 /*-----------------------------------------------------------------------------
59  Static variables
60  -----------------------------------------------------------------------------*/
61 
62 static char sinfo_utl_line_oh_select_description[] =
63  "sinfo_utl_line_oh_select -- SINFONI OH LINE table creation.\n"
64  "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
65  "raw-file.fits REF_LINE_OH \n" ;
66 
67 /*-----------------------------------------------------------------------------
68  Functions code
69  -----------------------------------------------------------------------------*/
70 
71 /*----------------------------------------------------------------------------*/
79 /*----------------------------------------------------------------------------*/
80 int cpl_plugin_get_info(cpl_pluginlist * list)
81 {
82  cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
83  cpl_plugin * plugin = &recipe->interface ;
84 
85  cpl_plugin_init(plugin,
86  CPL_PLUGIN_API,
87  SINFONI_BINARY_VERSION,
88  CPL_PLUGIN_TYPE_RECIPE,
89  "sinfo_utl_line_oh_select",
90  "OH line table creation",
91  sinfo_utl_line_oh_select_description,
92  "Andrea Modigliani",
93  "amodigli@eso.org",
94  sinfo_get_license(),
95  sinfo_utl_line_oh_select_create,
96  sinfo_utl_line_oh_select_exec,
97  sinfo_utl_line_oh_select_destroy) ;
98 
99  cpl_pluginlist_append(list, plugin) ;
100 
101  return 0;
102 }
103 
104 /*----------------------------------------------------------------------------*/
113 /*----------------------------------------------------------------------------*/
114 static int sinfo_utl_line_oh_select_create(cpl_plugin * plugin)
115 {
116  cpl_recipe * recipe ;
117  cpl_parameter* p=NULL;
118 
119  /* Get the recipe out of the plugin */
120  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
121  recipe = (cpl_recipe *)plugin ;
122  else return -1 ;
123 
124  /* Create the parameters list in the cpl_recipe object */
125  recipe->parameters = cpl_parameterlist_new() ;
126 
127  /* --doubleopt */
128  p = cpl_parameter_new_range("sinfoni.sinfo_utl_line_oh_select.wmin",
129  CPL_TYPE_DOUBLE, "wmin",
130  "sinfoni.sinfo_utl_line_oh_select",
131  1040.,1000.,2500.) ;
132  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wmin") ;
133  cpl_parameterlist_append(recipe->parameters, p) ;
134 
135 
136  p = cpl_parameter_new_range("sinfoni.sinfo_utl_line_oh_select.wmax",
137  CPL_TYPE_DOUBLE, "wmax",
138  "sinfoni.sinfo_utl_line_oh_select",
139  1880.,1000.,2500.) ;
140  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wmax") ;
141  cpl_parameterlist_append(recipe->parameters, p) ;
142 
143  p = cpl_parameter_new_value("sinfoni.sinfo_utl_line_oh_select.intnorm",
144  CPL_TYPE_DOUBLE, "intnorm",
145  "sinfoni.sinfo_utl_line_oh_select",
146  4.) ;
147  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intnorm") ;
148  cpl_parameterlist_append(recipe->parameters, p) ;
149 
150  p = cpl_parameter_new_value("sinfoni.sinfo_utl_line_oh_select.intlimit",
151  CPL_TYPE_DOUBLE, "intlimit",
152  "sinfoni.sinfo_utl_line_oh_select",
153  50.) ;
154  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intlimit") ;
155  cpl_parameterlist_append(recipe->parameters, p) ;
156 
157 
158 
159 
160  /* Return */
161  return 0;
162 }
163 
164 /*----------------------------------------------------------------------------*/
170 /*----------------------------------------------------------------------------*/
171 static int sinfo_utl_line_oh_select_exec(cpl_plugin * plugin)
172 {
173  cpl_recipe * recipe ;
174 
175  /* Get the recipe out of the plugin */
176  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
177  recipe = (cpl_recipe *)plugin ;
178  else return -1 ;
179 
180  return sinfo_utl_line_oh_select(recipe->parameters, recipe->frames) ;
181 }
182 
183 /*----------------------------------------------------------------------------*/
189 /*----------------------------------------------------------------------------*/
190 static int sinfo_utl_line_oh_select_destroy(cpl_plugin * plugin)
191 {
192  cpl_recipe * recipe ;
193 
194  /* Get the recipe out of the plugin */
195  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
196  recipe = (cpl_recipe *)plugin ;
197  else return -1 ;
198 
199  cpl_parameterlist_delete(recipe->parameters) ;
200  return 0 ;
201 }
202 
203 /*----------------------------------------------------------------------------*/
210 /*----------------------------------------------------------------------------*/
211 static int sinfo_utl_line_oh_select(
212  cpl_parameterlist * parlist,
213  cpl_frameset * framelist)
214 {
215  cpl_parameter* p=NULL;
216  cpl_frame* frame=NULL;
217 
218  cpl_frameset * rawframes ;
219  int nframes;
220  cpl_propertylist* phead=NULL;
221  cpl_table * tab_in ;
222  cpl_table * tab_ou ;
223 
224  int nm2AA=10.;
225 
226 
227  double wmin=0;
228  double wmax=0;
229  double intnorm=0;
230  double intlimit=0;
231  int next=0;
232  int nrow=0;
233  /* Identify the RAW and CALIB frames in the input frameset */
234  if (sinfo_dfs_set_groups(framelist)) {
235  cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
236  return -1 ;
237  }
238 
239  /* Retrieve raw frames */
240  if ((rawframes = sinfo_extract_frameset(framelist,
241  "REF_LINE_OH")) == NULL) {
242  cpl_msg_error(__func__, "Cannot find raw frames in the input list") ;
243  return -1 ;
244  }
245 
246  p=cpl_parameterlist_find(parlist, "sinfoni.sinfo_utl_line_oh_select.wmin");
247  wmin = cpl_parameter_get_double(p);
248 
249  p=cpl_parameterlist_find(parlist, "sinfoni.sinfo_utl_line_oh_select.wmax");
250  wmax = cpl_parameter_get_double(p);
251 
252  p=cpl_parameterlist_find(parlist, "sinfoni.sinfo_utl_line_oh_select.intnorm");
253  intnorm = cpl_parameter_get_double(p);
254  p=cpl_parameterlist_find(parlist, "sinfoni.sinfo_utl_line_oh_select.intlimit");
255  intlimit = cpl_parameter_get_double(p);
256 
257  nframes = cpl_frameset_get_size(rawframes) ;
258 
259  /* Load */
260  if(nframes > 0) {
261  frame=cpl_frameset_get_frame(rawframes,0);
262  }
263  tab_in=cpl_table_load(cpl_frame_get_filename(frame),1,0);
264  nrow=cpl_table_get_nrow(tab_in);
265 
266  cpl_table_divide_scalar(tab_in,"wave",nm2AA);
267  cpl_table_divide_scalar(tab_in,"int",intnorm);
268  sinfo_msg("wmin=%g wmax=%g",wmin,wmax);
269  sinfo_msg("nrow=%d",nrow);
270  cpl_table_dump(tab_in,1,2,stdout);
271  cpl_table_dump(tab_in,nrow-10,2,stdout);
272  next=cpl_table_and_selected_double(tab_in,"wave",CPL_GREATER_THAN,wmin);
273  sinfo_msg("next=%d",next);
274  next=cpl_table_and_selected_double(tab_in,"wave",CPL_LESS_THAN,wmax);
275  sinfo_msg("next=%d",next);
276  next=cpl_table_and_selected_double(tab_in,"int",CPL_GREATER_THAN,intlimit);
277  sinfo_msg("next=%d",next);
278  tab_ou=cpl_table_extract_selected(tab_in);
279 
280  cpl_table_save(tab_ou,phead,NULL,"oh_selected.fits",CPL_IO_DEFAULT);
281 
282  /* Free and return */
283  sinfo_free_table(&tab_in);
284  sinfo_free_table(&tab_ou);
285  sinfo_free_propertylist(&phead);
286 
287 
288  return 0 ;
289 }
290 
291 
292 
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.