MOONS Pipeline Reference Manual 0.13.2
moo_kernel.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 <string.h>
30#include "moo_pfits.h"
31#include "moo_fits.h"
32#include "moo_utils.h"
33#include "moo_kernel.h"
34/*----------------------------------------------------------------------------*/
49/*----------------------------------------------------------------------------*/
50
53/*-----------------------------------------------------------------------------
54 Function codes
55 -----------------------------------------------------------------------------*/
56
57/*----------------------------------------------------------------------------*/
65/*----------------------------------------------------------------------------*/
67{
68 moo_kernel* res = cpl_calloc(1,sizeof(moo_kernel));
69 return res;
70}
71
72/*----------------------------------------------------------------------------*/
79/*----------------------------------------------------------------------------*/
80moo_kernel* moo_kernel_load(const cpl_frame* frame)
81{
82 moo_kernel* res = NULL;
83
84 if(frame!=NULL){
85 const char* filename = cpl_frame_get_filename(frame);
86 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT,
87 NULL);
88
89 cpl_errorstate prev_state = cpl_errorstate_get();
90
91 res = moo_kernel_new();
92 res->filename = cpl_strdup(filename);
93
94 if ( !cpl_errorstate_is_equal(prev_state)){
96 res = NULL;
97 }
98 }
99 return res;
100}
101
102/*----------------------------------------------------------------------------*/
111/*----------------------------------------------------------------------------*/
112
114{
115 if ( self!= NULL){
116 cpl_free(self->filename);
117 cpl_free(self);
118 }
119}
120
121static char* _moo_get_extname(moo_detector_type type, int ntas,int rbn)
122{
123 char* extname = NULL;
124 const char* detector = moo_detector_get_name(type);
125 extname = cpl_sprintf(MOO_KERNEL_EXTNAME,detector,
126 ntas,rbn);
127 return extname;
128}
129/*----------------------------------------------------------------------------*/
141/*----------------------------------------------------------------------------*/
142cpl_propertylist* moo_kernel_get_header(moo_kernel* self,
143 moo_detector_type type, int ntas,int rbn)
144{
145 cpl_propertylist* header = NULL;
146
147 if(self!=NULL){
148 char* extname = _moo_get_extname(type,ntas,rbn);
149 if(extname!=NULL){
150 header = moo_fits_load_extension_header(self->filename,NULL,extname);
151 }
152 cpl_free(extname);
153 }
154 return header;
155}
156
157/*----------------------------------------------------------------------------*/
169/*----------------------------------------------------------------------------*/
171 moo_detector_type type, int ntas,int rbn)
172{
173 cpl_image* img = NULL;
174 cpl_matrix* matrix = NULL;
175
176 if(self!=NULL){
177 char* extname = _moo_get_extname(type,ntas,rbn);
178
179 if(extname!=NULL){
180 cpl_size extnum = cpl_fits_find_extension(self->filename, extname);
181 if(extnum >0){
182 img = cpl_image_load(self->filename, CPL_TYPE_DOUBLE, 0, extnum);
183 cpl_matrix *mat = cpl_matrix_wrap(
184 cpl_image_get_size_y(img),
185 cpl_image_get_size_x(img),
186 cpl_image_get_data_double(img));
187 matrix = cpl_matrix_duplicate(mat);
188
189 cpl_matrix_unwrap(mat);
190 cpl_image_delete(img);
191 }
192 }
193 cpl_free(extname);
194 }
195 return matrix;
196}
const char * moo_detector_get_name(moo_detector_type type)
Get the extension name of a detector.
Definition: moo_detector.c:183
enum _moo_detector_type_ moo_detector_type
The type code type.
Definition: moo_detector.h:64
void moo_kernel_delete(moo_kernel *self)
Delete a moo_kernel.
Definition: moo_kernel.c:113
cpl_propertylist * moo_kernel_get_header(moo_kernel *self, moo_detector_type type, int ntas, int rbn)
Get the header of the kernel for given idrbn or NULL.
Definition: moo_kernel.c:142
moo_kernel * moo_kernel_new(void)
Create a new moo_kernel.
Definition: moo_kernel.c:66
moo_kernel * moo_kernel_load(const cpl_frame *frame)
Load a new moo_kernel.
Definition: moo_kernel.c:80
cpl_matrix * moo_kernel_get_matrix(moo_kernel *self, moo_detector_type type, int ntas, int rbn)
Get the mtarix of the kernel for given idrbn or NULL.
Definition: moo_kernel.c:170
KERNEL format.
Definition: moo_kernel.h:44