CR2RE Pipeline Reference Manual 1.7.0
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/*----------------------------------------------------------------------------*/
41
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_ndsamples(const cpl_propertylist * plist)
376{
377 if (plist == NULL || !cpl_propertylist_has(plist, CR2RES_HEADER_NDSAMPLES))
378 return -1 ;
379 return cpl_propertylist_get_int(plist, CR2RES_HEADER_NDSAMPLES) ;
380}
381
382/*----------------------------------------------------------------------------*/
388/*----------------------------------------------------------------------------*/
389int cr2res_pfits_get_obs_id(const cpl_propertylist * plist)
390{
391 return cpl_propertylist_get_int(plist, CR2RES_HEADER_OBS_ID) ;
392}
393
394/*----------------------------------------------------------------------------*/
395 /*
396 @brief find out the ORDER value
397 @param plist property list to read from
398 @return the requested value
399 */
400/*----------------------------------------------------------------------------*/
401int cr2res_pfits_get_order(const cpl_propertylist * plist)
402{
403 return cpl_propertylist_get_int(plist, CR2RES_HEADER_GRAT1_ORDER) ;
404}
405
406/*----------------------------------------------------------------------------*/
407 /*
408 @brief find out the ZP_ORD value
409 @param plist property list to read from
410 @return the requested value
411 */
412/*----------------------------------------------------------------------------*/
413int cr2res_pfits_get_order_zp(const cpl_propertylist * plist)
414{
415 return cpl_propertylist_get_int(plist, CR2RES_HEADER_GRAT1_ZPORD) ;
416}
417
418/*----------------------------------------------------------------------------*/
425/*----------------------------------------------------------------------------*/
427 const cpl_propertylist * plist,
428 double yposition)
429{
430 int i;
431 int order_idx = -1000 ;
432 int min_order_idx = -49 ;
433 int max_order_idx = 50 ;
434 double curr_diff;
435 double best_diff = CR2RES_DETECTOR_SIZE;
436
437 /* Check entries */
438 if (plist == NULL) return -1 ;
439 if (yposition < 1) return -1 ;
440 if (cpl_error_get_code() != CPL_ERROR_NONE) {
441 cpl_msg_error(__func__, "Error already set - abort") ;
442 return -1 ;
443 }
444
445 for (i = min_order_idx; i <= max_order_idx; i++) {
446 char *key_name;
447 int order_idxp;
448 double ycen;
450 key_name = cpl_sprintf(CR2RES_HEADER_WLEN_CENY, order_idxp) ;
451 ycen = cpl_propertylist_get_double(plist, key_name);
452 cpl_free(key_name) ;
453 if (cpl_error_get_code() != CPL_ERROR_NONE) {
454 cpl_error_reset();
455 continue;
456 }
457 curr_diff = fabs(yposition - ycen );
458 if (curr_diff < best_diff){
459 best_diff = curr_diff;
460 order_idx = i;
461 }
462 }
463
464 cpl_msg_debug(__func__,
465 "Order %d identified with %.1f pix difference from expectation",
466 order_idx, best_diff);
467 if (best_diff > 100.0)
468 cpl_msg_warning(__func__,
469 "Order %d identified with large difference of %.1f pix",
470 order_idx, best_diff);
471 return order_idx ;
472}
473
474/*----------------------------------------------------------------------------*/
480/*----------------------------------------------------------------------------*/
481cr2res_decker cr2res_pfits_get_decker_position(const cpl_propertylist * plist)
482{
483 int decker_value ;
484 decker_value = cpl_propertylist_get_int(plist, CR2RES_HEADER_DECKER_POS);
485 if (cpl_error_get_code() != CPL_ERROR_NONE) {
486 cpl_error_reset();
487 return CR2RES_DECKER_INVALID ;
488 }
489 /* TODO: enter proper encoder values */
490 if (decker_value == 3) return CR2RES_DECKER_NONE ;
491 if (decker_value == 1) return CR2RES_DECKER_1_3 ;
492 if (decker_value == 2) return CR2RES_DECKER_2_4 ;
493 return CR2RES_DECKER_INVALID ;
494}
495
int cr2res_io_convert_order_idx_to_idxp(int order_idx)
Convert the order_idx to the order_idxp.
Definition cr2res_io.c:613
cr2res_decker cr2res_pfits_get_decker_position(const cpl_propertylist *plist)
find out the decker position
int cr2res_pfits_get_order_idx(const cpl_propertylist *plist, double yposition)
find out the order_idx closest to the passed y position
const char * cr2res_pfits_get_wlen_id(const cpl_propertylist *plist)
find out the Setting
const char * cr2res_pfits_get_progid(const cpl_propertylist *plist)
find out the PROG ID
double cr2res_pfits_get_wstrt(const cpl_propertylist *plist, int order_idx)
find out the Start wavelength for an order_idx (current detector)
double cr2res_pfits_get_wend(const cpl_propertylist *plist, int order_idx)
find out the End wavelength for an order_idx (current detector)
const char * cr2res_pfits_get_protype(const cpl_propertylist *plist)
find out the PRO.TYPE
double cr2res_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
double cr2res_pfits_get_mjd_obs(const cpl_propertylist *plist)
find out the MJD-OBS value
double cr2res_pfits_get_dec(const cpl_propertylist *plist)
find out the DEC
int cr2res_pfits_get_ndsamples(const cpl_propertylist *plist)
find out the NDSAMPLES value (up-the-ramp reads per DIT)
double cr2res_pfits_get_drot_posang(const cpl_propertylist *plist)
find out the DROT POSANG value
double cr2res_pfits_get_nodthrow(const cpl_propertylist *plist)
find out the NODTHROW value
int cr2res_pfits_get_ndit(const cpl_propertylist *plist)
find out the NDIT value
const char * cr2res_pfits_get_drstype(const cpl_propertylist *plist)
find out the DRS.TYPE
cr2res_nodding_pos cr2res_pfits_get_nodding_pos(const cpl_propertylist *plist)
find out the nodding position
double cr2res_pfits_get_ra(const cpl_propertylist *plist)
find out the RA
double cr2res_pfits_get_cwlen(const cpl_propertylist *plist)
find out the CWLEN value
const char * cr2res_pfits_get_poltype(const cpl_propertylist *plist)
find out the POL TYPE value
int cr2res_pfits_get_obs_id(const cpl_propertylist *plist)
find out the OBS ID value