irplib_match_cats.c

00001 /* $Id: irplib_match_cats.c,v 1.10 2009/12/18 10:44:48 cgarcia Exp $
00002  *
00003  * This file is part of the irplib package
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: cgarcia $
00023  * $Date: 2009/12/18 10:44:48 $
00024  * $Revision: 1.10 $
00025  * $Name: uves-4_9_1 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                    Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 
00037 #include <math.h>
00038 #include <cpl.h>
00039 #include <cpl_table.h>
00040 
00041 #include "irplib_match_cats.h"
00042 
00043 #define FILENAME_SZBUF 1024
00044 
00045 
00046 /*----------------------------------------------------------------------------*/
00047 /* Private functions
00048  */
00049 /*----------------------------------------------------------------------------*/
00050 
00051 cpl_error_code irplib_match_cats_get_all_matching_pairs
00052 (cpl_table ** catalogues,
00053  int          ncats,
00054  cpl_table  * matching_sets,
00055  int (*binary_match_condition)
00056    (cpl_table * catalogue1,
00057     cpl_table * catalogue2,
00058     int         iobj1,
00059     int         iobj2)  );
00060 
00061 cpl_error_code irplib_match_cats_get_all_matches_cresc
00062 (cpl_table ** catalogues,
00063  cpl_array  * cat_index_begin,
00064  cpl_array  * cats_idx_set,
00065  int          mincat_match,
00066  cpl_table * matching_sets);
00067 
00068 cpl_error_code irplib_match_cats_iterate_on_cat
00069 (cpl_table ** catalogues,
00070  cpl_array  * cats_idx_set,
00071  int          icat_iterate,
00072  cpl_array  * valid_iobjs,
00073  int          mincat_match,
00074  cpl_table  * matching_sets,
00075  cpl_table  * less_minmatch_sets);
00076 
00077 cpl_error_code irplib_match_cats_filter_obj_to_iter
00078 (cpl_array * cats_idx_set,
00079  int         order_begin,
00080  cpl_table * matches_set,
00081  cpl_array * excluded_objs,
00082  int         itercat_nobj);
00083 
00084 int irplib_match_cats_match_condition
00085 (cpl_table ** catalogues,
00086  int       *  cats_idx_set_ptr,
00087  int          ncats);
00088 
00089 int irplib_match_count_nonmatched
00090 (int * cats_idx_set_ptr,
00091  int   ncats);
00092 
00093 int nCombinations;
00094 int nFilter;
00095 
00096 /*----------------------------------------------------------------------------*/
00100 /*----------------------------------------------------------------------------*/
00101 
00104 /*---------------------------------------------------------------------------*/
00124 /*---------------------------------------------------------------------------*/
00125 cpl_table * irplib_match_cat_pairs
00126 (cpl_table ** catalogues,
00127  int          ncats,
00128  int (*binary_match_condition)
00129    (cpl_table * catalogue1,
00130     cpl_table * catalogue2,
00131     int         iobj1,
00132     int         iobj2)  )
00133 {
00134     cpl_table *  matching_sets;
00135 
00136     //Initialize the solution
00137     matching_sets = cpl_table_new(0);
00138     cpl_table_new_column_array(matching_sets, "MATCHING_SETS",
00139                                CPL_TYPE_INT, ncats);
00140 
00141     irplib_match_cats_get_all_matching_pairs
00142         (catalogues, ncats, matching_sets, binary_match_condition);
00143     
00144     return matching_sets;
00145 }
00146 
00147 cpl_error_code irplib_match_cats_get_all_matching_pairs
00148 (cpl_table ** catalogues,
00149  int          ncats,
00150  cpl_table  * matching_sets,
00151  int (*binary_match_condition)
00152    (cpl_table * catalogue1,
00153     cpl_table * catalogue2,
00154     int         iobj1,
00155     int         iobj2)  )
00156 {
00157     int icat1;
00158     int icat2;
00159     
00160     nCombinations = 0;
00161     nFilter = 0;
00162 
00163     for(icat1 = 0; icat1 < ncats ; ++icat1)
00164         for(icat2 = icat1 + 1 ; icat2 < ncats ; ++icat2)
00165         {
00166             int iobj1;
00167             int iobj2;
00168             int nobj1;
00169             int nobj2;
00170             
00171             nobj1 = cpl_table_get_nrow(catalogues[icat1]);
00172             nobj2 = cpl_table_get_nrow(catalogues[icat2]);
00173 
00174             for(iobj1 = 0; iobj1 < nobj1 ; ++iobj1)
00175                 for(iobj2 = 0 ; iobj2 < nobj2 ; ++iobj2)
00176                 {
00177                     ++nCombinations;
00178                     if(binary_match_condition(catalogues[icat1],
00179                                               catalogues[icat2],
00180                                               iobj1, iobj2))
00181                     {
00182                         cpl_array  * cats_idx_set;
00183                         int          icat;
00184                         
00185                         ++nFilter;
00186                         cats_idx_set = cpl_array_new(ncats, CPL_TYPE_INT);
00187                         for(icat = 0; icat < ncats; ++icat)
00188                         {
00189                             if(icat == icat1)
00190                                 cpl_array_set_int(cats_idx_set, icat, iobj1);
00191                             else if(icat == icat2)
00192                                 cpl_array_set_int(cats_idx_set, icat, iobj2);
00193                             else
00194                                 cpl_array_set_int(cats_idx_set, icat, -1);
00195                         }
00196                         
00197                         cpl_table_set_size(matching_sets,
00198                                            cpl_table_get_nrow(matching_sets)+1);
00199                         cpl_table_set_array(matching_sets,"MATCHING_SETS",
00200                                             cpl_table_get_nrow(matching_sets)-1,
00201                                             cats_idx_set);
00202                         cpl_array_delete(cats_idx_set);
00203                     }
00204                 }
00205         }
00206     
00207     return CPL_ERROR_NONE;
00208 }
00209 

Generated on 8 Mar 2011 for UVES Pipeline Reference Manual by  doxygen 1.6.1