source: trunk/src/mainDuchamp.cc @ 110

Last change on this file since 110 was 110, checked in by Matthew Whiting, 18 years ago

Final update of config-related files, as well as COPYING and README.
Minor fixes to plotting.cc and plots.hh.
mainDuchamp makes use of header info from config.h.
Added a fix to param.cc to get be able to print true/false even when
boolalpha not defined.
Final update to Guide, included Installation instructions.

File size: 6.0 KB
RevLine 
[3]1#include <iostream>
2#include <fstream>
3#include <string>
4#include <cpgplot.h>
5#include <math.h>
6#include <unistd.h>
[80]7#include <time.h>
[57]8
9#include <duchamp.hh>
[3]10#include <Detection/detection.hh>
11#include <Cubes/cubes.hh>
12#include <Utils/utils.hh>
13#include <ATrous/atrous.hh>
14
15using std::ofstream;
[103]16using std::string;
[3]17
18Filter reconFilter;
19
20int main(int argc, char * argv[])
21{
22
[85]23  string paramFile,fitsfile;
24  Cube *cube = new Cube;
25  Param *par = new Param;
[3]26
27  if(argc==1){
[57]28    std::cout << ERR_USAGE_MSG;
[85]29    return 1;
[3]30  }
31  else{
32    char c;
[85]33    while( ( c = getopt(argc,argv,"p:f:hv") )!=-1){
[3]34      switch(c) {
35      case 'p':
36        paramFile = optarg;
[85]37        cube->readParam(paramFile);
[3]38        break;
[85]39      case 'f':
40        fitsfile = optarg;
41        par->setImageFile(fitsfile);
42        cube->saveParam(*par);
43        break;
[57]44      case 'v':
[110]45        std::cout << PROGNAME << " version " << VERSION << std::endl;
[85]46        return 1;
[57]47        break;
[3]48      case 'h':
49      default :
[57]50        std::cout << ERR_USAGE_MSG;
[85]51        return 1;
[3]52        break;
53      }
54    }
55  }
56
[85]57  delete par;
58
[3]59  if(cube->pars().getImageFile().empty()){
[85]60    std::cerr << "ERROR : No input image has been given!\n";
61    std::cerr << "        Use the imageFile parameter in "<< paramFile << " to specify the FITS file.\n";
62    std::cerr << "Exiting...\n\n";
63    return 1;
[3]64  }
65
[106]66  std::cout << "Opening image: " << cube->pars().getFullImageFile() << std::endl;
67  if( cube->getCube() == FAILURE){
68    std::cerr << "ERROR : Unable to open image file : " << cube->pars().getFullImageFile() << std::endl;
[85]69    std::cerr << "Exiting...\n\n";
70    return 1;
[3]71  }
[103]72  else std::cout << "Opened successfully." << std::endl;
[3]73
[71]74  // If the reconstructed array is to be read in from disk
[76]75  if( cube->pars().getFlagReconExists() && cube->pars().getFlagATrous() ){
[103]76    std::cout << "Reading reconstructed array: "<<std::endl;
[71]77    if( cube->readReconCube() == FAILURE){
[85]78      std::cerr << "WARNING : Could not read in existing reconstructed array.\n"
[71]79                << "          Will perform reconstruction using assigned parameters.\n";
80      cube->pars().setFlagReconExists(false);
81    }
[103]82    else std::cout << "Reconstructed array available.\n";
[71]83  }
84
[103]85  // Filter needed for baseline removal and a trous reconstruction
86  if(cube->pars().getFlagATrous() || cube->pars().getFlagBaseline()){
87    reconFilter.define(cube->pars().getFilterCode());
88    cube->pars().setFilterName(reconFilter.getName());
89  }
90
91  // Write the parameters to screen.
[3]92  std::cout << cube->pars();
93
94  if(cube->pars().getFlagLog()){
[106]95    // Open the logfile and write the time on the first line
[3]96    ofstream logfile(cube->pars().getLogFile().c_str());
97    logfile << "New run of the Duchamp sourcefinder: ";
[80]98    time_t now = time(NULL);
99    logfile << asctime( localtime(&now) );
[3]100    logfile << cube->pars();
101    logfile.close();
102  }
103
104  if(cube->pars().getFlagBlankPix()){
[106]105    // Trim any blank pixels from the edges, and report the new size of the cube
[3]106    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
107    cube->trimCube();
[103]108    std::cout<<"Done."<<std::endl;
[3]109    std::cout << "New dimensions:  " << cube->getDimX();
110    if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY();
111    if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ();
[103]112    std::cout << std::endl;
[3]113  }
114
115  if(cube->pars().getFlagBaseline()){
116    std::cout<<"Removing the baselines... "<<std::flush;
117    cube->removeBaseline();
118    std::cout<<" Done.                 "<<std::endl;
119  }
120
121  if(cube->getDimZ()==1) cube->pars().setMinChannels(0);  // special case for 2D images.
122
[60]123  if(cube->pars().getFlagNegative()){
124    std::cout<<"Inverting the Cube... "<<std::flush;
125    cube->invert();
126    std::cout<<" Done."<<std::endl;
127  }
128
[76]129  if(cube->pars().getFlagATrous()){
[103]130    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
131    cube->ReconSearch();
132    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<std::endl;
[3]133  }
134  else{
[103]135    std::cout<<"Commencing search in cube..."<<std::endl;
136    cube->CubicSearch();
137    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<std::endl;
[3]138  }
139
140  std::cout<<"Merging lists...  "<<std::flush;
141  cube->ObjectMerger();
[103]142  std::cout<<"Done.                      "<<std::endl;
143  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
[3]144
[60]145  if(cube->pars().getFlagNegative()){
146    std::cout<<"Un-Inverting the Cube... "<<std::flush;
147    cube->reInvert();
148    std::cout<<" Done."<<std::endl;
149  }
150
[3]151  cube->replaceBaseline();
152
153  if(cube->pars().getFlagCubeTrimmed()){
154    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
155    cube->unTrimCube();
[103]156    std::cout<<"Done."<<std::endl;
[3]157  }
158
159  if(cube->getNumObj()>0){
160
161    cube->calcObjectWCSparams();
[87]162
163    cube->setObjectFlags();
[3]164   
165    cube->sortDetections();
166   
167    cube->outputDetectionList();
168  }
169
[87]170  std::cout<<"Creating the maps...  "<<std::flush;
171  cube->plotMomentMap("/xs");
[3]172  if(cube->pars().getFlagMaps()){
173    cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps");
174    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
175  }
[87]176  std::cout << "done.\n";
[3]177
[49]178  if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
[3]179    std::cout << "Plotting the individual spectra... " << std::flush;
180    cube->outputSpectra();
181    std::cout << "done.\n";
182  }
[87]183  else if(cube->getDimZ()<=1) std::cerr << "WARNING : Not plotting any spectra  -- no third dimension.\n";
[3]184
185  cpgend();
186
187  if(cube->pars().getFlagATrous()&&
188     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
189    std::cout << "Saving reconstructed cube... "<<std::flush;
190    cube->saveReconstructedCube();
191    std::cout << "done.\n";
192  }
193
194  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
195    ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
196    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
197    logfile << *cube;
198    logfile.close();
199  }
200
201  if(cube->pars().getFlagVOT()){
202    ofstream votfile(cube->pars().getVOTFile().c_str());
203    cube->outputDetectionsVOTable(votfile);
204    votfile.close();
205  }
206
[20]207  if(cube->pars().getFlagKarma()){
208    ofstream karmafile(cube->pars().getKarmaFile().c_str());
209    cube->outputDetectionsKarma(karmafile);
210    karmafile.close();
211  }
212
[3]213  delete cube;
214
215  return 0;
216}
217
Note: See TracBrowser for help on using the repository browser.