// ----------------------------------------------------------------------- // sorting.cc: Sort the list of Detections by channel or velocity. // ----------------------------------------------------------------------- // Copyright (C) 2006, Matthew Whiting, ATNF // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your // option) any later version. // // Duchamp is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License // along with Duchamp; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA // // Correspondence concerning Duchamp may be directed to: // Internet email: Matthew.Whiting [at] atnf.csiro.au // Postal address: Dr. Matthew Whiting // Australia Telescope National Facility, CSIRO // PO Box 76 // Epping NSW 1710 // AUSTRALIA // ----------------------------------------------------------------------- #include #include #include #include #include #include #include #include namespace duchamp { void SortByZ(std::vector &inputList) { /// A Function that takes a list of Detections and sorts them in /// order of increasing z-pixel value. Upon return, the inputList /// is sorted. /// /// We use the std::stable_sort function, so that the order of /// objects with the same z-value is preserved. /// \param inputList List of Detections to be sorted. /// \return The inputList is returned with the elements sorted. std::multimap complist; std::vector sorted; std::multimap::iterator comp; std::vector::iterator det; size_t ct=0; for (det=inputList.begin();det(det->getZcentre(), ct++)); } for (comp = complist.begin(); comp != complist.end(); comp++) sorted.push_back(inputList[comp->second]); inputList.clear(); for (det=sorted.begin();det &inputList) { /// @details /// A Function that takes a list of Detections and sorts them in /// order of increasing velocity. /// Every member of the vector needs to have WCS defined, (and if so, /// then vel is assumed to be defined for all), otherwise no sorting /// is done. /// /// We use the std::stable_sort function, so that the order of /// objects with the same z-value is preserved. /// /// \param inputList List of Detections to be sorted. /// \return The inputList is returned with the elements sorted, /// unless the WCS is not good for at least one element, in which /// case it is returned unaltered. bool isGood = true; for(size_t i=0;i complist; std::vector sorted; std::multimap::iterator comp; std::vector::iterator det; size_t ct=0; for (det=inputList.begin();det(det->getVel(), ct++)); } for (comp = complist.begin(); comp != complist.end(); comp++) sorted.push_back(inputList[comp->second]); inputList.clear(); for (det=sorted.begin();det &inputList, std::string parameter) { /// @details /// A Function that takes a list of Detections and sorts them in /// order of increasing value of the parameter given. /// /// For parameters that need the WCS (iflux, vel, ra, dec, w50), a /// check is made that the WCS is valid, using /// Detection::isWCS(). If it is not, the list is returned /// unsorted. /// /// \param inputList List of Detections to be sorted. /// \param parameter The name of the parameter to be sorted /// on. Options are listed in the param.hh file /// \return The inputList is returned with the elements sorted, /// unless the WCS is not good for at least one element, /// in which case it is returned unaltered. bool OK = false, reverseSort=(parameter[0]=='-'); std::string checkParam; if(reverseSort) checkParam = parameter.substr(1); else checkParam = parameter; for(int i=0;i sorted; std::vector::iterator det; if(checkParam=="xvalue" || checkParam=="yvalue" || checkParam=="zvalue" || checkParam=="iflux" || checkParam=="pflux" || checkParam=="snr"){ std::multimap complist; std::multimap::iterator comp; size_t ct=0; float reverse = reverseSort ? -1. : 1.; for (det=inputList.begin();det(reverse*det->getXcentre(), ct++)); else if(checkParam=="yvalue") complist.insert(std::pair(reverse*det->getYcentre(), ct++)); else if(checkParam=="zvalue") complist.insert(std::pair(reverse*det->getZcentre(), ct++)); else if(checkParam=="iflux") complist.insert(std::pair(reverse*det->getIntegFlux(), ct++)); else if(checkParam=="pflux") complist.insert(std::pair(reverse*det->getPeakFlux(), ct++)); else if(checkParam=="snr") complist.insert(std::pair(reverse*det->getPeakSNR(), ct++)); } for (comp = complist.begin(); comp != complist.end(); comp++) sorted.push_back(inputList[comp->second]); } else if(checkParam=="ra" || checkParam=="dec" || checkParam=="vel" || checkParam=="w50"){ std::multimap complist; std::multimap::iterator comp; size_t ct=0; double reverse = reverseSort ? -1. : 1.; for (det=inputList.begin();det(reverse*det->getRA(), ct++)); else if(checkParam=="dec") complist.insert(std::pair(reverse*det->getDec(), ct++)); else if(checkParam=="vel") complist.insert(std::pair(reverse*det->getVel(), ct++)); else if(checkParam=="w50") complist.insert(std::pair(reverse*det->getW50(), ct++)); } for (comp = complist.begin(); comp != complist.end(); comp++) sorted.push_back(inputList[comp->second]); } inputList.clear(); for (det=sorted.begin();det