fors_std_star-test.c

00001 /* $Id: fors_std_star-test.c,v 1.15 2007/12/12 16:11:48 jmlarsen Exp $
00002  *
00003  * This file is part of the FORS Library
00004  * Copyright (C) 2002-2006 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  02110-1301 USA
00019  */
00020 
00021 /*
00022  * $Author: jmlarsen $
00023  * $Date: 2007/12/12 16:11:48 $
00024  * $Revision: 1.15 $
00025  * $Name:  $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 #include <fors_data.h>
00033 #include <fors_dfs.h>
00034 
00035 #include <test_simulate.h>
00036 #include <test.h>
00037 
00038 #include <cpl.h>
00039 #include <math.h>
00040 
00048 #undef cleanup
00049 #define cleanup \
00050 do { \
00051     cpl_frameset_delete(cat_frames); \
00052     cpl_frame_delete(raw_frame); \
00053     cpl_frame_delete(phot_table); \
00054     fors_std_star_list_delete(&cat, fors_std_star_delete); \
00055     fors_setting_delete(&setting); \
00056 } while (0)
00057 
00061 static void
00062 test_new(void)
00063 {
00064     cpl_frameset *cat_frames = NULL;
00065     cpl_frame *phot_table = NULL;
00066     const char *filename = "std_cat.fits";
00067     fors_std_star_list *cat = NULL;
00068     fors_setting *setting = NULL;
00069     double color_term, dcolor_term;
00070     double ext_coeff, dext_coeff;
00071     double expected_zeropoint, dexpected_zeropoint;
00072 
00073     /* Simulate */
00074     cpl_frame *raw_frame = create_standard("std_cat_raw.fits", 
00075                                            STANDARD_IMG, CPL_FRAME_GROUP_RAW);
00076     
00077     phot_table = create_phot_table("std_cat_phot_table.fits",
00078                                    PHOT_TABLE, CPL_FRAME_GROUP_CALIB);
00079     
00080     cat_frames = cpl_frameset_new();
00081     cpl_frameset_insert(cat_frames,
00082                         create_std_cat(filename, 
00083                                        FLX_STD_IMG, CPL_FRAME_GROUP_CALIB));
00084 
00085     setting = fors_setting_new(raw_frame);
00086 
00087     fors_phot_table_load(phot_table, setting,
00088                          &color_term, &dcolor_term,
00089              &ext_coeff, &dext_coeff,
00090              &expected_zeropoint, &dexpected_zeropoint);
00091     
00092     /* Call function */
00093     cat = fors_std_cat_load(cat_frames, raw_frame, setting,
00094                             color_term, dcolor_term);
00095     
00096     /* Test results (TBI) */
00097     
00098     fors_std_star_print_list(CPL_MSG_DEBUG, cat);
00099     fors_std_star_print_list(CPL_MSG_INFO, cat);
00100 
00101     cleanup;
00102     return;
00103 }
00104 
00105 
00106 static void
00107 test_dist(void)
00108 {
00109     double ra  = 34.5;
00110     double dec = -0.4;
00111     double mag = 15;
00112     double dmag = 0.51;
00113     double cmag = 15.2;
00114     double dcmag = 0.21;
00115     double color = 0.2;
00116 
00117     double shift_arcsecs;
00118 
00119     for (shift_arcsecs = 0.1; shift_arcsecs <= 100; shift_arcsecs *= 2) {
00120         
00121         fors_std_star *s = fors_std_star_new(ra, dec, mag, dmag, 
00122                          cmag, dcmag,
00123                          color, "some");
00124         fors_std_star *t = fors_std_star_new(ra  + shift_arcsecs/3600,
00125                                              dec + shift_arcsecs/3600,
00126                                              mag, dmag, 
00127                          cmag, dcmag,
00128                          color, "star");
00129         
00130         /* At arcsecond scale and DEC ~= 0, RA and DEC directions
00131            are very perpendicular, so
00132            expect distance = sqrt(2) * shift_arcsecs 
00133         */
00134         test_rel( fors_std_star_dist_arcsec(s, t), sqrt(2)*shift_arcsecs, 0.01 );
00135         
00136         fors_std_star_delete(&s);
00137         fors_std_star_delete(&t);
00138     }
00139 
00140     return;
00141 }
00142 
00146 int main(void)
00147 {
00148     TEST_INIT;
00149 
00150     /* cpl_msg_set_level(CPL_MSG_DEBUG); */
00151     test_new();
00152 
00153     test_new();  /* The second call tests the reentrancy of WCSLIB and flex,
00154                     which is non-trivial */
00155 
00156     test_dist();
00157 
00158     TEST_END;
00159 }
00160 

Generated on Wed Sep 10 07:31:52 2008 for FORS Pipeline Reference Manual by  doxygen 1.4.6