bool DistributeInterpolate::loadDistributionAndDistribute(std::string FilePath) { long UnitID; long DataSrcID; int i; ColumnTextParser DistriFileParser("%"); if (boost::filesystem::exists(boost::filesystem::path(FilePath))) { if ((DistriFileParser.loadFromFile(FilePath)) && (DistriFileParser.getColsCount() == 2) && (DistriFileParser.getLinesCount() >0)) { for (i=0;i<DistriFileParser.getLinesCount();i++) { if (DistriFileParser.getLongValue(i,0,&UnitID) && DistriFileParser.getLongValue(i,1,&DataSrcID)) { if (m_InterpData.find(DataSrcID) != m_InterpData.end()) { m_UnitsData[UnitID] = m_InterpData[DataSrcID]; m_UnitsIndexedData[UnitID] = m_InterpIndexedData[DataSrcID]; } else { throw openfluid::base::OFException("OpenFLUID framework","DistributeInterpolate::loadDistributionAndDistribute","Error in distribution file " + m_DistributionFilename + ", data source ID not found"); return false; } } else { throw openfluid::base::OFException("OpenFLUID framework","DistributeInterpolate::loadDistributionAndDistribute","Error in distribution file " + m_DistributionFilename + ", format error"); return false; } } } else { throw openfluid::base::OFException("OpenFLUID framework","DistributeInterpolate::loadDistributionAndDistribute","Error in distribution file " + m_DistributionFilename + ", file not found or format error"); return false; } } else { throw openfluid::base::OFException("OpenFLUID framework","DistributeInterpolate::loadDistributionAndDistribute","Distribution file " + m_DistributionFilename + " not found"); return false; } return true; }
void DistributionTables::build(const std::string& BasePath, const std::string& SourcesFileName, const std::string& DistributionFileName) { SourcesTable.clear(); UnitsTable.clear(); // Sources file QDomDocument Doc; QDomElement Root; std::string SourcesFilePath = BasePath+"/"+SourcesFileName; QFile File(QString(SourcesFilePath.c_str())); if (!File.open(QIODevice::ReadOnly)) { throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION, "Error opening " + SourcesFilePath); } bool Parsed = Doc.setContent(&File); File.close(); if (Parsed) { Root = Doc.documentElement(); if (!Root.isNull()) { if (Root.tagName() == QString("openfluid")) { for(QDomElement CurrNode = Root.firstChildElement(); !CurrNode.isNull(); CurrNode = CurrNode.nextSiblingElement()) { if (CurrNode.tagName() == QString("datasources")) { for(QDomElement CurrNode2 = CurrNode.firstChildElement(); !CurrNode2.isNull(); CurrNode2 = CurrNode2.nextSiblingElement()) { if (CurrNode2.tagName() == QString("filesource")) { QString xmlID = CurrNode2.attributeNode(QString("ID")).value(); QString xmlFile = CurrNode2.attributeNode(QString("file")).value(); if (!xmlID.isNull() && !xmlFile.isNull()) { SourcesTable[xmlID.toStdString()] = BasePath + "/" + xmlFile.toStdString(); } } } } } } else throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION, "Cannot find <openfluid> tag in sources file " + SourcesFilePath); } else throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"Wrong formatted sources file " + SourcesFilePath); } else throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"Cannot open sources file " + SourcesFilePath); // Units distribution file long UnitID; std::string DataSrcID; ColumnTextParser DistriFileParser("%"); std::string DistributionFilePath = BasePath+"/"+DistributionFileName; if (openfluid::tools::Filesystem::isFile(DistributionFilePath)) { if (DistriFileParser.loadFromFile(DistributionFilePath) && DistriFileParser.getColsCount() == 2 && DistriFileParser.getLinesCount() >0) { for (unsigned int i=0;i<DistriFileParser.getLinesCount();i++) { if (DistriFileParser.getLongValue(i,0,&UnitID) && DistriFileParser.getStringValue(i,1,&DataSrcID)) { if (SourcesTable.find(DataSrcID) != SourcesTable.end()) UnitsTable[UnitID] = DataSrcID; else throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION, "Error in distribution file " + DistributionFilePath + ", data source ID not found"); } else throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION, "Error in distribution file " + DistributionFilePath + ", format error"); } } else throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION, "Error in distribution file " + DistributionFilePath + ", file not found or format error"); } else throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION, "Distribution file " + DistributionFilePath + " not found"); }