CR2RE Pipeline Reference Manual 1.6.7
cr2res_pfits.c
1/*
2 * This file is part of the CR2RES Pipeline
3 * Copyright (C) 2002,2003 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <cpl.h>
29#include <math.h>
30#include "cr2res_pfits.h"
31#include "cr2res_utils.h"
32#include "cr2res_io.h"
33
34/*----------------------------------------------------------------------------*/
39/*----------------------------------------------------------------------------*/
42/*-----------------------------------------------------------------------------
43 Function codes
44 -----------------------------------------------------------------------------*/
45
46/*----------------------------------------------------------------------------*/
52/*----------------------------------------------------------------------------*/
53cr2res_nodding_pos cr2res_pfits_get_nodding_pos(const cpl_propertylist * plist)
54{
55 const char * sval ;
56 sval = cpl_propertylist_get_string(plist, CR2RES_HEADER_NODPOS);
57
58 if (sval==NULL) {
59 cpl_error_reset() ;
60 return CR2RES_NODDING_NONE ;
61 }
62 if (sval[0] == 'A') return CR2RES_NODDING_A ;
63 if (sval[0] == 'B') return CR2RES_NODDING_B ;
64 return CR2RES_NODDING_NONE ;
65}
66#ifdef CR2RES_UNUSED
67/*----------------------------------------------------------------------------*/
73/*----------------------------------------------------------------------------*/
74const char * cr2res_pfits_get_procatg(const cpl_propertylist * plist)
75{
76 return (const char *) cpl_propertylist_get_string(plist, CPL_DFS_PRO_CATG);
77}
78#endif
79/*----------------------------------------------------------------------------*/
85/*----------------------------------------------------------------------------*/
86const char * cr2res_pfits_get_drstype(const cpl_propertylist * plist)
87{
88 return (const char *) cpl_propertylist_get_string(plist,
89 CR2RES_HEADER_DRS_TYPE);
90}
91/*----------------------------------------------------------------------------*/
97/*----------------------------------------------------------------------------*/
98const char * cr2res_pfits_get_protype(const cpl_propertylist * plist)
99{
100 return (const char *) cpl_propertylist_get_string(plist,
101 CPL_DFS_PRO_TYPE);
102}
103#ifdef CR2RES_UNUSED
104/*----------------------------------------------------------------------------*/
110/*----------------------------------------------------------------------------*/
111const char * cr2res_pfits_get_arcfile(const cpl_propertylist * plist)
112{
113 return (const char *) cpl_propertylist_get_string(plist,
114 CR2RES_HEADER_ARCFILE);
115}
116#endif
117/*----------------------------------------------------------------------------*/
123/*----------------------------------------------------------------------------*/
124const char * cr2res_pfits_get_progid(const cpl_propertylist * plist)
125{
126 return (const char *) cpl_propertylist_get_string(plist,
127 CR2RES_HEADER_PROG_ID);
128}
129
130/*----------------------------------------------------------------------------*/
136/*----------------------------------------------------------------------------*/
137const char * cr2res_pfits_get_wlen_id(const cpl_propertylist * plist)
138{
139 return (const char *) cpl_propertylist_get_string(plist,
140 CR2RES_HEADER_WLEN_ID);
141}
142
143/*----------------------------------------------------------------------------*/
149/*----------------------------------------------------------------------------*/
150double cr2res_pfits_get_dec(const cpl_propertylist * plist)
151{
152 return cpl_propertylist_get_double(plist, "DEC") ;
153}
154
155/*----------------------------------------------------------------------------*/
161/*----------------------------------------------------------------------------*/
162double cr2res_pfits_get_ra(const cpl_propertylist * plist)
163{
164 return cpl_propertylist_get_double(plist, "RA") ;
165}
166
167/*----------------------------------------------------------------------------*/
173/*----------------------------------------------------------------------------*/
174double cr2res_pfits_get_drot_posang(const cpl_propertylist * plist)
175{
176 return cpl_propertylist_get_double(plist, CR2RES_HEADER_DROT_POSANG) ;
177}
178
179/*----------------------------------------------------------------------------*/
185/*----------------------------------------------------------------------------*/
186double cr2res_pfits_get_nodthrow(const cpl_propertylist * plist)
187{
188 return cpl_propertylist_get_double(plist, CR2RES_HEADER_NODTHROW) ;
189}
190
191
192/*----------------------------------------------------------------------------*/
198/*----------------------------------------------------------------------------*/
199double cr2res_pfits_get_dit(const cpl_propertylist * plist)
200{
201 double val;
202 val = cpl_propertylist_get_double(plist, CR2RES_HEADER_DIT) ;
203 if (cpl_error_get_code() == CPL_ERROR_TYPE_MISMATCH){
204 cpl_error_reset();
205 val = (double) cpl_propertylist_get_int(plist, CR2RES_HEADER_DIT);
206 }
207 return val;
208}
209
210/*----------------------------------------------------------------------------*/
216/*----------------------------------------------------------------------------*/
217double cr2res_pfits_get_mjd_obs(const cpl_propertylist * plist)
218{
219 return cpl_propertylist_get_double(plist, CR2RES_HEADER_MJDOBS) ;
220}
221
222/*----------------------------------------------------------------------------*/
228/*----------------------------------------------------------------------------*/
229double cr2res_pfits_get_cwlen(const cpl_propertylist * plist)
230{
231 return cpl_propertylist_get_double(plist, CR2RES_HEADER_WLEN_CWLEN) ;
232}
233
234/*----------------------------------------------------------------------------*/
240/*----------------------------------------------------------------------------*/
241const char * cr2res_pfits_get_poltype(const cpl_propertylist * plist)
242{
243 return cpl_propertylist_get_string(plist, CR2RES_HEADER_POL_TYPE) ;
244}
245
246/*----------------------------------------------------------------------------*/
253/*----------------------------------------------------------------------------*/
254double cr2res_pfits_get_wstrt(const cpl_propertylist * plist, int order_idx)
255{
256 char * key_name ;
257 int order_idxp ;
258 double val ;
259
260 /* Check entries */
261 if (plist == NULL) return -1.0 ;
262
263 /* Conversion order_idx -> order_idxp */
264 if ((order_idxp = cr2res_io_convert_order_idx_to_idxp(order_idx)) < 0)
265 return -1.0 ;
266
267 /* Create key name */
268 key_name = cpl_sprintf(CR2RES_HEADER_WLEN_BEGIN, order_idxp) ;
269
270 /* Get the value */
271 val = cpl_propertylist_get_double(plist, key_name) ;
272
273 cpl_free(key_name) ;
274 return val ;
275}
276
277/*----------------------------------------------------------------------------*/
284/*----------------------------------------------------------------------------*/
285double cr2res_pfits_get_wend(const cpl_propertylist * plist, int order_idx)
286{
287 char * key_name ;
288 int order_idxp ;
289 double val ;
290
291 /* Check entries */
292 if (plist == NULL) return -1.0 ;
293
294 /* Conversion order_idx -> order_idxp */
295 if ((order_idxp = cr2res_io_convert_order_idx_to_idxp(order_idx)) < 0)
296 return -1.0 ;
297
298 /* Create key name */
299 key_name = cpl_sprintf(CR2RES_HEADER_WLEN_END, order_idxp) ;
300
301 /* Get the value */
302 val = cpl_propertylist_get_double(plist, key_name) ;
303
304 cpl_free(key_name) ;
305 return val ;
306}
307#ifdef CR2RES_UNUSED
308/*----------------------------------------------------------------------------*/
309 /*
310 @brief find out the NAXIS1 value
311 @param plist property list to read from
312 @return the requested value
313 */
314/*----------------------------------------------------------------------------*/
315int cr2res_pfits_get_naxis1(const cpl_propertylist * plist)
316{
317 return cpl_propertylist_get_int(plist, CR2RES_HEADER_NAXIS1) ;
318}
319
320/*----------------------------------------------------------------------------*/
326/*----------------------------------------------------------------------------*/
327int cr2res_pfits_get_naxis2(const cpl_propertylist * plist)
328{
329 return cpl_propertylist_get_int(plist, CR2RES_HEADER_NAXIS2) ;
330}
331
332/*----------------------------------------------------------------------------*/
338/*----------------------------------------------------------------------------*/
339int cr2res_pfits_get_nexp(const cpl_propertylist * plist)
340{
341 return cpl_propertylist_get_int(plist, CR2RES_HEADER_NEXP) ;
342}
343
344/*----------------------------------------------------------------------------*/
350/*----------------------------------------------------------------------------*/
351int cr2res_pfits_get_expno(const cpl_propertylist * plist)
352{
353 return cpl_propertylist_get_int(plist, CR2RES_HEADER_EXPNO) ;
354}
355#endif
356/*----------------------------------------------------------------------------*/
362/*----------------------------------------------------------------------------*/
363int cr2res_pfits_get_ndit(const cpl_propertylist * plist)
364{
365 return cpl_propertylist_get_int(plist, CR2RES_HEADER_NDIT) ;
366}
367
368/*----------------------------------------------------------------------------*/
374/*----------------------------------------------------------------------------*/
375int cr2res_pfits_get_obs_id(const cpl_propertylist * plist)
376{
377 return cpl_propertylist_get_int(plist, CR2RES_HEADER_OBS_ID) ;
378}
379
380/*----------------------------------------------------------------------------*/
381 /*
382 @brief find out the ORDER value
383 @param plist property list to read from
384 @return the requested value
385 */
386/*----------------------------------------------------------------------------*/
387int cr2res_pfits_get_order(const cpl_propertylist * plist)
388{
389 return cpl_propertylist_get_int(plist, CR2RES_HEADER_GRAT1_ORDER) ;
390}
391
392/*----------------------------------------------------------------------------*/
393 /*
394 @brief find out the ZP_ORD value
395 @param plist property list to read from
396 @return the requested value
397 */
398/*----------------------------------------------------------------------------*/
399int cr2res_pfits_get_order_zp(const cpl_propertylist * plist)
400{
401 return cpl_propertylist_get_int(plist, CR2RES_HEADER_GRAT1_ZPORD) ;
402}
403
404/*----------------------------------------------------------------------------*/
411/*----------------------------------------------------------------------------*/
413 const cpl_propertylist * plist,
414 double yposition)
415{
416 int i;
417 int order_idx = -1000 ;
418 int min_order_idx = -49 ;
419 int max_order_idx = 50 ;
420 double curr_diff;
421 double best_diff = CR2RES_DETECTOR_SIZE;
422
423 /* Check entries */
424 if (plist == NULL) return -1 ;
425 if (yposition < 1) return -1 ;
426 if (cpl_error_get_code() != CPL_ERROR_NONE) {
427 cpl_msg_error(__func__, "Error already set - abort") ;
428 return -1 ;
429 }
430
431 for (i = min_order_idx; i <= max_order_idx; i++) {
432 char *key_name;
433 int order_idxp;
434 double ycen;
436 key_name = cpl_sprintf(CR2RES_HEADER_WLEN_CENY, order_idxp) ;
437 ycen = cpl_propertylist_get_double(plist, key_name);
438 cpl_free(key_name) ;
439 if (cpl_error_get_code() != CPL_ERROR_NONE) {
440 cpl_error_reset();
441 continue;
442 }
443 curr_diff = fabs(yposition - ycen );
444 if (curr_diff < best_diff){
445 best_diff = curr_diff;
446 order_idx = i;
447 }
448 }
449
450 cpl_msg_debug(__func__,
451 "Order %d identified with %.1f pix difference from expectation",
452 order_idx, best_diff);
453 if (best_diff > 100.0)
454 cpl_msg_warning(__func__,
455 "Order %d identified with large difference of %.1f pix",
456 order_idx, best_diff);
457 return order_idx ;
458}
459
460/*----------------------------------------------------------------------------*/
466/*----------------------------------------------------------------------------*/
467cr2res_decker cr2res_pfits_get_decker_position(const cpl_propertylist * plist)
468{
469 int decker_value ;
470 decker_value = cpl_propertylist_get_int(plist, CR2RES_HEADER_DECKER_POS);
471 if (cpl_error_get_code() != CPL_ERROR_NONE) {
472 cpl_error_reset();
473 return CR2RES_DECKER_INVALID ;
474 }
475 /* TODO: enter proper encoder values */
476 if (decker_value == 3) return CR2RES_DECKER_NONE ;
477 if (decker_value == 1) return CR2RES_DECKER_1_3 ;
478 if (decker_value == 2) return CR2RES_DECKER_2_4 ;
479 return CR2RES_DECKER_INVALID ;
480}
481
int cr2res_io_convert_order_idx_to_idxp(int order_idx)
Convert the order_idx to the order_idxp.
Definition: cr2res_io.c:583
cr2res_decker cr2res_pfits_get_decker_position(const cpl_propertylist *plist)
find out the decker position
Definition: cr2res_pfits.c:467
int cr2res_pfits_get_order_idx(const cpl_propertylist *plist, double yposition)
find out the order_idx closest to the passed y position
Definition: cr2res_pfits.c:412
const char * cr2res_pfits_get_wlen_id(const cpl_propertylist *plist)
find out the Setting
Definition: cr2res_pfits.c:137
const char * cr2res_pfits_get_progid(const cpl_propertylist *plist)
find out the PROG ID
Definition: cr2res_pfits.c:124
double cr2res_pfits_get_wstrt(const cpl_propertylist *plist, int order_idx)
find out the Start wavelength for an order_idx (current detector)
Definition: cr2res_pfits.c:254
double cr2res_pfits_get_wend(const cpl_propertylist *plist, int order_idx)
find out the End wavelength for an order_idx (current detector)
Definition: cr2res_pfits.c:285
const char * cr2res_pfits_get_protype(const cpl_propertylist *plist)
find out the PRO.TYPE
Definition: cr2res_pfits.c:98
double cr2res_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
Definition: cr2res_pfits.c:199
double cr2res_pfits_get_mjd_obs(const cpl_propertylist *plist)
find out the MJD-OBS value
Definition: cr2res_pfits.c:217
double cr2res_pfits_get_dec(const cpl_propertylist *plist)
find out the DEC
Definition: cr2res_pfits.c:150
double cr2res_pfits_get_drot_posang(const cpl_propertylist *plist)
find out the DROT POSANG value
Definition: cr2res_pfits.c:174
double cr2res_pfits_get_nodthrow(const cpl_propertylist *plist)
find out the NODTHROW value
Definition: cr2res_pfits.c:186
int cr2res_pfits_get_ndit(const cpl_propertylist *plist)
find out the NDIT value
Definition: cr2res_pfits.c:363
const char * cr2res_pfits_get_drstype(const cpl_propertylist *plist)
find out the DRS.TYPE
Definition: cr2res_pfits.c:86
cr2res_nodding_pos cr2res_pfits_get_nodding_pos(const cpl_propertylist *plist)
find out the nodding position
Definition: cr2res_pfits.c:53
double cr2res_pfits_get_ra(const cpl_propertylist *plist)
find out the RA
Definition: cr2res_pfits.c:162
double cr2res_pfits_get_cwlen(const cpl_propertylist *plist)
find out the CWLEN value
Definition: cr2res_pfits.c:229
const char * cr2res_pfits_get_poltype(const cpl_propertylist *plist)
find out the POL TYPE value
Definition: cr2res_pfits.c:241
int cr2res_pfits_get_obs_id(const cpl_propertylist *plist)
find out the OBS ID value
Definition: cr2res_pfits.c:375