static void parseVELFPVELOCFile(const QString&datFileName, Mesh* mesh) { // these files are optional, so if not present, reading is skipped int nnodes = mesh->nodes().size(); QFileInfo fi(datFileName); QVector<float> maxVel(nnodes); { QString nodesFileName(fi.dir().filePath("VELFP.OUT")); QFile nodesFile(nodesFileName); if (!nodesFile.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream nodesStream(&nodesFile); int node_inx = 0; // VELFP.OUT - COORDINATES (NODE NUM, X, Y, MAX VEL) - Maximum floodplain flow velocity; 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]); maxVel[node_inx] = val; node_inx++; } } { QString nodesFileName(fi.dir().filePath("VELOC.OUT")); QFile nodesFile(nodesFileName); if (!nodesFile.open(QIODevice::ReadOnly | QIODevice::Text)) return; QTextStream nodesStream(&nodesFile); int node_inx = 0; // VELOC.OUT - COORDINATES (NODE NUM, X, Y, MAX VEL) - Maximum channel flow velocity 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]); if (!is_nodata(val)) { // overwrite value from VELFP if it is not 0 maxVel[node_inx] = val; } node_inx++; } } addStaticDataset(maxVel, "Velocity/Maximums", DataSet::Scalar, datFileName, mesh); }
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); }
Mesh* Crayfish::loadFlo2D( const QString& datFileName, LoadStatus* status ) { if (status) status->clear(); Mesh* mesh = 0; try { // Parse all nodes Mesh::Nodes nodes; parseCADPTSFile(datFileName, nodes); // Parse all elements Mesh::Elements elements; QVector<float> elevations = parseFPLAINFile(datFileName, elements); // Create mesh mesh = new Mesh(nodes, elements); // create output for bed elevation addStaticDataset(elevations, "Bed Elevation", DataSet::Bed, datFileName, mesh); // Create Depth and Velocity datasets Time varying datasets parseTIMDEPFile(datFileName, mesh, elevations); // Maximum Depth and Water Level parseDEPTHFile(datFileName, mesh, elevations); // Maximum Velocity parseVELFPVELOCFile(datFileName, mesh); } catch (LoadStatus::Error error) { if (status) status->mLastError = (error); if (mesh) delete mesh; mesh = 0; } return mesh; }
std::unique_ptr< MDAL::Mesh > MDAL::DriverFlo2D::load( const std::string &resultsFile, MDAL_Status *status ) { mDatFileName = resultsFile; if ( status ) *status = MDAL_Status::None; mMesh.reset(); std::vector<CellCenter> cells; try { // Parse mMesh info parseCADPTSFile( mDatFileName, cells ); std::vector<double> elevations; parseFPLAINFile( elevations, mDatFileName, cells ); double cell_size = calcCellSize( cells ); // Create mMesh createMesh( cells, cell_size / 2.0 ); // create output for bed elevation addStaticDataset( false, elevations, "Bed Elevation", mDatFileName ); if ( parseHDF5Datasets( mDatFileName ) ) { // some problem with HDF5 data, try text files parseOUTDatasets( mDatFileName, elevations ); } } catch ( MDAL_Status error ) { if ( status ) *status = ( error ); mMesh.reset(); } return std::unique_ptr<Mesh>( mMesh.release() ); }
void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName ) { // these files are optional, so if not present, reading is skipped size_t nVertices = mMesh->verticesCount(); std::vector<double> maxVel( nVertices ); { std::string velocityFile( fileNameFromDir( datFileName, "VELFP.OUT" ) ); if ( !MDAL::fileExists( velocityFile ) ) { return; //optional file } std::ifstream velocityStream( velocityFile, std::ifstream::in ); std::string line; size_t vertex_idx = 0; // VELFP.OUT - COORDINATES (ELEM NUM, X, Y, MAX VEL) - Maximum floodplain flow velocity; while ( std::getline( velocityStream, line ) ) { if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh; line = MDAL::rtrim( line ); std::vector<std::string> lineParts = MDAL::split( line, ' ' ); if ( lineParts.size() != 4 ) { throw MDAL_Status::Err_UnknownFormat; } double val = getDouble( lineParts[3] ); maxVel[vertex_idx] = val; vertex_idx++; } } { std::string velocityFile( fileNameFromDir( datFileName, "VELOC.OUT" ) ); if ( !MDAL::fileExists( velocityFile ) ) { return; //optional file } std::ifstream velocityStream( velocityFile, std::ifstream::in ); std::string line; size_t vertex_idx = 0; // VELOC.OUT - COORDINATES (ELEM NUM, X, Y, MAX VEL) - Maximum channel flow velocity while ( std::getline( velocityStream, line ) ) { if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh; line = MDAL::rtrim( line ); std::vector<std::string> lineParts = MDAL::split( line, ' ' ); if ( lineParts.size() != 4 ) { throw MDAL_Status::Err_UnknownFormat; } double val = getDouble( lineParts[3] ); if ( !is_nodata( val ) ) // overwrite value from VELFP if it is not 0 { maxVel[vertex_idx] = val; } vertex_idx++; } } addStaticDataset( true, maxVel, "Velocity/Maximums", datFileName ); }