39 static const size_t nLeaderSize = 24;
97 fprintf( fp,
"DDFRecord:\n" );
99 fprintf( fp,
" nDataSize = %d\n",
nDataSize );
101 " _sizeFieldLength=%d, _sizeFieldPos=%d, _sizeFieldTag=%d\n",
153 <<
"Data record is short on DDF file.\n" << std::endl;
190 char szLeader[nLeaderSize+1];
192 memset( szLeader,
' ', nLeaderSize );
194 sprintf( szLeader+0,
"%05d",
195 static_cast<int>(
nDataSize + nLeaderSize) );
199 sprintf( szLeader + 12,
"%05d",
266 char achLeader[nLeaderSize];
269 nReadBytes = (int)fread(achLeader,1,(
int)nLeaderSize,
poModule->
GetFP());
274 else if( nReadBytes != (
int) nLeaderSize )
277 <<
"Leader is short on DDF file." << std::endl;
285 int _recLength, _fieldAreaStart;
289 _leaderIden = achLeader[6];
296 if( _sizeFieldLength < 0 || _sizeFieldLength > 9
297 || _sizeFieldPos < 0 || _sizeFieldPos > 9
298 || _sizeFieldTag < 0 || _sizeFieldTag > 9 )
301 <<
"ISO8211 record leader appears to be corrupt." << std::endl;
305 if( _leaderIden ==
'R' )
313 if(( _recLength < 24 || _recLength > 100000000
314 || _fieldAreaStart < 24 || _fieldAreaStart > 100000 )
315 && (_recLength != 0))
318 <<
"Data record appears to be corrupt on DDF file.\n" 319 <<
" -- ensure that the files were uncompressed without modifying\n" 320 <<
"carriage return/linefeeds (by default WINZIP does this)." 329 if(_recLength != 0) {
340 <<
"Data record is short on DDF file." 359 <<
"Data record is short on DDF file." 365 <<
"Didn't find field terminator, read one more byte." 373 int nFieldEntryWidth;
377 for( i = 0; i <
nDataSize; i += nFieldEntryWidth )
393 int nEntryOffset = i*nFieldEntryWidth;
394 int nFieldLength, nFieldPos;
413 if( poFieldDefn == NULL )
416 <<
"Undefined field `%s' encountered in data record." 417 << szTag << std::endl;
425 pachData + _fieldAreaStart + nFieldPos - nLeaderSize,
440 <<
"Record with zero length, use variant (C.1.5.1) logic." 457 char *tmpBuf = (
char*)malloc(nFieldEntryWidth);
463 if(nFieldEntryWidth !=
464 (
int) fread(tmpBuf, 1, nFieldEntryWidth,
poModule->
GetFP())) {
466 <<
"Data record is short on DDF file." << std::endl;
471 char *newBuf = (
char*)malloc(
nDataSize+nFieldEntryWidth);
476 memcpy(&newBuf[
nDataSize], tmpBuf, nFieldEntryWidth);
487 int rewindSize = nFieldEntryWidth - 1;
489 long pos = ftell(fp) - rewindSize;
490 fseek(fp, pos, SEEK_SET);
500 char *tmpBuf = (
char*)malloc(nFieldLength);
506 <<
"Data record is short on DDF file." << std::endl;
511 char *newBuf = (
char*)malloc(
nDataSize+nFieldLength);
514 memcpy(&newBuf[
nDataSize], tmpBuf, nFieldLength);
528 int nEntryOffset = i*nFieldEntryWidth;
529 int nFieldLength, nFieldPos;
548 if( poFieldDefn == NULL )
551 <<
"Undefined field `%s' encountered in data record." 552 << szTag << std::endl;
562 + nFieldPos - nLeaderSize,
595 if( iFieldIndex == 0 )
647 const char * pszSubfield,
int iSubfieldIndex,
654 if( pnSuccess == NULL )
655 pnSuccess = &nDummyErr;
662 poField =
FindField( pszField, iFieldIndex );
663 if( poField == NULL )
672 if( poSFDefn == NULL )
713 const char * pszSubfield,
int iSubfieldIndex,
720 if( pnSuccess == NULL )
721 pnSuccess = &nDummyErr;
728 poField =
FindField( pszField, iFieldIndex );
729 if( poField == NULL )
738 if( poSFDefn == NULL )
782 const char * pszSubfield,
int iSubfieldIndex,
789 if( pnSuccess == NULL )
790 pnSuccess = &nDummyErr;
797 poField =
FindField( pszField, iFieldIndex );
798 if( poField == NULL )
807 if( poSFDefn == NULL )
980 for( iTarget = 0; iTarget <
nFieldCount; iTarget++ )
1038 for( iTarget = 0; iTarget <
nFieldCount; iTarget++ )
1053 int nBytesToAdd = nNewDataSize - poField->
GetDataSize();
1054 const char *pachOldData =
pachData;
1057 if( nBytesToAdd > 0 )
1084 if( nBytesToMove > 0 )
1100 if( nBytesToAdd < 0 )
1104 char *pszOldDataLocation;
1109 pszOldDataLocation + nBytesToAdd,
1117 char *pszOldDataLocation;
1122 pszOldDataLocation + nBytesToAdd,
1212 const char *pachRawData,
int nRawDataSize )
1215 int iTarget, nRepeatCount;
1220 for( iTarget = 0; iTarget <
nFieldCount; iTarget++ )
1231 if( iIndexWithinField < 0 || iIndexWithinField > nRepeatCount )
1238 if( iIndexWithinField == nRepeatCount
1241 char *pachFieldData;
1251 if( !
ResizeField( poField, nOldSize + nRawDataSize ) )
1254 pachFieldData = (
char *) poField->
GetData();
1255 memcpy( pachFieldData + nOldSize - 1,
1256 pachRawData, nRawDataSize );
1266 const char *pachWrkData;
1273 pachWrkData = poField->
GetData();
1286 int nPreBytes, nPostBytes, nNewFieldSize;
1288 nNewFieldSize = poField->
GetDataSize() - nInstanceSize + nRawDataSize;
1290 pachNewImage = (
char *) malloc(nNewFieldSize);
1292 nPreBytes = pachWrkData - poField->
GetData();
1293 nPostBytes = poField->
GetDataSize() - nPreBytes - nInstanceSize;
1295 memcpy( pachNewImage, poField->
GetData(), nPreBytes );
1296 memcpy( pachNewImage + nPreBytes + nRawDataSize,
1297 poField->
GetData() + nPreBytes + nInstanceSize,
1299 memcpy( pachNewImage + nPreBytes, pachRawData, nRawDataSize );
1306 memcpy( (
void *) poField->
GetData(), pachNewImage, nNewFieldSize );
1307 free( pachNewImage );
1318 int nStartOffset,
int nOldSize,
1319 const char *pachRawData,
int nRawDataSize )
1322 int iTarget, nRepeatCount;
1327 for( iTarget = 0; iTarget <
nFieldCount; iTarget++ )
1338 if( iIndexWithinField < 0 || iIndexWithinField >= nRepeatCount )
1345 int nInstanceSize, nPostBytes, nPreBytes;
1349 nPreBytes = pachWrkData - poField->
GetData() + nStartOffset;
1350 nPostBytes = poField->
GetDataSize() - nPreBytes - nOldSize;
1356 if( nOldSize == nRawDataSize )
1358 memcpy( pachWrkData + nStartOffset, pachRawData, nRawDataSize );
1366 if( nRawDataSize < nOldSize )
1368 memcpy( ((
char*) poField->
GetData()) + nPreBytes,
1369 pachRawData, nRawDataSize );
1370 memmove( ((
char *) poField->
GetData()) + nPreBytes + nRawDataSize,
1371 ((
char *) poField->
GetData()) + nPreBytes + nOldSize,
1379 poField->
GetDataSize() - nOldSize + nRawDataSize ) )
1386 if( nRawDataSize >= nOldSize )
1388 memmove( ((
char *) poField->
GetData()) + nPreBytes + nRawDataSize,
1389 ((
char *) poField->
GetData()) + nPreBytes + nOldSize,
1391 memcpy( ((
char*) poField->
GetData()) + nPreBytes,
1392 pachRawData, nRawDataSize );
1420 int nEntrySize, nDirSize;
1435 pachNewData = (
char *) malloc(nNewDataSize);
1436 memcpy( pachNewData + nDirSize,
1438 nNewDataSize - nDirSize );
1447 pachNewData + nOffset,
1466 sprintf( szFormat,
"%%%ds%%0%dd%%0%dd",
1469 sprintf(
pachData + nEntrySize * iField, szFormat,
1501 int iIndexWithinField )
1504 int nRawSize, nSuccess;
1508 if( pachRawData == NULL )
1511 nSuccess =
SetFieldRaw( poField, iIndexWithinField, pachRawData, nRawSize);
1513 free( pachRawData );
1541 const char *pszSubfield,
int iSubfieldIndex,
1542 const char *pszValue,
int nValueLength )
1550 poField =
FindField( pszField, iFieldIndex );
1551 if( poField == NULL )
1560 if( poSFDefn == NULL )
1576 char *pachSubfieldData = (
char *)
1589 pachSubfieldData = (
char *)
1598 int nExistingLength;
1600 poSFDefn->
GetDataLength( pachSubfieldData, nMaxBytes, &nExistingLength );
1602 if( nExistingLength == nFormattedLen )
1605 NULL, pszValue, nValueLength );
1611 const char *pachFieldInstData;
1612 int nInstanceSize, nStartOffset, nSuccess;
1618 nStartOffset = pachSubfieldData - pachFieldInstData;
1620 pachNewData = (
char *) malloc(nFormattedLen);
1622 pszValue, nValueLength );
1625 nStartOffset, nExistingLength,
1626 pachNewData, nFormattedLen );
1628 free( pachNewData );
1653 const char *pszSubfield,
int iSubfieldIndex,
1662 poField =
FindField( pszField, iFieldIndex );
1663 if( poField == NULL )
1672 if( poSFDefn == NULL )
1680 if( !poSFDefn->
FormatIntValue( NULL, 0, &nFormattedLen, nNewValue ) )
1687 char *pachSubfieldData = (
char *)
1700 pachSubfieldData = (
char *)
1709 int nExistingLength;
1711 poSFDefn->
GetDataLength( pachSubfieldData, nMaxBytes, &nExistingLength );
1713 if( nExistingLength == nFormattedLen )
1715 return poSFDefn->
FormatIntValue( pachSubfieldData, nFormattedLen,
1722 const char *pachFieldInstData;
1723 int nInstanceSize, nStartOffset, nSuccess;
1729 nStartOffset = pachSubfieldData - pachFieldInstData;
1731 pachNewData = (
char *) malloc(nFormattedLen);
1736 nStartOffset, nExistingLength,
1737 pachNewData, nFormattedLen );
1739 free( pachNewData );
1764 const char *pszSubfield,
int iSubfieldIndex,
1773 poField =
FindField( pszField, iFieldIndex );
1774 if( poField == NULL )
1783 if( poSFDefn == NULL )
1798 char *pachSubfieldData = (
char *)
1805 if( nMaxBytes == 0 ||
1811 pachSubfieldData = (
char *)
1820 int nExistingLength;
1822 poSFDefn->
GetDataLength( pachSubfieldData, nMaxBytes, &nExistingLength );
1824 if( nExistingLength == nFormattedLen )
1833 const char *pachFieldInstData;
1834 int nInstanceSize, nStartOffset, nSuccess;
1840 nStartOffset = (int) (pachSubfieldData - pachFieldInstData);
1842 pachNewData = (
char *) malloc(nFormattedLen);
1847 nStartOffset, nExistingLength,
1848 pachNewData, nFormattedLen );
1850 free( pachNewData );
void Dump(FILE *)
Write out record contents to debugging file.
void Initialize(ossimDDFFieldDefn *, const char *pszData, int nSize)
const char * ExtractStringData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a zero terminated string containing the data for this subfield.
void RemoveCloneRecord(ossimDDFRecord *)
Information from the DDR defining one field.
int FormatFloatValue(char *pachData, int nBytesAvailable, int *pnBytesUsed, double dfNewValue)
Format float subfield value.
int GetDataSize()
Return the number of bytes in the data block returned by GetData().
double ExtractFloatData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a subfield value as a float.
const char * GetName()
Fetch a pointer to the field name (tag).
char * GetDefaultValue(int *pnSize)
Return default data for field instance.
int FormatStringValue(char *pachData, int nBytesAvailable, int *pnBytesUsed, const char *pszValue, int nValueLength=-1)
Format string subfield value.
int GetDataSize()
Fetch size of records raw data (GetData()) in bytes.
int UpdateFieldRaw(ossimDDFField *poField, int iIndexWithinField, int nStartOffset, int nOldSize, const char *pachRawData, int nRawDataSize)
ossimDDFField * FindField(const char *, int=0)
Find the named field within this record.
int SetStringSubfield(const char *pszField, int iFieldIndex, const char *pszSubfield, int iSubfieldIndex, const char *pszValue, int nValueLength=-1)
Set a string subfield in record.
ossimDDFRecord * Clone()
Make a copy of a record.
int CreateDefaultFieldInstance(ossimDDFField *poField, int iIndexWithinField)
Initialize default instance.
int SetFloatSubfield(const char *pszField, int iFieldIndex, const char *pszSubfield, int iSubfieldIndex, double dfNewValue)
Set a float subfield in record.
const char * GetSubfieldData(ossimDDFSubfieldDefn *, int *=NULL, int=0)
Fetch raw data pointer for a particular subfield of this field.
ossimDDFFieldDefn * FindFieldDefn(const char *)
Fetch the definition of the named field.
ossimDDFField * GetField(int)
Fetch field object based on index.
int FormatIntValue(char *pachData, int nBytesAvailable, int *pnBytesUsed, int nNewValue)
Format int subfield value.
double GetFloatSubfield(const char *, int, const char *, int, int *=NULL)
Fetch value of a subfield as a float (double).
This object represents one field in a DDFRecord.
int DeleteField(ossimDDFField *poField)
Delete a field instance from a record.
ossimDDFRecord(ossimDDFModule *)
ossimDDFField * paoFields
int GetRepeatCount()
How many times do the subfields of this record repeat? This will always be one for non-repeating fie...
int Write()
Write record out to module.
int SetFieldRaw(ossimDDFField *poField, int iIndexWithinField, const char *pachRawData, int nRawDataSize)
Set the raw contents of a field instance.
ossimDDFSubfieldDefn * FindSubfieldDefn(const char *)
Find a subfield definition by it's mnemonic tag.
ossimDDFField * AddField(ossimDDFFieldDefn *)
Add a new field to record.
const char * GetStringSubfield(const char *, int, const char *, int, int *=NULL)
Fetch value of a subfield as a string.
int ResizeField(ossimDDFField *poField, int nNewDataSize)
Alter field data size within record.
const char * GetData()
Return the pointer to the entire data block for this record.
ossimDDFModule * poModule
const char * GetInstanceData(int nInstance, int *pnSize)
Get field instance data and size.
int SetIntSubfield(const char *pszField, int iFieldIndex, const char *pszSubfield, int iSubfieldIndex, int nValue)
Set an integer subfield in record.
void Dump(FILE *fp)
Write out field contents to debugging file.
int GetIntSubfield(const char *, int, const char *, int, int *=NULL)
Fetch value of a subfield as an integer.
ossimDDFFieldDefn * GetFieldDefn()
Fetch the corresponding DDFFieldDefn.
int ExtractIntData(const char *pachData, int nMaxBytes, int *pnConsumedBytes)
Extract a subfield value as an integer.
The primary class for reading ISO 8211 files.
int GetDataLength(const char *, int, int *)
Scan for the end of variable length data.
long ossimDDFScanInt(const char *pszString, int nMaxChars)
ossimDDFRecord * CloneOn(ossimDDFModule *)
Recreate a record referencing another module.
Contains instance data from one data record (DR).
OSSIMDLLEXPORT void * ossimCPLRealloc(void *pData, size_t nNewSize)
void AddCloneRecord(ossimDDFRecord *)
int IsRepeating()
Fetch repeating flag.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
Information from the DDR record describing one subfield of a DDFFieldDefn.
const char * GetData()
Fetch the raw data for this record.
#define OSSIM_DDF_FIELD_TERMINATOR