Removed dependency on NC_MAX_DIMS from libsrc4 files.

Improved HDF4 suport in CMakeLists.txt
Remaining files were not changed, but svn picks up
'property changes' on them.
This commit is contained in:
Ward Fisher 2013-01-28 19:58:06 +00:00
commit c20baac22b
6 changed files with 246 additions and 113 deletions

View File

@ -215,7 +215,7 @@ IF (ENABLE_HDF4)
MESSAGE(FATAL_ERROR "HDF4 Support enabled, but cannot find mfhdf lib.")
ENDIF()
SET(HDF4_LIBRARIES ${HDF4_DF_LIB} ${HDF4_MFHDF_LIB})
SET(HDF4_LIBRARIES ${HDF4_MFHDF_LIB} ${HDF4_DF_LIB})
# End include files, libraries.
MESSAGE(STATUS "HDF4 Libraries: ${HDF4_DF_LIB}, ${HDF4_MFHDF_LIB}")
OPTION(ENABLE_HDF4_FILE_TESTS "Run HDF4 File Tests.",OFF)

View File

@ -364,10 +364,10 @@ NC4_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp)
LOG((2, "nc_inq_unlimdims: ncid 0x%x", ncid));
/* 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;
/* 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;
/* Get our dim info. */
assert(h5);
{

View File

@ -1629,7 +1629,8 @@ read_dataset(NC_GRP_INFO_T *grp, char *obj_name)
hid_t datasetid = 0;
hid_t spaceid = 0, access_pid = 0;
int ndims;
hsize_t dims[NC_MAX_DIMS], max_dims[NC_MAX_DIMS];
hsize_t *dims = NULL;
hsize_t *max_dims = NULL;
int is_scale = 0;
int dim_without_var = 0;
int num_scales = 0;
@ -1654,8 +1655,17 @@ read_dataset(NC_GRP_INFO_T *grp, char *obj_name)
#endif
if ((ndims = H5Sget_simple_extent_ndims(spaceid)) < 0)
BAIL(NC_EHDFERR);
if (ndims > NC_MAX_DIMS)
BAIL(NC_EMAXDIMS);
/* Removed check to remove nc4 dependency on
maximum dimensions. */
//if (ndims > NC_MAX_DIMS)
// BAIL(NC_EMAXDIMS);
if( (dims = (hsize_t*)malloc(sizeof(hsize_t)*ndims)) == NULL)
BAIL(errno);
if( (max_dims = (hsize_t*)malloc(sizeof(hsize_t)*ndims)) == NULL)
BAIL(errno);
if (H5Sget_simple_extent_dims(spaceid, dims, max_dims) < 0)
BAIL(NC_EHDFERR);
@ -1697,9 +1707,13 @@ read_dataset(NC_GRP_INFO_T *grp, char *obj_name)
#ifdef EXTRA_TESTS
num_spaces--;
#endif
if(dims) free(dims);
if(max_dims) free(max_dims);
return NC_NOERR;
exit:
exit:
if (access_pid && H5Pclose(access_pid) < 0)
BAIL2(retval);
#ifdef EXTRA_TESTS
@ -1712,6 +1726,9 @@ read_dataset(NC_GRP_INFO_T *grp, char *obj_name)
#ifdef EXTRA_TESTS
num_spaces--;
#endif
if(dims) free(dims);
if(max_dims) free(max_dims);
return retval;
}
@ -2478,43 +2495,80 @@ nc4_open_hdf4_file(const char *path, int mode, NC *nc)
for (v = 0; v < num_datasets; v++)
{
int32 data_type, num_atts;
int32 dimsize[NC_MAX_DIMS];
/* Problem: Number of dims is returned by the call that requires
a pre-allocated array, 'dimsize'.
From SDS_SD website:
http://www.hdfgroup.org/training/HDFtraining/UsersGuide/SDS_SD.fm3.html
The maximum rank is 32, or MAX_VAR_DIMS (as defined in netcdf.h).
int32 dimsize[MAX_VAR_DIMS];
*/
int32 *dimsize = NULL;
size_t var_type_size;
int a;
/* Add a variable to the end of the group's var list. */
if ((retval = nc4_var_list_add(&grp->var, &var)))
return retval;
if ((retval = nc4_var_list_add(&grp->var, &var))) {
return retval;
}
var->varid = grp->nvars++;
var->created = 1;
var->written_to = 1;
/* Open this dataset in HDF4 file. */
if ((var->sdsid = SDselect(h5->sdid, v)) == FAIL)
return NC_EVARMETA;
if ((var->sdsid = SDselect(h5->sdid, v)) == FAIL) {
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;
if (!(var->name = malloc(NC_MAX_HDF4_NAME + 1))) {
return NC_ENOMEM;
}
/* Invoke SDgetInfo with null dimsize to get rank. */
if (SDgetinfo(var->sdsid, var->name, &rank, NULL, &data_type, &num_atts))
return NC_EVARMETA;
if(!(dimsize = (int32*)malloc(sizeof(int32)*rank))) {
return NC_ENOMEM;
}
if (SDgetinfo(var->sdsid, var->name, &rank, dimsize, &data_type, &num_atts)) {
if(dimsize) free(dimsize);
return NC_EVARMETA;
}
var->ndims = rank;
var->hdf4_data_type = data_type;
/* Fill special type_info struct for variable type information. */
if (!(var->type_info = calloc(1, sizeof(NC_TYPE_INFO_T))))
return NC_ENOMEM;
if ((retval = get_netcdf_type_from_hdf4(h5, data_type, &var->xtype, var->type_info)))
return retval;
if ((retval = nc4_get_typelen_mem(h5, var->xtype, 0, &var_type_size)))
return retval;
if (!(var->type_info = calloc(1, sizeof(NC_TYPE_INFO_T)))) {
if(dimsize) free(dimsize);
return NC_ENOMEM;
}
if ((retval = get_netcdf_type_from_hdf4(h5, data_type, &var->xtype, var->type_info))) {
if(dimsize) free(dimsize);
return retval;
}
if ((retval = nc4_get_typelen_mem(h5, var->xtype, 0, &var_type_size))) {
if(dimsize) free(dimsize);
return retval;
}
var->type_info->size = var_type_size;
LOG((3, "reading HDF4 dataset %s, rank %d netCDF type %d", var->name,
rank, var->xtype));
/* Get the fill value. */
if (!(var->fill_value = malloc(var_type_size)))
return NC_ENOMEM;
if (!(var->fill_value = malloc(var_type_size))) {
if(dimsize) free(dimsize);
return NC_ENOMEM;
}
if (SDgetfillvalue(var->sdsid, var->fill_value))
{
/* Whoops! No fill value! */
@ -2525,11 +2579,17 @@ nc4_open_hdf4_file(const char *path, int mode, NC *nc)
/* Allocate storage for dimension info in this variable. */
if (var->ndims)
{
if (!(var->dim = malloc(sizeof(NC_DIM_INFO_T *) * var->ndims)))
return NC_ENOMEM;
if (!(var->dimids = malloc(sizeof(int) * var->ndims)))
return NC_ENOMEM;
if (!(var->dim = malloc(sizeof(NC_DIM_INFO_T *) * var->ndims))) {
if(dimsize) free(dimsize);
return NC_ENOMEM;
}
if (!(var->dimids = malloc(sizeof(int) * var->ndims))) {
if(dimsize) free(dimsize);
return NC_ENOMEM;
}
}
/* Find its dimensions. */
for (d = 0; d < var->ndims; d++)
@ -2538,11 +2598,16 @@ nc4_open_hdf4_file(const char *path, int mode, NC *nc)
char dim_name[NC_MAX_NAME + 1];
NC_DIM_INFO_T *dim;
if ((dimid = SDgetdimid(var->sdsid, d)) == FAIL)
return NC_EDIMMETA;
if ((dimid = SDgetdimid(var->sdsid, d)) == FAIL) {
if(dimsize) free(dimsize);
return NC_EDIMMETA;
}
if (SDdiminfo(dimid, dim_name, &dim_len, &dim_data_type,
&dim_num_attrs))
return NC_EDIMMETA;
{
if(dimsize) free(dimsize);
return NC_EDIMMETA;
}
/* Do we already have this dimension? HDF4 explicitly uses
* the name to tell. */
@ -2582,33 +2647,49 @@ nc4_open_hdf4_file(const char *path, int mode, NC *nc)
size_t att_type_size;
/* Add to the end of the list of atts for this var. */
if ((retval = nc4_att_list_add(&var->att)))
return retval;
if ((retval = nc4_att_list_add(&var->att))) {
if(dimsize) free(dimsize);
return retval;
}
for (att = var->att; att->next; att = att->next)
;
;
att->attnum = var->natts++;
att->created++;
/* Learn about this attribute. */
if (!(att->name = malloc(NC_MAX_HDF4_NAME * sizeof(char))))
return NC_ENOMEM;
if (SDattrinfo(var->sdsid, a, att->name, &att_data_type, &att_count))
if (!(att->name = malloc(NC_MAX_HDF4_NAME * sizeof(char)))) {
if(dimsize) free(dimsize);
return NC_ENOMEM;
}
if (SDattrinfo(var->sdsid, a, att->name, &att_data_type, &att_count)) {
if(dimsize) free(dimsize);
return NC_EATTMETA;
}
if ((retval = get_netcdf_type_from_hdf4(h5, att_data_type,
&att->xtype, NULL)))
return retval;
&att->xtype, NULL))) {
if(dimsize) free(dimsize);
return retval;
}
att->len = att_count;
/* Allocate memory to hold the data. */
if ((retval = nc4_get_typelen_mem(h5, att->xtype, 0, &att_type_size)))
return retval;
if (!(att->data = malloc(att_type_size * att->len)))
return NC_ENOMEM;
if ((retval = nc4_get_typelen_mem(h5, att->xtype, 0, &att_type_size))) {
if(dimsize) free(dimsize);
return retval;
}
if (!(att->data = malloc(att_type_size * att->len))) {
if(dimsize) free(dimsize);
return NC_ENOMEM;
}
/* Read the data. */
if (SDreadattr(var->sdsid, a, att->data))
return NC_EHDFERR;
if (SDreadattr(var->sdsid, a, att->data)) {
if(dimsize) free(dimsize);
return NC_EHDFERR;
}
}
if(dimsize) free(dimsize);
} /* next var */
#ifdef LOGGING
@ -3111,10 +3192,10 @@ NC4_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp)
{
*nvarsp = 0;
for (var = grp->var; var; var= var->next)
(*nvarsp)++;
(*nvarsp)++;
}
if (nattsp)
{
{
*nattsp = 0;
for (att = grp->att; att; att = att->next)
(*nattsp)++;

View File

@ -170,7 +170,9 @@ nc4_pg_var1(NC_PG_T pg, NC *nc, int ncid, int varid,
NC_GRP_INFO_T *grp;
NC_VAR_INFO_T *var;
int i;
size_t start[NC_MAX_VAR_DIMS], count[NC_MAX_VAR_DIMS];
size_t *start = NULL;
size_t *count = NULL;
int retval;
/* Find file and var, cause I need the number of dims. */
@ -179,22 +181,37 @@ nc4_pg_var1(NC_PG_T pg, NC *nc, int ncid, int varid,
return retval;
assert(grp && var && var->name);
if(!(start = (size_t*)malloc(sizeof(size_t)*var->ndims))) {
return NC_ENOMEM;
}
if(!(count = (size_t*)malloc(sizeof(size_t)*var->ndims))) {
free(start);
return NC_ENOMEM;
}
/* Set up the count and start arrays. */
for (i=0; i<var->ndims; i++)
{
start[i] = indexp[i];
count[i] = 1;
start[i] = indexp[i];
count[i] = 1;
}
/* Get or put this data. */
if (pg == GET)
return nc4_get_vara(nc, ncid, varid, start, count, xtype,
is_long, ip);
else
return nc4_put_vara(nc, ncid, varid, start, count, xtype,
int res = 0;
if (pg == GET) {
res = nc4_get_vara(nc, ncid, varid, start, count, xtype,
is_long, ip);
} else {
res = nc4_put_vara(nc, ncid, varid, start, count, xtype,
is_long, ip);
}
free(start);
free(count);
return res;
}
/* Get the default fill value for an atomic type. Memory for
* fill_value must already be allocated, or you are DOOMED!!!*/
int
@ -1742,15 +1759,21 @@ commit_type(NC_GRP_INFO_T *grp, NC_TYPE_INFO_T *type)
if (field->ndims)
{
int d;
hsize_t dims[NC_MAX_DIMS];
for (d = 0; d < field->ndims; d++)
hsize_t *dims = NULL;
if( (dims = (hsize_t*)malloc(sizeof(hsize_t)*field->ndims)) == NULL)
return errno;
for (d = 0; d < field->ndims; d++)
dims[d] = field->dim_size[d];
if ((hdf_typeid = H5Tarray_create(hdf_base_typeid, field->ndims,
dims, NULL)) < 0)
return NC_EHDFERR;
}
dims, NULL)) < 0) {
free(dims);
return NC_EHDFERR;
}
free(dims);
}
else
hdf_typeid = hdf_base_typeid;
hdf_typeid = hdf_base_typeid;
LOG((4, "inserting field %s offset %d hdf_typeid 0x%x", field->name,
field->offset, hdf_typeid));
if (H5Tinsert(type->hdf_typeid, field->name, field->offset,
@ -2776,16 +2799,26 @@ nc4_pg_varm(NC_PG_T pg, NC *nc, int ncid, int varid, const size_t *start,
goto done;
/* Don't check unlimited dimension on PUTs. */
if (pg == PUT)
{
int stop = 0, d, num_unlim_dim, unlim_dimids[NC_MAX_DIMS];
if ((retval = NC4_inq_unlimdims(ncid, &num_unlim_dim, unlim_dimids)))
goto done;
{
int stop = 0, d, num_unlim_dim;
int *unlim_dimids = NULL;
NC4_inq_unlimdims(ncid, &num_unlim_dim, NULL);
if(!(unlim_dimids=(int*)malloc(sizeof(int)*num_unlim_dim)))
return errno;
if ((retval = NC4_inq_unlimdims(ncid, &num_unlim_dim, unlim_dimids)))
{
free(unlim_dimids);
goto done;
}
for (d = 0; d < num_unlim_dim; d++)
if (var->dimids[idim] == unlim_dimids[d])
stop++;
if (stop)
break;
}
}
LOG((4, "idim=%d mystart[idim]=%d myedge[idim]=%d dimlen=%d",
idim, mystart[idim], myedges[idim], dimlen));
if (mystart[idim] >= dimlen)

View File

@ -473,8 +473,8 @@ nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len)
{
NC_GRP_INFO_T *g;
NC_VAR_INFO_T *var;
int d, ndims, dimids[NC_MAX_DIMS];
size_t dimlen[NC_MAX_DIMS];
int d, ndims, *dimids = NULL;
size_t *dimlen = NULL;
int retval;
assert(grp && len);
@ -490,24 +490,31 @@ nc4_find_dim_len(NC_GRP_INFO_T *grp, int dimid, size_t **len)
* dimension, and remember the max length. */
for (var = grp->var; var; var = var->next)
{
/* Find dimensions of this var. */
if ((retval = find_var_shape_grp(grp, var->varid, &ndims,
dimids, dimlen)))
return retval;
/* Check for any dimension that matches dimid. If found, check
* if its length is longer than *lenp. */
for (d = 0; d < ndims; d++)
{
if(var->ndims > 0) {
dimids = (int*)malloc(sizeof(int)*var->ndims);
dimlen = (size_t*)malloc(sizeof(size_t)*var->ndims);
}
/* Find dimensions of this var. */
if ((retval = find_var_shape_grp(grp, var->varid, &ndims,
dimids, dimlen)))
return retval;
/* Check for any dimension that matches dimid. If found, check
* if its length is longer than *lenp. */
for (d = 0; d < ndims; d++)
{
if (dimids[d] == dimid)
{
/* Remember the max length in *lenp. */
**len = dimlen[d] > **len ? dimlen[d] : **len;
break;
}
}
{
/* Remember the max length in *lenp. */
**len = dimlen[d] > **len ? dimlen[d] : **len;
break;
}
}
free(dimids); dimids = NULL;
free(dimlen); dimlen = NULL;
}
return NC_NOERR;
}
@ -1316,7 +1323,7 @@ rec_print_metadata(NC_GRP_INFO_T *grp, int *tab_count)
NC_TYPE_INFO_T *type;
NC_FIELD_INFO_T *field;
char tabs[MAX_NESTS] = "";
char dims_string[NC_MAX_DIMS*4];
char *dims_string = NULL;
char temp_string[10];
int t, retval, d;
@ -1345,18 +1352,20 @@ rec_print_metadata(NC_GRP_INFO_T *grp, int *tab_count)
;
for( ; var; var = var->prev)
{
strcpy(dims_string, "");
for (d = 0; d < var->ndims; d++)
{
dims_string = (char*)malloc(sizeof(char)*(var->ndims*4));
strcpy(dims_string, "");
for (d = 0; d < var->ndims; d++)
{
sprintf(temp_string, " %d", var->dimids[d]);
strcat(dims_string, temp_string);
}
}
LOG((2, "%s VARIABLE - varid: %d name: %s type: %d ndims: %d dimscale: %d dimids:%s",
tabs, var->varid, var->name, var->xtype, var->ndims, var->dimscale,
dims_string));
for(att = var->att; att; att = att->next)
LOG((2, "%s VAR ATTRIBUTE - attnum: %d name: %s type: %d len: %d",
tabs, att->attnum, att->name, att->xtype, att->len));
free(dims_string); dims_string = NULL;
}
for (type = grp->type; type; type = type->next)

View File

@ -1258,9 +1258,11 @@ nc4_put_vara_tc(int ncid, int varid, nc_type mem_type, int mem_type_is_long,
const size_t *startp, const size_t *countp, const void *op)
{
NC *nc;
#ifdef USE_PNETCDF
NC_HDF5_FILE_INFO_T *h5;
#endif
int res = -1;
LOG((2, "nc4_put_vara_tc: ncid 0x%x varid %d mem_type %d mem_type_is_long %d",
ncid, varid, mem_type, mem_type_is_long));
@ -1275,8 +1277,12 @@ nc4_put_vara_tc(int ncid, int varid, nc_type mem_type, int mem_type_is_long,
/* Handle files opened/created with the parallel-netcdf library. */
if (h5->pnetcdf_file)
{
MPI_Offset mpi_start[NC_MAX_DIMS], mpi_count[NC_MAX_DIMS];
int d;
MPI_Offset *mpi_start;
MPI_Offset *mpi_count;
int d;
mpi_start = (MPI_Offset*)malloc(sizeof(MPI_Offset)*h5->pnetcdf_ndims[varid]);
mpi_count = (MPI_Offset*)malloc(sizeof(MPI_Offset)*h5->pnetcdf_ndims[varid]);
/* No NC_LONGs for parallel-netcdf library! */
if (mem_type_is_long)
@ -1295,48 +1301,52 @@ nc4_put_vara_tc(int ncid, int varid, nc_type mem_type, int mem_type_is_long,
switch(mem_type)
{
case NC_BYTE:
return ncmpi_put_vara_schar(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_schar(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_UBYTE:
return ncmpi_put_vara_uchar(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_uchar(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_CHAR:
return ncmpi_put_vara_text(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_text(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_SHORT:
return ncmpi_put_vara_short(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_short(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_INT:
return ncmpi_put_vara_int(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_int(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_FLOAT:
return ncmpi_put_vara_float(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_float(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_DOUBLE:
return ncmpi_put_vara_double(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_double(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_NAT:
default:
return NC_EBADTYPE;
res = NC_EBADTYPE;
}
}
}
else
{
switch(mem_type)
{
case NC_BYTE:
return ncmpi_put_vara_schar_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_schar_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_UBYTE:
return ncmpi_put_vara_uchar_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_uchar_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_CHAR:
return ncmpi_put_vara_text_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_text_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_SHORT:
return ncmpi_put_vara_short_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_short_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_INT:
return ncmpi_put_vara_int_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_int_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_FLOAT:
return ncmpi_put_vara_float_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_float_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_DOUBLE:
return ncmpi_put_vara_double_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
res = ncmpi_put_vara_double_all(nc->int_ncid, varid, mpi_start, mpi_count, op);
case NC_NAT:
default:
return NC_EBADTYPE;
res = NC_EBADTYPE;
}
}
free(mpi_start); mpi_start = NULL;
free(mpi_count); mpi_count = NULL;
return res;
}
#endif /* USE_PNETCDF */
return nc4_put_vara(nc, ncid, varid, startp, countp, mem_type,