/***********************************************************************//** * @brief Equality operator * * @param[in] a First sky direction. * @param[in] b Second sky direction. * * Compare two sky directions. If the coordinate is at the pole, the Right * Ascension or Longitude value is irrelevant. * * Comparisons are done dependent on the available coordinate system. This * speeds up things and avoids unnecessary coordinate transformations. ***************************************************************************/ bool operator==(const GSkyDir &a, const GSkyDir &b) { // Initialise result bool equal = false; // Compute dependent on coordinate system availability. This speeds // up things by avoiding unnecessary coordinate transformations. if (a.m_has_lb && b.m_has_lb) { if (std::abs(a.m_b) == 90.0) equal = (a.m_b == b.m_b); else equal = (a.m_b == b.m_b && a.m_l == b.m_l); } else if (a.m_has_radec && b.m_has_radec) { if (std::abs(a.m_dec) == 90.0) equal = (a.m_dec == b.m_dec); else equal = (a.m_dec == b.m_dec && a.m_ra == b.m_ra); } else if (a.m_has_lb) { if (std::abs(a.m_b) == 90.0) equal = (a.m_b == b.b()); else equal = (a.m_b == b.b() && a.m_l == b.l()); } else if (a.m_has_radec) { if (std::abs(a.m_dec) == 90.0) equal = (a.m_dec == b.dec()); else equal = (a.m_dec == b.dec() && a.m_ra == b.ra()); } else { if (std::abs(b.dec()) == 90.0) equal = (b.dec() == a.dec()); else equal = (b.dec() == a.dec() && b.ra() == a.ra()); } // Return equality return equal; }
/***********************************************************************//** * @brief Read model from XML element * * @param[in] xml XML element. * * @exception GException::model_invalid_parnum * Invalid number of model parameters found in XML element. * @exception GException::model_invalid_parnames * Invalid model parameter names found in XML element. * * Read the radial source location information from an XML element. The XML * element is required to have at least 2 parameters. * The location is named either "RA" and "DEC" or "GLON" and "GLAT". ***************************************************************************/ void GModelRadial::read(const GXmlElement& xml) { // Determine number of parameter nodes in XML element int npars = xml.elements("parameter"); // Verify that XML element has at least 2 parameters if (xml.elements() < 2 || npars < 2) { throw GException::model_invalid_parnum(G_READ, xml, "Radial model requires at least 2 parameters."); } // Extract model parameters bool has_glon = false; bool has_glat = false; int npar[2] = {0, 0}; for (int i = 0; i < npars; ++i) { // Get parameter element GXmlElement* par = static_cast<GXmlElement*>(xml.element("parameter", i)); // Handle RA/GLON if (par->attribute("name") == "RA") { m_ra.read(*par); npar[0]++; } else if (par->attribute("name") == "GLON") { m_ra.read(*par); npar[0]++; has_glon = true; } // Handle DEC/GLAT else if (par->attribute("name") == "DEC") { m_dec.read(*par); npar[1]++; } else if (par->attribute("name") == "GLAT") { m_dec.read(*par); npar[1]++; has_glat = true; } } // endfor: looped over all parameters // Check if we have to convert GLON/GLAT into RA/DEC if (has_glon && has_glat) { GSkyDir dir; dir.lb_deg(ra(), dec()), m_ra.real_value(dir.ra_deg()); m_dec.real_value(dir.dec_deg()); } else if (has_glon || has_glat) { throw GException::model_invalid_parnames(G_READ, xml, "Require either \"RA\"/\"DEC\" or \"GLON\"/\"GLAT\"."); } // Verify that all parameters were found if (npar[0] != 1 || npar[1] != 1) { throw GException::model_invalid_parnames(G_READ, xml, "Require \"RA\"/\"DEC\" and \"GLON\"/\"GLAT\" parameters."); } // Return return; }