CR2RE Pipeline Reference Manual 1.7.0
irplib_match_cats.c
1/* $Id: irplib_match_cats.c,v 1.10 2009-12-18 10:44:48 cgarcia Exp $
2 *
3 * This file is part of the irplib package
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: cgarcia $
23 * $Date: 2009-12-18 10:44:48 $
24 * $Revision: 1.10 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#include "irplib_match_cats.h"
37
38#include <math.h>
39
40/*-----------------------------------------------------------------------------
41 Defines
42 -----------------------------------------------------------------------------*/
43
44#define FILENAME_SZBUF 1024
45
46/*----------------------------------------------------------------------------*/
47/* Private functions
48 */
49/*----------------------------------------------------------------------------*/
50
51cpl_error_code irplib_match_cats_get_all_matching_pairs(
52 cpl_table **catalogues,
53 int ncats,
54 cpl_table *matching_sets,
55 int (*binary_match_condition)(cpl_table *catalogue1,
56 cpl_table *catalogue2,
57 int iobj1,
58 int iobj2));
59
60cpl_error_code
61irplib_match_cats_get_all_matches_cresc(cpl_table **catalogues,
62 cpl_array *cat_index_begin,
63 cpl_array *cats_idx_set,
64 int mincat_match,
65 cpl_table *matching_sets);
66
67cpl_error_code irplib_match_cats_iterate_on_cat(cpl_table **catalogues,
68 cpl_array *cats_idx_set,
69 int icat_iterate,
70 cpl_array *valid_iobjs,
71 int mincat_match,
72 cpl_table *matching_sets,
73 cpl_table *less_minmatch_sets);
74
75cpl_error_code irplib_match_cats_filter_obj_to_iter(cpl_array *cats_idx_set,
76 int order_begin,
77 cpl_table *matches_set,
78 cpl_array *excluded_objs,
79 int itercat_nobj);
80
81int irplib_match_cats_match_condition(cpl_table **catalogues,
82 int *cats_idx_set_ptr,
83 int ncats);
84
85int irplib_match_count_nonmatched(int *cats_idx_set_ptr, int ncats);
86
87int irplib_nCombinations;
88int irplib_nFilter;
89
90/*----------------------------------------------------------------------------*/
94/*----------------------------------------------------------------------------*/
95
97
98/*---------------------------------------------------------------------------*/
118/*---------------------------------------------------------------------------*/
119cpl_table *
120irplib_match_cat_pairs(cpl_table **catalogues,
121 int ncats,
122 int (*binary_match_condition)(cpl_table *catalogue1,
123 cpl_table *catalogue2,
124 int iobj1,
125 int iobj2))
126{
127 cpl_table *matching_sets;
128
129 //Initialize the solution
130 matching_sets = cpl_table_new(0);
131 cpl_table_new_column_array(matching_sets, "MATCHING_SETS", CPL_TYPE_INT,
132 ncats);
133
134 irplib_match_cats_get_all_matching_pairs(catalogues, ncats, matching_sets,
135 binary_match_condition);
136
137 return matching_sets;
138}
139
140cpl_error_code
141irplib_match_cats_get_all_matching_pairs(
142 cpl_table **catalogues,
143 int ncats,
144 cpl_table *matching_sets,
145 int (*binary_match_condition)(cpl_table *catalogue1,
146 cpl_table *catalogue2,
147 int iobj1,
148 int iobj2))
149{
150 int icat1;
151 int icat2;
152
153 irplib_nCombinations = 0;
154 irplib_nFilter = 0;
155
156 for (icat1 = 0; icat1 < ncats; ++icat1)
157 for (icat2 = icat1 + 1; icat2 < ncats; ++icat2) {
158 int iobj1;
159 int iobj2;
160 int nobj1;
161 int nobj2;
162
163 nobj1 = cpl_table_get_nrow(catalogues[icat1]);
164 nobj2 = cpl_table_get_nrow(catalogues[icat2]);
165
166 for (iobj1 = 0; iobj1 < nobj1; ++iobj1)
167 for (iobj2 = 0; iobj2 < nobj2; ++iobj2) {
168 ++irplib_nCombinations;
169 if (binary_match_condition(catalogues[icat1],
170 catalogues[icat2], iobj1,
171 iobj2)) {
172 cpl_array *cats_idx_set;
173 int icat;
174
175 ++irplib_nFilter;
176 cats_idx_set = cpl_array_new(ncats, CPL_TYPE_INT);
177 for (icat = 0; icat < ncats; ++icat) {
178 if (icat == icat1)
179 cpl_array_set_int(cats_idx_set, icat, iobj1);
180 else if (icat == icat2)
181 cpl_array_set_int(cats_idx_set, icat, iobj2);
182 else
183 cpl_array_set_int(cats_idx_set, icat, -1);
184 }
185
186 cpl_table_set_size(matching_sets,
187 cpl_table_get_nrow(matching_sets) +
188 1);
189 cpl_table_set_array(matching_sets, "MATCHING_SETS",
190 cpl_table_get_nrow(matching_sets) -
191 1,
192 cats_idx_set);
193 cpl_array_delete(cats_idx_set);
194 }
195 }
196 }
197
198 return CPL_ERROR_NONE;
199}
200
cpl_table * irplib_match_cat_pairs(cpl_table **catalogues, int ncats, int(*binary_match_condition)(cpl_table *catalogue1, cpl_table *catalogue2, int iobj1, int iobj2))
Finds all the objects that appear at least in some of the catalogues.