irplib_wcs.c

00001 /* $Id: irplib_wcs.c,v 1.2 2009/02/12 13:49:09 lbilbao Exp $
00002  *
00003  * This file is part of the irplib package
00004  * Copyright (C) 2002,2003 European Southern Observatory
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., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: lbilbao $
00023  * $Date: 2009/02/12 13:49:09 $
00024  * $Revision: 1.2 $
00025  * $Name: naco-4_1_2 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                    Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <math.h>
00037 #include <cpl.h>
00038 
00039 #include "irplib_wcs.h"
00040 
00041 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)
00042 /*----------------------------------------------------------------------------*/
00046 /*----------------------------------------------------------------------------*/
00047 
00050 /*----------------------------------------------------------------------------*/
00062 /*----------------------------------------------------------------------------*/
00063 cpl_error_code irplib_wcs_xytoradec
00064 (cpl_wcs *wcs, double x, double y, double *ra, double *dec) 
00065 {
00066     double *        xy;
00067     double *        radec;
00068     cpl_matrix *    from;
00069     cpl_matrix *    to;
00070     cpl_array *     status;
00071     cpl_error_code  err_code;
00072 
00073     /* Load up the information */
00074     
00075     from = cpl_matrix_new(1,2);
00076     xy = cpl_matrix_get_data(from);
00077     xy[0] = x;
00078     xy[1] = y;
00079 
00080     /* Call the conversion routine */
00081 
00082     err_code =  cpl_wcs_convert(wcs,from,&to,&status,CPL_WCS_PHYS2WORLD);
00083 
00084     /* Pass it back now */
00085 
00086     radec = cpl_matrix_get_data(to);
00087     *ra = radec[0];
00088     *dec = radec[1];
00089 
00090     /* Tidy and exit */
00091 
00092     cpl_matrix_delete(from);
00093     cpl_matrix_delete(to);
00094     cpl_array_delete(status);
00095 
00096     return err_code;
00097 }
00098 
00099 /*----------------------------------------------------------------------------*/
00110 /*----------------------------------------------------------------------------*/
00111 cpl_error_code irplib_wcs_radectoxy
00112 (cpl_wcs * wcs,
00113  double    ra, 
00114  double    dec,
00115  double *  x,
00116  double *  y)
00117 {
00118     cpl_matrix *    radec_coord;
00119     cpl_matrix *    xy_coord;
00120     cpl_array *     status;
00121     cpl_error_code  err_code;
00122     
00123     /* Feed the matrix with RA, DEC */
00124     radec_coord = cpl_matrix_new(1, 2);
00125     cpl_matrix_set(radec_coord, 0, 0, ra);
00126     cpl_matrix_set(radec_coord, 0, 1, dec);
00127     
00128     xy_coord = NULL;
00129     status   = NULL;
00130     err_code = cpl_wcs_convert(wcs, radec_coord, &xy_coord, 
00131                                &status, CPL_WCS_WORLD2PHYS);
00132     
00133     *x  = cpl_matrix_get(xy_coord, 0, 0);
00134     *y  = cpl_matrix_get(xy_coord, 0, 1);
00135   
00136     /* Tidy and exit */
00137 
00138     cpl_array_delete(status);
00139     cpl_matrix_delete(radec_coord);
00140     cpl_matrix_delete(xy_coord);
00141     
00142     return err_code;
00143     
00144 }   
00145 
00146 #endif
00147 

Generated on Fri Jul 3 11:23:58 2009 for NACO Pipeline Reference Manual by  doxygen 1.5.8