Beispiel #1
0
void findInExtensions(nitf_Extensions* ext)
{
    /*  These iterators are for going through the image segments  */
    nitf_ListIterator  iter;
    nitf_ListIterator  end;
    nitf_List* list;
    assert( ext );

    list = nitf_Extensions_get(ext, "ACFTB");
    if (list)
    {
        /*  Set the iterator to traverse the list of image segments  */
        iter = nitf_List_begin(list);
        /*  And set this one to the end, so we'll know when we're done!  */
        end  = nitf_List_end(list);

        /*  While we are not done...  */
        while ( nitf_ListIterator_notEqualTo(&iter, &end) )
        {
            nitf_TRE* tre;

            printf("Found ACFTB instance\n");

            /*  Get the image segment as its proper object  */
            tre = (nitf_TRE*)nitf_ListIterator_get(&iter);
            if ( nitf_HashTable_exists( tre->hash, "raw_data" ) )
            {
                printf("Your plugin for ACFTB was not loaded so the data is contained in the RAW section\n");
            }
            else
            {
                nitf_Pair* mission = nitf_HashTable_find( tre->hash,
                                     "ACMSNID" );
                if (! mission )
                {
                    printf("Error: no Mission ID available\n");
                    nitf_HashTable_print( tre->hash );

                }


                else
                {
                    nitf_Field* field = (nitf_Field*)mission->data;

                    printf("Mission ID: [%.*s]\n", field->length, field->raw);
                }
            }

            /*  Increment the iterator so we can continue  */
            nitf_ListIterator_increment(&iter);
        }
    }
    else
    {
        printf("No ACFTB\n");
    }

}
Beispiel #2
0
int main(int argc, char **argv)
{
    /*  Get the error object       */
    nitf_Error error;

    /* so I can remember what Im doing with args */
    const char* treName;
    const char* fieldName;

    /*  This is the reader object  */
    nitf_Reader *reader;
    nitf_Record *record;
	
    /*  The IO handle  */
    nitf_IOHandle io;
    int num;

    /*  Check argv and make sure we are happy  */
    if (argc != 4)
    {
        printf("Usage: %s <nitf-file> <TRE> <field>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    if (nitf_Reader_getNITFVersion(argv[1]) == NITF_VER_UNKNOWN)
    {
	printf("File: %s is not a NITF\n", argv[1]);
	exit(EXIT_FAILURE);
    }
	
    treName = argv[2];
    fieldName = argv[3];

    io = nitf_IOHandle_create(argv[1], NITF_ACCESS_READONLY,
                              NITF_OPEN_EXISTING, &error);

    if (NITF_INVALID_HANDLE(io))
    {
        nitf_Error_print(&error, stdout, "Exiting...");
        exit(EXIT_FAILURE);
    }

    reader = nitf_Reader_construct(&error);
    if (!reader)
    {
        nitf_Error_print(&error, stdout, "Exiting (1) ...");
        exit(EXIT_FAILURE);
    }
   
#if NITF_VERBOSE_READER
    printf("Here are the loaded handlers\n");
    printf("* * * * * * * * * * * * * * * *\n");
    nitf_HashTable_print(reader->reg->treHandlers);
    printf("* * * * * * * * * * * * * * * *\n");
#endif
    record = nitf_Reader_read(reader, io, &error);


    lookForTREField(record->header->extendedSection, treName, fieldName);
    lookForTREField(record->header->userDefinedSection, treName, fieldName);



    if (!nitf_Field_get(record->header->numImages,
                        &num, NITF_CONV_INT, NITF_INT32_SZ, &error))
        goto CATCH_ERROR;

    /* And now show the image information */
    if (num > 0)
    {

        /*  Walk each image and show  */
        nitf_ListIterator iter = nitf_List_begin(record->images);
        nitf_ListIterator end = nitf_List_end(record->images);

        while (nitf_ListIterator_notEqualTo(&iter, &end))
        {
            nitf_ImageSegment *segment =
                (nitf_ImageSegment *) nitf_ListIterator_get(&iter);

	    lookForTREField(segment->subheader->extendedSection, treName, fieldName);
	    lookForTREField(segment->subheader->userDefinedSection, treName, fieldName);
            nitf_ListIterator_increment(&iter);
        }
    }
    else
    {
        printf("No image in file!\n");
    }

    nitf_IOHandle_close(io);
    nitf_Record_destruct(&record);

    nitf_Reader_destruct(&reader);

    return 0;

CATCH_ERROR:
    printf("!!! we had a problem reading the file !!!\n");
    nitf_Error_print(&error, stdout, "Exiting...");
    exit(EXIT_FAILURE);
}
Beispiel #3
0
int main(int argc, char **argv)
{
    /*  Get the error object       */
    nitf_Error     error;

    /*  This is the reader object  */
    nitf_Reader* reader;
    nitf_Record* record;

    /*  The IO handle  */
    nitf_IOHandle io;
    int num;

    /*  Check argv and make sure we are happy  */
    if ( argc != 2 )
    {
        printf("Usage: %s <nitf-file>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    io = nitf_IOHandle_create(argv[1], NITF_ACCESS_READONLY, NITF_OPEN_EXISTING, &error);
    if ( NITF_INVALID_HANDLE( io ) )
    {
        nitf_Error_print(&error, stdout, "Exiting...");
        exit( EXIT_FAILURE );
    }

    reader = nitf_Reader_construct(&error);
    if (!reader)
    {
        nitf_Error_print(&error, stdout, "Exiting (1) ...");
        exit( EXIT_FAILURE );
    }

    /*    record = nitf_Record_construct(&error);
    if (!record)
    {
    nitf_Error_print(&error, stdout, "Exiting (2) ...");
    nitf_Reader_destruct(&reader);
    exit( EXIT_FAILURE );
    }*/


#if NITF_VERBOSE_READER
    printf("Here are the loaded handlers\n");
    printf("* * * * * * * * * * * * * * * *\n");
    nitf_HashTable_print(reader->reg->treHandlers);
    printf("* * * * * * * * * * * * * * * *\n");
#endif

    if ( ! (record = nitf_Reader_read(reader, io, &error  )) )
    {
        nitf_Error_print(&error, stdout, "Exiting ...");
        exit(EXIT_FAILURE);
    }

    printf("User defined: in file header\n");
    showExtSection(record->header->userDefinedSection);
    printf("Extended defined: in file header\n");
    showExtSection(record->header->extendedSection);



    if (!nitf_Field_get(record->header->numImages,
                        &num,
                        NITF_CONV_INT,
                        NITF_INT32_SZ,
                        &error))
        nitf_Error_print(&error, stdout, "Skipping b/c Invalid numImages");
    /* And now show the image information */
    else if (num > 0)
    {

        /*  Walk each image and show  */
        nitf_ListIterator iter = nitf_List_begin(record->images);
        nitf_ListIterator end  = nitf_List_end(record->images);

        while ( nitf_ListIterator_notEqualTo(&iter, &end) )
        {
            nitf_ImageSegment* segment =
                (nitf_ImageSegment*)nitf_ListIterator_get(&iter);

            printf("User defined: in image segment\n");
            showExtSection(segment->subheader->userDefinedSection);
            printf("Extended defined: in image segment\n");
            showExtSection(segment->subheader->extendedSection);


            nitf_ListIterator_increment(&iter);

        }
    }
    else
    {
        printf("No image in file!\n");
    }




    nitf_IOHandle_close(io);
    nitf_Record_destruct(&record);

    if ( !nitf_List_isEmpty(reader->warningList))
    {
        /*  Iterator to a list  */
        nitf_ListIterator it;

        /*  Iterator to the end of list  */
        nitf_ListIterator endList;

        it      = nitf_List_begin(reader->warningList);

        /*  End of list pointer  */
        endList = nitf_List_end(reader->warningList);

        printf("WARNINGS: ");
        printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");

        /*  While we are not at the end  */
        while ( nitf_ListIterator_notEqualTo( &it, &endList ) )
        {
            /*  Get the last data  */
            char* p = (char*)nitf_ListIterator_get(&it);
            /*  Make sure  */
            assert(p != NULL);

            /*  Show the data  */
            printf("\tFound problem: [%s]\n\n", p);

            /*  Increment the list iterator  */
            nitf_ListIterator_increment(&it);
        }
        printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
    }

    nitf_Reader_destruct(&reader);

    return 0;
}
Beispiel #4
0
int main(int argc, char **argv)
{
    /*  This is the reader object  */
    nitf_Reader* reader;
    nitf_Record*   record;
    /*  The IO handle  */
    nitf_IOHandle io;
    /*  Get the error object       */
    nitf_Error     error;

    /*  Check argv and make sure we are happy  */
    if ( argc != 2 )
    {
        printf("Usage: %s <nitf-file>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    io = nitf_IOHandle_create(argv[1],
                              NITF_ACCESS_READONLY,
                              NITF_OPEN_EXISTING,
                              &error);
    if ( NITF_INVALID_HANDLE( io ) )
    {
        nitf_Error_print(&error, stdout, "Exiting...");
        exit( EXIT_FAILURE );
    }

    reader = nitf_Reader_construct(&error);
    if (!reader)
    {
        nitf_Error_print(&error, stdout, "Exiting (1) ...");
        exit( EXIT_FAILURE );
    }

    printf("Here are the loaded handlers\n");
    printf("* * * * * * * * * * * * * * * *\n");
    {
        nitf_PluginRegistry* reg = nitf_PluginRegistry_getInstance(&error);
        nitf_HashTable_print( reg->treHandlers);
    }
    printf("* * * * * * * * * * * * * * * *\n");

    record = nitf_Reader_read(reader, io, &error);
    if (!record)
    {
        nitf_Error_print(&error, stderr, "Failed to read the file");
        exit(EXIT_FAILURE);

    }

    /* Now show the header */
    showFileHeader(record->header);

    /* And now show the image information */
    if (record->header->numImages)
    {

        /*  Walk each image and show  */
        nitf_ListIterator iter = nitf_List_begin(record->images);
        nitf_ListIterator end  = nitf_List_end(record->images);

        while ( nitf_ListIterator_notEqualTo(&iter, &end) )
        {
            nitf_ImageSegment* segment =
                (nitf_ImageSegment*)nitf_ListIterator_get(&iter);

            nitf_ImageSubheader* dolly =
                nitf_ImageSubheader_clone(segment->subheader, &error);
            if (!dolly)
            {
                nitf_Error_print(&error, stdout, "During cloning!");
                exit(EXIT_FAILURE);
            }

            SHOW_IMSUB(segment->subheader);
            SHOW_IMSUB(dolly);

            nitf_ImageSubheader_destruct(&dolly);

            nitf_ListIterator_increment(&iter);

        }
    }
    else
    {
        printf("No image in file!\n");
    }

    nitf_IOHandle_close(io);
    nitf_Record_destruct(&record);
    nitf_Reader_destruct(&reader);

    return 0;
}
Beispiel #5
0
void nitf::HashTable::print()
{
    nitf_HashTable_print(getNative());
}
Beispiel #6
0
int main(int argc, char**argv)
{
    nitf_Error error;
    nitf_PluginRegistry* reg;
    NITF_PLUGIN_TRE_HANDLER_FUNCTION test_main;
    int bad = 0;
    if (argc != 2)
    {
        printf("Usage: %s <TRE>\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    reg = nitf_PluginRegistry_getInstance(&error);

    if (!reg)
    {
        nitf_Error_print(&error, stdout, "Exiting...");
        exit(EXIT_FAILURE);
    }
    /*  Don't need this now that it is a singleton
     *
     * if (! nitf_PluginRegistry_load(reg, &error) )
     * {
     *   nitf_Error_print(&error, stdout, "Exiting...");
     *   exit(EXIT_FAILURE);
     * }
     */

    nitf_HashTable_print(reg->treHandlers);

    test_main =
        nitf_PluginRegistry_retrieveTREHandler(reg,
                                               argv[1],
                                               &bad,
                                               &error);


    if (bad)
    {
        nitf_Error_print(&error, stderr, "Error!");
    }
    else if (test_main == (NITF_PLUGIN_TRE_HANDLER_FUNCTION)NULL)
    {
        printf("No such plugin could be found\n");
    }
    else
    {
        int ok;
        printf("Found DLL and main!!!\n");
        ok = (*test_main)(0, NULL, NULL, &error);
        if (!ok)
        {
            nitf_Error_print(&error, stderr , "");
        }

    }


    /*  Don't need this now that the registry is a singleton
     *  if (! nitf_PluginRegistry_unload(reg, &error) )
     *  {
     *    nitf_Error_print(&error, stdout, "Exiting...");
     *    exit(EXIT_FAILURE);
     *  }
     */

    /*  Don't need this now that the registry is a singleton
     *
     *  nitf_PluginRegistry_destruct(&reg);
     */
    return 0;

}