69 std::size_t bytesReadSoFar,
70 std::size_t totalSizeOfAllDatFiles)
72 const SGPath path = sceneryLocation.
datPath;
73 sg_gzifstream in( path );
74 const std::string utf8path = path.utf8Str();
76 if ( !in.is_open() ) {
77 throw sg_io_exception(
78 "Cannot open file (" + simgear::strutils::error_string(errno) +
")",
83 for (
int i = 0;
i < 2;
i++) {
85 throwExceptionIfStreamError(in, path);
88 unsigned int lineNumber = 3;
91 for (std::string line; std::getline(in, line); lineNumber++) {
92 std::vector<std::string> fields = simgear::strutils::split(line);
93 std::vector<std::string>::size_type nb_fields = fields.size();
94 const std::string endOfData =
"99";
98 }
else if (nb_fields == 1) {
99 if (fields[0] == endOfData)
102 SG_LOG(SG_NAVAID, SG_WARN, utf8path <<
": malformed line #" <<
103 lineNumber <<
": only one field, but it is not '99'");
106 }
else if (nb_fields < 3) {
107 SG_LOG(SG_NAVAID, SG_WARN, utf8path <<
": malformed line #" <<
108 lineNumber <<
": expected at least 3 fields, but got " <<
111 }
else if (nb_fields != 3 && nb_fields != 5 && nb_fields != 6) {
116 SG_LOG(SG_NAVAID, SG_INFO, utf8path <<
": line #" <<
117 lineNumber <<
": ignoring extra fields, past the first three " <<
118 "(expected 3 or 5 or 6 fields, but got " << fields.size() <<
")");
121 std::string ident = fields[2];
124 lat = std::stod(fields[0]);
125 lon = std::stod(fields[1]);
126 }
catch (
const std::exception&) {
127 SG_LOG(SG_NAVAID, SG_WARN, utf8path <<
": malformed line #" <<
128 lineNumber <<
": error parsing coordinates: " << fields[0] <<
132 SGGeod pos(SGGeod::fromDeg(lon, lat));
133 bool duplicate =
false;
134 auto range = _loadedFixes.equal_range(ident);
135 for (
auto it = range.first; it != range.second; ++it) {
136 double distNm = dist(SGVec3d::fromGeod(pos),
137 SGVec3d::fromGeod(it->second)) * SG_METER_TO_NM;
139 SG_LOG(SG_NAVAID, SG_INFO,
140 utf8path <<
":" << lineNumber <<
": skipping fix " <<
141 ident <<
" (already defined nearby)");
149 _loadedFixes.insert({ident, pos});
152 if ((lineNumber % 100) == 0) {
154 unsigned int percent = ((bytesReadSoFar + in.approxOffset()) * 100)
155 / totalSizeOfAllDatFiles;
160 throwExceptionIfStreamError(in, path);