void MDAL::DriverFlo2D::parseDEPTHFile( const std::string &datFileName, const std::vector<double> &elevations ) { // this file is optional, so if not present, reading is skipped std::string depthFile( fileNameFromDir( datFileName, "DEPTH.OUT" ) ); if ( !MDAL::fileExists( depthFile ) ) { return; //optional file } std::ifstream depthStream( depthFile, std::ifstream::in ); std::string line; size_t nVertices = mMesh->verticesCount(); std::vector<double> maxDepth( nVertices ); std::vector<double> maxWaterLevel( nVertices ); size_t vertex_idx = 0; // DEPTH.OUT - COORDINATES (ELEM NUM, X, Y, MAX DEPTH) while ( std::getline( depthStream, line ) ) { line = MDAL::rtrim( line ); if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh; std::vector<std::string> lineParts = MDAL::split( line, ' ' ); if ( lineParts.size() != 4 ) { throw MDAL_Status::Err_UnknownFormat; } double val = getDouble( lineParts[3] ); maxDepth[vertex_idx] = val; //water level if ( !is_nodata( val ) ) val += elevations[vertex_idx]; maxWaterLevel[vertex_idx] = val; vertex_idx++; } addStaticDataset( true, maxDepth, "Depth/Maximums", datFileName ); addStaticDataset( true, maxWaterLevel, "Water Level/Maximums", datFileName ); }
static void parseDEPTHFile(const QString&datFileName, Mesh* mesh, const QVector<float>& elevations) { // this file is optional, so if not present, reading is skipped QFileInfo fi(datFileName); QString nodesFileName(fi.dir().filePath("DEPTH.OUT")); QFile nodesFile(nodesFileName); if (!nodesFile.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream nodesStream(&nodesFile); int nnodes = mesh->nodes().size(); QVector<float> maxDepth(nnodes); QVector<float> maxWaterLevel(nnodes); int node_inx = 0; // DEPTH.OUT - COORDINATES (NODE NUM, X, Y, MAX DEPTH) while (!nodesStream.atEnd()) { if (node_inx == nnodes) throw LoadStatus::Err_IncompatibleMesh; QString line = nodesStream.readLine(); QStringList lineParts = line.split(" ", QString::SkipEmptyParts); if (lineParts.size() != 4) { throw LoadStatus::Err_UnknownFormat; } float val = getFloat(lineParts[3]); maxDepth[node_inx] = val; //water level if (!is_nodata(val)) val += elevations[node_inx]; maxWaterLevel[node_inx] = val; node_inx++; } addStaticDataset(maxDepth, "Depth/Maximums", DataSet::Scalar, datFileName, mesh); addStaticDataset(maxWaterLevel, "Water Level/Maximums", DataSet::Scalar, datFileName, mesh); }