MOONS Pipeline Reference Manual 0.13.2
moo_masklist.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 <hdrl.h>
30#include <assert.h>
31#include "moo_masklist.h"
32#include "moo_utils.h"
33/*----------------------------------------------------------------------------*/
39/*----------------------------------------------------------------------------*/
40
43/*-----------------------------------------------------------------------------
44 Function codes
45 -----------------------------------------------------------------------------*/
46
47/*----------------------------------------------------------------------------*/
55moo_masklist *
57{
58 return (moo_masklist *)cpl_calloc(1, sizeof(moo_masklist));
59}
60
61/*----------------------------------------------------------------------------*/
70moo_masklist *
72{
73 cpl_ensure(size > 0, CPL_ERROR_NULL_INPUT, NULL);
74 int i;
75 moo_masklist *res = moo_masklist_new();
76
77 res->list = cpl_calloc(size, sizeof(moo_mask));
78 res->size = size;
79 for (i = 0; i < size; i++) {
80 res->list[i] = moo_mask_new();
81 }
82
83 return res;
84}
85
86/*----------------------------------------------------------------------------*/
96/*----------------------------------------------------------------------------*/
97cpl_size
98moo_masklist_get_size(const moo_masklist *self)
99{
100 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1);
101
102 assert(self->size >= 0);
103
104 return self->size;
105}
106
107/*----------------------------------------------------------------------------*/
119/*----------------------------------------------------------------------------*/
120moo_mask *
121moo_masklist_get(moo_masklist *self, int i)
122{
123 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
124 cpl_ensure(i >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
125 int size = moo_masklist_get_size(self);
126 cpl_ensure(i < size, CPL_ERROR_ILLEGAL_INPUT, NULL);
127
128 return self->list[i];
129}
130
131/*----------------------------------------------------------------------------*/
145/*----------------------------------------------------------------------------*/
146cpl_mask *
147moo_masklist_get_mask(moo_masklist *self,
148 int i,
150 int num)
151{
152 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
153 moo_mask *mask = moo_masklist_get(self, i);
154 return moo_mask_get(mask, type, num);
155}
156
157/*----------------------------------------------------------------------------*/
164void
165moo_masklist_delete(moo_masklist *self)
166{
167 if (self != NULL) {
168 for (int i = 0; i < self->size; i++) {
169 moo_mask_delete(self->list[i]);
170 }
171 cpl_free(self->list);
172 cpl_free(self);
173 }
174
175 return;
176}
177
enum _moo_detector_type_ moo_detector_type
The type code type.
Definition: moo_detector.h:64
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
moo_mask * moo_mask_new(void)
Create a new moo_mask
Definition: moo_mask.c:64
moo_mask * moo_masklist_get(moo_masklist *self, int i)
Get the MASK at the position i in the list.
Definition: moo_masklist.c:121
cpl_mask * moo_masklist_get_mask(moo_masklist *self, int i, moo_detector_type type, int num)
Get the CPL_MASK at the position i,type,num in the list.
Definition: moo_masklist.c:147
moo_masklist * moo_masklist_new(void)
Create a new moo_masklist
Definition: moo_masklist.c:56
cpl_size moo_masklist_get_size(const moo_masklist *self)
Get the number of MASK in the masklist.
Definition: moo_masklist.c:98
moo_masklist * moo_masklist_create(int size)
Create a new moo_masklist from the given MASK frameset.
Definition: moo_masklist.c:71
void moo_masklist_delete(moo_masklist *self)
Free all memory used by a moo_masklist object including the MASK.
Definition: moo_masklist.c:165