VIRCAM Pipeline  1.3.3
vircam/vircam_darkcor.c
1 /* $Id: vircam_darkcor.c,v 1.19 2009-05-20 12:18:42 jim Exp $
2  *
3  * This file is part of the VIRCAM Pipeline
4  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jim $
23  * $Date: 2009-05-20 12:18:42 $
24  * $Revision: 1.19 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 /* Includes */
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #include <cpl.h>
35 #include "vircam_mods.h"
36 #include "vircam_utils.h"
37 #include "vircam_fits.h"
38 
41 /*---------------------------------------------------------------------------*/
83 /*---------------------------------------------------------------------------*/
84 
85 extern int vircam_darkcor(vir_fits *infile, vir_fits *darksrc, float darkscl,
86  int *status) {
87  long n,i;
88  float *idata,*ddata;
89  cpl_image *im,*dm;
90  cpl_propertylist *oplist;
91  const char *fctid = "vircam_darkcor";
92 
93  /* Inherited status */
94 
95  if (*status != VIR_OK)
96  return(*status);
97 
98  /* See if this file has already been done */
99 
100  oplist = vircam_fits_get_ehu(infile);
101  if (cpl_propertylist_has(oplist,"ESO DRS DARKCOR"))
102  return(*status);
103 
104  /* Get the images and check the dimension to make sure they match */
105 
106  im = vircam_fits_get_image(infile);
107  dm = vircam_fits_get_image(darksrc);
108  if (vircam_compare_dims(im,dm) != VIR_OK) {
109  cpl_msg_error(fctid,"Object and dark data array dimensions don't match");
110  FATAL_ERROR
111  }
112 
113  /* If the scale factor is 1, then just use the cpl image routine to do
114  the arithmetic */
115 
116  if (darkscl == 1.0) {
117  if (cpl_image_subtract(im,dm) != CPL_ERROR_NONE)
118  FATAL_ERROR
119 
120  /* Otherwise, do it by hand */
121 
122  } else {
123  idata = cpl_image_get_data_float(im);
124  ddata = cpl_image_get_data_float(dm);
125  if (idata == NULL || ddata == NULL)
126  FATAL_ERROR;
127  n = (long)cpl_image_get_size_x(im)*(long)cpl_image_get_size_y(im);
128  for (i = 0; i < n; i++)
129  idata[i] -= darkscl*ddata[i];
130  }
131 
132  /* Now put some stuff in the DRS extension... */
133 
134  oplist = vircam_fits_get_ehu(infile);
135  if (oplist != NULL) {
136  if (vircam_fits_get_fullname(darksrc) != NULL)
137  cpl_propertylist_update_string(oplist,"ESO DRS DARKCOR",
138  vircam_fits_get_fullname(darksrc));
139  else
140  cpl_propertylist_update_string(oplist,"ESO DRS DARKCOR",
141  "Memory File");
142  cpl_propertylist_set_comment(oplist,"ESO DRS DARKCOR",
143  "Image used for dark correction");
144  cpl_propertylist_update_float(oplist,"ESO DRS DARKSCL",darkscl);
145  cpl_propertylist_set_comment(oplist,"ESO DRS DARKSCL",
146  "Scaling factor used in dark correction");
147  } else
148  WARN_RETURN
149 
150  /* Get out of here */
151 
152  GOOD_STATUS
153 }
154 
155 
158 /*
159 
160 $Log: not supported by cvs2svn $
161 Revision 1.18 2007/10/25 17:34:00 jim
162 Modified to remove lint warnings
163 
164 Revision 1.17 2007/03/29 12:19:39 jim
165 Little changes to improve documentation
166 
167 Revision 1.16 2007/03/01 12:42:41 jim
168 Modified slightly after code checking
169 
170 Revision 1.15 2006/06/09 11:26:25 jim
171 Small changes to keep lint happy
172 
173 Revision 1.14 2006/04/20 11:18:23 jim
174 Now adds an extension name to the error messages rather than an extension number
175 
176 Revision 1.13 2006/03/23 21:18:47 jim
177 Minor changes mainly to comment headers
178 
179 Revision 1.12 2006/03/22 13:31:04 jim
180 cosmetic change to keep lint happy
181 
182 Revision 1.11 2006/03/17 13:53:46 jim
183 Added comments to DRS headers
184 
185 Revision 1.10 2006/03/15 10:43:41 jim
186 Fixed a few things
187 
188 Revision 1.9 2006/03/08 14:32:21 jim
189 Lots of little modifications
190 
191 Revision 1.8 2006/03/06 13:49:08 jim
192 Modified so that the DRS keywords are written directly to the extension header
193 for the input image
194 
195 Revision 1.7 2006/03/01 10:31:28 jim
196 Now uses new vir_fits objects
197 
198 Revision 1.6 2006/01/23 10:30:49 jim
199 Mainly documentation mods
200 
201 Revision 1.5 2006/01/03 10:30:04 jim
202 Given inherited status
203 
204 Revision 1.4 2006/01/03 10:11:28 jim
205 Modified to be slightly higher level than originally written. Now write
206 info to an output property list
207 
208 Revision 1.3 2005/12/14 22:17:32 jim
209 Updated docs
210 
211 Revision 1.2 2005/11/25 09:56:14 jim
212 Tidied up some more documentation
213 
214 Revision 1.1 2005/09/13 13:33:58 jim
215 Forgot to add these
216 
217 
218 */