38 lines
1.0 KiB
C++
38 lines
1.0 KiB
C++
#include "io/gpr/IprbReader.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <stdexcept>
|
|
|
|
namespace geopro::io::gpr {
|
|
|
|
BScan readIprb(const std::string& path, const IprHeader& h) {
|
|
std::ifstream f(path, std::ios::binary | std::ios::ate);
|
|
if (!f) {
|
|
throw std::runtime_error("readIprb: 无法打开文件: " + path);
|
|
}
|
|
|
|
const std::streamsize fileSize = f.tellg();
|
|
const std::int64_t traces = static_cast<std::int64_t>(h.lastTrace) + 1;
|
|
const std::int64_t count = static_cast<std::int64_t>(h.samples) * traces;
|
|
const std::int64_t expected = count * 2;
|
|
if (fileSize != expected) {
|
|
throw std::runtime_error("readIprb: 文件大小与 samples*traces*2 不符: " + path);
|
|
}
|
|
|
|
BScan b;
|
|
b.samples = h.samples;
|
|
b.traces = traces;
|
|
b.data.resize(static_cast<std::size_t>(h.samples) * traces);
|
|
|
|
f.seekg(0, std::ios::beg);
|
|
f.read(reinterpret_cast<char*>(b.data.data()), static_cast<std::streamsize>(expected));
|
|
if (!f) {
|
|
throw std::runtime_error("readIprb: 读取数据失败: " + path);
|
|
}
|
|
|
|
return b;
|
|
}
|
|
|
|
} // namespace geopro::io::gpr
|