source: trunk/src/mainDuchamp.cc @ 326

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

Minor changes to help compilation.

File size: 8.2 KB
RevLine 
[299]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// -----------------------------------------------------------------------
[3]28#include <iostream>
29#include <fstream>
30#include <string>
31#include <math.h>
32#include <unistd.h>
[80]33#include <time.h>
[57]34
35#include <duchamp.hh>
[142]36#include <param.hh>
[317]37#include <pgheader.hh>
[3]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
[232]46  std::string paramFile,fitsfile;
[85]47  Cube *cube = new Cube;
[3]48
[168]49  if(cube->getopts(argc,argv)==FAILURE) return FAILURE;
[3]50
51  if(cube->pars().getImageFile().empty()){
[139]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";
[168]56    duchampError("Duchamp", errmsg.str());
57    return FAILURE;
[3]58  }
59
[258]60  if(cube->pars().getFlagSubsection() || cube->pars().getFlagStatSec()){
[168]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  }     
[164]68
[139]69  std::cout << "Opening image: "
70            << cube->pars().getFullImageFile() << std::endl;
71
[106]72  if( cube->getCube() == FAILURE){
[139]73    std::stringstream errmsg;
74    errmsg << "Unable to open image file "
75           << cube->pars().getFullImageFile()
76           << "\nExiting...\n";
[168]77    duchampError("Duchamp", errmsg.str());
78    return FAILURE;
[3]79  }
[103]80  else std::cout << "Opened successfully." << std::endl;
[3]81
[208]82  // Read in any saved arrays that are in FITS files on disk.
83  cube->readSavedArrays();
[71]84
[139]85  // special case for 2D images -- ignore the minChannels requirement
86  if(cube->getDimZ()==1) cube->pars().setMinChannels(0); 
87
[103]88  // Write the parameters to screen.
[3]89  std::cout << cube->pars();
90
91  if(cube->pars().getFlagLog()){
[106]92    // Open the logfile and write the time on the first line
[232]93    std::ofstream logfile(cube->pars().getLogFile().c_str());
[3]94    logfile << "New run of the Duchamp sourcefinder: ";
[80]95    time_t now = time(NULL);
96    logfile << asctime( localtime(&now) );
[120]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;
[3]101    logfile << cube->pars();
102    logfile.close();
103  }
104
[285]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
[3]109    std::cout<<"Trimming the Blank Pixels from the edges...  "<<std::flush;
110    cube->trimCube();
[103]111    std::cout<<"Done."<<std::endl;
[3]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();
[103]115    std::cout << std::endl;
[3]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
[60]124  if(cube->pars().getFlagNegative()){
125    std::cout<<"Inverting the Cube... "<<std::flush;
126    cube->invert();
127    std::cout<<" Done."<<std::endl;
128  }
129
[208]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()){
[275]135    std::cout<<"Commencing search in smoothed cube..."<<std::endl;
[201]136    cube->SmoothSearch();
137  }
[3]138  else{
[103]139    std::cout<<"Commencing search in cube..."<<std::endl;
140    cube->CubicSearch();
[3]141  }
[258]142  std::cout << "Done. Intermediate list has " << cube->getNumObj();
[201]143  if(cube->getNumObj()==1) std::cout << " object.\n";
144  else std::cout << " objects.\n";
[3]145
[146]146  if(cube->getNumObj() > 1){
[265]147    if(cube->pars().getFlagGrowth())
148      std::cout<<"Merging, Growing and Rejecting...  "<<std::flush;
149    else
150      std::cout<<"Merging and Rejecting...  "<<std::flush;
[146]151    cube->ObjectMerger();
152    std::cout<<"Done.                      "<<std::endl;
153  }
[103]154  std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl;
[3]155
[60]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
[258]162  if(cube->pars().getFlagBaseline()){
163    std::cout<<"Replacing the baselines...  "<<std::flush;
164    cube->replaceBaseline();
165    std::cout<<"Done."<<std::endl;
166  }
[3]167
168  if(cube->pars().getFlagCubeTrimmed()){
169    std::cout<<"Replacing the trimmed pixels on the edges...  "<<std::flush;
170    cube->unTrimCube();
[103]171    std::cout<<"Done."<<std::endl;
[3]172  }
173
[275]174  cube->prepareOutputFile();
175
[3]176  if(cube->getNumObj()>0){
177
178    cube->calcObjectWCSparams();
[87]179
180    cube->setObjectFlags();
[3]181   
182    cube->sortDetections();
183  }
[312]184 
185  cube->outputDetectionList();
[3]186
[315]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");
[258]196    std::cout << "Done.\n";
[315]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");
[3]206  }
[315]207  else{
208    std::cout << "PGPLOT has not been enabled, so no graphical output.\n";
209  }
210  endPGPLOT();
[3]211
212  if(cube->pars().getFlagATrous()&&
213     (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){
[258]214    std::cout << "Saving reconstructed cube to "
[208]215              << cube->pars().outputReconFile() << "... "<<std::flush;
[3]216    cube->saveReconstructedCube();
217    std::cout << "done.\n";
218  }
[208]219  if(cube->pars().getFlagSmooth()&& cube->pars().getFlagOutputSmooth()){
[290]220    std::cout << "Saving smoothed cube to "
[208]221              << cube->pars().outputSmoothFile() << "... " <<std::flush;
222    cube->saveSmoothedCube();
223    std::cout << "done.\n";
224  }
[3]225
226  if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){
[232]227    std::ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app);
[3]228    logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n";
229    logfile << *cube;
230    logfile.close();
231  }
232
233  if(cube->pars().getFlagVOT()){
[232]234    std::ofstream votfile(cube->pars().getVOTFile().c_str());
[3]235    cube->outputDetectionsVOTable(votfile);
236    votfile.close();
237  }
238
[20]239  if(cube->pars().getFlagKarma()){
[232]240    std::ofstream karmafile(cube->pars().getKarmaFile().c_str());
[20]241    cube->outputDetectionsKarma(karmafile);
242    karmafile.close();
243  }
244
[313]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
[3]255  delete cube;
256
[168]257  return SUCCESS;
[3]258}
259
Note: See TracBrowser for help on using the repository browser.