IIINSTRUMENT Pipeline Reference Manual 4.4.13
naco_utils.c
1/* $Id: naco_utils.c,v 1.32 2009-10-13 08:05:57 llundin Exp $
2 *
3 * This file is part of the NACO 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: 2009-10-13 08:05:57 $
24 * $Revision: 1.32 $
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#include <math.h>
38#include <cpl.h>
39
40#include "naco_utils.h"
41#include "naco_pfits.h"
42
43/*----------------------------------------------------------------------------*/
47/*----------------------------------------------------------------------------*/
48
51/*----------------------------------------------------------------------------*/
60/*----------------------------------------------------------------------------*/
61cpl_error_code naco_get_filter_infos(const char * f, double * lam,
62 double * dlam)
63{
64
65 bug_if(cpl_error_get_code());
66 bug_if( f == NULL);
67 bug_if( lam == NULL);
68 bug_if( dlam == NULL);
69
70 if (!strncmp(f, "J", IRPLIB_FITS_STRLEN)) {
71 *lam = 1.265; *dlam = 0.250;
72 } else if (!strncmp(f, "Jc", IRPLIB_FITS_STRLEN)) {
73 *lam = 1.265; *dlam = 0.250;
74 } else if (!strncmp(f, "H", IRPLIB_FITS_STRLEN)) {
75 *lam = 1.660; *dlam = 0.330;
76 } else if (!strncmp(f, "K", IRPLIB_FITS_STRLEN)) {
77 *lam = 2.230; *dlam = 0.390;
78 } else if (!strncmp(f, "Ks", IRPLIB_FITS_STRLEN)) {
79 *lam = 2.180; *dlam = 0.350;
80 } else if (!strncmp(f, "L", IRPLIB_FITS_STRLEN)) {
81 *lam = 3.500; *dlam = 0.610;
82 } else if (!strncmp(f, "L_prime", IRPLIB_FITS_STRLEN)) {
83 *lam = 3.800; *dlam = 0.620;
84 } else if (!strncmp(f, "M_prime", IRPLIB_FITS_STRLEN)) {
85 *lam = 4.780; *dlam = 0.590;
86 } else if (!strncmp(f, "SJ", IRPLIB_FITS_STRLEN)) {
87 *lam = 1.160; *dlam = 0.470;
88 } else if (!strncmp(f, "SH", IRPLIB_FITS_STRLEN)) {
89 *lam = 1.630; *dlam = 0.430;
90 } else if (!strncmp(f, "SK", IRPLIB_FITS_STRLEN)) {
91 *lam = 2.270; *dlam = 0.760;
92 } else if (!strncmp(f, "NB_1.04", IRPLIB_FITS_STRLEN)) {
93 *lam = 1.040; *dlam = 0.015;
94 } else if (!strncmp(f, "NB_1.08", IRPLIB_FITS_STRLEN)) {
95 *lam = 1.083; *dlam = 0.015;
96 } else if (!strncmp(f, "NB_1.09", IRPLIB_FITS_STRLEN)) {
97 *lam = 1.094; *dlam = 0.015;
98 } else if (!strncmp(f, "NB_1.24", IRPLIB_FITS_STRLEN)) {
99 *lam = 1.237; *dlam = 0.015;
100 } else if (!strncmp(f, "NB_1.26", IRPLIB_FITS_STRLEN)) {
101 *lam = 1.257; *dlam = 0.014;
102 } else if (!strncmp(f, "NB_1.28", IRPLIB_FITS_STRLEN)) {
103 *lam = 1.282; *dlam = 0.014;
104 } else if (!strncmp(f, "NB_1.64", IRPLIB_FITS_STRLEN)) {
105 *lam = 1.644; *dlam = 0.018;
106 } else if (!strncmp(f, "NB_1.75", IRPLIB_FITS_STRLEN)) {
107 *lam = 1.748; *dlam = 0.026;
108 } else if (!strncmp(f, "NB_3.74", IRPLIB_FITS_STRLEN)) {
109 *lam = 3.740; *dlam = 0.020;
110 } else if (!strncmp(f, "IB_2.00", IRPLIB_FITS_STRLEN)) {
111 *lam = 2.000; *dlam = 0.060;
112 } else if (!strncmp(f, "IB_2.03", IRPLIB_FITS_STRLEN)) {
113 *lam = 2.030; *dlam = 0.060;
114 } else if (!strncmp(f, "IB_2.06", IRPLIB_FITS_STRLEN)) {
115 *lam = 2.060; *dlam = 0.060;
116 } else if (!strncmp(f, "IB_2.09", IRPLIB_FITS_STRLEN)) {
117 *lam = 2.090; *dlam = 0.060;
118 } else if (!strncmp(f, "IB_2.12", IRPLIB_FITS_STRLEN)) {
119 *lam = 2.120; *dlam = 0.060;
120 } else if (!strncmp(f, "NB_2.12", IRPLIB_FITS_STRLEN)) {
121 *lam = 2.122; *dlam = 0.022;
122 } else if (!strncmp(f, "IB_2.15", IRPLIB_FITS_STRLEN)) {
123 *lam = 2.150; *dlam = 0.060;
124 } else if (!strncmp(f, "NB_2.17", IRPLIB_FITS_STRLEN)) {
125 *lam = 2.166; *dlam = 0.023;
126 } else if (!strncmp(f, "IB_2.18", IRPLIB_FITS_STRLEN)) {
127 *lam = 2.180; *dlam = 0.060;
128 } else if (!strncmp(f, "IB_2.21", IRPLIB_FITS_STRLEN)) {
129 *lam = 2.210; *dlam = 0.060;
130 } else if (!strncmp(f, "IB_2.24", IRPLIB_FITS_STRLEN)) {
131 *lam = 2.240; *dlam = 0.060;
132 } else if (!strncmp(f, "IB_2.27", IRPLIB_FITS_STRLEN)) {
133 *lam = 2.270; *dlam = 0.060;
134 } else if (!strncmp(f, "IB_2.30", IRPLIB_FITS_STRLEN)) {
135 *lam = 2.300; *dlam = 0.060;
136 } else if (!strncmp(f, "IB_2.33", IRPLIB_FITS_STRLEN)) {
137 *lam = 2.330; *dlam = 0.060;
138 } else if (!strncmp(f, "IB_2.36", IRPLIB_FITS_STRLEN)) {
139 *lam = 2.360; *dlam = 0.060;
140 } else if (!strncmp(f, "IB_2.39", IRPLIB_FITS_STRLEN)) {
141 *lam = 2.390; *dlam = 0.060;
142 } else if (!strncmp(f, "IB_2.42", IRPLIB_FITS_STRLEN)) {
143 *lam = 2.420; *dlam = 0.060;
144 } else if (!strncmp(f, "IB_2.45", IRPLIB_FITS_STRLEN)) {
145 *lam = 2.450; *dlam = 0.060;
146 } else if (!strncmp(f, "IB_2.48", IRPLIB_FITS_STRLEN)) {
147 *lam = 2.480; *dlam = 0.060;
148 } else if (!strncmp(f, "NB_4.05", IRPLIB_FITS_STRLEN)) {
149 *lam = 4.051; *dlam = 0.020;
150 } else if (!strncmp(f, "IB_4.05", IRPLIB_FITS_STRLEN)) {
151 /* As per email 2009-10-13 from epompei@eso.org */
152 *lam = 4.05; *dlam = 0.100;
153 } else
154 irplib_ensure(0, CPL_ERROR_DATA_NOT_FOUND, "Unknown filter: %s", f);
155
156 end_skip;
157
158 return cpl_error_get_code();
159}
160
161/*----------------------------------------------------------------------------*/
175/*----------------------------------------------------------------------------*/
176const char ** naco_framelist_set_tag(irplib_framelist * self,
177 char * (*pftag)(const cpl_frame *,
178 const cpl_propertylist *,
179 int),
180 int *pntags)
181{
182
183 const char ** taglist = NULL; /* Must be initialized due to realloc call */
184 int iframe, size;
185
186 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
187 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
188 cpl_ensure(pftag != NULL, CPL_ERROR_NULL_INPUT, NULL);
189 cpl_ensure(pntags != NULL, CPL_ERROR_NULL_INPUT, NULL);
190
191 size = irplib_framelist_get_size(self);
192
193 cpl_ensure(size > 0, CPL_ERROR_DATA_NOT_FOUND, NULL);
194
195 *pntags = 0;
196
197 for (iframe = 0; iframe < size ; iframe++) {
198 cpl_frame * frame = irplib_framelist_get(self, iframe);
199 const cpl_propertylist * plist
200 = irplib_framelist_get_propertylist_const(self, iframe);
201 char * tag;
202 const char * newtag;
203 int i;
204
205
206 /* This should really be an assert() */
207 cpl_ensure(frame != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
208 cpl_ensure(plist != NULL, CPL_ERROR_ILLEGAL_INPUT, NULL);
209
210 tag = (*pftag)(frame, plist, iframe);
211
212 cpl_ensure(tag != NULL, cpl_error_get_code(), NULL);
213
214 /* From this point on failures should not really happen */
215
216 (void)cpl_frame_set_tag(frame, tag);
217 cpl_free(tag);
218
219 newtag = cpl_frame_get_tag(frame);
220
221 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL);
222
223 /* Compare the new tags with those of previous frames */
224 for (i=0; i < *pntags; i++)
225 if (strcmp(newtag, taglist[i]) == 0) break;
226
227 if (i == *pntags) {
228 /* The new tag is different from the previous ones
229 - add it to the list */
230 (*pntags)++;
231 taglist = (const char **)cpl_realloc(taglist, *pntags *
232 sizeof(const char *));
233 taglist[i] = newtag;
234 }
235
236 }
237
238 return taglist;
239
240}
241
cpl_error_code naco_get_filter_infos(const char *f, double *lam, double *dlam)
Get the infos of one of the filters.
Definition: naco_utils.c:61
const char ** naco_framelist_set_tag(irplib_framelist *self, char *(*pftag)(const cpl_frame *, const cpl_propertylist *, int), int *pntags)
Retag a framelist according to the given tagging function.
Definition: naco_utils.c:176