In ogdi/drivers/rpf/utils.c:
NITF header length detection:
if (strcmp(NITF, "NITF") == 0) /* Match: skip NITF hdr */
{
fseek(fin,413, SEEK_SET) ;
fseek(fin, 31, SEEK_CUR) ; /* Key off date, pos 32 in RPF header */
fread( date, sizeof(date), 1, fin);
if (strncmp(date,"199",3) == 0) /* Check for short 413 hdr */
file->NITF_hdr_len = 413L;
else /* Else long 426 hdr */
file->NITF_hdr_len = 426L;
}
This code does not work in all cases, specifically in CIB archives created by Erdas Imagine 9.3.
These archives have a 413 byte NITF header, but contain a string starting with "2000" at pos 32 in the RPF header.
Further research finds that the newest version of mil-std-2411 was released on March 28, 2000, which is the date the Erdas Imagine archive has in its header.
I would suggest using the filename field rather than the date to detect the length of the NITF header:
const char * find_last_of(const char *haystack, char needle)
{
const char *last_ptr = 0;
const char *cur_ptr = haystack;
while ( (cur_ptr = strchr(cur_ptr, needle)) != NULL)
{
++cur_ptr;
last_ptr = cur_ptr;
}
return last_ptr;
}
if (strcmp(NITF, "NITF") == 0) /* Match: skip NITF hdr */
{
const char *file_only = find_last_of(filename, DIR_CHAR);
fseek(fin,413, SEEK_SET) ;
fseek(fin, 3, SEEK_CUR) ; /* Key off date, pos 3 in RPF header */
fread( rpf_filename, sizeof(rpf_filename), 1, fin);
if (strncmp(rpf_filename, file_only, strlen(file_only)) == 0) /* Check for short 413 hdr */
file->NITF_hdr_len = 413L;
else /* Else long 426 hdr */
file->NITF_hdr_len = 426L;
}