MCPcopy Create free account
hub / github.com/OSGeo/gdal / LoadRPCTxtFile

Method LoadRPCTxtFile

gcore/mdreader/reader_alos.cpp:297–373  ·  view source on GitHub ↗

* LoadRPCTxtFile */

Source from the content-addressed store, hash-verified

295 * LoadRPCTxtFile
296 */
297char **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

Callers

nothing calls this directly

Calls 6

CSLLoadFunction · 0.85
CPLErrorFunction · 0.85
SetNameValueMethod · 0.80
StealListMethod · 0.80
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected