IIINSTRUMENT Pipeline Reference Manual 6.2.5
isaac_util_stdstars.c
1/* $Id: isaac_util_stdstars.c,v 1.9 2013-03-12 08:06:48 llundin 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., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: llundin $
23 * $Date: 2013-03-12 08:06:48 $
24 * $Revision: 1.9 $
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 "isaac_utils.h"
43#include "isaac_pfits.h"
44#include "isaac_dfs.h"
45
46/*-----------------------------------------------------------------------------
47 Functions prototypes
48 -----------------------------------------------------------------------------*/
49
50static int isaac_util_stdstars_create(cpl_plugin *);
51static int isaac_util_stdstars_exec(cpl_plugin *);
52static int isaac_util_stdstars_destroy(cpl_plugin *);
53static int isaac_util_stdstars(cpl_frameset *);
54static cpl_table * isaac_util_stdstars_convert(const char *);
55
56/*-----------------------------------------------------------------------------
57 Static variables
58 -----------------------------------------------------------------------------*/
59
60static char isaac_util_stdstars_description[] =
61"isaac_util_stdstars -- ISAAC standard stars catalog creation.\n"
62"The files listed in the Set Of Frames (sof-file) must be tagged:\n"
63"raw-file.fits "ISAAC_UTIL_STDSTARS_RAW"\n";
64
65/*-----------------------------------------------------------------------------
66 Functions code
67 -----------------------------------------------------------------------------*/
68
69/*----------------------------------------------------------------------------*/
77/*----------------------------------------------------------------------------*/
78int cpl_plugin_get_info(cpl_pluginlist * list)
79{
80 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe));
81 cpl_plugin * plugin = &recipe->interface;
82
83 cpl_plugin_init(plugin,
84 CPL_PLUGIN_API,
85 ISAAC_BINARY_VERSION,
86 CPL_PLUGIN_TYPE_RECIPE,
87 "isaac_util_stdstars",
88 "Standard stars catalog creation",
89 isaac_util_stdstars_description,
90 "Lars Lundin",
91 PACKAGE_BUGREPORT,
93 isaac_util_stdstars_create,
94 isaac_util_stdstars_exec,
95 isaac_util_stdstars_destroy);
96
97 cpl_pluginlist_append(list, plugin);
98
99 return 0;
100}
101
102/*----------------------------------------------------------------------------*/
111/*----------------------------------------------------------------------------*/
112static int isaac_util_stdstars_create(cpl_plugin * plugin)
113{
114 cpl_recipe * recipe;
115
116 /* Get the recipe out of the plugin */
117 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
118 recipe = (cpl_recipe *)plugin;
119 else return CPL_ERROR_UNSPECIFIED;
120
121 /* Create the parameters list in the cpl_recipe object */
122 recipe->parameters = cpl_parameterlist_new();
123
124 /* Return */
125 return 0;
126}
127
128/*----------------------------------------------------------------------------*/
134/*----------------------------------------------------------------------------*/
135static int isaac_util_stdstars_exec(cpl_plugin * plugin)
136{
137 cpl_recipe * recipe;
138
139 /* Get the recipe out of the plugin */
140 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
141 recipe = (cpl_recipe *)plugin;
142 else return CPL_ERROR_UNSPECIFIED;
143
144 return isaac_util_stdstars(recipe->frames);
145}
146
147/*----------------------------------------------------------------------------*/
153/*----------------------------------------------------------------------------*/
154static int isaac_util_stdstars_destroy(cpl_plugin * plugin)
155{
156 cpl_recipe * recipe;
157
158 /* Get the recipe out of the plugin */
159 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
160 recipe = (cpl_recipe *)plugin;
161 else return CPL_ERROR_UNSPECIFIED;
162
163 cpl_parameterlist_delete(recipe->parameters);
164 return 0;
165}
166
167/*----------------------------------------------------------------------------*/
173/*----------------------------------------------------------------------------*/
174static int isaac_util_stdstars(
175 cpl_frameset * framelist)
176{
177 cpl_frameset * rawframes;
178
179 /* Identify the RAW and CALIB frames in the input frameset */
180 if (isaac_dfs_set_groups(framelist)) {
181 cpl_msg_error(cpl_func, "Cannot identify RAW and CALIB frames");
182 return CPL_ERROR_UNSPECIFIED;
183 }
184
185 /* Retrieve raw frames */
186 if ((rawframes = isaac_extract_frameset(framelist,
187 ISAAC_UTIL_STDSTARS_RAW)) == NULL) {
188 cpl_msg_error(cpl_func, "Cannot find raw frames in the input list");
189 return CPL_ERROR_UNSPECIFIED;
190 }
191
192 /* Write the catalog */
193 if (irplib_stdstar_write_catalogs(framelist,
194 rawframes,
195 "isaac_util_stdstars",
196 ISAAC_UTIL_STDSTARS_RES,
197 NULL,
198 PACKAGE "/" PACKAGE_VERSION,
199 "ISAAC",
200 isaac_util_stdstars_convert)) {
201 cpl_msg_error(cpl_func, "Cannot write the catalogs");
202 cpl_frameset_delete(rawframes);
203 return CPL_ERROR_UNSPECIFIED;
204 }
205 cpl_frameset_delete(rawframes);
206 return 0;
207}
208
209/*----------------------------------------------------------------------------*/
230/*----------------------------------------------------------------------------*/
231static cpl_table * isaac_util_stdstars_convert(const char * filename)
232{
233 cpl_table * out;
234 int nfilters;
235 const char * filters[8];
236 double mags[8];
237 int nbentries;
238 FILE * in;
239 char line[1024];
240 double ra, dec;
241 char sname[512];
242 char stype[512];
243 int i;
244
245 /* Check entries */
246 if (filename == NULL) return NULL;
247
248 /* Initialise */
249 nfilters = 8;
250 filters[0] = "J";
251 filters[1] = "H";
252 filters[2] = "K";
253 filters[3] = "Ks";
254 filters[4] = "L";
255 filters[5] = "M";
256 filters[6] = "Lp";
257 filters[7] = "Mp";
258
259 /* Get the number of lines */
260 nbentries = 0;
261 if ((in = fopen(filename, "r")) == NULL) {
262 return NULL;
263 }
264 while (fgets(line, 1024, in) != NULL) {
265 if (line[0] != '#') nbentries ++;
266 }
267 fclose(in);
268
269 /* Create the table */
270 out = cpl_table_new(nbentries);
271 cpl_table_new_column(out, IRPLIB_STDSTAR_STAR_COL, CPL_TYPE_STRING);
272 cpl_table_new_column(out, IRPLIB_STDSTAR_TYPE_COL, CPL_TYPE_STRING);
273 cpl_table_new_column(out, IRPLIB_STDSTAR_RA_COL, CPL_TYPE_DOUBLE);
274 cpl_table_new_column(out, IRPLIB_STDSTAR_DEC_COL, CPL_TYPE_DOUBLE);
275 for (i=0; i<nfilters; i++)
276 cpl_table_new_column(out, filters[i], CPL_TYPE_DOUBLE);
277
278 /* Parse the file */
279 if ((in = fopen(filename, "r")) == NULL) {
280 cpl_table_delete(out);
281 return NULL;
282 }
283 nbentries = 0;
284 while (fgets(line, 1024, in) != NULL) {
285 if (line[0] != '#') {
286 if (sscanf(line,
287 "%511s %lg %lg %511s %lg %lg %lg %lg %lg %lg %lg %lg",
288 sname, &ra, &dec, stype, &(mags[0]), &(mags[1]),
289 &(mags[2]), &(mags[3]), &(mags[4]), &(mags[5]),
290 &(mags[6]), &(mags[7])) != 12) {
291 cpl_table_delete(out);
292 fclose(in);
293 return NULL;
294 }
295 cpl_table_set_string(out, IRPLIB_STDSTAR_STAR_COL,nbentries, sname);
296 cpl_table_set_string(out, IRPLIB_STDSTAR_TYPE_COL,nbentries, stype);
297 cpl_table_set_double(out, IRPLIB_STDSTAR_RA_COL, nbentries, ra);
298 cpl_table_set_double(out, IRPLIB_STDSTAR_DEC_COL, nbentries, dec);
299 for (i=0; i<nfilters; i++)
300 cpl_table_set_double(out, filters[i], nbentries, mags[i]);
301 nbentries ++;
302 }
303 }
304 fclose(in);
305
306 return out;
307}
308
int isaac_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: isaac_dfs.c:60
cpl_frameset * isaac_extract_frameset(const cpl_frameset *self, const char *tag)
Extract the frames with the given tag from a frameset.
Definition: isaac_utils.c:356
const char * isaac_get_license(void)
Get the pipeline copyright and license.
Definition: isaac_utils.c:62