vircam_darkcor.c

00001 /* $Id: vircam_darkcor.c,v 1.19 2009/05/20 12:18:42 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: 2009/05/20 12:18:42 $
00024  * $Revision: 1.19 $
00025  * $Name: vcam-1_3_0 $
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     /* See if this file has already been done */
00099 
00100     oplist = vircam_fits_get_ehu(infile);
00101     if (cpl_propertylist_has(oplist,"ESO DRS DARKCOR"))
00102         return(*status);
00103 
00104     /* Get the images and check the dimension to make sure they match */
00105     
00106     im = vircam_fits_get_image(infile);
00107     dm = vircam_fits_get_image(darksrc);
00108     if (vircam_compare_dims(im,dm) != VIR_OK) {
00109         cpl_msg_error(fctid,"Object and dark data array dimensions don't match");
00110         FATAL_ERROR
00111     }
00112 
00113     /* If the scale factor is 1, then just use the cpl image routine to do
00114        the arithmetic */
00115 
00116     if (darkscl == 1.0) {
00117         if (cpl_image_subtract(im,dm) != CPL_ERROR_NONE)
00118             FATAL_ERROR
00119 
00120     /* Otherwise, do it by hand */
00121 
00122     } else {
00123         idata = cpl_image_get_data_float(im);
00124         ddata = cpl_image_get_data_float(dm);
00125         if (idata == NULL || ddata == NULL) 
00126             FATAL_ERROR;
00127         n = (long)cpl_image_get_size_x(im)*(long)cpl_image_get_size_y(im);
00128         for (i = 0; i < n; i++) 
00129             idata[i] -= darkscl*ddata[i];
00130     }
00131 
00132     /* Now put some stuff in the DRS extension... */
00133 
00134     oplist = vircam_fits_get_ehu(infile);
00135     if (oplist != NULL) {
00136         if (vircam_fits_get_fullname(darksrc) != NULL) 
00137             cpl_propertylist_update_string(oplist,"ESO DRS DARKCOR",
00138                                            vircam_fits_get_fullname(darksrc));
00139         else
00140             cpl_propertylist_update_string(oplist,"ESO DRS DARKCOR",
00141                                            "Memory File");
00142         cpl_propertylist_set_comment(oplist,"ESO DRS DARKCOR",
00143                                      "Image used for dark correction");
00144         cpl_propertylist_update_float(oplist,"ESO DRS DARKSCL",darkscl);
00145         cpl_propertylist_set_comment(oplist,"ESO DRS DARKSCL",
00146                                      "Scaling factor used in dark correction");
00147     } else
00148         WARN_RETURN
00149 
00150     /* Get out of here */
00151 
00152     GOOD_STATUS
00153 }
00154 
00155 
00158 /*
00159 
00160 $Log: vircam_darkcor.c,v $
00161 Revision 1.19  2009/05/20 12:18:42  jim
00162 Modified so that if the operation is already done, then it just returns
00163 
00164 Revision 1.18  2007/10/25 17:34:00  jim
00165 Modified to remove lint warnings
00166 
00167 Revision 1.17  2007/03/29 12:19:39  jim
00168 Little changes to improve documentation
00169 
00170 Revision 1.16  2007/03/01 12:42:41  jim
00171 Modified slightly after code checking
00172 
00173 Revision 1.15  2006/06/09 11:26:25  jim
00174 Small changes to keep lint happy
00175 
00176 Revision 1.14  2006/04/20 11:18:23  jim
00177 Now adds an extension name to the error messages rather than an extension number
00178 
00179 Revision 1.13  2006/03/23 21:18:47  jim
00180 Minor changes mainly to comment headers
00181 
00182 Revision 1.12  2006/03/22 13:31:04  jim
00183 cosmetic change to keep lint happy
00184 
00185 Revision 1.11  2006/03/17 13:53:46  jim
00186 Added comments to DRS headers
00187 
00188 Revision 1.10  2006/03/15 10:43:41  jim
00189 Fixed a few things
00190 
00191 Revision 1.9  2006/03/08 14:32:21  jim
00192 Lots of little modifications
00193 
00194 Revision 1.8  2006/03/06 13:49:08  jim
00195 Modified so that the DRS keywords are written directly to the extension header
00196 for the input image
00197 
00198 Revision 1.7  2006/03/01 10:31:28  jim
00199 Now uses new vir_fits objects
00200 
00201 Revision 1.6  2006/01/23 10:30:49  jim
00202 Mainly documentation mods
00203 
00204 Revision 1.5  2006/01/03 10:30:04  jim
00205 Given inherited status
00206 
00207 Revision 1.4  2006/01/03 10:11:28  jim
00208 Modified to be slightly higher level than originally written. Now write
00209 info to an output property list
00210 
00211 Revision 1.3  2005/12/14 22:17:32  jim
00212 Updated docs
00213 
00214 Revision 1.2  2005/11/25 09:56:14  jim
00215 Tidied up some more documentation
00216 
00217 Revision 1.1  2005/09/13 13:33:58  jim
00218 Forgot to add these
00219 
00220 
00221 */

Generated on 15 Mar 2012 for VIRCAM Pipeline by  doxygen 1.6.1