"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/metgm/MetGmCommentAttributeParser.cc" between
fimex-1.4.1.tar.gz and fimex-1.4.2.tar.gz

About: Fimex is a the File Interpolation, Manipulation and EXtraction library for gridded geospatial data. It converts between different, extensible dataformats (currently netcdf, NcML, grib1/2 and felt).

MetGmCommentAttributeParser.cc  (fimex-1.4.1):MetGmCommentAttributeParser.cc  (fimex-1.4.2)
/* /*
* Fimex * Fimex
* *
* (C) Copyright 2011, met.no * (C) Copyright 2011-2019, met.no
* *
* Project Info: https://wiki.met.no/fimex/start * Project Info: https://wiki.met.no/fimex/start
* *
* This library is free software; you can redistribute it and/or modify it * This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by * under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, but * This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
skipping to change at line 31 skipping to change at line 31
* USA. * USA.
*/ */
// internals // internals
// //
#include "MetGmCommentAttributeParser.h" #include "MetGmCommentAttributeParser.h"
// fimex // fimex
// //
#include "fimex/CDM.h" #include "fimex/CDM.h"
#include "fimex/CDMAttribute.h"
#include "fimex/CDMException.h" #include "fimex/CDMException.h"
#include "fimex/CDMReader.h"
#include "fimex/Logger.h" #include "fimex/Logger.h"
#include "fimex/Units.h"
#include "fimex/XMLDoc.h" #include "fimex/XMLDoc.h"
// libxml2 // libxml2
// //
#include <libxml/tree.h> #include <libxml/tree.h>
#include <libxml/xpath.h> #include <libxml/xpath.h>
// standard
//
#include <iostream>
namespace MetNoFimex { namespace MetNoFimex {
static Logger_p logger = getLogger("fimex.MetGmCDMWriter.MetGmCommentAttribute") ; static Logger_p logger = getLogger("fimex.MetGmCDMWriter.MetGmCommentAttribute") ;
const std::string FREE_TEXT = "metgm_free_text";
const std::string VERSION = "metgm_version";
const std::string ANALYSIS_DATE_TIME = "metgm_analysis_date_time";
const std::string START_DATE_TIME = "metgm_start_date_time";
const std::string DATA_TYPE = "metgm_data_type";
const std::string MODEL_TYPE = "metgm_model_type";
const std::string PRODUCTION_NATION = "metgm_production_nation";
std::shared_ptr<MetGmCommentAttributeParser> MetGmCommentAttributeParser::create MetGmCommentAttributeParser(const CDMReader_p& pCdmReader) std::shared_ptr<MetGmCommentAttributeParser> MetGmCommentAttributeParser::create MetGmCommentAttributeParser(const CDMReader_p& pCdmReader)
{ {
std::shared_ptr<MetGmCommentAttributeParser> parser = std::shared_ptr<MetGmC ommentAttributeParser>(new MetGmCommentAttributeParser); std::shared_ptr<MetGmCommentAttributeParser> parser = std::shared_ptr<MetGmC ommentAttributeParser>(new MetGmCommentAttributeParser);
CDMAttribute metgmMetaData; // encoded within comment CDMAttribute metgmMetaData; // encoded within comment
if(pCdmReader->getCDM().getAttribute(pCdmReader->getCDM().globalAttributeNS( ), "comment", metgmMetaData)) { if(pCdmReader->getCDM().getAttribute(pCdmReader->getCDM().globalAttributeNS( ), "comment", metgmMetaData)) {
try { try {
std::string commentStr = metgmMetaData.getStringValue(); std::string commentStr = metgmMetaData.getStringValue();
if (! (commentStr.size() > 0 && commentStr.substr(0,1) == "<")) thro w CDMException("comment not xml"); if (! (commentStr.size() > 0 && commentStr.substr(0,1) == "<")) thro w CDMException("comment not xml");
XMLDoc_p doc = XMLDoc::fromString(metgmMetaData.getStringValue()); XMLDoc_p doc = XMLDoc::fromString(metgmMetaData.getStringValue());
if(doc.get() != 0) { if(doc.get() != 0) {
xmlXPathObject_p xpathObj = doc->getXPathObject("/meta_data/attr ibute"); xmlXPathObject_p xpathObj = doc->getXPathObject("/meta_data/attr ibute");
xmlNodeSetPtr nodes = xpathObj->nodesetval; xmlNodeSetPtr nodes = xpathObj->nodesetval;
size_t size = (nodes) ? nodes->nodeNr : 0; size_t size = (nodes) ? nodes->nodeNr : 0;
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
xmlNodePtr node = nodes->nodeTab[i]; xmlNodePtr node = nodes->nodeTab[i];
std::string attributeName = getXmlProp(node, "name"); std::string attributeName = getXmlProp(node, "name");
if(attributeName == std::string(FREE_TEXT)) { if (attributeName == FREE_TEXT) {
parser->freeText_ = getXmlProp(node, "value"); parser->freeText_ = getXmlProp(node, "value");
} else if(attributeName == std::string(VERSION)) { } else if (attributeName == VERSION) {
parser->version_ = getXmlProp(node, "value"); parser->version_ = getXmlProp(node, "value");
} else if(attributeName == std::string(DATA_TYPE)) { } else if (attributeName == DATA_TYPE) {
parser->dataType_ = getXmlProp(node, "value"); parser->dataType_ = getXmlProp(node, "value");
} else if(attributeName == std::string(MODEL_TYPE)) { } else if (attributeName == MODEL_TYPE) {
parser->modelType_ = getXmlProp(node, "value"); parser->modelType_ = getXmlProp(node, "value");
} else if(attributeName == std::string(PRODUCTION_NATION)) { } else if (attributeName == PRODUCTION_NATION) {
parser->productNation_ = getXmlProp(node, "value"); parser->productNation_ = getXmlProp(node, "value");
} else if(attributeName == std::string(ANALYSIS_DATE_TIME)) { } else if (attributeName == ANALYSIS_DATE_TIME) {
parser->analysisDateTime_ = getXmlProp(node, "value"); parser->analysisDateTime_ = getXmlProp(node, "value");
} else if(attributeName == std::string(START_DATE_TIME)) { } else if (attributeName == START_DATE_TIME) {
parser->startDateTime_ = getXmlProp(node, "value"); parser->startDateTime_ = getXmlProp(node, "value");
} }
} }
} }
} catch (CDMException& exception) { } catch (CDMException& exception) {
// ignore // ignore
LOG4FIMEX(logger, Logger::DEBUG, "failed parsing global attribute 'c omment' as xml: '" << metgmMetaData.getStringValue() << "'"); LOG4FIMEX(logger, Logger::DEBUG, "failed parsing global attribute 'c omment' as xml: '" << metgmMetaData.getStringValue() << "'");
} }
} }
return parser; return parser;
} }
} } // namespace MetNoFimex
 End of changes. 14 change blocks. 
13 lines changed or deleted 18 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)