From 181f260a20c6893513f02628814a3394783b5258 Mon Sep 17 00:00:00 2001 From: edwardhartnett Date: Fri, 2 Aug 2019 09:14:35 -0600 Subject: [PATCH] adding, and starting to use nc4_file_list_add() --- include/nc4internal.h | 2 ++ libhdf4/hdf4file.c | 6 ++++-- libsrc4/nc4internal.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/nc4internal.h b/include/nc4internal.h index e0c076aa9..51a6f4218 100644 --- a/include/nc4internal.h +++ b/include/nc4internal.h @@ -334,6 +334,8 @@ int nc4_get_typeclass(const NC_FILE_INFO_T *h5, nc_type xtype, int nc4_type_free(NC_TYPE_INFO_T *type); /* These list functions add and delete vars, atts. */ +int nc4_file_list_add(int ncid, const char *path, int mode, + void **dispatchdata); int nc4_nc4f_list_add(NC *nc, const char *path, int mode); int nc4_nc4f_list_del(NC_FILE_INFO_T *h5); int nc4_var_list_add(NC_GRP_INFO_T* grp, const char* name, int ndims, diff --git a/libhdf4/hdf4file.c b/libhdf4/hdf4file.c index 36b54cd16..af0a8d772 100644 --- a/libhdf4/hdf4file.c +++ b/libhdf4/hdf4file.c @@ -629,9 +629,11 @@ NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp, return NC_EHDFERR; /* Add necessary structs to hold netcdf-4 file data. */ - if ((retval = nc4_nc4f_list_add(nc, path, mode))) + /* if ((retval = nc4_nc4f_list_add(nc, path, mode))) */ + /* return retval; */ + /* h5 = (NC_FILE_INFO_T *)nc->dispatchdata; */ + if ((retval = nc4_file_list_add(ncid, path, mode, &h5))) return retval; - h5 = (NC_FILE_INFO_T *)nc->dispatchdata; assert(h5 && h5->root_grp); h5->no_write = NC_TRUE; h5->root_grp->atts_read = 1; diff --git a/libsrc4/nc4internal.c b/libsrc4/nc4internal.c index c57a8b1b4..d3864db57 100644 --- a/libsrc4/nc4internal.c +++ b/libsrc4/nc4internal.c @@ -82,6 +82,40 @@ nc4_check_name(const char *name, char *norm_name) return NC_NOERR; } +/** + * @internal Add a file to the list of libsrc4 open files. This is + * used by dispatch layers that wish to use the libsrc4 metadata + * model, but don't know about struct NC. This is the same as + * nc4_nc4f_list_add(), except it takes an ncid instead of an NC *. + * + * @param ncid The ncid of the file (aka ext_ncid). + * @param path The file name of the new file. + * @param mode The mode flag. + * + * @return ::NC_NOERR No error. + * @return ::NC_EBADID No NC struct with this ext_ncid. + * @return ::NC_ENOMEM Out of memory. + * @author Ed Hartnett + */ +int +nc4_file_list_add(int ncid, const char *path, int mode, void **dispatchdata) +{ + NC *nc; + int ret; + + /* Find NC pointer for this file. */ + if ((ret = NC_check_id(ncid, &nc))) + return ret; + + /* Add necessary structs to hold netcdf-4 file data. */ + if ((ret = nc4_nc4f_list_add(nc, path, mode))) + return ret; + + *dispatchdata = nc->dispatchdata; + + return NC_NOERR; +} + /** * @internal Given an NC pointer, add the necessary stuff for a * netcdf-4 file.