more changes to make netcdf-4 use less memory per variable

This commit is contained in:
Ed Hartnett 2010-07-01 11:39:34 +00:00
parent 2ca9240913
commit 0e855e0dc5
6 changed files with 19 additions and 17 deletions

View File

@ -202,6 +202,9 @@ extern "C" {
/* As a rule, NC_MAX_VAR_DIMS <= NC_MAX_DIMS*/
#define NC_MAX_VAR_DIMS 1024 /* max per variable dimensions */
/* This is the max size of an SD dataset name in HDF4. */
#define NC_MAX_HDF4_NAME 64 /* From HDF4 documentation. */
/* In HDF5 files you can set the endianness of variables with
* nc_def_var_endian(). These defines are used there. */
#define NC_ENDIAN_NATIVE 0

View File

@ -1277,6 +1277,10 @@ read_var(NC_GRP_INFO_T *grp, hid_t datasetid, char *obj_name,
return NC_EHDFERR;
var->chunk_cache_preemption = rdcc_w0;
/* Allocate space for the name. */
if (!(var->name = malloc((strlen(obj_name) + 1) * sizeof(char))))
return NC_ENOMEM;
/* Check for a weird case: a non-coordinate variable that has the
* same name as a dimension. It's legal in netcdf, and requires
* that the HDF5 dataset name be changed. */
@ -2098,6 +2102,8 @@ nc4_open_hdf4_file(const char *path, int mode, NC_FILE_INFO_T *nc)
return NC_EVARMETA;
/* Get shape, name, type, and attribute info about this dataset. */
if (!(var->name = malloc(NC_MAX_HDF4_NAME + 1)))
return NC_ENOMEM;
if (SDgetinfo(var->sdsid, var->name, &rank, dimsize, &data_type, &num_atts))
return NC_EVARMETA;
var->ndims = rank;

View File

@ -915,6 +915,8 @@ var_list_del(NC_VAR_INFO_T **list, NC_VAR_INFO_T *var)
free(var->chunksizes);
if (var->hdf5_name)
free(var->hdf5_name);
if (var->name)
free(var->name);
/* Remove the var from the linked list. */
if(*list == var)

View File

@ -159,7 +159,7 @@ typedef struct hdf5_objid
/* This is a struct to handle the var metadata. */
typedef struct NC_VAR_INFO
{
char name[NC_MAX_NAME + 1];
char *name;
char *hdf5_name; /* used if different from name */
int ndims;
int dimids[NC_MAX_VAR_DIMS];

View File

@ -340,6 +340,8 @@ nc_def_var_nc4(int ncid, const char *name, nc_type xtype,
return retval;
/* Now fill in the values in the var info structure. */
if (!(var->name = malloc((strlen(norm_name) + 1) * sizeof(char))))
return NC_ENOMEM;
strcpy(var->name, norm_name);
var->varid = grp->nvars++;
var->xtype = xtype;
@ -514,6 +516,7 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
/* Find info for this file and group, and set pointer to each. */
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
return retval;
assert(nc && grp && h5);
#ifdef USE_PNETCDF
/* Take care of files created/opened with parallel-netcdf library. */
@ -522,17 +525,6 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
dimidsp, nattsp);
#endif /* USE_PNETCDF */
/* Handle netcdf-3 cases. Better not ask for var options for a
* netCDF-3 file! */
if (!h5)
{
if (contiguousp)
*contiguousp = NC_CONTIGUOUS;
return nc3_inq_var(nc->int_ncid, varid, name, xtypep, ndimsp,
dimidsp, nattsp);
}
assert(nc && grp && h5);
/* Walk through the list of vars, and return the info about the one
with a matching varid. If the varid is -1, find the global
atts and call it a day. */
@ -582,7 +574,7 @@ NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
}
if (contiguousp)
*contiguousp = var->contiguous;
*contiguousp = var->contiguous ? NC_CONTIGUOUS : NC_CHUNKED;
/* Filter stuff. */
if (deflatep)
@ -1110,6 +1102,9 @@ NC4_rename_var(int ncid, int varid, const char *name)
}
/* Now change the name in our metadata. */
free(var->name);
if (!(var->name = malloc((strlen(name) + 1) * sizeof(char))))
return NC_ENOMEM;
strcpy(var->name, name);
exit:

View File

@ -765,8 +765,6 @@ main(int argc, char **argv)
if (strcmp(name_in, VAR_NAME6) || xtype_in != NC_INT || ndims != 1 || natts != 0 ||
dimids_in[0] != 0) ERR;
if (nc_inq_var_chunking(ncid, 0, &storage_in, chunksize_in)) ERR;
for (d = 0; d < NDIMS6; d++)
if (chunksize_in[d] != 0) ERR;
if (storage_in != NC_CONTIGUOUS) ERR;
if (nc_get_var_int(ncid, varid, data_in)) ERR;
for (i = 0; i < DIM6_LEN; i++)
@ -788,8 +786,6 @@ main(int argc, char **argv)
if (strcmp(name_in, VAR_NAME6) || xtype_in != NC_INT || ndims != 1 || natts != 0 ||
dimids_in[0] != 0) ERR;
if (nc_inq_var_chunking(ncid, 0, &storage_in, chunksize_in)) ERR;
for (d = 0; d < NDIMS6; d++)
if (chunksize_in[d] != 0) ERR;
if (storage_in != NC_CONTIGUOUS) ERR;
if (nc_get_var_int(ncid, varid, data_in)) ERR;
for (i = 0; i < DIM6_LEN; i++)