File: irplib_match_cats.c

package info (click to toggle)
cpl-plugin-xshoo 3.5.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 20,920 kB
  • sloc: ansic: 170,001; sh: 4,369; python: 2,391; makefile: 1,211
file content (211 lines) | stat: -rw-r--r-- 6,692 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* $Id: irplib_match_cats.c,v 1.10 2009-12-18 10:44:48 cgarcia Exp $
 *
 * This file is part of the irplib package
 * Copyright (C) 2002,2003 European Southern Observatory
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
 */

/*
 * $Author: cgarcia $
 * $Date: 2009-12-18 10:44:48 $
 * $Revision: 1.10 $
 * $Name: not supported by cvs2svn $
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/*-----------------------------------------------------------------------------
                                   Includes
 -----------------------------------------------------------------------------*/

#include "irplib_match_cats.h"

#include <math.h>

/*-----------------------------------------------------------------------------
                                   Defines
 -----------------------------------------------------------------------------*/

#define FILENAME_SZBUF 1024

/*----------------------------------------------------------------------------*/
/* Private functions
 */
/*----------------------------------------------------------------------------*/

cpl_error_code irplib_match_cats_get_all_matching_pairs
(cpl_table ** catalogues,
 int          ncats,
 cpl_table  * matching_sets,
 int (*binary_match_condition)
   (cpl_table * catalogue1,
    cpl_table * catalogue2,
    int         iobj1,
    int         iobj2)  );

cpl_error_code irplib_match_cats_get_all_matches_cresc
(cpl_table ** catalogues,
 cpl_array  * cat_index_begin,
 cpl_array  * cats_idx_set,
 int          mincat_match,
 cpl_table * matching_sets);

cpl_error_code irplib_match_cats_iterate_on_cat
(cpl_table ** catalogues,
 cpl_array  * cats_idx_set,
 int          icat_iterate,
 cpl_array  * valid_iobjs,
 int          mincat_match,
 cpl_table  * matching_sets,
 cpl_table  * less_minmatch_sets);

cpl_error_code irplib_match_cats_filter_obj_to_iter
(cpl_array * cats_idx_set,
 int         order_begin,
 cpl_table * matches_set,
 cpl_array * excluded_objs,
 int         itercat_nobj);

int irplib_match_cats_match_condition
(cpl_table ** catalogues,
 int       *  cats_idx_set_ptr,
 int          ncats);

int irplib_match_count_nonmatched
(int * cats_idx_set_ptr,
 int   ncats);

int irplib_nCombinations;
int irplib_nFilter;

/*----------------------------------------------------------------------------*/
/**
 * @defgroup irplib_cat   Functions for matching of catalogues
 */
/*----------------------------------------------------------------------------*/

/**@{*/

/*---------------------------------------------------------------------------*/
/**
 * @brief
 *       Finds all the objects that appear at least in some of the catalogues
 * @param catalogues
 *       All the catalogues
 * @param ncats
 *       Number of catalogues
 * @return
 *   The matching table if sucess, NULL otherwise.
 *
 *
 *   Implementation notes:
 *
 *   cat_indexing_order tells you in which order the catalogues are being
 *   iterated. For example cat_indexing_order[2] gives the index of the
 *   catalogue that is being iterated in the 3rd postion.
 *
 *
*/
/*---------------------------------------------------------------------------*/
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)  )
{
    cpl_table *  matching_sets;

    //Initialize the solution
    matching_sets = cpl_table_new(0);
    cpl_table_new_column_array(matching_sets, "MATCHING_SETS",
                               CPL_TYPE_INT, ncats);

    irplib_match_cats_get_all_matching_pairs
        (catalogues, ncats, matching_sets, binary_match_condition);
    
    return matching_sets;
}

cpl_error_code irplib_match_cats_get_all_matching_pairs
(cpl_table ** catalogues,
 int          ncats,
 cpl_table  * matching_sets,
 int (*binary_match_condition)
   (cpl_table * catalogue1,
    cpl_table * catalogue2,
    int         iobj1,
    int         iobj2)  )
{
    int icat1;
    int icat2;
    
    irplib_nCombinations = 0;
    irplib_nFilter = 0;

    for(icat1 = 0; icat1 < ncats ; ++icat1)
        for(icat2 = icat1 + 1 ; icat2 < ncats ; ++icat2)
        {
            int iobj1;
            int iobj2;
            int nobj1;
            int nobj2;
            
            nobj1 = cpl_table_get_nrow(catalogues[icat1]);
            nobj2 = cpl_table_get_nrow(catalogues[icat2]);

            for(iobj1 = 0; iobj1 < nobj1 ; ++iobj1)
                for(iobj2 = 0 ; iobj2 < nobj2 ; ++iobj2)
                {
                    ++irplib_nCombinations;
                    if(binary_match_condition(catalogues[icat1],
                                              catalogues[icat2],
                                              iobj1, iobj2))
                    {
                        cpl_array  * cats_idx_set;
                        int          icat;
                        
                        ++irplib_nFilter;
                        cats_idx_set = cpl_array_new(ncats, CPL_TYPE_INT);
                        for(icat = 0; icat < ncats; ++icat)
                        {
                            if(icat == icat1)
                                cpl_array_set_int(cats_idx_set, icat, iobj1);
                            else if(icat == icat2)
                                cpl_array_set_int(cats_idx_set, icat, iobj2);
                            else
                                cpl_array_set_int(cats_idx_set, icat, -1);
                        }
                        
                        cpl_table_set_size(matching_sets,
                                           cpl_table_get_nrow(matching_sets)+1);
                        cpl_table_set_array(matching_sets,"MATCHING_SETS",
                                            cpl_table_get_nrow(matching_sets)-1,
                                            cats_idx_set);
                        cpl_array_delete(cats_idx_set);
                    }
                }
        }
    
    return CPL_ERROR_NONE;
}

/**@}*/