00001 /* $Id: vircam_darkcor.c,v 1.18 2007/10/25 17:34:00 jim Exp $ 00002 * 00003 * This file is part of the VIRCAM Pipeline 00004 * Copyright (C) 2005 Cambridge Astronomy Survey Unit 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 /* 00022 * $Author: jim $ 00023 * $Date: 2007/10/25 17:34:00 $ 00024 * $Revision: 1.18 $ 00025 * $Name: $ 00026 */ 00027 00028 /* Includes */ 00029 00030 #ifdef HAVE_CONFIG_H 00031 #include <config.h> 00032 #endif 00033 00034 #include <cpl.h> 00035 #include "vircam_mods.h" 00036 #include "vircam_utils.h" 00037 #include "vircam_fits.h" 00038 00041 /*---------------------------------------------------------------------------*/ 00083 /*---------------------------------------------------------------------------*/ 00084 00085 extern int vircam_darkcor(vir_fits *infile, vir_fits *darksrc, float darkscl, 00086 int *status) { 00087 long n,i; 00088 float *idata,*ddata; 00089 cpl_image *im,*dm; 00090 cpl_propertylist *oplist; 00091 const char *fctid = "vircam_darkcor"; 00092 00093 /* Inherited status */ 00094 00095 if (*status != VIR_OK) 00096 return(*status); 00097 00098 /* Get the images and check the dimension to make sure they match */ 00099 00100 im = vircam_fits_get_image(infile); 00101 dm = vircam_fits_get_image(darksrc); 00102 if (vircam_compare_dims(im,dm) != VIR_OK) { 00103 cpl_msg_error(fctid,"Object and dark data array dimensions don't match"); 00104 FATAL_ERROR 00105 } 00106 00107 /* If the scale factor is 1, then just use the cpl image routine to do 00108 the arithmetic */ 00109 00110 if (darkscl == 1.0) { 00111 if (cpl_image_subtract(im,dm) != CPL_ERROR_NONE) 00112 FATAL_ERROR 00113 00114 /* Otherwise, do it by hand */ 00115 00116 } else { 00117 idata = cpl_image_get_data_float(im); 00118 ddata = cpl_image_get_data_float(dm); 00119 if (idata == NULL || ddata == NULL) 00120 FATAL_ERROR; 00121 n = (long)cpl_image_get_size_x(im)*(long)cpl_image_get_size_y(im); 00122 for (i = 0; i < n; i++) 00123 idata[i] -= darkscl*ddata[i]; 00124 } 00125 00126 /* Now put some stuff in the DRS extension... */ 00127 00128 oplist = vircam_fits_get_ehu(infile); 00129 if (oplist != NULL) { 00130 if (vircam_fits_get_fullname(darksrc) != NULL) 00131 cpl_propertylist_update_string(oplist,"ESO DRS DARKCOR", 00132 vircam_fits_get_fullname(darksrc)); 00133 else 00134 cpl_propertylist_update_string(oplist,"ESO DRS DARKCOR", 00135 "Memory File"); 00136 cpl_propertylist_set_comment(oplist,"ESO DRS DARKCOR", 00137 "Image used for dark correction"); 00138 cpl_propertylist_update_float(oplist,"ESO DRS DARKSCL",darkscl); 00139 cpl_propertylist_set_comment(oplist,"ESO DRS DARKSCL", 00140 "Scaling factor used in dark correction"); 00141 } else 00142 WARN_RETURN 00143 00144 /* Get out of here */ 00145 00146 GOOD_STATUS 00147 } 00148 00149 00152 /* 00153 00154 $Log: vircam_darkcor.c,v $ 00155 Revision 1.18 2007/10/25 17:34:00 jim 00156 Modified to remove lint warnings 00157 00158 Revision 1.17 2007/03/29 12:19:39 jim 00159 Little changes to improve documentation 00160 00161 Revision 1.16 2007/03/01 12:42:41 jim 00162 Modified slightly after code checking 00163 00164 Revision 1.15 2006/06/09 11:26:25 jim 00165 Small changes to keep lint happy 00166 00167 Revision 1.14 2006/04/20 11:18:23 jim 00168 Now adds an extension name to the error messages rather than an extension number 00169 00170 Revision 1.13 2006/03/23 21:18:47 jim 00171 Minor changes mainly to comment headers 00172 00173 Revision 1.12 2006/03/22 13:31:04 jim 00174 cosmetic change to keep lint happy 00175 00176 Revision 1.11 2006/03/17 13:53:46 jim 00177 Added comments to DRS headers 00178 00179 Revision 1.10 2006/03/15 10:43:41 jim 00180 Fixed a few things 00181 00182 Revision 1.9 2006/03/08 14:32:21 jim 00183 Lots of little modifications 00184 00185 Revision 1.8 2006/03/06 13:49:08 jim 00186 Modified so that the DRS keywords are written directly to the extension header 00187 for the input image 00188 00189 Revision 1.7 2006/03/01 10:31:28 jim 00190 Now uses new vir_fits objects 00191 00192 Revision 1.6 2006/01/23 10:30:49 jim 00193 Mainly documentation mods 00194 00195 Revision 1.5 2006/01/03 10:30:04 jim 00196 Given inherited status 00197 00198 Revision 1.4 2006/01/03 10:11:28 jim 00199 Modified to be slightly higher level than originally written. Now write 00200 info to an output property list 00201 00202 Revision 1.3 2005/12/14 22:17:32 jim 00203 Updated docs 00204 00205 Revision 1.2 2005/11/25 09:56:14 jim 00206 Tidied up some more documentation 00207 00208 Revision 1.1 2005/09/13 13:33:58 jim 00209 Forgot to add these 00210 00211 00212 */