mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-27 08:49:16 +08:00
59e04ae071
cloud using a variant of the Zarr protocol and storage format. This enhancement is generically referred to as "NCZarr". The data model supported by NCZarr is netcdf-4 minus the user-defined types and the String type. In this sense it is similar to the CDF-5 data model. More detailed information about enabling and using NCZarr is described in the document NUG/nczarr.md and in a [Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in). WARNING: this code has had limited testing, so do use this version for production work. Also, performance improvements are ongoing. Note especially the following platform matrix of successful tests: Platform | Build System | S3 support ------------------------------------ Linux+gcc | Automake | yes Linux+gcc | CMake | yes Visual Studio | CMake | no Additionally, and as a consequence of the addition of NCZarr, major changes have been made to the Filter API. NOTE: NCZarr does not yet support filters, but these changes are enablers for that support in the future. Note that it is possible (probable?) that there will be some accidental reversions if the changes here did not correctly mimic the existing filter testing. In any case, previously filter ids and parameters were of type unsigned int. In order to support the more general zarr filter model, this was all converted to char*. The old HDF5-specific, unsigned int operations are still supported but they are wrappers around the new, char* based nc_filterx_XXX functions. This entailed at least the following changes: 1. Added the files libdispatch/dfilterx.c and include/ncfilter.h 2. Some filterx utilities have been moved to libdispatch/daux.c 3. A new entry, "filter_actions" was added to the NCDispatch table and the version bumped. 4. An overly complex set of structs was created to support funnelling all of the filterx operations thru a single dispatch "filter_actions" entry. 5. Move common code to from libhdf5 to libsrc4 so that it is accessible to nczarr. Changes directly related to Zarr: 1. Modified CMakeList.txt and configure.ac to support both C and C++ -- this is in support of S3 support via the awd-sdk libraries. 2. Define a size64_t type to support nczarr. 3. More reworking of libdispatch/dinfermodel.c to support zarr and to regularize the structure of the fragments section of a URL. Changes not directly related to Zarr: 1. Make client-side filter registration be conditional, with default off. 2. Hack include/nc4internal.h to make some flags added by Ed be unique: e.g. NC_CREAT, NC_INDEF, etc. 3. cleanup include/nchttp.h and libdispatch/dhttp.c. 4. Misc. changes to support compiling under Visual Studio including: * Better testing under windows for dirent.h and opendir and closedir. 5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags and to centralize error reporting. 6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them. 7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible. Changes Left TO-DO: 1. fix provenance code, it is too HDF5 specific.
133 lines
3.8 KiB
C
133 lines
3.8 KiB
C
/* Copyright 2003-2018, University Corporation for Atmospheric
|
|
* Research. See COPYRIGHT file for copying and redistribution
|
|
* conditions. */
|
|
|
|
/**
|
|
* @file
|
|
* @internal The netCDF-4 file functions relating to file creation.
|
|
*
|
|
* @author Dennis Heimbigner, Ed Hartnett
|
|
*/
|
|
|
|
#include "zincludes.h"
|
|
|
|
/** @internal These flags may not be set for create. */
|
|
static const int ILLEGAL_CREATE_FLAGS = (NC_NOWRITE|NC_MMAP|NC_DISKLESS|NC_64BIT_OFFSET|NC_CDF5);
|
|
|
|
/**
|
|
* @internal Create a netCDF-4/NCZ file.
|
|
*
|
|
* @param path The file name of the new file.
|
|
* @param cmode The creation mode flag.
|
|
* @param initialsz The proposed initial file size (advisory)
|
|
* @param nc Pointer to an instance of NC.
|
|
*
|
|
* @return ::NC_NOERR No error.
|
|
* @return ::NC_EINVAL Invalid input (check cmode).
|
|
* @return ::NC_EEXIST File exists and NC_NOCLOBBER used.
|
|
* @return ::NC_EHDFERR ZARR returned error.
|
|
* @ingroup netcdf4
|
|
* @author Dennis Heimbigner, Ed Hartnett
|
|
*/
|
|
static int
|
|
ncz_create_file(const char *path, int cmode, size_t initialsz, const char** controls, int ncid)
|
|
{
|
|
int retval = NC_NOERR;
|
|
NC_FILE_INFO_T* h5 = NULL;
|
|
|
|
assert(path);
|
|
LOG((3, "%s: path %s mode 0x%x", __func__, path, cmode));
|
|
|
|
/* Add necessary structs to hold netcdf-4 file data. */
|
|
if ((retval = nc4_file_list_add(ncid, path, cmode, (void**)&h5)))
|
|
BAIL(retval);
|
|
assert(h5 && h5->root_grp);
|
|
h5->root_grp->atts_read = 1;
|
|
|
|
h5->mem.inmemory = ((cmode & NC_INMEMORY) == NC_INMEMORY);
|
|
h5->mem.diskless = ((cmode & NC_DISKLESS) == NC_DISKLESS);
|
|
h5->mem.persist = ((cmode & NC_PERSIST) == NC_PERSIST);
|
|
|
|
/* Do format specific setup */
|
|
/* Should check if file already exists, and if NC_NOCLOBBER is specified,
|
|
return an error */
|
|
if((retval = ncz_create_dataset(h5,h5->root_grp,controls)))
|
|
BAIL(retval);
|
|
|
|
/* Define mode gets turned on automatically on create. */
|
|
h5->flags |= NC_INDEF;
|
|
|
|
/* Set provenance. */
|
|
if ((retval = NCZ_new_provenance(h5)))
|
|
BAIL(retval);
|
|
|
|
return NC_NOERR;
|
|
|
|
exit: /*failure exit*/
|
|
if(!h5) return retval;
|
|
#ifdef LOOK
|
|
ncz_close_ncz_file(h5, 1, NULL); /* treat like abort */
|
|
#endif
|
|
return retval;
|
|
}
|
|
|
|
/**
|
|
* @internal Create a netCDF-4/NCZ file.
|
|
*
|
|
* @param path The file name of the new file.
|
|
* @param cmode The creation mode flag.
|
|
* @param initialsz Ignored by this function.
|
|
* @param basepe Ignored by this function.
|
|
* @param chunksizehintp Ignored by this function.
|
|
* @param parameters pointer to struct holding extra data (e.g. for
|
|
* parallel I/O) layer. Ignored if NULL.
|
|
* @param dispatch Pointer to the dispatch table for this file.
|
|
* @param nc_file Pointer to an instance of NC.
|
|
*
|
|
* @return ::NC_NOERR No error.
|
|
* @return ::NC_EINVAL Invalid input (check cmode).
|
|
* @ingroup netcdf4
|
|
* @author Dennis Heimbigner, Ed Hartnett
|
|
*/
|
|
int
|
|
NCZ_create(const char* path, int cmode, size_t initialsz, int basepe,
|
|
size_t *chunksizehintp, void *parameters,
|
|
const NC_Dispatch *dispatch, int ncid)
|
|
{
|
|
int stat = NC_NOERR;
|
|
NCURI* uri = NULL;
|
|
|
|
NC_UNUSED(parameters);
|
|
|
|
assert(path);
|
|
|
|
LOG((1, "%s: path %s cmode 0x%x ncid %d",
|
|
__func__, path, cmode ,ncid));
|
|
|
|
/* If this is our first file, initialize */
|
|
if (!ncz_initialized) NCZ_initialize();
|
|
|
|
#ifdef LOGGING
|
|
/* If nc logging level has changed, see if we need to turn on
|
|
* NCZ's error messages. */
|
|
NCZ_set_log_level();
|
|
#endif /* LOGGING */
|
|
|
|
/* Check the cmode for validity. */
|
|
if((cmode & ILLEGAL_CREATE_FLAGS) != 0)
|
|
{stat = NC_EINVAL; goto done;}
|
|
|
|
/* Turn on NC_WRITE */
|
|
cmode |= NC_WRITE;
|
|
|
|
/* Get the controls */
|
|
if(ncuriparse(path,&uri)) goto done;
|
|
|
|
/* Create the file */
|
|
stat = ncz_create_file(path, cmode, initialsz, ncurifragmentparams(uri), ncid);
|
|
|
|
done:
|
|
ncurifree(uri);
|
|
return stat;
|
|
}
|