fors_std_star-test.c

00001 /* $Id: fors_std_star-test.c,v 1.22 2009/03/26 20:23:48 hlorch 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: hlorch $
00023  * $Date: 2009/03/26 20:23:48 $
00024  * $Revision: 1.22 $
00025  * $Name: fors-4_8_6 $
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 #include <fors_instrument.h>
00035 #include <fors_std_cat.h>
00036 
00037 #include <test_simulate.h>
00038 #include <test.h>
00039 
00040 #include <cpl.h>
00041 #include <math.h>
00042 
00050 #undef cleanup
00051 #define cleanup \
00052 do { \
00053     cpl_frameset_delete(cat_frames); \
00054     cpl_frame_delete(raw_frame); \
00055     cpl_frame_delete(phot_table); \
00056     fors_std_star_list_delete(&cat, fors_std_star_delete); \
00057     fors_setting_delete(&setting); \
00058     cpl_propertylist_delete(raw_header); raw_header = NULL; \
00059 } while (0)
00060 
00064 static void
00065 test_new(void)
00066 {
00067     cpl_frameset *cat_frames = NULL;
00068     cpl_frame *phot_table = NULL;
00069     const char *filename = "std_cat.fits";
00070     fors_std_star_list *cat = NULL;
00071     fors_setting *setting = NULL;
00072     cpl_propertylist    *raw_header = NULL;
00073     double color_term, dcolor_term;
00074     double ext_coeff, dext_coeff;
00075     double expected_zeropoint, dexpected_zeropoint;
00076     char    band;
00077 
00078     /* Simulate */
00079     cpl_frame *raw_frame = create_standard("std_cat_raw.fits", 
00080                                            STANDARD_IMG, CPL_FRAME_GROUP_RAW);
00081     
00082     phot_table = create_phot_table("std_cat_phot_table.fits",
00083                                    PHOT_TABLE, CPL_FRAME_GROUP_CALIB);
00084     
00085     cat_frames = cpl_frameset_new();
00086     cpl_frameset_insert(cat_frames,
00087                         create_std_cat(filename, 
00088                                        FLX_STD_IMG, CPL_FRAME_GROUP_CALIB));
00089 
00090     setting = fors_setting_new(raw_frame);
00091 
00092     fors_phot_table_load(phot_table, setting,
00093                          &color_term, &dcolor_term,
00094              &ext_coeff, &dext_coeff,
00095              &expected_zeropoint, &dexpected_zeropoint);
00096     
00097     /* Call function */
00098     band = fors_instrument_filterband_get_by_setting(setting);
00099     cat = fors_std_cat_load(                cat_frames,
00100                                             band,
00101                                             0,
00102                                             color_term,
00103                                             dcolor_term);
00104     raw_header = cpl_propertylist_load(cpl_frame_get_filename(raw_frame), 0);
00105     fors_std_star_list_apply_wcs(cat, raw_header);
00106     
00107     /* Test results (TBI) */
00108     
00109     fors_std_star_print_list(CPL_MSG_DEBUG, cat);
00110     fors_std_star_print_list(CPL_MSG_INFO, cat);
00111 
00112     cleanup;
00113     return;
00114 }
00115 
00116 
00117 static void
00118 test_dist(void)
00119 {
00120     double ra  = 34.5;
00121     double dec = -0.4;
00122     double mag = 15;
00123     double dmag = 0.51;
00124     double cmag = 15.2;
00125     double dcmag = 0.21;
00126     double color = 0.2;
00127     double dcolor = dcmag;
00128     double cov_catm_col = dcolor;
00129 
00130     double shift_arcsecs;
00131 
00132     for (shift_arcsecs = 0.1; shift_arcsecs <= 100; shift_arcsecs *= 2) {
00133         
00134         fors_std_star *s = fors_std_star_new(ra, dec, mag, dmag, 
00135                          cmag, dcmag,
00136                          color, dcolor,
00137                          cov_catm_col,
00138                          "some");
00139         fors_std_star *t = fors_std_star_new(ra  + shift_arcsecs/3600,
00140                                              dec + shift_arcsecs/3600,
00141                                              mag, dmag, 
00142                          cmag, dcmag,
00143                          color, dcolor,
00144                          cov_catm_col,
00145                          "star");
00146         
00147         /* At arcsecond scale and DEC ~= 0, RA and DEC directions
00148            are very perpendicular, so
00149            expect distance = sqrt(2) * shift_arcsecs 
00150         */
00151         test_rel( fors_std_star_dist_arcsec(s, t), sqrt(2)*shift_arcsecs, 0.01 );
00152         
00153         fors_std_star_delete(&s);
00154         fors_std_star_delete(&t);
00155     }
00156 
00157     return;
00158 }
00159 
00163 int main(void)
00164 {
00165     TEST_INIT;
00166 
00167     /* cpl_msg_set_level(CPL_MSG_DEBUG); */
00168     test_new();
00169 
00170     test_new();  /* The second call tests the reentrancy of WCSLIB and flex,
00171                     which is non-trivial */
00172 
00173     test_dist();
00174 
00175     TEST_END;
00176 }
00177 

Generated on Fri Mar 4 09:46:01 2011 for FORS Pipeline Reference Manual by  doxygen 1.4.7