removing unneeded file lookups

This commit is contained in:
Ed Hartnett 2018-08-14 08:56:58 -06:00
parent 5800fdd617
commit d6c0cbe234
3 changed files with 65 additions and 61 deletions

View File

@ -152,6 +152,10 @@ extern size_t nc_sizevector0[NC_MAX_VAR_DIMS];
extern size_t nc_sizevector1[NC_MAX_VAR_DIMS];
extern ptrdiff_t nc_ptrdiffvector1[NC_MAX_VAR_DIMS];
/* Prototypes. */
int NC_check_nulls(int ncid, int varid, const size_t *start, size_t **count,
ptrdiff_t **stride);
/**************************************************/
/* Forward */
#ifndef USE_NETCDF4

View File

@ -626,6 +626,67 @@ nc_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value)
return ncp->dispatch->def_var_fill(ncid,varid,no_fill,fill_value);
}
/**
* @internal Check the start, count, and stride parameters for gets
* and puts, and handle NULLs.
*
* @param ncid The file ID.
* @param varid The variable ID.
* @param start Pointer to start array. If NULL NC_EINVALCOORDS will
* be returned for non-scalar variable.
* @param count Pointer to pointer to count array. If *count is NULL,
* an array of the correct size will be allocated, and filled with
* counts that represent the full extent of the variable. In this
* case, the memory must be freed by the caller.
* @param stride Pointer to pointer to stride array. If NULL, stide is
* ignored. If *stride is NULL an array of the correct size will be
* allocated, and filled with ones. In this case, the memory must be
* freed by the caller.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_ENOTVAR Variable not found.
* @return ::NC_ENOMEM Out of memory.
* @return ::NC_EINVALCOORS Missing start array.
* @author Ed Hartnett
*/
int
NC_check_nulls(int ncid, int varid, const size_t *start, size_t **count,
ptrdiff_t **stride)
{
int varndims;
int stat;
if ((stat = nc_inq_varndims(ncid, varid, &varndims)))
return stat;
/* For non-scalar vars, start is required. */
if (!start && varndims)
return NC_EINVALCOORDS;
/* If count is NULL, assume full extent of var. */
if (!*count)
{
if (!(*count = malloc(varndims * sizeof(size_t))))
return NC_ENOMEM;
if ((stat = NC_getshape(ncid, varid, varndims, *count)))
return stat;
}
/* If stride is NULL, do nothing, if *stride is NULL use all 1s. */
if (stride && !*stride)
{
int i;
if (!(*stride = malloc(varndims * sizeof(size_t))))
return NC_ENOMEM;
for (i = 0; i < varndims; i++)
*stride[i] = 1;
}
return NC_NOERR;
}
#ifdef USE_NETCDF4
/** \ingroup variables

View File

@ -83,67 +83,6 @@ odom_next(struct GETodometer* odom)
return 1;
}
/**
* @internal Check the start, count, and stride parameters for gets
* and puts, and handle NULLs.
*
* @param ncid The file ID.
* @param varid The variable ID.
* @param start Pointer to start array. If NULL NC_EINVALCOORDS will
* be returned for non-scalar variable.
* @param count Pointer to pointer to count array. If *count is NULL,
* an array of the correct size will be allocated, and filled with
* counts that represent the full extent of the variable. In this
* case, the memory must be freed by the caller.
* @param stride Pointer to pointer to stride array. If NULL, stide is
* ignored. If *stride is NULL an array of the correct size will be
* allocated, and filled with ones. In this case, the memory must be
* freed by the caller.
*
* @return ::NC_NOERR No error.
* @return ::NC_EBADID Bad ncid.
* @return ::NC_ENOTVAR Variable not found.
* @return ::NC_ENOMEM Out of memory.
* @return ::NC_EINVALCOORS Missing start array.
* @author Ed Hartnett
*/
int
NC_check_nulls(int ncid, int varid, const size_t *start, size_t **count,
ptrdiff_t **stride)
{
int varndims;
int stat;
if ((stat = nc_inq_varndims(ncid, varid, &varndims)))
return stat;
/* For non-scalar vars, start is required. */
if (!start && varndims)
return NC_EINVALCOORDS;
/* If count is NULL, assume full extent of var. */
if (!*count)
{
if (!(*count = malloc(varndims * sizeof(size_t))))
return NC_ENOMEM;
if ((stat = NC_getshape(ncid, varid, varndims, *count)))
return stat;
}
/* If stride is NULL, do nothing, if *stride is NULL use all 1s. */
if (stride && !*stride)
{
int i;
if (!(*stride = malloc(varndims * sizeof(size_t))))
return NC_ENOMEM;
for (i = 0; i < varndims; i++)
*stride[i] = 1;
}
return NC_NOERR;
}
/** \internal
\ingroup variables