Removing reliance on NC_MAX_VAR_DIMS

This commit is contained in:
Ward Fisher 2013-01-22 20:59:39 +00:00
parent 23647a6910
commit fae7d90194

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_GRP_INFO_T *grp;
NC_VAR_INFO_T *var; NC_VAR_INFO_T *var;
int i; int i;
size_t start[NC_MAX_VAR_DIMS], count[NC_MAX_VAR_DIMS]; size_t *start = NULL;
size_t *count = NULL;
int retval; int retval;
/* Find file and var, cause I need the number of dims. */ /* Find file and var, cause I need the number of dims. */
@ -179,6 +181,16 @@ nc4_pg_var1(NC_PG_T pg, NC *nc, int ncid, int varid,
return retval; return retval;
assert(grp && var && var->name); 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. */ /* Set up the count and start arrays. */
for (i=0; i<var->ndims; i++) for (i=0; i<var->ndims; i++)
{ {
@ -187,13 +199,18 @@ nc4_pg_var1(NC_PG_T pg, NC *nc, int ncid, int varid,
} }
/* Get or put this data. */ /* Get or put this data. */
if (pg == GET) int res = 0;
return nc4_get_vara(nc, ncid, varid, start, count, xtype, if (pg == GET) {
res = nc4_get_vara(nc, ncid, varid, start, count, xtype,
is_long, ip); is_long, ip);
else } else {
return nc4_put_vara(nc, ncid, varid, start, count, xtype, res = nc4_put_vara(nc, ncid, varid, start, count, xtype,
is_long, ip); is_long, ip);
} }
free(start);
free(count);
return res;
}
/* Get the default fill value for an atomic type. Memory for /* Get the default fill value for an atomic type. Memory for
* fill_value must already be allocated, or you are DOOMED!!!*/ * fill_value must already be allocated, or you are DOOMED!!!*/