37 #include "irplib_match_cats.h"
42 static void irplib_match_cats_all_test(
void);
50 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
52 irplib_match_cats_all_test();
54 return cpl_test_end(0);
57 static void irplib_match_cats_all_test(
void)
59 cpl_table ** catalogues;
60 int nsource_per_cat = 9;
61 int ntotal_sources = nsource_per_cat + 2 + 3;
70 catalogues = cpl_malloc(ncat *
sizeof(cpl_table *));
71 for(icat = 0; icat < ncat; icat++)
73 catalogues[icat] = cpl_table_new(nsource_per_cat);
74 cpl_table_new_column(catalogues[icat],
"X_POS",CPL_TYPE_DOUBLE);
75 cpl_table_new_column(catalogues[icat],
"Y_POS",CPL_TYPE_DOUBLE);
77 for(iobj = 0 ; iobj < ntotal_sources; ++iobj)
80 x = ((double)rand()/(double)RAND_MAX) * 1000;
81 y = ((double)rand()/(double)RAND_MAX) * 1000;
82 cpl_msg_warning(__func__,
"obj %d x %f y %f", iobj, x, y);
83 for(icat = 0; icat < ncat; icat++)
85 if(icat == 0 && iobj >= 2 && iobj <= nsource_per_cat +1)
87 cpl_table_set_double(catalogues[icat],
"X_POS", iobj - 2 , x);
88 cpl_table_set_double(catalogues[icat],
"Y_POS", iobj - 2 , y);
90 if(icat == 1 && iobj >= 3 && iobj <= nsource_per_cat+2)
92 cpl_table_set_double(catalogues[icat],
"X_POS", iobj - 3 , x);
93 cpl_table_set_double(catalogues[icat],
"Y_POS", iobj - 3 , y);
95 if(icat == 2 && iobj >= 1 && iobj <= nsource_per_cat)
97 cpl_table_set_double(catalogues[icat],
"X_POS", iobj - 1 , x);
98 cpl_table_set_double(catalogues[icat],
"Y_POS", iobj - 1 , y);
100 if(icat == 3 && iobj >= 5 && iobj <= nsource_per_cat+4)
102 cpl_table_set_double(catalogues[icat],
"X_POS", iobj - 5 , x);
103 cpl_table_set_double(catalogues[icat],
"Y_POS", iobj - 5 , y);
105 if(icat == 4 && iobj <= nsource_per_cat-1)
107 cpl_table_set_double(catalogues[icat],
"X_POS", iobj , x);
108 cpl_table_set_double(catalogues[icat],
"Y_POS", iobj , y);
110 if(icat >= 5 && iobj <= nsource_per_cat-1)
112 cpl_table_set_double(catalogues[icat],
"X_POS", iobj , x);
113 cpl_table_set_double(catalogues[icat],
"Y_POS", iobj , y);
120 matches = irplib_match_cats(catalogues, ncat, mincat_match,
121 irplib_match_cats_match_condition);
124 cpl_msg_warning(__func__,
"Final matches:");
125 for(imatch = 0; imatch < cpl_table_get_nrow(matches); ++imatch)
127 for(icat = 0; icat< ncat; ++icat)
129 printf(
" %d ",cpl_array_get_int
131 (matches,
"MATCHING_SETS",imatch),icat, NULL));
137 cpl_test_error(CPL_ERROR_NONE);
142 for(icat = 0; icat < ncat; icat++)
143 cpl_table_delete(catalogues[icat]);
144 cpl_free(catalogues);
145 cpl_table_delete(matches);
int main(void)
Various tests of low-level library functions.