mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-03 08:01:25 +08:00
Remove obsolete code
re: https://github.com/Unidata/netcdf-c/pull/2179 The above PR cleaned up reclaiming of complex type instances. As a temporary measure, the old code was left in place demarcated by ````#ifdef SEPDATA````. Since it appears that this change was successful, this PR removes that old SEPDATA marked code.
This commit is contained in:
parent
10828c5fda
commit
822998ab7f
@ -7,11 +7,13 @@ This file contains a high-level description of this package's evolution. Release
|
||||
|
||||
## 4.9.2 - TBD
|
||||
|
||||
* Fix 'make distcheck' error in run_interop.sh. See [Github #????](https://github.com/Unidata/netcdf-c/pull/????).
|
||||
* Remove obsolete code. See [Github #????](https://github.com/Unidata/netcdf-c/pull/????).
|
||||
* Simplify the handling of XGetopt. See [Github #2678](https://github.com/Unidata/netcdf-c/pull/2678).
|
||||
* Fix 'make distcheck' error in run_interop.sh. See [Github #2631](https://github.com/Unidata/netcdf-c/pull/2631).
|
||||
* Update `nc-config` to remove inclusion from automatically-detected `nf-config` and `ncxx-config` files, as the wrong files could be included in the output. This is in support of [GitHub #2274](https://github.com/Unidata/netcdf-c/issues/2274).
|
||||
* Update H5FDhttp.[ch] to work with HDF5 version 1.13.2 and later. See [Github #2635](https://github.com/Unidata/netcdf-c/pull/2635).
|
||||
* [Bug Fix] Update DAP code to enable CURLOPT_ACCEPT_ENCODING by default. See [Github #2630](https://github.com/Unidata/netcdf-c/pull/2630).
|
||||
* [Bug Fix] Fix byterange failures for certain URLs. See [Github #????](https://github.com/Unidata/netcdf-c/pull/????).
|
||||
* [Bug Fix] Fix byterange failures for certain URLs. See [Github #2649](https://github.com/Unidata/netcdf-c/pull/2649).
|
||||
* [Bug Fix] Fix 'make distcheck' error in run_interop.sh. See [Github #2631](https://github.com/Unidata/netcdf-c/pull/2631).
|
||||
* [Enhancement] Update `nc-config` to remove inclusion from automatically-detected `nf-config` and `ncxx-config` files, as the wrong files could be included in the output. This is in support of [GitHub #2274](https://github.com/Unidata/netcdf-c/issues/2274).
|
||||
* [Enhancement] Update H5FDhttp.[ch] to work with HDF5 version 1.14.0. See [Github #2615](https://github.com/Unidata/netcdf-c/pull/2615).
|
||||
|
@ -168,10 +168,6 @@ typedef struct NC_ATT_INFO
|
||||
nc_type nc_typeid; /**< NetCDF type of attribute's data. */
|
||||
void *format_att_info; /**< Pointer to format-specific att info. */
|
||||
void *data; /**< The attribute data. */
|
||||
#ifdef SEPDATA
|
||||
nc_vlen_t *vldata; /**< VLEN data (only used for vlen types). */
|
||||
char **stdata; /**< String data (only for string type). */
|
||||
#endif
|
||||
} NC_ATT_INFO_T;
|
||||
|
||||
/** This is a struct to handle the var metadata. */
|
||||
|
@ -520,88 +520,6 @@ NC_copy_att(int ncid_in, int varid_in, const char *name,
|
||||
if ((res = nc_inq_att(ncid_in, varid_in, name, &xtype, &len)))
|
||||
return res;
|
||||
|
||||
#ifdef SEPDATA
|
||||
if (xtype < NC_STRING)
|
||||
{
|
||||
/* Handle non-string atomic types. */
|
||||
if (len)
|
||||
{
|
||||
size_t size = NC_atomictypelen(xtype);
|
||||
|
||||
assert(size > 0);
|
||||
if (!(data = malloc(len * size)))
|
||||
return NC_ENOMEM;
|
||||
}
|
||||
|
||||
res = nc_get_att(ncid_in, varid_in, name, data);
|
||||
if (!res)
|
||||
res = nc_put_att(ncid_out, varid_out, name, xtype,
|
||||
len, data);
|
||||
if (len)
|
||||
free(data);
|
||||
}
|
||||
#ifdef USE_NETCDF4
|
||||
else if (xtype == NC_STRING)
|
||||
{
|
||||
/* Copy string attributes. */
|
||||
char **str_data;
|
||||
if (!(str_data = malloc(sizeof(char *) * len)))
|
||||
return NC_ENOMEM;
|
||||
res = nc_get_att_string(ncid_in, varid_in, name, str_data);
|
||||
if (!res)
|
||||
res = nc_put_att_string(ncid_out, varid_out, name, len,
|
||||
(const char **)str_data);
|
||||
nc_free_string(len, str_data);
|
||||
free(str_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Copy user-defined type attributes. */
|
||||
int class;
|
||||
size_t size;
|
||||
void *data;
|
||||
nc_type xtype_out = NC_NAT;
|
||||
|
||||
/* Find out if there is an equal type in the output file. */
|
||||
/* Note: original code used a libsrc4 specific internal function
|
||||
which we had to "duplicate" here */
|
||||
if ((res = NC_find_equal_type(ncid_in, xtype, ncid_out, &xtype_out)))
|
||||
return res;
|
||||
if (xtype_out)
|
||||
{
|
||||
/* We found an equal type! */
|
||||
if ((res = nc_inq_user_type(ncid_in, xtype, NULL, &size,
|
||||
NULL, NULL, &class)))
|
||||
return res;
|
||||
if (class == NC_VLEN) /* VLENs are different... */
|
||||
{
|
||||
nc_vlen_t *vldata;
|
||||
int i;
|
||||
if (!(vldata = malloc(sizeof(nc_vlen_t) * len)))
|
||||
return NC_ENOMEM;
|
||||
if ((res = nc_get_att(ncid_in, varid_in, name, vldata)))
|
||||
return res;
|
||||
if ((res = nc_put_att(ncid_out, varid_out, name, xtype_out,
|
||||
len, vldata)))
|
||||
return res;
|
||||
for (i = 0; i < len; i++)
|
||||
if((res = nc_free_vlen(&vldata[i])))
|
||||
return res;
|
||||
free(vldata);
|
||||
}
|
||||
else /* not VLEN */
|
||||
{
|
||||
if (!(data = malloc(size * len)))
|
||||
return NC_ENOMEM;
|
||||
res = nc_get_att(ncid_in, varid_in, name, data);
|
||||
if (!res)
|
||||
res = nc_put_att(ncid_out, varid_out, name, xtype_out, len, data);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /*!USE_NETCDF4*/
|
||||
#else /*!SEPDATA*/
|
||||
{
|
||||
/* Copy arbitrary attributes. */
|
||||
int class;
|
||||
@ -629,7 +547,6 @@ NC_copy_att(int ncid_in, int varid_in, const char *name,
|
||||
res = nc_put_att(ncid_out, varid_out, name, xtype_out, len, data);
|
||||
(void)nc_reclaim_data_all(ncid_out,xtype_out,data,len);
|
||||
}
|
||||
#endif /*SEPDATA*/
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -552,26 +552,6 @@ nc4_put_att(NC_GRP_INFO_T* grp, int varid, const char *name, nc_type file_type,
|
||||
if ((retval = nc4_get_typelen_mem(h5, file_type, &type_size)))
|
||||
return retval;
|
||||
|
||||
#ifdef SEPDATA
|
||||
/* If this att has vlen or string data, release it before we lose the length value. */
|
||||
if (att->stdata)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < att->len; i++)
|
||||
if(att->stdata[i])
|
||||
free(att->stdata[i]);
|
||||
free(att->stdata);
|
||||
att->stdata = NULL;
|
||||
}
|
||||
if (att->vldata)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < att->len; i++) {
|
||||
nc_free_vlen(&att->vldata[i]); /* FIX: see warning of nc_free_vlen */
|
||||
free(att->vldata);
|
||||
att->vldata = NULL;
|
||||
}
|
||||
#else
|
||||
if (att->data)
|
||||
{
|
||||
assert(attsave.data == NULL);
|
||||
@ -579,7 +559,6 @@ nc4_put_att(NC_GRP_INFO_T* grp, int varid, const char *name, nc_type file_type,
|
||||
attsave.len = att->len;
|
||||
att->data = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If this is the _FillValue attribute, then we will also have to
|
||||
* copy the value to the fill_vlue pointer of the NC_VAR_INFO_T
|
||||
@ -611,74 +590,15 @@ nc4_put_att(NC_GRP_INFO_T* grp, int varid, const char *name, nc_type file_type,
|
||||
* one. Make up your damn mind, would you? */
|
||||
if (var->fill_value)
|
||||
{
|
||||
#ifdef SEPDATA
|
||||
if (var->type_info->nc_type_class == NC_VLEN)
|
||||
{
|
||||
if ((retval = nc_free_vlen(var->fill_value)))
|
||||
BAIL(retval);
|
||||
}
|
||||
else if (var->type_info->nc_type_class == NC_STRING)
|
||||
{
|
||||
if (*(char **)var->fill_value)
|
||||
free(*(char **)var->fill_value);
|
||||
}
|
||||
free(var->fill_value);
|
||||
#else
|
||||
/* reclaim later */
|
||||
fillsave.data = var->fill_value;
|
||||
fillsave.type = var->type_info->hdr.id;
|
||||
fillsave.len = 1;
|
||||
#endif
|
||||
var->fill_value = NULL;
|
||||
}
|
||||
|
||||
/* Determine the size of the fill value in bytes. */
|
||||
#ifdef SEPDATA
|
||||
if (var->type_info->nc_type_class == NC_VLEN)
|
||||
size = sizeof(hvl_t);
|
||||
else if (var->type_info->nc_type_class == NC_STRING)
|
||||
size = sizeof(char *);
|
||||
else
|
||||
size = type_size;
|
||||
#endif
|
||||
|
||||
#ifdef SEPDATA
|
||||
/* Allocate space for the fill value. */
|
||||
if (!(var->fill_value = calloc(1, size)))
|
||||
BAIL(NC_ENOMEM);
|
||||
|
||||
/* Copy the fill_value. */
|
||||
LOG((4, "Copying fill value into metadata for variable %s", var->hdr.name));
|
||||
if (var->type_info->nc_type_class == NC_VLEN)
|
||||
{
|
||||
nc_vlen_t *in_vlen = (nc_vlen_t *)data, *fv_vlen = (nc_vlen_t *)(var->fill_value);
|
||||
NC_TYPE_INFO_T* basetype;
|
||||
size_t basetypesize = 0;
|
||||
|
||||
/* get the basetype and its size */
|
||||
basetype = var->type_info;
|
||||
if ((retval = nc4_get_typelen_mem(grp->nc4_info, basetype->hdr.id, &basetypesize)))
|
||||
BAIL(retval);
|
||||
/* shallow clone the content of the vlen; shallow because it has only a temporary existence */
|
||||
fv_vlen->len = in_vlen->len;
|
||||
if (!(fv_vlen->p = malloc(basetypesize * in_vlen->len)))
|
||||
BAIL(NC_ENOMEM);
|
||||
memcpy(fv_vlen->p, in_vlen->p, in_vlen->len * basetypesize);
|
||||
}
|
||||
else if (var->type_info->nc_type_class == NC_STRING)
|
||||
{
|
||||
if (*(char **)data)
|
||||
{
|
||||
if (!(*(char **)(var->fill_value) = malloc(strlen(*(char **)data) + 1)))
|
||||
BAIL(NC_ENOMEM);
|
||||
strcpy(*(char **)var->fill_value, *(char **)data);
|
||||
}
|
||||
else
|
||||
*(char **)var->fill_value = NULL;
|
||||
}
|
||||
else
|
||||
memcpy(var->fill_value, data, type_size);
|
||||
#else
|
||||
{
|
||||
nc_type var_type = var->type_info->hdr.id;
|
||||
size_t var_type_size = var->type_info->size;
|
||||
@ -704,7 +624,6 @@ nc4_put_att(NC_GRP_INFO_T* grp, int varid, const char *name, nc_type file_type,
|
||||
var->fill_value = copy;
|
||||
copy = NULL;
|
||||
}
|
||||
#endif
|
||||
/* Indicate that the fill value was changed, if the variable has already
|
||||
* been created in the file, so the dataset gets deleted and re-created. */
|
||||
if (var->created)
|
||||
@ -721,82 +640,6 @@ nc4_put_att(NC_GRP_INFO_T* grp, int varid, const char *name, nc_type file_type,
|
||||
BAIL(retval);
|
||||
|
||||
assert(data);
|
||||
#ifdef SEPDATA
|
||||
if (type_class == NC_VLEN)
|
||||
{
|
||||
const hvl_t *vldata1;
|
||||
NC_TYPE_INFO_T *vltype;
|
||||
size_t base_typelen;
|
||||
|
||||
/* Get the type object for the attribute's type */
|
||||
if ((retval = nc4_find_type(h5, file_type, &vltype)))
|
||||
BAIL(retval);
|
||||
|
||||
/* Retrieve the size of the base type */
|
||||
if ((retval = nc4_get_typelen_mem(h5, vltype->u.v.base_nc_typeid, &base_typelen)))
|
||||
BAIL(retval);
|
||||
|
||||
vldata1 = data;
|
||||
if (!(att->vldata = (nc_vlen_t*)malloc(att->len * sizeof(hvl_t))))
|
||||
BAIL(NC_ENOMEM);
|
||||
for (i = 0; i < att->len; i++)
|
||||
{
|
||||
att->vldata[i].len = vldata1[i].len;
|
||||
/* Warning, this only works for cases described for nc_free_vlen() */
|
||||
if (!(att->vldata[i].p = malloc(base_typelen * att->vldata[i].len)))
|
||||
BAIL(NC_ENOMEM);
|
||||
memcpy(att->vldata[i].p, vldata1[i].p, base_typelen * att->vldata[i].len);
|
||||
}
|
||||
}
|
||||
else if (type_class == NC_STRING)
|
||||
{
|
||||
LOG((4, "copying array of NC_STRING"));
|
||||
if (!(att->stdata = malloc(sizeof(char *) * att->len))) {
|
||||
BAIL(NC_ENOMEM);
|
||||
}
|
||||
|
||||
/* If we are overwriting an existing attribute,
|
||||
specifically an NC_CHAR, we need to clean up
|
||||
the pre-existing att->data. */
|
||||
if (!new_att && att->data) {
|
||||
|
||||
free(att->data);
|
||||
att->data = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < att->len; i++)
|
||||
{
|
||||
if(NULL != ((char **)data)[i]) {
|
||||
LOG((5, "copying string %d of size %d", i, strlen(((char **)data)[i]) + 1));
|
||||
if (!(att->stdata[i] = strdup(((char **)data)[i])))
|
||||
BAIL(NC_ENOMEM);
|
||||
}
|
||||
else
|
||||
att->stdata[i] = ((char **)data)[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* [Re]allocate memory for the attribute data */
|
||||
if (!new_att)
|
||||
free (att->data);
|
||||
if (!(att->data = malloc(att->len * type_size)))
|
||||
BAIL(NC_ENOMEM);
|
||||
|
||||
/* Just copy the data, for non-atomic types */
|
||||
if (type_class == NC_OPAQUE || type_class == NC_COMPOUND || type_class == NC_ENUM)
|
||||
memcpy(att->data, data, len * type_size);
|
||||
else
|
||||
{
|
||||
/* Data types are like religions, in that one can convert. */
|
||||
if ((retval = nc4_convert_type(data, att->data, mem_type, file_type,
|
||||
len, &range_error, NULL,
|
||||
(h5->cmode & NC_CLASSIC_MODEL),
|
||||
NC_NOQUANTIZE, 0)))
|
||||
BAIL(retval);
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
/* Allocate top level of the copy */
|
||||
if (!(copy = malloc(len * type_size)))
|
||||
@ -816,7 +659,6 @@ nc4_put_att(NC_GRP_INFO_T* grp, int varid, const char *name, nc_type file_type,
|
||||
/* Store it */
|
||||
att->data = copy; copy = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
att->dirty = NC_TRUE;
|
||||
att->created = NC_FALSE;
|
||||
|
@ -613,18 +613,11 @@ close_vars(NC_GRP_INFO_T *grp)
|
||||
{
|
||||
if (var->type_info)
|
||||
{
|
||||
#ifdef SEPDATA
|
||||
if (var->type_info->nc_type_class == NC_VLEN)
|
||||
nc_free_vlen((nc_vlen_t *)var->fill_value);
|
||||
else if (var->type_info->nc_type_class == NC_STRING && *(char **)var->fill_value)
|
||||
free(*(char **)var->fill_value);
|
||||
#else
|
||||
int stat = NC_NOERR;
|
||||
if((stat = nc_reclaim_data(grp->nc4_info->controller->ext_ncid,var->type_info->hdr.id,var->fill_value,1)))
|
||||
return stat;
|
||||
nullfree(var->fill_value);
|
||||
}
|
||||
#endif
|
||||
var->fill_value = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -1158,20 +1158,6 @@ static int get_fill_info(hid_t propid, NC_VAR_INFO_T *var)
|
||||
/* Allocate space to hold the fill value. */
|
||||
if (!var->fill_value)
|
||||
{
|
||||
#ifdef SEPDATA
|
||||
|
||||
if (var->type_info->nc_type_class == NC_VLEN)
|
||||
{
|
||||
if (!(var->fill_value = malloc(sizeof(nc_vlen_t))))
|
||||
return NC_ENOMEM;
|
||||
}
|
||||
else if (var->type_info->nc_type_class == NC_STRING)
|
||||
{
|
||||
if (!(var->fill_value = malloc(sizeof(char *))))
|
||||
return NC_ENOMEM;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
assert(var->type_info->size);
|
||||
if (!(var->fill_value = malloc(var->type_info->size)))
|
||||
@ -1866,70 +1852,6 @@ read_hdf5_att(NC_GRP_INFO_T *grp, hid_t attid, NC_ATT_INFO_T *att)
|
||||
if ((retval = nc4_get_typelen_mem(grp->nc4_info, att->nc_typeid,
|
||||
&type_size)))
|
||||
return retval;
|
||||
#ifdef SEPDATA
|
||||
if (att_class == H5T_VLEN)
|
||||
{
|
||||
if (!(att->vldata = malloc((unsigned int)(att->len * sizeof(hvl_t)))))
|
||||
BAIL(NC_ENOMEM);
|
||||
if (H5Aread(attid, hdf5_att->native_hdf_typeid, att->vldata) < 0)
|
||||
BAIL(NC_EATTMETA);
|
||||
}
|
||||
else if (att->nc_typeid == NC_STRING)
|
||||
{
|
||||
if (!(att->stdata = calloc(att->len, sizeof(char *))))
|
||||
BAIL(NC_ENOMEM);
|
||||
/* For a fixed length HDF5 string, the read requires
|
||||
* contiguous memory. Meanwhile, the netCDF API requires that
|
||||
* nc_free_string be called on string arrays, which would not
|
||||
* work if one contiguous memory block were used. So here I
|
||||
* convert the contiguous block of strings into an array of
|
||||
* malloced strings -- each string with its own malloc. Then I
|
||||
* copy the data and free the contiguous memory. This
|
||||
* involves copying the data, which is bad, but this only
|
||||
* occurs for fixed length string attributes, and presumably
|
||||
* these are small. Note also that netCDF-4 does not create them - it
|
||||
* always uses variable length strings. */
|
||||
if (fixed_len_string)
|
||||
{
|
||||
int i;
|
||||
char *contig_buf, *cur;
|
||||
|
||||
/* Alloc space for the contiguous memory read. */
|
||||
if (!(contig_buf = malloc(att->len * fixed_size * sizeof(char))))
|
||||
BAIL(NC_ENOMEM);
|
||||
|
||||
/* Read the fixed-len strings as one big block. */
|
||||
if (H5Aread(attid, hdf5_att->native_hdf_typeid, contig_buf) < 0) {
|
||||
free(contig_buf);
|
||||
BAIL(NC_EATTMETA);
|
||||
}
|
||||
|
||||
/* Copy strings, one at a time, into their new home. Alloc
|
||||
space for each string. The user will later free this
|
||||
space with nc_free_string. */
|
||||
cur = contig_buf;
|
||||
for (i = 0; i < att->len; i++)
|
||||
{
|
||||
if (!(att->stdata[i] = malloc(fixed_size))) {
|
||||
free(contig_buf);
|
||||
BAIL(NC_ENOMEM);
|
||||
}
|
||||
strncpy(att->stdata[i], cur, fixed_size);
|
||||
cur += fixed_size;
|
||||
}
|
||||
|
||||
/* Free contiguous memory buffer. */
|
||||
free(contig_buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Read variable-length string atts. */
|
||||
if (H5Aread(attid, hdf5_att->native_hdf_typeid, att->stdata) < 0)
|
||||
BAIL(NC_EATTMETA);
|
||||
}
|
||||
}
|
||||
else
|
||||
#else
|
||||
{
|
||||
if (!(att->data = malloc((unsigned int)(att->len * type_size))))
|
||||
BAIL(NC_ENOMEM);
|
||||
@ -1986,7 +1908,6 @@ read_hdf5_att(NC_GRP_INFO_T *grp, hid_t attid, NC_ATT_INFO_T *att)
|
||||
BAIL(NC_EATTMETA);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (H5Tclose(file_typeid) < 0)
|
||||
|
@ -2184,35 +2184,11 @@ NC4_get_vars(int ncid, int varid, const size_t *startp, const size_t *countp,
|
||||
for (i = 0; i < fill_len; i++)
|
||||
{
|
||||
|
||||
#ifdef SEPDATA
|
||||
if (var->type_info->nc_type_class == NC_STRING)
|
||||
{
|
||||
if (*(char **)fillvalue)
|
||||
{
|
||||
if (!(*(char **)filldata = strdup(*(char **)fillvalue)))
|
||||
BAIL(NC_ENOMEM);
|
||||
}
|
||||
else
|
||||
*(char **)filldata = NULL;
|
||||
}
|
||||
else if (var->type_info->nc_type_class == NC_VLEN)
|
||||
{
|
||||
if (fillvalue)
|
||||
{
|
||||
memcpy(filldata,fillvalue,file_type_size);
|
||||
} else {
|
||||
*(char **)filldata = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
memcpy(filldata, fillvalue, file_type_size);
|
||||
#else
|
||||
{
|
||||
/* Copy one instance of the fill_value */
|
||||
if((retval = nc_copy_data(ncid,var->type_info->hdr.id,fillvalue,1,filldata)))
|
||||
BAIL(retval);
|
||||
}
|
||||
#endif
|
||||
filldata = (char *)filldata + file_type_size;
|
||||
}
|
||||
}
|
||||
|
@ -470,12 +470,6 @@ put_att_grpa(NC_GRP_INFO_T *grp, int varid, NC_ATT_INFO_T *att)
|
||||
* some phoney data (which won't be written anyway.)*/
|
||||
if (!dims[0])
|
||||
data = &phoney_data;
|
||||
#ifdef SEPDATA
|
||||
else if (att->vldata)
|
||||
data = att->vldata;
|
||||
else if (att->stdata)
|
||||
data = att->stdata;
|
||||
#endif
|
||||
else
|
||||
data = att->data;
|
||||
|
||||
|
@ -138,55 +138,10 @@ nc4_get_att_ptrs(NC_FILE_INFO_T *h5, NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var,
|
||||
bugs! */
|
||||
if (data)
|
||||
{
|
||||
#ifdef SEPDATA
|
||||
if (att->vldata)
|
||||
{
|
||||
size_t base_typelen;
|
||||
nc_hvl_t *vldest = data;
|
||||
NC_TYPE_INFO_T *type;
|
||||
int i;
|
||||
|
||||
/* Get the type object for the attribute's type */
|
||||
if ((retval = nc4_find_type(h5, att->nc_typeid, &type)))
|
||||
BAIL(retval);
|
||||
|
||||
/* Retrieve the size of the base type */
|
||||
if ((retval = nc4_get_typelen_mem(h5, type->u.v.base_nc_typeid, &base_typelen)))
|
||||
BAIL(retval);
|
||||
|
||||
for (i = 0; i < att->len; i++)
|
||||
{
|
||||
vldest[i].len = att->vldata[i].len;
|
||||
if (!(vldest[i].p = malloc(vldest[i].len * base_typelen)))
|
||||
BAIL(NC_ENOMEM);
|
||||
memcpy(vldest[i].p, att->vldata[i].p, vldest[i].len * base_typelen);
|
||||
}
|
||||
}
|
||||
else if (att->stdata)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < att->len; i++)
|
||||
{
|
||||
/* Check for NULL pointer for string (valid in HDF5) */
|
||||
if(att->stdata[i])
|
||||
{
|
||||
if (!(((char **)data)[i] = strdup(att->stdata[i])))
|
||||
BAIL(NC_ENOMEM);
|
||||
}
|
||||
else
|
||||
((char **)data)[i] = att->stdata[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(data, bufr, (size_t)(att->len * type_size));
|
||||
}
|
||||
#else
|
||||
{
|
||||
if((retval = nc_copy_data(h5->controller->ext_ncid,mem_type,bufr,att->len,data)))
|
||||
BAIL(retval);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
exit:
|
||||
|
@ -1334,37 +1334,6 @@ nc4_att_free(NC_ATT_INFO_T *att)
|
||||
if (att->hdr.name)
|
||||
free(att->hdr.name);
|
||||
|
||||
#ifdef SEPDATA
|
||||
/* Free memory that was malloced to hold data for this
|
||||
* attribute. */
|
||||
if (att->data) {
|
||||
free(att->data);
|
||||
}
|
||||
|
||||
/* If this is a string array attribute, delete all members of the
|
||||
* string array, then delete the array of pointers to strings. (The
|
||||
* array was filled with pointers by HDF5 when the att was read,
|
||||
* and memory for each string was allocated by HDF5. That's why I
|
||||
* use free and not nc_free, because the netCDF library didn't
|
||||
* allocate the memory that is being freed.) */
|
||||
if (att->stdata)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < att->len; i++)
|
||||
if(att->stdata[i])
|
||||
free(att->stdata[i]);
|
||||
free(att->stdata);
|
||||
}
|
||||
|
||||
/* If this att has vlen data, release it. */
|
||||
if (att->vldata)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < att->len; i++)
|
||||
nc_free_vlen(&att->vldata[i]);
|
||||
free(att->vldata);
|
||||
}
|
||||
#else
|
||||
if (att->data) {
|
||||
NC_OBJ* parent;
|
||||
NC_FILE_INFO_T* h5 = NULL;
|
||||
@ -1379,7 +1348,6 @@ nc4_att_free(NC_ATT_INFO_T *att)
|
||||
free(att->data); /* reclaim top level */
|
||||
att->data = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
done:
|
||||
free(att);
|
||||
|
@ -263,53 +263,14 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
|
||||
{
|
||||
/* Do we have a fill value for this var? */
|
||||
if (var->fill_value)
|
||||
#ifdef SEPDATA
|
||||
{
|
||||
if (var->type_info->nc_type_class == NC_STRING)
|
||||
{
|
||||
assert(*(char **)var->fill_value);
|
||||
/* This will allocate memory and copy the string. */
|
||||
if (!(*(char **)fill_valuep = strdup(*(char **)var->fill_value)))
|
||||
{
|
||||
free(*(char **)fill_valuep);
|
||||
return NC_ENOMEM;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(var->type_info->size);
|
||||
memcpy(fill_valuep, var->fill_value, var->type_info->size);
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
int xtype = var->type_info->hdr.id;
|
||||
if((retval = nc_copy_data(ncid,xtype,var->fill_value,1,fill_valuep))) return retval;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
#ifdef SEPDATA
|
||||
if (var->type_info->nc_type_class == NC_STRING)
|
||||
{
|
||||
if (!(*(char **)fill_valuep = calloc(1, sizeof(char *))))
|
||||
return NC_ENOMEM;
|
||||
|
||||
if ((retval = nc4_get_default_fill_value(var->type_info->hdr.ud, (char **)fill_valuep)))
|
||||
{
|
||||
free(*(char **)fill_valuep);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((retval = nc4_get_default_fill_value(var->type_info->hdr.id, fill_valuep)))
|
||||
return retval;
|
||||
}
|
||||
#else
|
||||
if ((retval = nc4_get_default_fill_value(var->type_info, fill_valuep)))
|
||||
return retval;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user