MOONS Pipeline Reference Manual 0.13.1
moo_mask.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_pfits.h"
30#include "moo_fits.h"
31#include "moo_mask.h"
32/*----------------------------------------------------------------------------*/
47/*----------------------------------------------------------------------------*/
48
51/*-----------------------------------------------------------------------------
52 Function codes
53 -----------------------------------------------------------------------------*/
54
55/*----------------------------------------------------------------------------*/
63/*----------------------------------------------------------------------------*/
64moo_mask* moo_mask_new(void)
65{
66 moo_mask* res = cpl_calloc(1,sizeof(moo_mask));
67 return res;
68}
69
70
71/*----------------------------------------------------------------------------*/
80/*----------------------------------------------------------------------------*/
81cpl_mask* moo_mask_get(moo_mask* self,moo_detector_type type, int num)
82{
83 cpl_mask* result = NULL;
84
85 cpl_ensure(self!=NULL, CPL_ERROR_NULL_INPUT, NULL);
86 cpl_ensure(num>=1 && num<=2, CPL_ERROR_ILLEGAL_INPUT, NULL);
87
88 result = self->data[type+(num-1)*3];
89
90 return result;
91}
92
93/*----------------------------------------------------------------------------*/
102/*----------------------------------------------------------------------------*/
103cpl_error_code moo_mask_set(moo_mask* self,moo_detector_type type, int num,
104 cpl_mask* mask)
105{
106 cpl_ensure_code(self!=NULL, CPL_ERROR_NULL_INPUT);
107 cpl_ensure_code(num>=1 && num<=2, CPL_ERROR_ILLEGAL_INPUT);
108
109 self->data[type+(num-1)*3] = mask;
110
111 return CPL_ERROR_NONE;
112}
113/*----------------------------------------------------------------------------*/
122/*----------------------------------------------------------------------------*/
123
124void moo_mask_delete(moo_mask* self)
125{
126 if ( self!= NULL){
127 int i;
128
129 for(i = 0; i< 6; i++){
130 if ( self->data[i]!= NULL){
131 cpl_mask_delete(self->data[i]);
132 }
133 }
134
135 cpl_free(self);
136 }
137}
138
139/*----------------------------------------------------------------------------*/
149/*----------------------------------------------------------------------------*/
150void moo_mask_save(moo_mask* self, const char* filename)
151{
152 if ( self != NULL){
153 moo_fits_create(filename);
154 for(int i = 0; i< 2; i++){
155 for(int j = 0; j< 3; j++){
156 const char* extname = moo_detector_get_extname(j, i+1);
157 moo_fits_write_extension_mask(self->data[j+i*3], filename,
158 MASK_EXTENSION, extname, NULL);
159 }
160 }
161 }
162}
163
const char * moo_detector_get_extname(moo_detector_type type, int ntas)
Get the extension name of a detector.
Definition: moo_detector.c:137
enum _moo_detector_type_ moo_detector_type
The type code type.
Definition: moo_detector.h:64
cpl_error_code moo_fits_write_extension_mask(cpl_mask *mask, const char *filename, const char *name, const char *detectorname, cpl_propertylist *header)
Write a mask as extension in FITS file.
Definition: moo_fits.c:61
cpl_error_code moo_fits_create(const char *filename)
Create a new fits file with empty propertylist.
Definition: moo_fits.c:533
cpl_mask * moo_mask_get(moo_mask *self, moo_detector_type type, int num)
Get the cpl_mask associated to given type,num.
Definition: moo_mask.c:81
void moo_mask_delete(moo_mask *self)
Delete a moo_mask.
Definition: moo_mask.c:124
void moo_mask_save(moo_mask *self, const char *filename)
Save a moo_mask to a FITS file.
Definition: moo_mask.c:150
cpl_error_code moo_mask_set(moo_mask *self, moo_detector_type type, int num, cpl_mask *mask)
Set the cpl_mask associated to given type,num.
Definition: moo_mask.c:103
moo_mask * moo_mask_new(void)
Create a new moo_mask
Definition: moo_mask.c:64