MOONS Pipeline Reference Manual 0.13.1
moo_sky_lines_list.c
1/*
2 * This file is part of the MOONS Pipeline
3 * Copyright (C) 2002-2016 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27#include <math.h>
28#include <cpl.h>
29#include "moo_sky_lines_list.h"
30#include "moo_fits.h"
31#include "moo_utils.h"
32/*----------------------------------------------------------------------------*/
47/*----------------------------------------------------------------------------*/
48
51/*-----------------------------------------------------------------------------
52 Function codes
53 -----------------------------------------------------------------------------*/
54
55/*----------------------------------------------------------------------------*/
63/*----------------------------------------------------------------------------*/
64moo_sky_lines_list* moo_sky_lines_list_new(void)
65{
66 moo_sky_lines_list* res = cpl_calloc(1,sizeof(moo_sky_lines_list));
67 return res;
68}
69
70/*----------------------------------------------------------------------------*/
80/*----------------------------------------------------------------------------*/
81moo_sky_lines_list* moo_sky_lines_list_load(const cpl_frame* frame)
82{
83 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT,
84 NULL);
85 const char* filename = cpl_frame_get_filename(frame);
86 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT,
87 NULL);
88
89 moo_sky_lines_list* res = moo_sky_lines_list_new();
90 res->filename = cpl_strdup(filename);
91
92 return res;
93
94}
95
96
97/*----------------------------------------------------------------------------*/
106/*----------------------------------------------------------------------------*/
107void moo_sky_lines_list_delete(moo_sky_lines_list* self)
108{
109 if ( self!= NULL){
110 if ( self->filename!= NULL){
111 cpl_free(self->filename);
112 }
113 if ( self->linecat!= NULL){
114 cpl_table_delete(self->linecat);
115 }
116 if ( self->free_zones!= NULL){
117 cpl_table_delete(self->free_zones);
118 }
119 cpl_free(self);
120 }
121}
122
123/*----------------------------------------------------------------------------*/
135/*----------------------------------------------------------------------------*/
136cpl_error_code moo_sky_lines_list_get_free_zones(moo_sky_lines_list* self,
137 double wmin, double wmax, double** zwmin, double** zwmax, cpl_array** sel)
138{
139 cpl_ensure_code(self!=NULL, CPL_ERROR_NULL_INPUT);
140 cpl_errorstate prev_state = cpl_errorstate_get();
141
142 if (self->free_zones==NULL){
143 moo_try_check(self->free_zones = moo_fits_load_extension_table(self->filename,
144 NULL, MOO_SKY_LINES_LIST_FREEZONE_TNAME)," ");
145 }
146 cpl_table_select_all(self->free_zones);
147 cpl_table_and_selected_double(self->free_zones,MOO_SKY_LINES_LIST_WMAX_COLNAME,
148 CPL_GREATER_THAN,wmin);
149 cpl_table_and_selected_double(self->free_zones,MOO_SKY_LINES_LIST_WMIN_COLNAME,
150 CPL_LESS_THAN,wmax);
151 *zwmin = cpl_table_get_data_double(self->free_zones,
152 MOO_SKY_LINES_LIST_WMIN_COLNAME);
153 *zwmax = cpl_table_get_data_double(self->free_zones,
154 MOO_SKY_LINES_LIST_WMAX_COLNAME);
155 *sel = cpl_table_where_selected(self->free_zones);
156
157 moo_try_cleanup:
158 if ( !cpl_errorstate_is_equal(prev_state)){
159 cpl_msg_error(__func__,"Can't load skylines for filename %s",
160 self->filename);
161 cpl_errorstate_set(prev_state);
162 }
163 return CPL_ERROR_NONE;
164}
cpl_table * moo_fits_load_extension_table(const char *filename, const char *name, const char *detectorname)
Load a table from FITS file.
Definition: moo_fits.c:359
cpl_error_code moo_sky_lines_list_get_free_zones(moo_sky_lines_list *self, double wmin, double wmax, double **zwmin, double **zwmax, cpl_array **sel)
Get free zones for a specific wave range.
moo_sky_lines_list * moo_sky_lines_list_load(const cpl_frame *frame)
Load a SKY_LINES_LIST frame and create a moo_sky_lines_list.
void moo_sky_lines_list_delete(moo_sky_lines_list *self)
Delete a moo_sky_lines_list.
moo_sky_lines_list * moo_sky_lines_list_new(void)
Create a new moo_sky_lines_list.