source: tags/release-1.0.1/src/mainDuchamp.cc @ 1077

Last change on this file since 1077 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
Line 
1#include <iostream>
2#include <fstream>
3#include <string>
4#include <cpgplot.h>
5#include <math.h>
6#include <unistd.h>
7#include <time.h>
8
9#include <duchamp.hh>
10#include <Detection/detection.hh>
11#include <Cubes/cubes.hh>
12#include <Utils/utils.hh>
13#include <ATrous/atrous.hh>
14
15using std::ofstream;
16using std::string;
17
18Filter reconFilter;
19
20int main(int argc, char * argv[])
21{
22
23  string paramFile,fitsfile;
24  Cube *cube = new Cube;
25  Param *par = new Param;
26
27  if(argc==1){
28    std::cout << ERR_USAGE_MSG;
29    return 1;
30  }
31  else{
32    char c;
33    while( ( c = getopt(argc,argv,"p:f:hv") )!=-1){
34      switch(c) {
35      case 'p':
36        paramFile = optarg;
37        cube->readParam(paramFile);
38        break;
39      case 'f':
40        fitsfile = optarg;
41        par->setImageFile(fitsfile);
42        cube->saveParam(*par);
43        break;
44      case 'v':
45        std::cout << PROGNAME << " version " << VERSION << std::endl;
46        return 1;
47        break;
48      case 'h':
49      default :
50        std::cout << ERR_USAGE_MSG;
51        return 1;
52        break;
53      }
54    }
55  }
56
57  delete par;
58
59  if(cube->pars().getImageFile().empty()){
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;
64  }
65
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;
69    std::cerr << "Exiting...\n\n";
70    return 1;
71  }
72  else std::cout << "Opened successfully." << std::endl;
73
74  // If the reconstructed array is to be read in from disk
75  if( cube->pars().getFlagReconExists() && cube->pars().getFlagATrous() ){
76    std::cout << "Reading reconstructed array: "<<std::endl;
77    if( cube->readReconCube() == FAILURE){
78      std::cerr << "WARNING : Could not read in existing reconstructed array.\n"
79                << "          Will perform reconstruction using assigned parameters.\n";
80      cube->pars().setFlagReconExists(false);
81    }
82    else std::cout << "Reconstructed array available.\n";
83  }
84
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.
92  std::cout << cube->pars();
93
94  if(cube->pars().getFlagLog()){
95    // Open the logfile and write the time on the first line
96    ofstream logfile(cube->pars().getLogFile().c_str());
97    logfile << "New run of the Duchamp sourcefinder: ";
98    time_t now = time(NULL);
99    logfile << asctime( localtime(&now) );
100    logfile << cube->pars();
101    logfile.close();
102  }
103
104  if(cube->pars().getFlagBlankPix()){
105    // Trim any blank pixels from the edges, and report the new size of the cube
106    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
107    cube->trimCube();
108    std::cout<<"Done."<<std::endl;
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();
112    std::cout << std::endl;
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
123  if(cube->pars().getFlagNegative()){
124    std::cout<<"Inverting the Cube... "<<std::flush;
125    cube->invert();
126    std::cout<<" Done."<<std::endl;
127  }
128
129  if(cube->pars().getFlagATrous()){
130    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
131    cube->ReconSearch();
132    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<std::endl;
133  }
134  else{
135    std::cout<<"Commencing search in cube..."<<std::endl;
136    cube->CubicSearch();
137    std::cout<<"Done. Found "<<cube->getNumObj()<<" objects."<<std::endl;
138  }
139
140  std::cout<<"Merging lists...  "<<std::flush;
141  cube->ObjectMerger();
142  std::cout<<"Done.                      "<<std::endl;
143  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
144
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
151  cube->replaceBaseline();
152
153  if(cube->pars().getFlagCubeTrimmed()){
154    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
155    cube->unTrimCube();
156    std::cout<<"Done."<<std::endl;
157  }
158
159  if(cube->getNumObj()>0){
160
161    cube->calcObjectWCSparams();
162
163    cube->setObjectFlags();
164   
165    cube->sortDetections();
166   
167    cube->outputDetectionList();
168  }
169
170  std::cout<<"Creating the maps...  "<<std::flush;
171  cube->plotMomentMap("/xs");
172  if(cube->pars().getFlagMaps()){
173    cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps");
174    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
175  }
176  std::cout << "done.\n";
177
178  if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
179    std::cout << "Plotting the individual spectra... " << std::flush;
180    cube->outputSpectra();
181    std::cout << "done.\n";
182  }
183  else if(cube->getDimZ()<=1) std::cerr << "WARNING : Not plotting any spectra  -- no third dimension.\n";
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
207  if(cube->pars().getFlagKarma()){
208    ofstream karmafile(cube->pars().getKarmaFile().c_str());
209    cube->outputDetectionsKarma(karmafile);
210    karmafile.close();
211  }
212
213  delete cube;
214
215  return 0;
216}
217
Note: See TracBrowser for help on using the repository browser.