* LoadRPCTxtFile */
| 295 | * LoadRPCTxtFile |
| 296 | */ |
| 297 | char **GDALMDReaderALOS::LoadRPCTxtFile() |
| 298 | { |
| 299 | if (m_osRPBSourceFilename.empty()) |
| 300 | return nullptr; |
| 301 | |
| 302 | const CPLStringList aosLines(CSLLoad(m_osRPBSourceFilename)); |
| 303 | if (aosLines.empty()) |
| 304 | return nullptr; |
| 305 | |
| 306 | const char *pszFirstRow = aosLines[0]; |
| 307 | CPLStringList aosRPB; |
| 308 | if (nullptr != pszFirstRow) |
| 309 | { |
| 310 | static const struct |
| 311 | { |
| 312 | const char *pszName; |
| 313 | int nSize; |
| 314 | } apsFieldDescriptors[] = { |
| 315 | {RPC_LINE_OFF, 6}, {RPC_SAMP_OFF, 5}, {RPC_LAT_OFF, 8}, |
| 316 | {RPC_LONG_OFF, 9}, {RPC_HEIGHT_OFF, 5}, {RPC_LINE_SCALE, 6}, |
| 317 | {RPC_SAMP_SCALE, 5}, {RPC_LAT_SCALE, 8}, {RPC_LONG_SCALE, 9}, |
| 318 | {RPC_HEIGHT_SCALE, 5}, |
| 319 | }; |
| 320 | |
| 321 | int nRequiredSize = 0; |
| 322 | for (const auto &sFieldDescriptor : apsFieldDescriptors) |
| 323 | { |
| 324 | nRequiredSize += sFieldDescriptor.nSize; |
| 325 | } |
| 326 | |
| 327 | static const char *const apszRPCTXT20ValItems[] = { |
| 328 | RPC_LINE_NUM_COEFF, RPC_LINE_DEN_COEFF, RPC_SAMP_NUM_COEFF, |
| 329 | RPC_SAMP_DEN_COEFF}; |
| 330 | |
| 331 | constexpr int RPC_COEFF_COUNT1 = CPL_ARRAYSIZE(apszRPCTXT20ValItems); |
| 332 | constexpr int RPC_COEFF_COUNT2 = 20; |
| 333 | constexpr int RPC_COEFF_SIZE = 12; |
| 334 | nRequiredSize += RPC_COEFF_COUNT1 * RPC_COEFF_COUNT2 * RPC_COEFF_SIZE; |
| 335 | if (strlen(pszFirstRow) < static_cast<size_t>(nRequiredSize)) |
| 336 | { |
| 337 | CPLError(CE_Failure, CPLE_AppDefined, |
| 338 | "%s has only %d bytes wherea %d are required", |
| 339 | m_osRPBSourceFilename.c_str(), int(strlen(pszFirstRow)), |
| 340 | nRequiredSize); |
| 341 | return nullptr; |
| 342 | } |
| 343 | |
| 344 | int nOffset = 0; |
| 345 | char buff[16] = {0}; |
| 346 | for (const auto &sFieldDescriptor : apsFieldDescriptors) |
| 347 | { |
| 348 | CPLAssert(sFieldDescriptor.nSize < int(sizeof(buff))); |
| 349 | memcpy(buff, pszFirstRow + nOffset, sFieldDescriptor.nSize); |
| 350 | buff[sFieldDescriptor.nSize] = 0; |
| 351 | aosRPB.SetNameValue(sFieldDescriptor.pszName, buff); |
| 352 | nOffset += sFieldDescriptor.nSize; |
| 353 | } |
| 354 |