jp_neighbours.cpp

Go to the documentation of this file.
00001 
00002 
00003 //-----------------------------------------------------------------------------
00004 // CVS: $Revision: 2866 $, $Date: 2006-09-15 12:04:57 +0100 (Fri, 15 Sep 2006) $, $Author: rsc $
00005 //-----------------------------------------------------------------------------
00006 /*                                                       Based on frcm_file.cpp
00007  * Command line options are:
00008  *
00009  * <a_dir> [optional - default is ./]
00010  *   The common directory prefix for all file I/O
00011  * <main_file>
00012  *   Main catalogue file name - this should be the *larger* catalogue
00013  * <binary|ascii>
00014  *   indicates if the file is binary or ascii.
00015  * <large|small>
00016  *   indicates whether the main catalogue is larger than 2 Gb
00017  * <external_file>
00018  *   External catalogue file name - this should be the *smaller* catalogue
00019  * <binary|ascii>
00020  *   indicates if the file is binary or ascii.
00021  * <large|small>
00022  *   indicates whether the external catalogue is larger than 2 Gb
00023  * <maxDistInArcSecs>
00024  *   as it says.
00025  * <index|list>
00026  *   Indexed or list for the active list.
00027  * <filter|nested|sweep>
00028  *   Use CM filter, or generic nested loop, or generic plane sweep.
00029  * <outfile_name>
00030  *   Name of the output file for the final matches.
00031  * <binary|ascii>
00032  *   indicates if the file is binary or ascii.
00033  * <swap|noswap>
00034  *   indicates whether the output file will be larger than 2 Gb
00035  */
00036 //-----------------------------------------------------------------------------
00037 #include <iostream>
00038 #include "String.h"
00039 
00040 #include "ActiveList.h"
00041 #include "BoundingBoxRefine.h"
00042 #include "CrossNeighboursTextFileWriter.h"
00043 #include "CrossNeighboursBinaryFileWriter.h"
00044 #include "DecPlaneSweepFilter.h"
00045 #include "FileReader.h"
00046 #include "FileWriter.h"
00047 #include "Filter.h"
00048 #include "FixedRadiusCrossMatch.h"
00049 #include "IndexedActiveList.h"
00050 #include "Matcher.h"
00051 #include "NestedLoopFilter.h"
00052 #include "Object.h"
00053 #include "ObjectConsumer.h"
00054 #include "ObjectPairConsumer.h"
00055 #include "ObjectPairRefineConsumer.h"
00056 #include "ObjectProducer.h"
00057 #include "SimpleActiveList.h"
00058 #include "Timer.h"
00059 #include "WithinDistanceRefine.h"
00060 #include "JPTextFileReader.h"
00061 #include "WSAReader.h"
00062 //-----------------------------------------------------------------------------
00063 static void usage(char const * const prog_name)
00064 {
00065   std::cerr << prog_name
00066             << " [dir] <main_file> <binary|ascii> <large|small>"
00067             << " <external_file> <binary|ascii> <large|small>"
00068             << " <maxDistInArcSecs> <index|list> <filter|nested|sweep>"
00069             << " <outfile_name> <binary|ascii> <swap|noswap>" << std::endl;
00070 }
00071 //-----------------------------------------------------------------------------
00072 int main(int argc, char * argv[])
00073 {
00074 #ifdef PLOT_TIMES
00075   Timer::globalTimer()->cont();        // need to start the timer
00076 #endif
00077 
00078   int status = 0;
00079   const int cAllParamCt = 13;
00080   const int cOptParamCt = 1;
00081   const int cSupParamCt = argc-1;
00082 
00083   if (cSupParamCt < cAllParamCt - cOptParamCt ||
00084       cSupParamCt > cAllParamCt)
00085   {
00086     usage(argv[0]);
00087     status = 1;
00088   }
00089   else
00090   {
00091 // ******** Read in Arguments ***********
00092     int param = 1;
00093     char *dirStr = (cSupParamCt == cAllParamCt) ? argv[param++]
00094                                                 : 0;
00095     String directory;
00096     if (dirStr)
00097     {
00098       directory = String(dirStr);
00099       if (directory[directory.size()-1] != '/')
00100       {
00101         directory += '/';
00102       }
00103     } else {
00104       directory = "";
00105     }
00106 
00107     char *mainNameStr = argv[param++];
00108     String mainFilePath = directory + String(mainNameStr);
00109     String mainFileDtd = mainFilePath;
00110     mainFileDtd.replace(mainFileDtd.find("."), 4, ".dtd");
00111     bool isMainBinary = (strcmp(argv[param++], "binary") == 0);
00112     bool isMainLarge = (strcmp(argv[param++], "large") == 0);
00113 
00114     char *externNameStr = argv[param++];
00115     String externFilePath = directory + String(externNameStr);
00116     String externFileDtd = externFilePath;
00117     externFileDtd.replace(externFileDtd.find("."), 4, ".dtd");
00118     bool isExternBinary = (strcmp(argv[param++], "binary") == 0);
00119     bool isExternLarge = (strcmp(argv[param++], "large") == 0);
00120 
00121     double maxDist = atof(argv[param++])/3600.0;
00122 
00123     bool useIndex =      (strcmp(argv[param++], "index") == 0);
00124     bool useFilter =     (strcmp(argv[param], "filter") == 0);
00125     bool useNestedLoop = (!useFilter && strcmp(argv[param], "nested") == 0);
00126 
00127     char *outFileStr = argv[++param];
00128     bool isOutBinary = (strcmp(argv[++param], "binary") == 0);
00129     bool isOutLarge = true;
00130 
00131     bool isSwap = (strcmp(argv[++param], "noswap") != 0);
00132 
00133 #ifndef SILENT
00134     if (useFilter)
00135       std::cout << "Using FRCM filter         : true" << std::endl; 
00136     else if (useNestedLoop)
00137       std::cout << "Using generic nested loop : true" << std::endl;
00138     else
00139       std::cout << "Using generic plane sweep : true" << std::endl;
00140     std::cout << "Using index active list   : "
00141               << ((useIndex) ? "true" : "false")
00142               << std::endl;
00143     std::cout << "Max distance (Dec Degs)   : " << maxDist << std::endl;
00144 #endif
00145 
00146 // ******** Create Matcher ***********
00147 
00148     // Create ObjectProducers to read in objects from both catalogues
00149     ObjectProducer* mainProd =
00150       new ObjectProducer(new FileReader(
00151         (isMainBinary) ? (FileObjectReader *) new WSAReader(mainFileDtd)
00152                        : (FileObjectReader *) new JPTextFileReader(),
00153         mainFilePath.c_str(),
00154         isMainLarge));
00155 
00156     ObjectProducer* externProd =
00157       new ObjectProducer(new FileReader(
00158         (isExternBinary) ? (FileObjectReader *) new WSAReader(externFileDtd)
00159                          : (FileObjectReader *) new JPTextFileReader(),
00160         externFilePath.c_str(),
00161         isExternLarge));
00162 
00163     // Create the active list
00164     ActiveList * aList = (useIndex) ? (ActiveList *) new IndexedActiveList()
00165                                     : (ActiveList *) new SimpleActiveList();
00166 
00167     // Write out matched pairs to a file
00168     String outputFilePath = directory + String(outFileStr);
00169 
00170     ObjectPairConsumer accWithinDistPairCons
00171     (
00172       WithinDistanceRefine::name() + " accept",
00173       (isOutBinary) ? (ObjectPairWriter*) new
00174                       CrossNeighboursBinaryFileWriter(outputFilePath.c_str(),
00175                                                       isOutLarge,
00176                                                       isSwap)
00177                     : (ObjectPairWriter*) new
00178                       CrossNeighboursTextFileWriter(outputFilePath.c_str(),
00179                                                     isOutLarge)
00180     );
00181     // Ignore rejected pairs
00182     ObjectPairConsumer rejWithinDistPairCons(WithinDistanceRefine::name()
00183                                              + " reject");
00184 
00185     // Refine matched pairs using WithinDistance
00186     WithinDistanceRefine withinDistRefine(maxDist,
00187                                           &accWithinDistPairCons,
00188                                           &rejWithinDistPairCons);
00189     ObjectPairRefineConsumer pairCons
00190     (
00191       (useNestedLoop) ? NestedLoopFilter::name()
00192                       : DecPlaneSweepFilter::name(),
00193       &withinDistRefine
00194     );
00195 
00196     ObjectConsumer mainRejCons("Main catalogue points reject");
00197     ObjectConsumer externRejCons("External catalogue points reject");
00198 
00199     Matcher * matcher = new FixedRadiusCrossMatch(mainProd,     // log(M)
00200                                                   externProd,   // N
00201                                                   aList,
00202                                                   &pairCons,
00203                                                   &mainRejCons,
00204                                                   &externRejCons,
00205                                                   maxDist);
00206 // ******** Filter ***********
00207 
00208     Filter * filter = 0;
00209 
00210     if (useFilter)
00211       filter = new Filter(matcher);
00212     else if (useNestedLoop)
00213       filter = new NestedLoopFilter(matcher);
00214     else
00215       filter = new DecPlaneSweepFilter(matcher);
00216 
00217     filter->filter();
00218 
00219     delete filter;
00220   }
00221 
00222   return status;
00223 }
00224 //-----------------------------------------------------------------------------
Generated on Mon Oct 4 10:39:55 2010 for Matching.kdevelop by  doxygen 1.6.3