CR2RE Pipeline Reference Manual 1.6.8
cr2res_nodding.c
1/*
2 * This file is part of the CR2RES Pipeline
3 * Copyright (C) 2002,2003 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 St, Fifth Floor, Boston, MA 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <string.h>
29#include <math.h>
30#include <cpl.h>
31
32#include "cr2res_nodding.h"
33#include "cr2res_pfits.h"
34
35/*----------------------------------------------------------------------------*/
39/*----------------------------------------------------------------------------*/
40
43/*----------------------------------------------------------------------------*/
49/*----------------------------------------------------------------------------*/
50cr2res_nodding_pos * cr2res_nodding_read_positions(const cpl_frameset * in)
51{
52 cr2res_nodding_pos * out ;
53 cpl_size nframes, i ;
54
55 /* Check entries */
56 if (in == NULL) return NULL ;
57
58 /* Initialise */
59 nframes = cpl_frameset_get_size(in) ;
60
61 /* Allocate the vector */
62 out = cpl_malloc(nframes * sizeof(cr2res_nodding_pos));
63 for (i = 0; i < nframes; i++) out[i] = CR2RES_NODDING_NONE;
64
65 /* Loop on the frames */
66 for (i=0 ; i< nframes ; i++) {
67 cpl_propertylist * plist ;
68 plist = cpl_propertylist_load(cpl_frame_get_filename(
69 cpl_frameset_get_position_const(in, i)), 0) ;
70 out[i] = cr2res_pfits_get_nodding_pos(plist) ;
71 cpl_propertylist_delete(plist) ;
72 }
73 return out ;
74}
75
76/*----------------------------------------------------------------------------*/
82/*----------------------------------------------------------------------------*/
83char cr2res_nodding_position_char(cr2res_nodding_pos pos)
84{
85 if (pos == CR2RES_NODDING_A) return 'A' ;
86 if (pos == CR2RES_NODDING_B) return 'B' ;
87 return '-' ;
88}
89
90/*----------------------------------------------------------------------------*/
99/*----------------------------------------------------------------------------*/
101 const cpl_frameset * in,
102 const cr2res_nodding_pos * positions,
103 cpl_frameset ** pos_a,
104 cpl_frameset ** pos_b)
105{
106 cpl_frameset * nod_a ;
107 cpl_frameset * nod_b ;
108 const cpl_frame * cur_frame ;
109 cpl_size alist_idx, blist_idx, i, nframes ;
110
111 /* Check entries */
112 if (in==NULL || positions==NULL || pos_a==NULL || pos_b==NULL)
113 return -1;
114
115 /* Initialise */
116 nframes = cpl_frameset_get_size(in) ;
117 alist_idx = blist_idx = 0 ;
118
119 /* Create A/B positions */
120 nod_a = cpl_frameset_new() ;
121 nod_b = cpl_frameset_new() ;
122
123 /* Loop on the positions */
124 for (i=0 ; i<nframes ; i++) {
125 if (positions[i] == CR2RES_NODDING_A) {
126 cur_frame = cpl_frameset_get_position_const(in, i) ;
127 cpl_frameset_insert(nod_a, cpl_frame_duplicate(cur_frame)) ;
128 alist_idx++ ;
129 cur_frame = NULL ;
130 }
131 if (positions[i] == CR2RES_NODDING_B) {
132 cur_frame = cpl_frameset_get_position_const(in, i) ;
133 cpl_frameset_insert(nod_b, cpl_frame_duplicate(cur_frame)) ;
134 blist_idx++ ;
135 cur_frame = NULL ;
136 }
137 }
138 *pos_a = nod_a ;
139 *pos_b = nod_b ;
140 return 0 ;
141}
142
143/*----------------------------------------------------------------------------*/
152/*----------------------------------------------------------------------------*/
154 const hdrl_imagelist * in,
155 const cr2res_nodding_pos * positions,
156 hdrl_imagelist ** pos_a,
157 hdrl_imagelist ** pos_b)
158{
159 hdrl_imagelist * nod_a ;
160 hdrl_imagelist * nod_b ;
161 hdrl_image * cur_ima ;
162 cpl_size alist_idx, blist_idx, i, nima ;
163
164 /* Check entries */
165 if (in==NULL || positions==NULL || pos_a==NULL || pos_b==NULL)
166 return -1;
167
168 /* Initialise */
169 nima = hdrl_imagelist_get_size(in) ;
170 alist_idx = blist_idx = 0 ;
171
172 /* Create A/B positions */
173 nod_a = hdrl_imagelist_new() ;
174 nod_b = hdrl_imagelist_new() ;
175
176 /* Loop on the positions */
177 for (i=0 ; i<nima ; i++) {
178 if (positions[i] == CR2RES_NODDING_A) {
179 cur_ima = hdrl_image_duplicate(hdrl_imagelist_get(in, i)) ;
180 hdrl_imagelist_set(nod_a, cur_ima, alist_idx) ;
181 alist_idx++ ;
182 cur_ima = NULL ;
183 }
184 if (positions[i] == CR2RES_NODDING_B) {
185 cur_ima = hdrl_image_duplicate(hdrl_imagelist_get(in, i)) ;
186 hdrl_imagelist_set(nod_b, cur_ima, blist_idx) ;
187 blist_idx++ ;
188 cur_ima = NULL ;
189 }
190 }
191 *pos_a = nod_a ;
192 *pos_b = nod_b ;
193 return 0 ;
194}
195
cr2res_nodding_pos cr2res_pfits_get_nodding_pos(const cpl_propertylist *plist)
find out the nodding position
Definition: cr2res_pfits.c:53
int cr2res_combine_nodding_split_frames(const cpl_frameset *in, const cr2res_nodding_pos *positions, cpl_frameset **pos_a, cpl_frameset **pos_b)
Split A/B positions in 2 framesets.
char cr2res_nodding_position_char(cr2res_nodding_pos pos)
Get the nodding position character for display.
int cr2res_combine_nodding_split(const hdrl_imagelist *in, const cr2res_nodding_pos *positions, hdrl_imagelist **pos_a, hdrl_imagelist **pos_b)
Split A/B positions in 2 image lists.
cr2res_nodding_pos * cr2res_nodding_read_positions(const cpl_frameset *in)
Get the nodding positions from a frame set.
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
Definition: hdrl_image.c:391
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.