[299] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // mainRrose: A program to re-analyse detected objects from a Duchamp run. |
---|
| 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 | // ----------------------------------------------------------------------- |
---|
[218] | 28 | #include <iostream> |
---|
| 29 | #include <fstream> |
---|
| 30 | #include <string> |
---|
| 31 | #include <cpgplot.h> |
---|
| 32 | #include <math.h> |
---|
| 33 | #include <unistd.h> |
---|
| 34 | #include <time.h> |
---|
| 35 | |
---|
[393] | 36 | #include <duchamp/duchamp.hh> |
---|
| 37 | #include <duchamp/param.hh> |
---|
| 38 | #include <duchamp/PixelMap/Voxel.hh> |
---|
| 39 | #include <duchamp/Detection/detection.hh> |
---|
| 40 | #include <duchamp/Cubes/cubes.hh> |
---|
| 41 | #include <duchamp/Utils/utils.hh> |
---|
| 42 | #include <duchamp/ATrous/atrous.hh> |
---|
[218] | 43 | |
---|
[258] | 44 | using namespace PixelInfo; |
---|
| 45 | |
---|
[218] | 46 | int main(int argc, char * argv[]) |
---|
| 47 | { |
---|
| 48 | |
---|
[232] | 49 | std::string paramFile,fitsfile,temp; |
---|
[218] | 50 | Cube *cube = new Cube; |
---|
| 51 | |
---|
| 52 | if(cube->getopts(argc,argv)==FAILURE) return FAILURE; |
---|
| 53 | |
---|
| 54 | if(cube->pars().getImageFile().empty()){ |
---|
| 55 | std::stringstream errmsg; |
---|
| 56 | errmsg << "No input image has been given!\n" |
---|
| 57 | << "Use the imageFile parameter in " |
---|
| 58 | << paramFile << " to specify the FITS file.\nExiting...\n"; |
---|
| 59 | duchampError("Duchamp", errmsg.str()); |
---|
| 60 | return FAILURE; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if(cube->pars().getFlagSubsection()){ |
---|
| 64 | // make sure the subsection is OK. |
---|
| 65 | if(cube->pars().verifySubsection() == FAILURE){ |
---|
| 66 | duchampError("Duchamp", |
---|
| 67 | "Unable to use the subsection provided.\nExiting...\n"); |
---|
| 68 | return FAILURE; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | std::cout << "Opening image: " |
---|
| 73 | << cube->pars().getFullImageFile() << std::endl; |
---|
| 74 | |
---|
| 75 | if( cube->getCube() == FAILURE){ |
---|
| 76 | std::stringstream errmsg; |
---|
| 77 | errmsg << "Unable to open image file " |
---|
| 78 | << cube->pars().getFullImageFile() |
---|
| 79 | << "\nExiting...\n"; |
---|
| 80 | duchampError("Duchamp", errmsg.str()); |
---|
| 81 | return FAILURE; |
---|
| 82 | } |
---|
| 83 | else std::cout << "Opened successfully." << std::endl; |
---|
| 84 | |
---|
| 85 | // Read in any saved arrays that are in FITS files on disk. |
---|
| 86 | cube->readSavedArrays(); |
---|
| 87 | |
---|
| 88 | |
---|
[232] | 89 | std::ifstream logfile(cube->pars().getLogFile().c_str()); |
---|
[218] | 90 | |
---|
| 91 | if(!logfile.is_open()){ |
---|
| 92 | std::cerr << "\aUnable to open file " |
---|
| 93 | << cube->pars().getLogFile() << "\nExiting...\n"; |
---|
| 94 | return 1; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | // read down until first Detection # line |
---|
| 98 | cube->setCubeStats(); |
---|
| 99 | std::cerr << "Reading from logfile : " << cube->pars().getLogFile() << "\n"; |
---|
| 100 | while(getline(logfile,temp), temp.substr(0,11)!="Detection #"){ } |
---|
| 101 | int xpix, ypix, zpix; |
---|
| 102 | float fpix; |
---|
| 103 | while(!logfile.eof()){ |
---|
| 104 | Detection obj; |
---|
| 105 | while(getline(logfile,temp), temp.substr(0,3)!="---"){ |
---|
| 106 | std::stringstream ss; |
---|
| 107 | ss.str(temp); |
---|
| 108 | ss >> xpix >> ypix >> zpix >> fpix; |
---|
| 109 | Voxel vox(xpix,ypix,zpix,fpix); |
---|
| 110 | obj.addPixel(vox); |
---|
| 111 | } |
---|
[221] | 112 | obj.setOffsets(cube->pars()); |
---|
[218] | 113 | obj.calcParams(); |
---|
| 114 | if(obj.getSize()>0) cube->addObject(obj); |
---|
| 115 | getline(logfile,temp); // reads next line -- should be Detection #... |
---|
| 116 | if(temp.substr(0,4)=="----") getline(logfile,temp); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | std::cout<<"Final object count = "<<cube->getNumObj()<<std::endl; |
---|
| 120 | |
---|
| 121 | cube->calcObjectWCSparams(); |
---|
| 122 | cube->setObjectFlags(); |
---|
| 123 | |
---|
| 124 | if((cube->getDimZ()>1) && (cube->getNumObj()>0)){ |
---|
| 125 | std::cout << "Plotting the individual spectra... " << std::flush; |
---|
| 126 | cube->outputSpectra(); |
---|
| 127 | std::cout << "done.\n"; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | } |
---|