00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00041
00042 static void irplib_match_cats_all_test(void);
00043
00044
00045
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
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
00120 matches = irplib_match_cats(catalogues, ncat, mincat_match,
00121 irplib_match_cats_match_condition);
00122
00123
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
00139
00140
00141
00142 for(icat = 0; icat < ncat; icat++)
00143 cpl_table_delete(catalogues[icat]);
00144 cpl_free(catalogues);
00145 cpl_table_delete(matches);
00146
00147 }