Exemple #1
0
void traverse_product()
{
    int result;

    result = coda_open(traverse_info.file_name, &traverse_info.pf);
    if (result != 0 && coda_errno == CODA_ERROR_FILE_OPEN)
    {
        /* maybe not enough memory space to map the file in memory =>
         * temporarily disable memory mapping of files and try again
         */
        coda_set_option_use_mmap(0);
        result = coda_open(traverse_info.file_name, &traverse_info.pf);
        coda_set_option_use_mmap(1);
    }
    if (result != 0)
    {
        handle_coda_error();
    }
    if (coda_cursor_set_product(&traverse_info.cursor, traverse_info.pf) != 0)
    {
        handle_coda_error();
    }
    if (coda_get_product_root_type(traverse_info.pf, &traverse_info.type[traverse_info.current_depth]) != 0)
    {
        handle_coda_error();
    }
    traverse_data();

    coda_close(traverse_info.pf);
    traverse_info.pf = NULL;
}
Exemple #2
0
static int coda_match_file(coda_expression *expr, NameBuffer *path_name,
                           int (*callback) (const char *, coda_filefilter_status, const char *, void *), void *userdata)
{
    coda_product *product;
    coda_cursor cursor;
    int filter_result;
    int result;

    result = coda_open(path_name->buffer, &product);
    if (result != 0 && coda_errno == CODA_ERROR_FILE_OPEN)
    {
        /* maybe not enough memory space to map the file in memory =>
         * temporarily disable memory mapping of files and try again
         */
        coda_set_option_use_mmap(0);
        result = coda_open(path_name->buffer, &product);
        coda_set_option_use_mmap(1);
    }
    if (result != 0)
    {
        if (coda_errno == CODA_ERROR_UNSUPPORTED_PRODUCT)
        {
            return callback(path_name->buffer, coda_ffs_unsupported_file, NULL, userdata);
        }
        else
        {
            return callback(path_name->buffer, coda_ffs_could_not_open_file, coda_errno_to_string(coda_errno),
                            userdata);
        }
    }

    if (coda_cursor_set_product(&cursor, product) != 0)
    {
        coda_close(product);
        return callback(path_name->buffer, coda_ffs_error, coda_errno_to_string(coda_errno), userdata);
    }
    if (coda_expression_eval_bool(expr, &cursor, &filter_result) != 0)
    {
        return callback(path_name->buffer, coda_ffs_error, coda_errno_to_string(coda_errno), userdata);
    }
    coda_close(product);


    return callback(path_name->buffer, filter_result ? coda_ffs_match : coda_ffs_no_match, NULL, userdata);
}
Exemple #3
0
void traverse_info_done()
{
    if (traverse_info.pf != NULL)
    {
        coda_close(traverse_info.pf);
    }
    if (traverse_info.filter[0] != NULL)
    {
        codadump_filter_remove(&traverse_info.filter[0]);
    }
}
Exemple #4
0
static int open_file(const char *filename, coda_format format, int64_t file_size,
                     const coda_product_definition *definition, coda_product **product_file)
{
    switch (format)
    {
        case coda_format_ascii:
            if (coda_ascii_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
        case coda_format_binary:
            if (coda_bin_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
        case coda_format_xml:
            if (coda_xml_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
        case coda_format_hdf4:
#ifdef HAVE_HDF4
            if (coda_hdf4_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
#else
            coda_set_error(CODA_ERROR_NO_HDF4_SUPPORT, NULL);
            return -1;
#endif
        case coda_format_hdf5:
#ifdef HAVE_HDF5
            if (coda_hdf5_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
#else
            coda_set_error(CODA_ERROR_NO_HDF5_SUPPORT, NULL);
            return -1;
#endif
        case coda_format_cdf:
            if (coda_cdf_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
        case coda_format_netcdf:
            if (coda_netcdf_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
        case coda_format_grib1:
        case coda_format_grib2:
            if (coda_grib_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
        case coda_format_rinex:
            if (coda_rinex_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
        case coda_format_sp3:
            if (coda_sp3_open(filename, file_size, definition, product_file) != 0)
            {
                return -1;
            }
            break;
    }

    /* initialize product variables */
    if ((*product_file)->product_definition != NULL && (*product_file)->product_definition->num_product_variables > 0)
    {
        int num_product_variables;
        int i;

        num_product_variables = (*product_file)->product_definition->num_product_variables;
        (*product_file)->product_variable_size = malloc(num_product_variables * sizeof(long *));
        if ((*product_file)->product_variable_size == NULL)
        {
            coda_close(*product_file);
            coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
                           num_product_variables * sizeof(long *), __FILE__, __LINE__);
            return -1;
        }
        (*product_file)->product_variable = malloc(num_product_variables * sizeof(int64_t **));
        if ((*product_file)->product_variable == NULL)
        {
            coda_close(*product_file);
            coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
                           num_product_variables * sizeof(int64_t **), __FILE__, __LINE__);
            return -1;
        }

        for (i = 0; i < num_product_variables; i++)
        {
            (*product_file)->product_variable[i] = NULL;
        }
    }

    return 0;
}
Exemple #5
0
int coda_hdf4_reopen(coda_product **product)
{
    coda_hdf4_product *product_file;

    product_file = (coda_hdf4_product *)malloc(sizeof(coda_hdf4_product));
    if (product_file == NULL)
    {
        coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
                       sizeof(coda_hdf4_product), __FILE__, __LINE__);
        coda_close(*product);
        return -1;
    }
    product_file->filename = NULL;
    product_file->file_size = (*product)->file_size;
    product_file->format = coda_format_hdf4;
    product_file->root_type = NULL;
    product_file->product_definition = NULL;
    product_file->product_variable_size = NULL;
    product_file->product_variable = NULL;
    product_file->mem_size = 0;
    product_file->mem_ptr = NULL;
    product_file->is_hdf = 0;
    product_file->file_id = -1;
    product_file->gr_id = -1;
    product_file->sd_id = -1;
    product_file->an_id = -1;
    product_file->num_gr_file_attributes = 0;
    product_file->num_sd_file_attributes = 0;
    product_file->num_sds = 0;
    product_file->sds = NULL;
    product_file->num_images = 0;
    product_file->gri = NULL;
    product_file->num_vgroup = 0;
    product_file->vgroup = NULL;
    product_file->num_vdata = 0;
    product_file->vdata = NULL;

    product_file->filename = strdup((*product)->filename);
    if (product_file->filename == NULL)
    {
        coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not duplicate filename string) (%s:%u)",
                       __FILE__, __LINE__);
        coda_hdf4_close((coda_product *)product_file);
        coda_close(*product);
        return -1;
    }

    coda_close(*product);

    product_file->is_hdf = Hishdf(product_file->filename);      /* is this a real HDF4 file or a (net)CDF file */
    if (product_file->is_hdf)
    {
        product_file->file_id = Hopen(product_file->filename, DFACC_READ, 0);
        if (product_file->file_id == -1)
        {
            coda_set_error(CODA_ERROR_HDF4, NULL);
            coda_hdf4_close((coda_product *)product_file);
            return -1;
        }
        if (Vstart(product_file->file_id) != 0)
        {
            coda_set_error(CODA_ERROR_HDF4, NULL);
            coda_hdf4_close((coda_product *)product_file);
            return -1;
        }
        product_file->gr_id = GRstart(product_file->file_id);
        if (product_file->gr_id == -1)
        {
            coda_set_error(CODA_ERROR_HDF4, NULL);
            coda_hdf4_close((coda_product *)product_file);
            return -1;
        }
        product_file->an_id = ANstart(product_file->file_id);
        if (product_file->an_id == -1)
        {
            coda_set_error(CODA_ERROR_HDF4, NULL);
            coda_hdf4_close((coda_product *)product_file);
            return -1;
        }
    }
    product_file->sd_id = SDstart(product_file->filename, DFACC_READ);
    if (product_file->sd_id == -1)
    {
        coda_set_error(CODA_ERROR_HDF4, NULL);
        coda_hdf4_close((coda_product *)product_file);
        return -1;
    }
    product_file->root_type = NULL;

    if (init_SDSs(product_file) != 0)
    {
        coda_hdf4_close((coda_product *)product_file);
        return -1;
    }
    if (product_file->is_hdf)
    {
        if (init_GRImages(product_file) != 0)
        {
            coda_hdf4_close((coda_product *)product_file);
            return -1;
        }
        if (init_Vdatas(product_file) != 0)
        {
            coda_hdf4_close((coda_product *)product_file);
            return -1;
        }
        /* initialization of Vgroup entries should happen last, so we can build the structural tree */
        if (init_Vgroups(product_file) != 0)
        {
            coda_hdf4_close((coda_product *)product_file);
            return -1;
        }
    }

    if (coda_hdf4_create_root(product_file) != 0)
    {
        coda_hdf4_close((coda_product *)product_file);
        return -1;
    }

    *product = (coda_product *)product_file;

    return 0;
}