Ejemplo n.º 1
0
coda_netcdf_array *coda_netcdf_array_new(int num_dims, long dim[CODA_MAX_NUM_DIMS], coda_netcdf_basic_type *base_type)
{
    coda_netcdf_array *type;
    int i;

    type = malloc(sizeof(coda_netcdf_array));
    if (type == NULL)
    {
        coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
                       (long)sizeof(coda_netcdf_array), __FILE__, __LINE__);
        return NULL;
    }
    type->backend = coda_backend_netcdf;
    type->definition = NULL;
    type->attributes = NULL;
    type->base_type = NULL;

    type->definition = coda_type_array_new(coda_format_netcdf);
    if (type->definition == NULL)
    {
        coda_dynamic_type_delete((coda_dynamic_type *)type);
        return NULL;
    }
    if (coda_type_array_set_base_type(type->definition, base_type->definition) != 0)
    {
        coda_dynamic_type_delete((coda_dynamic_type *)type);
        return NULL;
    }
    for (i = 0; i < num_dims; i++)
    {
        if (coda_type_array_add_fixed_dimension(type->definition, dim[i]) != 0)
        {
            coda_dynamic_type_delete((coda_dynamic_type *)type);
            return NULL;
        }
    }

    type->base_type = base_type;

    return type;
}
Ejemplo n.º 2
0
void coda_netcdf_type_delete(coda_dynamic_type *type)
{
    assert(type != NULL);
    assert(type->backend == coda_backend_netcdf);

    if (type->definition->type_class == coda_array_class)
    {
        if (((coda_netcdf_array *)type)->base_type != NULL)
        {
            coda_dynamic_type_delete((coda_dynamic_type *)((coda_netcdf_array *)type)->base_type);
        }
    }
    if (((coda_netcdf_type *)type)->attributes != NULL)
    {
        coda_dynamic_type_delete((coda_dynamic_type *)((coda_netcdf_type *)type)->attributes);
    }
    if (type->definition != NULL)
    {
        coda_type_release((coda_type *)type->definition);
    }
    free(type);
}
Ejemplo n.º 3
0
coda_netcdf_basic_type *coda_netcdf_basic_type_new(int nc_type, int64_t offset, int record_var, int length)
{
    coda_netcdf_basic_type *type;
    coda_native_type read_type;
    int byte_size;

    type = malloc(sizeof(coda_netcdf_basic_type));
    if (type == NULL)
    {
        coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
                       (long)sizeof(coda_netcdf_basic_type), __FILE__, __LINE__);
        return NULL;
    }
    type->backend = coda_backend_netcdf;
    type->definition = NULL;
    type->attributes = NULL;
    type->offset = offset;
    type->record_var = record_var;

    switch (nc_type)
    {
        case 1:
            read_type = coda_native_type_int8;
            byte_size = 1;
            type->definition = (coda_type *)coda_type_number_new(coda_format_netcdf, coda_integer_class);
            break;
        case 2:
            read_type = (length > 1) ? coda_native_type_string : coda_native_type_char;
            byte_size = length;
            type->definition = (coda_type *)coda_type_text_new(coda_format_netcdf);
            break;
        case 3:
            read_type = coda_native_type_int16;
            byte_size = 2;
            type->definition = (coda_type *)coda_type_number_new(coda_format_netcdf, coda_integer_class);
            break;
        case 4:
            read_type = coda_native_type_int32;
            byte_size = 4;
            type->definition = (coda_type *)coda_type_number_new(coda_format_netcdf, coda_integer_class);
            break;
        case 5:
            read_type = coda_native_type_float;
            byte_size = 4;
            type->definition = (coda_type *)coda_type_number_new(coda_format_netcdf, coda_real_class);
            break;
        case 6:
            read_type = coda_native_type_double;
            byte_size = 8;
            type->definition = (coda_type *)coda_type_number_new(coda_format_netcdf, coda_real_class);
            break;
        default:
            assert(0);
            exit(1);
    }
    if (type->definition == NULL)
    {
        coda_dynamic_type_delete((coda_dynamic_type *)type);
        return NULL;
    }
    if (coda_type_set_read_type(type->definition, read_type) != 0)
    {
        coda_dynamic_type_delete((coda_dynamic_type *)type);
        return NULL;
    }
    if (coda_type_set_byte_size(type->definition, byte_size) != 0)
    {
        coda_dynamic_type_delete((coda_dynamic_type *)type);
        return NULL;
    }

    return type;
}
Ejemplo n.º 4
0
int coda_hdf4_close(coda_product *product)
{
    coda_hdf4_product *product_file = (coda_hdf4_product *)product;
    int i;

    if (product_file->filename != NULL)
    {
        free(product_file->filename);
    }
    if (product_file->mem_ptr != NULL)
    {
        free(product_file->mem_ptr);
    }

    /* first remove everything that was not added to the root_type */
    if (product_file->vgroup != NULL)
    {
        for (i = 0; i < product_file->num_vgroup; i++)
        {
            if (product_file->vgroup[i] != NULL && (product_file->vgroup[i]->group_count != 0 ||
                                                    product_file->vgroup[i]->hide))
            {
                coda_dynamic_type_delete((coda_dynamic_type *)product_file->vgroup[i]);
            }
        }
        free(product_file->vgroup);
    }
    if (product_file->vdata != NULL)
    {
        for (i = 0; i < product_file->num_vdata; i++)
        {
            if (product_file->vdata[i] != NULL && (product_file->vdata[i]->group_count != 0 ||
                                                   product_file->vdata[i]->hide))
            {
                coda_dynamic_type_delete((coda_dynamic_type *)product_file->vdata[i]);
            }
        }
        free(product_file->vdata);
    }
    if (product_file->sds != NULL)
    {
        for (i = 0; i < product_file->num_sds; i++)
        {
            if (product_file->sds[i] != NULL && product_file->sds[i]->group_count != 0)
            {
                coda_dynamic_type_delete((coda_dynamic_type *)product_file->sds[i]);
            }
        }
        free(product_file->sds);
    }
    if (product_file->gri != NULL)
    {
        for (i = 0; i < product_file->num_images; i++)
        {
            if (product_file->gri[i] != NULL && product_file->gri[i]->group_count != 0)
            {
                coda_dynamic_type_delete((coda_dynamic_type *)product_file->gri[i]);
            }
        }
        free(product_file->gri);
    }

    /* then remove the root_type (which recursively removes its members) */
    if (product_file->root_type != NULL)
    {
        coda_dynamic_type_delete((coda_dynamic_type *)product_file->root_type);
    }


    if (product_file->sd_id != -1)
    {
        SDend(product_file->sd_id);
    }
    if (product_file->is_hdf)
    {
        if (product_file->gr_id != -1)
        {
            GRend(product_file->gr_id);
        }
        if (product_file->an_id != -1)
        {
            ANend(product_file->an_id);
        }
        if (product_file->file_id != -1)
        {
            Vend(product_file->file_id);
            Hclose(product_file->file_id);
        }
    }

    free(product_file);

    return 0;
}