From d8ff280adf0852a8593aa45fcbc11822af26d2fd Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 6 Jul 2019 06:42:29 -0600 Subject: [PATCH] adding more functions to netcdf integration layer --- src/ncint/ncintdispatch.c | 92 ++++++++++++++++++++++++++++++++++++--- src/ncint/ncintdispatch.h | 12 +++++ 2 files changed, 99 insertions(+), 5 deletions(-) diff --git a/src/ncint/ncintdispatch.c b/src/ncint/ncintdispatch.c index 446db789932..216a285f53b 100644 --- a/src/ncint/ncintdispatch.c +++ b/src/ncint/ncintdispatch.c @@ -42,13 +42,13 @@ NC_Dispatch NCINT_dispatcher = { PIO_NCINT_inq_format_extended, PIO_NCINT_inq, - NC4_inq_type, + PIO_NCINT_inq_type, PIO_NCINT_def_dim, - NC4_inq_dimid, - NC4_inq_dim, - NC4_inq_unlimdim, - NC_RO_rename_dim, + PIO_NCINT_inq_dimid, + PIO_NCINT_inq_dim, + PIO_NCINT_inq_unlimdim, + PIO_NCINT_rename_dim, NC4_inq_att, NC4_inq_attid, @@ -223,6 +223,88 @@ PIO_NCINT_def_dim(int ncid, const char *name, size_t len, int *idp) return PIOc_def_dim(ncid, name, len, idp); } +/** + * @internal Given dim name, find its id. + * + * @param ncid File and group ID. + * @param name Name of the dimension to find. + * @param idp Pointer that gets dimension ID. + * + * @return ::NC_NOERR No error. + * @return ::NC_EBADID Bad ncid. + * @return ::NC_EBADDIM Dimension not found. + * @return ::NC_EINVAL Invalid input. Name must be provided. + * @author Ed Hartnett + */ +int +PIO_NCINT_inq_dimid(int ncid, const char *name, int *idp) +{ + return PIOc_inq_dimid(ncid, name, idp); +} + +/** + * @internal Find out name and len of a dim. For an unlimited + * dimension, the length is the largest length so far written. If the + * name of lenp pointers are NULL, they will be ignored. + * + * @param ncid File and group ID. + * @param dimid Dimension ID. + * @param name Pointer that gets name of the dimension. + * @param lenp Pointer that gets length of dimension. + * + * @return ::NC_NOERR No error. + * @return ::NC_EBADID Bad ncid. + * @return ::NC_EDIMSIZE Dimension length too large. + * @return ::NC_EBADDIM Dimension not found. + * @author Ed Hartnett + */ +int +PIO_NCINT_inq_dim(int ncid, int dimid, char *name, size_t *lenp) +{ + return PIOc_inq_dim(ncid, dimid, name, (PIO_Offset *)lenp); +} + +/** + * @internal Netcdf-4 files might have more than one unlimited + * dimension, but return the first one anyway. + * + * @note that this code is inconsistent with nc_inq + * + * @param ncid File and group ID. + * @param unlimdimidp Pointer that gets ID of first unlimited + * dimension, or -1. + * + * @return ::NC_NOERR No error. + * @return ::NC_EBADID Bad ncid. + * @author Ed Hartnett + */ +int +PIO_NCINT_inq_unlimdim(int ncid, int *unlimdimidp) +{ + return PIOc_inq_unlimdim(ncid, unlimdimidp); +} + +/** + * @internal Rename a dimension, for those who like to prevaricate. + * + * @note If we're not in define mode, new name must be of equal or + * less size, if strict nc3 rules are in effect for this file. But we + * don't check this because reproducing the exact classic behavior + * would be too difficult. See github issue #1340. + * + * @param ncid File and group ID. + * @param dimid Dimension ID. + * @param name New dimension name. + * + * @return 0 on success, error code otherwise. + * @author Ed Hartnett + */ +int +PIO_NCINT_rename_dim(int ncid, int dimid, const char *name) +{ + return PIOc_rename_dim(ncid, dimid, name); +} + int PIO_NCINT_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp) diff --git a/src/ncint/ncintdispatch.h b/src/ncint/ncintdispatch.h index 944ec9bfa80..c25f6ca7368 100644 --- a/src/ncint/ncintdispatch.h +++ b/src/ncint/ncintdispatch.h @@ -86,6 +86,18 @@ extern "C" { extern int PIO_NCINT_inq_type(int ncid, nc_type typeid1, char *name, size_t *size); + extern int + PIO_NCINT_inq_dimid(int ncid, const char *name, int *idp); + + extern int + PIO_NCINT_inq_dim(int ncid, int dimid, char *name, size_t *lenp); + + extern int + PIO_NCINT_inq_unlimdim(int ncid, int *unlimdimidp); + + extern int + PIO_NCINT_rename_dim(int ncid, int dimid, const char *name); + extern int PIO_NCINT_get_vara(int ncid, int varid, const size_t *start, const size_t *count, void *value, nc_type);