#include #include #include #include #include #include #include #include #include #include #include #include #include using std::ofstream; using std::string; Filter reconFilter; int main(int argc, char * argv[]) { string paramFile,fitsfile; Cube *cube = new Cube; if(cube->getopts(argc,argv)==FAILURE) return FAILURE; if(cube->pars().getImageFile().empty()){ std::stringstream errmsg; errmsg << "No input image has been given!\n" << "Use the imageFile parameter in " << paramFile << " to specify the FITS file.\nExiting...\n"; duchampError("Duchamp", errmsg.str()); return FAILURE; } if(cube->pars().getFlagSubsection()){ // make sure the subsection is OK. if(cube->pars().verifySubsection() == FAILURE){ duchampError("Duchamp", "Unable to use the subsection provided.\nExiting...\n"); return FAILURE; } } std::cout << "Opening image: " << cube->pars().getFullImageFile() << std::endl; if( cube->getCube() == FAILURE){ std::stringstream errmsg; errmsg << "Unable to open image file " << cube->pars().getFullImageFile() << "\nExiting...\n"; duchampError("Duchamp", errmsg.str()); return FAILURE; } else std::cout << "Opened successfully." << std::endl; // If the reconstructed array is to be read in from disk if( cube->pars().getFlagReconExists() && cube->pars().getFlagATrous() ){ std::cout << "Reading reconstructed array: "<readReconCube() == FAILURE){ std::stringstream errmsg; errmsg <<"Could not read in existing reconstructed array.\n" <<"Will perform reconstruction using assigned parameters.\n"; duchampWarning("Duchamp", errmsg.str()); cube->pars().setFlagReconExists(false); } else std::cout << "Reconstructed array available.\n"; } // Filter needed for baseline removal and a trous reconstruction if(cube->pars().getFlagATrous() || cube->pars().getFlagBaseline()){ reconFilter.define(cube->pars().getFilterCode()); cube->pars().setFilterName(reconFilter.getName()); } // special case for 2D images -- ignore the minChannels requirement if(cube->getDimZ()==1) cube->pars().setMinChannels(0); // Write the parameters to screen. std::cout << cube->pars(); if(cube->pars().getFlagLog()){ // Open the logfile and write the time on the first line ofstream logfile(cube->pars().getLogFile().c_str()); logfile << "New run of the Duchamp sourcefinder: "; time_t now = time(NULL); logfile << asctime( localtime(&now) ); // Write out the command-line statement logfile << "Executing statement : "; for(int i=0;ipars(); logfile.close(); } if(cube->pars().getFlagBlankPix()){ // Trim any blank pixels from the edges, // and report the new size of the cube std::cout<<"Trimming the Blank Pixels from the edges... "<trimCube(); std::cout<<"Done."<getDimX(); if(cube->getNumDim()>1) std::cout << "x" << cube->getDimY(); if(cube->getNumDim()>2) std::cout << "x" << cube->getDimZ(); std::cout << std::endl; } if(cube->pars().getFlagBaseline()){ std::cout<<"Removing the baselines... "<removeBaseline(); std::cout<<" Done. "<pars().getFlagNegative()){ std::cout<<"Inverting the Cube... "<invert(); std::cout<<" Done."<pars().getFlagATrous()){ std::cout<<"Commencing search in reconstructed cube..."<ReconSearch(); std::cout << "Done. Intermediate list has " << cube->getNumObj(); if(cube->getNumObj()==1) std::cout << " object.\n"; else std::cout << " objects.\n"; } else{ std::cout<<"Commencing search in cube..."<CubicSearch(); std::cout << "Done. Intermediate list has " << cube->getNumObj(); if(cube->getNumObj()==1) std::cout << " object.\n"; else std::cout << " objects.\n"; } if(cube->getNumObj() > 1){ std::cout<<"Merging lists... "<ObjectMerger(); std::cout<<"Done. "<reInvert(); std::cout<<" Done."<replaceBaseline(); if(cube->pars().getFlagCubeTrimmed()){ std::cout<<"Replacing the trimmed pixels on the edges... "<unTrimCube(); std::cout<<"Done."<getNumObj()>0){ cube->calcObjectWCSparams(); cube->setObjectFlags(); cube->sortDetections(); cube->outputDetectionList(); } std::cout<<"Creating the maps... "<plotMomentMap("/xs"); if(cube->pars().getFlagMaps()){ cube->plotMomentMap(cube->pars().getMomentMap()+"/vcps"); cube->plotDetectionMap(cube->pars().getDetectionMap()+"/vcps"); } std::cout << "done.\n"; if((cube->getDimZ()>1) && (cube->getNumObj()>0)){ std::cout << "Plotting the individual spectra... " << std::flush; cube->outputSpectra(); std::cout << "done.\n"; } else if(cube->getDimZ()<=1) duchampWarning("Duchamp", "Not plotting any spectra -- no third dimension.\n"); cpgend(); if(cube->pars().getFlagATrous()&& (cube->pars().getFlagOutputRecon()||cube->pars().getFlagOutputResid()) ){ std::cout << "Saving reconstructed cube... "<saveReconstructedCube(); std::cout << "done.\n"; } if(cube->pars().getFlagLog() && (cube->getNumObj()>0)){ ofstream logfile(cube->pars().getLogFile().c_str(),std::ios::app); logfile << "=-=-=-=-=-=-=-\nCube summary\n=-=-=-=-=-=-=-\n"; logfile << *cube; logfile.close(); } if(cube->pars().getFlagVOT()){ ofstream votfile(cube->pars().getVOTFile().c_str()); cube->outputDetectionsVOTable(votfile); votfile.close(); } if(cube->pars().getFlagKarma()){ ofstream karmafile(cube->pars().getKarmaFile().c_str()); cube->outputDetectionsKarma(karmafile); karmafile.close(); } delete cube; return SUCCESS; }