source: tags/release-1.0.5/src/mainDuchamp.cc @ 1455

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

A couple of changes:

  • Removed the Fortran search in the configure script -- we don't use it.
  • Cleaned up some of the fits-I/O tasks, adding some functions that check for the existence of the FITS file (fits_file_exists).
  • This task is only in v2.5+ of cfitsio, so added notes to this effect in README and the Guide.
  • Improved the exiting and warning messages in mainDuchamp.cc.
File size: 6.4 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 <param.hh>
11#include <Detection/detection.hh>
12#include <Cubes/cubes.hh>
13#include <Utils/utils.hh>
14#include <ATrous/atrous.hh>
15
16using std::ofstream;
17using std::string;
18
19Filter reconFilter;
20
21int main(int argc, char * argv[])
22{
23
24  string paramFile,fitsfile;
25  Cube *cube = new Cube;
26
27  if(cube->getopts(argc,argv)==FAILURE) return FAILURE;
28
29  if(cube->pars().getImageFile().empty()){
30    std::stringstream errmsg;
31    errmsg << "No input image has been given!\n"
32           << "Use the imageFile parameter in "
33           << paramFile << " to specify the FITS file.\nExiting...\n";
34    duchampError("Duchamp", errmsg.str());
35    return FAILURE;
36  }
37
38  if(cube->pars().getFlagSubsection()){
39    // make sure the subsection is OK.
40    if(cube->pars().verifySubsection() == FAILURE){
41      duchampError("Duchamp",
42                   "Unable to use the subsection provided.\nExiting...\n");
43      return FAILURE;
44    }
45  }     
46
47  std::cout << "Opening image: "
48            << cube->pars().getFullImageFile() << std::endl;
49
50  if( cube->getCube() == FAILURE){
51    std::stringstream errmsg;
52    errmsg << "Unable to open image file "
53           << cube->pars().getFullImageFile()
54           << "\nExiting...\n";
55    duchampError("Duchamp", errmsg.str());
56    return FAILURE;
57  }
58  else std::cout << "Opened successfully." << std::endl;
59
60  // If the reconstructed array is to be read in from disk
61  if( cube->pars().getFlagReconExists() && cube->pars().getFlagATrous() ){
62    std::cout << "Reading reconstructed array: "<<std::endl;
63    if( cube->readReconCube() == FAILURE){
64      std::stringstream errmsg;
65      errmsg <<"Could not read in existing reconstructed array.\n"
66             <<"Will perform reconstruction using assigned parameters.\n";
67      duchampWarning("Duchamp", errmsg.str());
68      cube->pars().setFlagReconExists(false);
69    }
70    else std::cout << "Reconstructed array available.\n";
71  }
72
73  // Filter needed for baseline removal and a trous reconstruction
74  if(cube->pars().getFlagATrous() || cube->pars().getFlagBaseline()){
75    reconFilter.define(cube->pars().getFilterCode());
76    cube->pars().setFilterName(reconFilter.getName());
77  }
78
79  // special case for 2D images -- ignore the minChannels requirement
80  if(cube->getDimZ()==1) cube->pars().setMinChannels(0); 
81
82  // Write the parameters to screen.
83  std::cout << cube->pars();
84
85  if(cube->pars().getFlagLog()){
86    // Open the logfile and write the time on the first line
87    ofstream logfile(cube->pars().getLogFile().c_str());
88    logfile << "New run of the Duchamp sourcefinder: ";
89    time_t now = time(NULL);
90    logfile << asctime( localtime(&now) );
91    // Write out the command-line statement
92    logfile << "Executing statement : ";
93    for(int i=0;i<argc;i++) logfile << argv[i] << " ";
94    logfile << std::endl;
95    logfile << cube->pars();
96    logfile.close();
97  }
98
99  if(cube->pars().getFlagBlankPix()){
100    // Trim any blank pixels from the edges,
101    //  and report the new size of the cube
102    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
103    cube->trimCube();
104    std::cout<<"Done."<<std::endl;
105    std::cout << "New dimensions:  " << cube->getDimX();
106    if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY();
107    if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ();
108    std::cout << std::endl;
109  }
110
111  if(cube->pars().getFlagBaseline()){
112    std::cout<<"Removing the baselines... "<<std::flush;
113    cube->removeBaseline();
114    std::cout<<" Done.                 "<<std::endl;
115  }
116
117  if(cube->pars().getFlagNegative()){
118    std::cout<<"Inverting the Cube... "<<std::flush;
119    cube->invert();
120    std::cout<<" Done."<<std::endl;
121  }
122
123  if(cube->pars().getFlagATrous()){
124    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
125    cube->ReconSearch();
126    std::cout << "Done. Intermediate list has "
127              << cube->getNumObj();
128    if(cube->getNumObj()==1) std::cout << " object.\n";
129    else std::cout << " objects.\n";
130  }
131  else{
132    std::cout<<"Commencing search in cube..."<<std::endl;
133    cube->CubicSearch();
134    std::cout << "Done. Intermediate list has "
135              << cube->getNumObj();
136    if(cube->getNumObj()==1) std::cout << " object.\n";
137    else std::cout << " objects.\n";
138  }
139
140  if(cube->getNumObj() > 1){
141    std::cout<<"Merging lists...  "<<std::flush;
142    cube->ObjectMerger();
143    std::cout<<"Done.                      "<<std::endl;
144  }
145  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
146
147  if(cube->pars().getFlagNegative()){
148    std::cout<<"Un-Inverting the Cube... "<<std::flush;
149    cube->reInvert();
150    std::cout<<" Done."<<std::endl;
151  }
152
153  cube->replaceBaseline();
154
155  if(cube->pars().getFlagCubeTrimmed()){
156    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
157    cube->unTrimCube();
158    std::cout<<"Done."<<std::endl;
159  }
160
161  if(cube->getNumObj()>0){
162
163    cube->calcObjectWCSparams();
164
165    cube->setObjectFlags();
166   
167    cube->sortDetections();
168   
169    cube->outputDetectionList();
170  }
171
172  std::cout<<"Creating the maps...  "<<std::flush;
173  cube->plotMomentMap("/xs");
174  if(cube->pars().getFlagMaps()){
175    cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps");
176    cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
177  }
178  std::cout << "done.\n";
179
180  if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
181    std::cout << "Plotting the individual spectra... " << std::flush;
182    cube->outputSpectra();
183    std::cout << "done.\n";
184  }
185  else if(cube->getDimZ()<=1)
186    duchampWarning("Duchamp",
187                   "Not plotting any spectra  -- no third dimension.\n");
188
189  cpgend();
190
191  if(cube->pars().getFlagATrous()&&
192     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
193    std::cout << "Saving reconstructed cube... "<<std::flush;
194    cube->saveReconstructedCube();
195    std::cout << "done.\n";
196  }
197
198  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
199    ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
200    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
201    logfile << *cube;
202    logfile.close();
203  }
204
205  if(cube->pars().getFlagVOT()){
206    ofstream votfile(cube->pars().getVOTFile().c_str());
207    cube->outputDetectionsVOTable(votfile);
208    votfile.close();
209  }
210
211  if(cube->pars().getFlagKarma()){
212    ofstream karmafile(cube->pars().getKarmaFile().c_str());
213    cube->outputDetectionsKarma(karmafile);
214    karmafile.close();
215  }
216
217  delete cube;
218
219  return SUCCESS;
220}
221
Note: See TracBrowser for help on using the repository browser.