MOONS Pipeline Reference Manual 0.13.2
moo_atm.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 <ctype.h>
30#include <string.h>
31#include "moo_pfits.h"
32#include "moo_fits.h"
33#include "moo_atm.h"
34/*----------------------------------------------------------------------------*/
49/*----------------------------------------------------------------------------*/
50
53/*-----------------------------------------------------------------------------
54 Function codes
55 -----------------------------------------------------------------------------*/
56
57/*----------------------------------------------------------------------------*/
65/*----------------------------------------------------------------------------*/
66moo_atm* moo_atm_new(void)
67{
68 moo_atm* res = cpl_calloc(1,sizeof(moo_atm));
69 return res;
70}
71
72
73/*----------------------------------------------------------------------------*/
82/*----------------------------------------------------------------------------*/
83moo_atm* moo_atm_load(const cpl_frame* frame)
84{
85 cpl_ensure(frame != NULL, CPL_ERROR_NULL_INPUT, NULL);
86
87 const char* filename = cpl_frame_get_filename(frame);
88 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT,
89 NULL);
90 cpl_errorstate prev_state = cpl_errorstate_get();
91
92 moo_atm* res = moo_atm_new();
93 res->filename = cpl_strdup(filename);
94 res->primary_header = cpl_propertylist_load( filename,0);
95
96 cpl_size qnum = cpl_fits_find_extension(filename,
98 if ( qnum > 0){
99 res->table = cpl_table_load(res->filename,qnum,0);
100 }
101
102 if ( !cpl_errorstate_is_equal(prev_state)){
103 cpl_msg_debug(__func__,"Error in loading atm : %d",cpl_error_get_code());
104 moo_atm_delete(res);
105 res = NULL;
106 cpl_errorstate_set(prev_state);
107 }
108 return res;
109}
110
111/*----------------------------------------------------------------------------*/
121/*----------------------------------------------------------------------------*/
122cpl_table* moo_atm_convert_mag_to_flux(moo_atm* self,double airm)
123{
124 cpl_ensure(self!=NULL,CPL_ERROR_NULL_INPUT,NULL);
125
126 cpl_table* res = cpl_table_duplicate(self->table);
127 cpl_table_new_column(res, MOO_ATM_FLUX, CPL_TYPE_DOUBLE);
128 int nrow = cpl_table_get_nrow(res);
129 const double* extinction = cpl_table_get_data_double_const(
130 res,MOO_ATM_EXTINCTION);
131
132 for(int i=0; i<nrow; i++){
133 double e = extinction[i];
134 double flux = pow(10,-airm*e*0.4);
135 cpl_table_set_double(res,MOO_ATM_FLUX,i,flux);
136 }
137
138 #if MOO_DEBUG_ATM
139 cpl_table_save(res,NULL,NULL,"extinction.fits",CPL_IO_CREATE);
140 #endif
141 return res;
142}
143
144/*----------------------------------------------------------------------------*/
153/*----------------------------------------------------------------------------*/
154void moo_atm_delete(moo_atm* self)
155{
156 if ( self!= NULL){
157 if ( self->filename != NULL){
158 cpl_free(self->filename);
159 }
160 if ( self->primary_header!= NULL){
161 cpl_propertylist_delete(self->primary_header);
162 }
163 if ( self->table != NULL){
164 cpl_table_delete(self->table);
165 }
166 cpl_free(self);
167 }
168}
169
cpl_table * moo_atm_convert_mag_to_flux(moo_atm *self, double airm)
Get the extinction table with additonal column FLUX.
Definition: moo_atm.c:122
moo_atm * moo_atm_load(const cpl_frame *frame)
Load a ATM frame and create a moo_atm.
Definition: moo_atm.c:83
moo_atm * moo_atm_new(void)
Create a new moo_atm.
Definition: moo_atm.c:66
void moo_atm_delete(moo_atm *self)
Delete a moo_atm.
Definition: moo_atm.c:154
#define MOO_ATM_EXTNAME
ATM format.
Definition: moo_atm.h:35