irplib_match_cats-test.c

00001 /* $Id: irplib_match_cats-test.c,v 1.2 2013-01-29 08:43:33 jtaylor Exp $
00002  *
00003  * This file is part of the ESO Common Pipeline Library
00004  * Copyright (C) 2001-2008 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: jtaylor $
00023  * $Date: 2013-01-29 08:43:33 $
00024  * $Revision: 1.2 $
00025  * $Name: not supported by cvs2svn $
00026  */
00027 
00028 /*-----------------------------------------------------------------------------
00029                                    Includes
00030  -----------------------------------------------------------------------------*/
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif
00034 
00035 #include <cpl_test.h>
00036 
00037 #include "irplib_match_cats.h"
00038 
00039 /*-----------------------------------------------------------------------------
00040                                    Static functions
00041  -----------------------------------------------------------------------------*/
00042 static void irplib_match_cats_all_test(void);
00043 
00044 /*-----------------------------------------------------------------------------
00045                                   Main
00046  -----------------------------------------------------------------------------*/
00047 int main (void)
00048 {
00049 
00050     cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00051 
00052     irplib_match_cats_all_test();
00053 
00054     return cpl_test_end(0);
00055 }
00056 
00057 static void irplib_match_cats_all_test(void)
00058 {
00059     cpl_table   **  catalogues;
00060     int             nsource_per_cat = 9;
00061     int             ntotal_sources = nsource_per_cat + 2 + 3;
00062     int             ncat = 5;
00063     int             mincat_match = 2;
00064     int             icat;
00065     int             iobj;
00066     cpl_table   *   matches;
00067     int             imatch;
00068 
00069     /* Create the catalogues */
00070     catalogues = cpl_malloc(ncat * sizeof(cpl_table *));
00071     for(icat = 0; icat < ncat; icat++)
00072     {
00073         catalogues[icat] = cpl_table_new(nsource_per_cat);
00074         cpl_table_new_column(catalogues[icat],"X_POS",CPL_TYPE_DOUBLE);
00075         cpl_table_new_column(catalogues[icat],"Y_POS",CPL_TYPE_DOUBLE);
00076     }
00077     for(iobj = 0 ; iobj < ntotal_sources; ++iobj)
00078     {
00079         double x,y;
00080         x = ((double)rand()/(double)RAND_MAX) * 1000;
00081         y = ((double)rand()/(double)RAND_MAX) * 1000;
00082         cpl_msg_warning(__func__,"obj %d x %f y %f", iobj, x, y);
00083         for(icat = 0; icat < ncat; icat++)
00084         {
00085             if(icat == 0 && iobj >= 2 && iobj <= nsource_per_cat +1)
00086             {
00087                 cpl_table_set_double(catalogues[icat], "X_POS", iobj - 2 , x);
00088                 cpl_table_set_double(catalogues[icat], "Y_POS", iobj - 2 , y);
00089             }
00090             if(icat == 1 && iobj >= 3 && iobj <= nsource_per_cat+2)
00091             {
00092                 cpl_table_set_double(catalogues[icat], "X_POS", iobj - 3 , x);
00093                 cpl_table_set_double(catalogues[icat], "Y_POS", iobj - 3 , y);
00094             }
00095             if(icat == 2 && iobj >= 1 && iobj <= nsource_per_cat)
00096             {
00097                 cpl_table_set_double(catalogues[icat], "X_POS", iobj - 1 , x);
00098                 cpl_table_set_double(catalogues[icat], "Y_POS", iobj - 1 , y);
00099             }
00100             if(icat == 3 && iobj >= 5 && iobj <= nsource_per_cat+4)
00101             {
00102                 cpl_table_set_double(catalogues[icat], "X_POS", iobj - 5 , x);
00103                 cpl_table_set_double(catalogues[icat], "Y_POS", iobj - 5 , y);
00104             }
00105             if(icat == 4 && iobj <= nsource_per_cat-1)
00106             {
00107                 cpl_table_set_double(catalogues[icat], "X_POS", iobj    , x);
00108                 cpl_table_set_double(catalogues[icat], "Y_POS", iobj    , y);
00109             }
00110             if(icat >= 5 && iobj <= nsource_per_cat-1)
00111             {
00112                 cpl_table_set_double(catalogues[icat], "X_POS", iobj    , x);
00113                 cpl_table_set_double(catalogues[icat], "Y_POS", iobj    , y);
00114             }
00115         }
00116     }
00117 
00118 
00119     /* Match the catalogues */
00120     matches = irplib_match_cats(catalogues, ncat, mincat_match, 
00121                                 irplib_match_cats_match_condition);
00122     
00123     /* Output the matches */
00124     cpl_msg_warning(__func__,"Final matches:");
00125     for(imatch = 0; imatch < cpl_table_get_nrow(matches); ++imatch)
00126     {
00127         for(icat = 0; icat< ncat; ++icat)
00128         {
00129             printf(" %d ",cpl_array_get_int
00130                    (cpl_table_get_array
00131                     (matches, "MATCHING_SETS",imatch),icat, NULL));
00132         }
00133         printf("\n");
00134     }
00135     
00136 
00137     cpl_test_error(CPL_ERROR_NONE);
00138     //cpl_test_leq(ra1 - 0.00, DBL_EPSILON);
00139 
00140 
00141     /* Free */
00142     for(icat = 0; icat < ncat; icat++)
00143         cpl_table_delete(catalogues[icat]);
00144     cpl_free(catalogues);
00145     cpl_table_delete(matches);
00146 
00147 }
Generated on Mon Feb 17 15:01:44 2014 for NACO Pipeline Reference Manual by  doxygen 1.6.3