UVES Pipeline Reference Manual  5.4.0
irplib_match_cats-test.c
1 /* $Id: irplib_match_cats-test.c,v 1.2 2013-01-29 08:43:33 jtaylor Exp $
2  *
3  * This file is part of the ESO Common Pipeline Library
4  * Copyright (C) 2001-2008 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: jtaylor $
23  * $Date: 2013-01-29 08:43:33 $
24  * $Revision: 1.2 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 /*-----------------------------------------------------------------------------
29  Includes
30  -----------------------------------------------------------------------------*/
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 
35 #include <cpl_test.h>
36 
37 #include "irplib_match_cats.h"
38 
39 /*-----------------------------------------------------------------------------
40  Static functions
41  -----------------------------------------------------------------------------*/
42 static void irplib_match_cats_all_test(void);
43 
44 /*-----------------------------------------------------------------------------
45  Main
46  -----------------------------------------------------------------------------*/
47 int main (void)
48 {
49 
50  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
51 
52  irplib_match_cats_all_test();
53 
54  return cpl_test_end(0);
55 }
56 
57 static void irplib_match_cats_all_test(void)
58 {
59  cpl_table ** catalogues;
60  int nsource_per_cat = 9;
61  int ntotal_sources = nsource_per_cat + 2 + 3;
62  int ncat = 5;
63  int mincat_match = 2;
64  int icat;
65  int iobj;
66  cpl_table * matches;
67  int imatch;
68 
69  /* Create the catalogues */
70  catalogues = cpl_malloc(ncat * sizeof(cpl_table *));
71  for(icat = 0; icat < ncat; icat++)
72  {
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);
76  }
77  for(iobj = 0 ; iobj < ntotal_sources; ++iobj)
78  {
79  double x,y;
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++)
84  {
85  if(icat == 0 && iobj >= 2 && iobj <= nsource_per_cat +1)
86  {
87  cpl_table_set_double(catalogues[icat], "X_POS", iobj - 2 , x);
88  cpl_table_set_double(catalogues[icat], "Y_POS", iobj - 2 , y);
89  }
90  if(icat == 1 && iobj >= 3 && iobj <= nsource_per_cat+2)
91  {
92  cpl_table_set_double(catalogues[icat], "X_POS", iobj - 3 , x);
93  cpl_table_set_double(catalogues[icat], "Y_POS", iobj - 3 , y);
94  }
95  if(icat == 2 && iobj >= 1 && iobj <= nsource_per_cat)
96  {
97  cpl_table_set_double(catalogues[icat], "X_POS", iobj - 1 , x);
98  cpl_table_set_double(catalogues[icat], "Y_POS", iobj - 1 , y);
99  }
100  if(icat == 3 && iobj >= 5 && iobj <= nsource_per_cat+4)
101  {
102  cpl_table_set_double(catalogues[icat], "X_POS", iobj - 5 , x);
103  cpl_table_set_double(catalogues[icat], "Y_POS", iobj - 5 , y);
104  }
105  if(icat == 4 && iobj <= nsource_per_cat-1)
106  {
107  cpl_table_set_double(catalogues[icat], "X_POS", iobj , x);
108  cpl_table_set_double(catalogues[icat], "Y_POS", iobj , y);
109  }
110  if(icat >= 5 && iobj <= nsource_per_cat-1)
111  {
112  cpl_table_set_double(catalogues[icat], "X_POS", iobj , x);
113  cpl_table_set_double(catalogues[icat], "Y_POS", iobj , y);
114  }
115  }
116  }
117 
118 
119  /* Match the catalogues */
120  matches = irplib_match_cats(catalogues, ncat, mincat_match,
121  irplib_match_cats_match_condition);
122 
123  /* Output the matches */
124  cpl_msg_warning(__func__,"Final matches:");
125  for(imatch = 0; imatch < cpl_table_get_nrow(matches); ++imatch)
126  {
127  for(icat = 0; icat< ncat; ++icat)
128  {
129  printf(" %d ",cpl_array_get_int
130  (cpl_table_get_array
131  (matches, "MATCHING_SETS",imatch),icat, NULL));
132  }
133  printf("\n");
134  }
135 
136 
137  cpl_test_error(CPL_ERROR_NONE);
138  //cpl_test_leq(ra1 - 0.00, DBL_EPSILON);
139 
140 
141  /* Free */
142  for(icat = 0; icat < ncat; icat++)
143  cpl_table_delete(catalogues[icat]);
144  cpl_free(catalogues);
145  cpl_table_delete(matches);
146 
147 }