SINFONI Pipeline Reference Manual  2.5.2
sinfo_utl_stdstars.c
1 /* $Id: sinfo_utl_stdstars.c,v 1.5 2012-05-04 08:12:07 amodigli Exp $
2  *
3  * This file is part of the ISAAC 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-05-04 08:12:07 $
24  * $Revision: 1.5 $
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 "irplib_stdstar.h"
41 
42 #include "sinfo_raw_types.h"
43 #include "sinfo_pro_types.h"
44 #include "sinfo_tpl_utils.h"
45 #include "sinfo_tpl_dfs.h"
46 
47 /*
48 #include "isaac_utils.h"
49 #include "isaac_pfits.h"
50 #include "isaac_dfs.h"
51  */
52 
53 /*-----------------------------------------------------------------------------
54  Functions prototypes
55  -----------------------------------------------------------------------------*/
56 
57 static int sinfo_utl_stdstars_create(cpl_plugin *) ;
58 static int sinfo_utl_stdstars_exec(cpl_plugin *) ;
59 static int sinfo_utl_stdstars_destroy(cpl_plugin *) ;
60 static int sinfo_utl_stdstars(cpl_frameset *) ;
61 static cpl_table * sinfo_utl_stdstars_convert(const char *) ;
62 
63 /*-----------------------------------------------------------------------------
64  Static variables
65  -----------------------------------------------------------------------------*/
66 
67 static char sinfo_utl_stdstars_description[] =
68  "sinfo_utl_stdstars -- SINFONI standard stars catalog creation.\n"
69  "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
70  "raw-file.fits "SINFO_UTL_STDSTARS_RAW"\n" ;
71 
72 /*-----------------------------------------------------------------------------
73  Functions code
74  -----------------------------------------------------------------------------*/
75 
76 
77 /*--------------------------------------------------------------------------*/
81 /*---------------------------------------------------------------------------*/
82 
83 /*----------------------------------------------------------------------------*/
91 /*----------------------------------------------------------------------------*/
92 int cpl_plugin_get_info(cpl_pluginlist * list)
93 {
94  cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
95  cpl_plugin * plugin = &recipe->interface ;
96 
97  cpl_plugin_init(plugin,
98  CPL_PLUGIN_API,
99  SINFONI_BINARY_VERSION,
100  CPL_PLUGIN_TYPE_RECIPE,
101  "sinfo_utl_stdstars",
102  "Standard stars catalog creation",
103  sinfo_utl_stdstars_description,
104  "Andrea Modigliani",
105  "amodigli@eso.org",
106  sinfo_get_license(),
107  sinfo_utl_stdstars_create,
108  sinfo_utl_stdstars_exec,
109  sinfo_utl_stdstars_destroy) ;
110 
111  cpl_pluginlist_append(list, plugin) ;
112 
113  return 0;
114 }
115 
116 /*----------------------------------------------------------------------------*/
125 /*----------------------------------------------------------------------------*/
126 static int sinfo_utl_stdstars_create(cpl_plugin * plugin)
127 {
128  cpl_recipe * recipe ;
129 
130  /* Get the recipe out of the plugin */
131  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
132  recipe = (cpl_recipe *)plugin ;
133  else return -1 ;
134 
135  /* Create the parameters list in the cpl_recipe object */
136  recipe->parameters = cpl_parameterlist_new() ;
137 
138  /* Return */
139  return 0;
140 }
141 
142 /*----------------------------------------------------------------------------*/
148 /*----------------------------------------------------------------------------*/
149 static int sinfo_utl_stdstars_exec(cpl_plugin * plugin)
150 {
151  cpl_recipe * recipe ;
152 
153  /* Get the recipe out of the plugin */
154  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
155  recipe = (cpl_recipe *)plugin ;
156  else return -1 ;
157 
158  return sinfo_utl_stdstars(recipe->frames) ;
159 }
160 
161 /*----------------------------------------------------------------------------*/
167 /*----------------------------------------------------------------------------*/
168 static int sinfo_utl_stdstars_destroy(cpl_plugin * plugin)
169 {
170  cpl_recipe * recipe ;
171 
172  /* Get the recipe out of the plugin */
173  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
174  recipe = (cpl_recipe *)plugin ;
175  else return -1 ;
176 
177  cpl_parameterlist_delete(recipe->parameters) ;
178  return 0 ;
179 }
180 
181 /*----------------------------------------------------------------------------*/
187 /*----------------------------------------------------------------------------*/
188 static int sinfo_utl_stdstars(
189  cpl_frameset * framelist)
190 {
191  cpl_frameset * rawframes ;
192 
193  /* Identify the RAW and CALIB frames in the input frameset */
194  if (sinfo_dfs_set_groups(framelist)) {
195  cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
196  return -1 ;
197  }
198 
199  /* Retrieve raw frames */
200  if ((rawframes = sinfo_extract_frameset(framelist,
201  SINFO_UTL_STDSTARS_RAW)) == NULL) {
202  cpl_msg_error(__func__, "Cannot find raw frames in the input list") ;
203  return -1 ;
204  }
205 
206  /* Write the catalog */
207  if (irplib_stdstar_write_catalogs(framelist,
208  rawframes,
209  "sinfo_utl_stdstars",
210  SINFO_UTL_STDSTARS_RES, NULL,
211  PACKAGE "/" PACKAGE_VERSION,
212  "SINFONI",
213  sinfo_utl_stdstars_convert) == -1) {
214  cpl_msg_error(__func__, "Cannot write the catalogs") ;
215  cpl_frameset_delete(rawframes) ;
216  return -1 ;
217  }
218  cpl_frameset_delete(rawframes) ;
219  return 0 ;
220 }
221 
222 /*----------------------------------------------------------------------------*/
243 /*----------------------------------------------------------------------------*/
244 static cpl_table * sinfo_utl_stdstars_convert(const char * filename)
245 {
246  cpl_table * out ;
247  int nfilters ;
248  const char * filters[8];
249  double mags[8] ;
250  int nbentries ;
251  FILE * in ;
252  char line[1024];
253  double ra, dec ;
254  char sname[512];
255  char stype[512];
256  int i ;
257 
258  /* Check entries */
259  if (filename == NULL) return NULL ;
260 
261  /* Initialise */
262  nfilters = 8 ;
263  filters[0] = "J" ;
264  filters[1] = "H" ;
265  filters[2] = "K" ;
266  filters[3] = "Ks" ;
267  filters[4] = "L" ;
268  filters[5] = "M" ;
269  filters[6] = "Lp" ;
270  filters[7] = "Mp" ;
271 
272  /* Get the number of lines */
273  nbentries = 0 ;
274  if ((in = fopen(filename, "r")) == NULL) {
275  return NULL ;
276  }
277  while (fgets(line, 1024, in) != NULL) {
278  if (line[0] != '#') nbentries ++ ;
279  }
280  fclose(in) ;
281 
282  /* Create the table */
283  out = cpl_table_new(nbentries);
284  cpl_table_new_column(out, IRPLIB_STDSTAR_STAR_COL, CPL_TYPE_STRING);
285  cpl_table_new_column(out, IRPLIB_STDSTAR_TYPE_COL, CPL_TYPE_STRING);
286  cpl_table_new_column(out, IRPLIB_STDSTAR_RA_COL, CPL_TYPE_DOUBLE);
287  cpl_table_new_column(out, IRPLIB_STDSTAR_DEC_COL, CPL_TYPE_DOUBLE);
288  for (i=0 ; i<nfilters ; i++)
289  cpl_table_new_column(out, filters[i], CPL_TYPE_DOUBLE);
290 
291  /* Parse the file */
292  if ((in = fopen(filename, "r")) == NULL) {
293  cpl_table_delete(out) ;
294  return NULL ;
295  }
296  nbentries = 0 ;
297  while (fgets(line, 1024, in) != NULL) {
298  if (line[0] != '#') {
299  if (sscanf(line, "%s %lg %lg %s %lg %lg %lg %lg %lg %lg %lg %lg",
300  sname, &ra, &dec, stype, &(mags[0]), &(mags[1]),
301  &(mags[2]), &(mags[3]), &(mags[4]), &(mags[5]),
302  &(mags[6]), &(mags[7])) != 12) {
303  cpl_table_delete(out) ;
304  fclose(in) ;
305  return NULL ;
306  }
307  cpl_table_set_string(out, IRPLIB_STDSTAR_STAR_COL,nbentries, sname);
308  cpl_table_set_string(out, IRPLIB_STDSTAR_TYPE_COL,nbentries, stype);
309  cpl_table_set_double(out, IRPLIB_STDSTAR_RA_COL, nbentries, ra);
310  cpl_table_set_double(out, IRPLIB_STDSTAR_DEC_COL, nbentries, dec);
311  for (i=0 ; i<nfilters ; i++)
312  cpl_table_set_double(out, filters[i], nbentries, mags[i]);
313  nbentries ++ ;
314  }
315  }
316  fclose(in) ;
317 
318  return out ;
319 }
320