Skip to content

GetField15C

anna-dodd edited this page Jun 3, 2015 · 1 revision

Getting and manipulating fields in C (1.5)


Getting a field as a string:

/* Get the FHDR (NITF|NSIF)*/
char fhdr[NITF_FHDR_SZ + 1]; /* Fields are not null-terminated, so add a byte to our array */

/* Retrieve the data as a string with a null-byte on the end */
if (!nitf_Field_get(fhdr, fhdr_str, NITF_CONV_STRING, NITF_FHDR_SZ + 1, &error))
{
    nitf_Error_print(&error, stdout, "Error occured!");
    exit(EXIT_FAILURE);
}


Getting a field as an int:

nitf_Int32 int32;

/* Get the header length out as an integer */
if (!nitf_Field_get(hl, &int32, NITF_CONV_INT, 4, &error))
{
    nitf_Error_print(&error, stdout, "Error occured!");
    exit(EXIT_FAILURE);
}


Getting a field as a real:

/* Get this field as a double */
if (!nitf_Field_get(realField, &doubleData, NITF_CONV_REAL, sizeof(double), &error))
{
    nitf_Error_print(&error, stdout, "Error occured!");
    exit(EXIT_FAILURE);
}

/* Now get the same data as a float */
if (!nitf_Field_get(realField, &floatData, NITF_CONV_REAL, sizeof(float), &error))
{
    nitf_Error_print(&error, stdout, "Error occured!");
    exit(EXIT_FAILURE);
}


Getting a field from a TRE:

/* Get the first element of numpts out */
nitf_Pair* pair = nitf_HashTable_find(tre->hash, "NUMPTS[0]");
nitf_Field* field = (nitf_Field*)pair->data;
int value;
if (!nitf_Field_get(field, &value, NITF_CONV_INT, sizeof(int), &error))
{
     /* ... Handle error ... */
}
Clone this wiki locally