/***********************************************************************//** * @brief Read observations from XML document * * @param[in] xml XML document. * * @exception GException::invalid_instrument * Invalid instrument encountered. * * Reads observations from the first observation list that is found in the * XML document. The decoding of the instrument specific observation * definition is done within the observation's read() method. * * @todo Observation names and IDs are not verified so far for uniqueness. * This would be required to achieve an unambiguous update of parameters * in an already existing XML file when using the write method. ***************************************************************************/ void GObservations::read(const GXml& xml) { // Get pointer on observation library GXmlElement* lib = xml.element("observation_list", 0); // Loop over all observations int n = lib->elements("observation"); for (int i = 0; i < n; ++i) { // Get pointer on observation GXmlElement* obs = static_cast<GXmlElement*>(lib->element("observation", i)); // Get attributes std::string name = obs->attribute("name"); std::string id = obs->attribute("id"); std::string instrument = obs->attribute("instrument"); // Get model GObservationRegistry registry; GObservation* ptr = registry.alloc(instrument); // If observation is valid then read its definition from XML file if (ptr != NULL) { // Read definition ptr->read(*obs); // Set attributes ptr->name(name); ptr->id(id); } // endif: observation was valid // ... otherwise throw an exception else { throw GException::invalid_instrument(G_READ, instrument); } // Append observation to container append(*ptr); // Free model (appending clones the observation) delete ptr; } // endfor: looped over all observations // Return return; }