source: tags/release-1.1.1/src/mainDuchamp.cc @ 1323

Last change on this file since 1323 was 317, checked in by Matthew Whiting, 17 years ago

Minor changes to help compilation.

File size: 8.2 KB
Line 
1// -----------------------------------------------------------------------
2// mainDuchamp.cc: Main program for Duchamp source finder.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#include <iostream>
29#include <fstream>
30#include <string>
31#include <math.h>
32#include <unistd.h>
33#include <time.h>
34
35#include <duchamp.hh>
36#include <param.hh>
37#include <pgheader.hh>
38#include <Detection/detection.hh>
39#include <Cubes/cubes.hh>
40#include <Utils/utils.hh>
41#include <ATrous/atrous.hh>
42
43int main(int argc, char * argv[])
44{
45
46  std::string paramFile,fitsfile;
47  Cube *cube = new Cube;
48
49  if(cube->getopts(argc,argv)==FAILURE) return FAILURE;
50
51  if(cube->pars().getImageFile().empty()){
52    std::stringstream errmsg;
53    errmsg << "No input image has been given!\n"
54           << "Use the imageFile parameter in "
55           << paramFile << " to specify the FITS file.\nExiting...\n";
56    duchampError("Duchamp", errmsg.str());
57    return FAILURE;
58  }
59
60  if(cube->pars().getFlagSubsection() || cube->pars().getFlagStatSec()){
61    // make sure the subsection is OK.
62    if(cube->pars().verifySubsection() == FAILURE){
63      duchampError("Duchamp",
64                   "Unable to use the subsection provided.\nExiting...\n");
65      return FAILURE;
66    }
67  }     
68
69  std::cout << "Opening image: "
70            << cube->pars().getFullImageFile() << std::endl;
71
72  if( cube->getCube() == FAILURE){
73    std::stringstream errmsg;
74    errmsg << "Unable to open image file "
75           << cube->pars().getFullImageFile()
76           << "\nExiting...\n";
77    duchampError("Duchamp", errmsg.str());
78    return FAILURE;
79  }
80  else std::cout << "Opened successfully." << std::endl;
81
82  // Read in any saved arrays that are in FITS files on disk.
83  cube->readSavedArrays();
84
85  // special case for 2D images -- ignore the minChannels requirement
86  if(cube->getDimZ()==1) cube->pars().setMinChannels(0); 
87
88  // Write the parameters to screen.
89  std::cout << cube->pars();
90
91  if(cube->pars().getFlagLog()){
92    // Open the logfile and write the time on the first line
93    std::ofstream logfile(cube->pars().getLogFile().c_str());
94    logfile << "New run of the Duchamp sourcefinder: ";
95    time_t now = time(NULL);
96    logfile << asctime( localtime(&now) );
97    // Write out the command-line statement
98    logfile << "Executing statement : ";
99    for(int i=0;i<argc;i++) logfile << argv[i] << " ";
100    logfile << std::endl;
101    logfile << cube->pars();
102    logfile.close();
103  }
104
105  //if(cube->pars().getFlagBlankPix()){
106  if(cube->pars().getFlagTrim()){
107    // Trim any blank pixels from the edges, and report the new size
108    // of the cube
109    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
110    cube->trimCube();
111    std::cout<<"Done."<<std::endl;
112    std::cout << "New dimensions:  " << cube->getDimX();
113    if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY();
114    if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ();
115    std::cout << std::endl;
116  }
117
118  if(cube->pars().getFlagBaseline()){
119    std::cout<<"Removing the baselines... "<<std::flush;
120    cube->removeBaseline();
121    std::cout<<" Done.                 "<<std::endl;
122  }
123
124  if(cube->pars().getFlagNegative()){
125    std::cout<<"Inverting the Cube... "<<std::flush;
126    cube->invert();
127    std::cout<<" Done."<<std::endl;
128  }
129
130  if(cube->pars().getFlagATrous()){
131    std::cout<<"Commencing search in reconstructed cube..."<<std::endl;
132    cube->ReconSearch();
133  } 
134  else if(cube->pars().getFlagSmooth()){
135    std::cout<<"Commencing search in smoothed cube..."<<std::endl;
136    cube->SmoothSearch();
137  }
138  else{
139    std::cout<<"Commencing search in cube..."<<std::endl;
140    cube->CubicSearch();
141  }
142  std::cout << "Done. Intermediate list has " << cube->getNumObj();
143  if(cube->getNumObj()==1) std::cout << " object.\n";
144  else std::cout << " objects.\n";
145
146  if(cube->getNumObj() > 1){
147    if(cube->pars().getFlagGrowth())
148      std::cout<<"Merging, Growing and Rejecting...  "<<std::flush;
149    else
150      std::cout<<"Merging and Rejecting...  "<<std::flush;
151    cube->ObjectMerger();
152    std::cout<<"Done.                      "<<std::endl;
153  }
154  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
155
156  if(cube->pars().getFlagNegative()){
157    std::cout<<"Un-Inverting the Cube... "<<std::flush;
158    cube->reInvert();
159    std::cout<<" Done."<<std::endl;
160  }
161
162  if(cube->pars().getFlagBaseline()){
163    std::cout<<"Replacing the baselines...  "<<std::flush;
164    cube->replaceBaseline();
165    std::cout<<"Done."<<std::endl;
166  }
167
168  if(cube->pars().getFlagCubeTrimmed()){
169    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
170    cube->unTrimCube();
171    std::cout<<"Done."<<std::endl;
172  }
173
174  cube->prepareOutputFile();
175
176  if(cube->getNumObj()>0){
177
178    cube->calcObjectWCSparams();
179
180    cube->setObjectFlags();
181   
182    cube->sortDetections();
183  }
184 
185  cube->outputDetectionList();
186
187  if(USE_PGPLOT){
188    std::cout<<"Creating the maps...  "<<std::flush;
189    std::vector<std::string> devices;
190    if(cube->pars().getFlagXOutput()) devices.push_back("/xs");
191    if(cube->pars().getFlagMaps())
192      devices.push_back(cube->pars().getMomentMap()+"/vcps");
193    cube->plotMomentMap(devices);
194    if(cube->pars().getFlagMaps())
195      cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps");
196    std::cout << "Done.\n";
197   
198    if((cube->getDimZ()>1) && (cube->getNumObj()>0)){
199      std::cout << "Plotting the individual spectra... " << std::flush;
200      cube->outputSpectra();
201      std::cout << "Done.\n";
202    }
203    else if(cube->getDimZ()<=1)
204      duchampWarning("Duchamp",
205                     "Not plotting any spectra : no third dimension.\n");
206  }
207  else{
208    std::cout << "PGPLOT has not been enabled, so no graphical output.\n";
209  }
210  endPGPLOT();
211
212  if(cube->pars().getFlagATrous()&&
213     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
214    std::cout << "Saving reconstructed cube to "
215              << cube->pars().outputReconFile() << "... "<<std::flush;
216    cube->saveReconstructedCube();
217    std::cout << "done.\n";
218  }
219  if(cube->pars().getFlagSmooth()&& cube->pars().getFlagOutputSmooth()){
220    std::cout << "Saving smoothed cube to "
221              << cube->pars().outputSmoothFile() << "... " <<std::flush;
222    cube->saveSmoothedCube();
223    std::cout << "done.\n";
224  }
225
226  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
227    std::ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
228    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
229    logfile << *cube;
230    logfile.close();
231  }
232
233  if(cube->pars().getFlagVOT()){
234    std::ofstream votfile(cube->pars().getVOTFile().c_str());
235    cube->outputDetectionsVOTable(votfile);
236    votfile.close();
237  }
238
239  if(cube->pars().getFlagKarma()){
240    std::ofstream karmafile(cube->pars().getKarmaFile().c_str());
241    cube->outputDetectionsKarma(karmafile);
242    karmafile.close();
243  }
244
245  if(cube->pars().getFlagLog()){
246    // Open the logfile and write the time on the first line
247    std::ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
248    logfile << "Duchamp completed: ";
249    time_t now = time(NULL);
250    logfile << asctime( localtime(&now) );
251    logfile.close();
252  }
253
254
255  delete cube;
256
257  return SUCCESS;
258}
259
Note: See TracBrowser for help on using the repository browser.