This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2018, University Corporation for Atmospheric Research
|
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "zincludes.h"
|
2021-01-29 11:11:01 +08:00
|
|
|
#include <stdarg.h>
|
2020-10-14 09:12:15 +08:00
|
|
|
#include "ncpathmgr.h"
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/* Import the current implementations */
|
|
|
|
|
2021-01-29 11:11:01 +08:00
|
|
|
extern NCZMAP_DS_API zmap_file;
|
|
|
|
#ifdef USE_HDF5
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
extern NCZMAP_DS_API zmap_nz4;
|
2021-01-29 11:11:01 +08:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_NCZARR_ZIP
|
|
|
|
extern NCZMAP_DS_API zmap_zip;
|
|
|
|
#endif
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
#ifdef ENABLE_S3_SDK
|
|
|
|
extern NCZMAP_DS_API zmap_s3sdk;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**************************************************/
|
2021-01-29 11:11:01 +08:00
|
|
|
|
2021-02-25 04:46:11 +08:00
|
|
|
NCZM_FEATURES
|
|
|
|
nczmap_features(NCZM_IMPL impl)
|
2021-01-29 11:11:01 +08:00
|
|
|
{
|
|
|
|
switch (impl) {
|
2021-02-25 04:46:11 +08:00
|
|
|
case NCZM_FILE: return zmap_file.features;
|
2021-01-29 11:11:01 +08:00
|
|
|
#ifdef ENABLE_NCZARR_ZIP
|
2021-02-25 04:46:11 +08:00
|
|
|
case NCZM_ZIP: return zmap_zip.features;
|
2021-01-29 11:11:01 +08:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_S3_SDK
|
2021-02-25 04:46:11 +08:00
|
|
|
case NCZM_S3: return zmap_s3sdk.features;
|
2021-01-29 11:11:01 +08:00
|
|
|
#endif
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return NCZM_UNIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
int
|
|
|
|
nczmap_create(NCZM_IMPL impl, const char *path, int mode, size64_t flags, void* parameters, NCZMAP** mapp)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
NCZMAP* map = NULL;
|
|
|
|
NCURI* uri = NULL;
|
|
|
|
|
|
|
|
if(path == NULL || strlen(path) == 0)
|
|
|
|
{stat = NC_EINVAL; goto done;}
|
|
|
|
|
|
|
|
if(mapp) *mapp = NULL;
|
|
|
|
|
|
|
|
switch (impl) {
|
2021-01-29 11:11:01 +08:00
|
|
|
case NCZM_FILE:
|
|
|
|
stat = zmap_file.create(path, mode, flags, parameters, &map);
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
if(stat) goto done;
|
|
|
|
break;
|
2021-01-29 11:11:01 +08:00
|
|
|
#ifdef ENABLE_NCZARR_ZIP
|
|
|
|
case NCZM_ZIP:
|
|
|
|
stat = zmap_zip.create(path, mode, flags, parameters, &map);
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
if(stat) goto done;
|
|
|
|
break;
|
2021-01-29 11:11:01 +08:00
|
|
|
#endif
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
#ifdef ENABLE_S3_SDK
|
|
|
|
case NCZM_S3:
|
|
|
|
stat = zmap_s3sdk.create(path, mode, flags, parameters, &map);
|
|
|
|
if(stat) goto done;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
{stat = NC_ENOTBUILT; goto done;}
|
|
|
|
}
|
|
|
|
if(mapp) *mapp = map;
|
|
|
|
done:
|
|
|
|
ncurifree(uri);
|
|
|
|
return THROW(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nczmap_open(NCZM_IMPL impl, const char *path, int mode, size64_t flags, void* parameters, NCZMAP** mapp)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
NCZMAP* map = NULL;
|
|
|
|
NCURI* uri = NULL;
|
|
|
|
|
|
|
|
if(path == NULL || strlen(path) == 0)
|
|
|
|
{stat = NC_EINVAL; goto done;}
|
|
|
|
|
|
|
|
if(mapp) *mapp = NULL;
|
|
|
|
|
|
|
|
switch (impl) {
|
2021-01-29 11:11:01 +08:00
|
|
|
case NCZM_FILE:
|
|
|
|
stat = zmap_file.open(path, mode, flags, parameters, &map);
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
if(stat) goto done;
|
|
|
|
break;
|
2021-01-29 11:11:01 +08:00
|
|
|
#ifdef ENABLE_NCZARR_ZIP
|
|
|
|
case NCZM_ZIP:
|
|
|
|
stat = zmap_zip.open(path, mode, flags, parameters, &map);
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
if(stat) goto done;
|
|
|
|
break;
|
2021-01-29 11:11:01 +08:00
|
|
|
#endif
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
#ifdef ENABLE_S3_SDK
|
|
|
|
case NCZM_S3:
|
|
|
|
stat = zmap_s3sdk.open(path, mode, flags, parameters, &map);
|
|
|
|
if(stat) goto done;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
{stat = NC_ENOTBUILT; goto done;}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
ncurifree(uri);
|
|
|
|
if(!stat) {
|
|
|
|
if(mapp) *mapp = map;
|
|
|
|
}
|
|
|
|
return THROW(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/* API Wrapper */
|
|
|
|
|
|
|
|
int
|
|
|
|
nczmap_close(NCZMAP* map, int delete)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
if(map && map->api)
|
|
|
|
stat = map->api->close(map,delete);
|
|
|
|
return THROW(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nczmap_exists(NCZMAP* map, const char* key)
|
|
|
|
{
|
|
|
|
return map->api->exists(map, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nczmap_len(NCZMAP* map, const char* key, size64_t* lenp)
|
|
|
|
{
|
|
|
|
return map->api->len(map, key, lenp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nczmap_read(NCZMAP* map, const char* key, size64_t start, size64_t count, void* content)
|
|
|
|
{
|
|
|
|
return map->api->read(map, key, start, count, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nczmap_write(NCZMAP* map, const char* key, size64_t start, size64_t count, const void* content)
|
|
|
|
{
|
|
|
|
return map->api->write(map, key, start, count, content);
|
|
|
|
}
|
|
|
|
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
/* Define a static qsort comparator for strings for use with qsort */
|
|
|
|
static int
|
|
|
|
cmp_strings(const void* a1, const void* a2)
|
|
|
|
{
|
|
|
|
const char** s1 = (const char**)a1;
|
|
|
|
const char** s2 = (const char**)a2;
|
|
|
|
return strcmp(*s1,*s2);
|
|
|
|
}
|
|
|
|
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
int
|
|
|
|
nczmap_search(NCZMAP* map, const char* prefix, NClist* matches)
|
|
|
|
{
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
int stat = NC_NOERR;
|
|
|
|
if((stat = map->api->search(map, prefix, matches)) == NC_NOERR) {
|
|
|
|
/* sort the list */
|
|
|
|
if(nclistlength(matches) > 1) {
|
|
|
|
void* base = nclistcontents(matches);
|
|
|
|
qsort(base, nclistlength(matches), sizeof(char*), cmp_strings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stat;
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/* Utilities */
|
|
|
|
|
|
|
|
int
|
|
|
|
nczm_split(const char* path, NClist* segments)
|
|
|
|
{
|
|
|
|
return nczm_split_delim(path,NCZM_SEP[0],segments);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nczm_split_delim(const char* path, char delim, NClist* segments)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
const char* p = NULL;
|
|
|
|
const char* q = NULL;
|
|
|
|
ptrdiff_t len = 0;
|
|
|
|
char* seg = NULL;
|
|
|
|
|
|
|
|
if(path == NULL || strlen(path)==0 || segments == NULL)
|
|
|
|
{stat = NC_EINVAL; goto done;}
|
|
|
|
|
|
|
|
p = path;
|
|
|
|
if(p[0] == delim) p++;
|
|
|
|
for(;*p;) {
|
|
|
|
q = strchr(p,delim);
|
|
|
|
if(q==NULL)
|
|
|
|
q = p + strlen(p); /* point to trailing nul */
|
|
|
|
len = (q - p);
|
|
|
|
if(len == 0)
|
|
|
|
{stat = NC_EURL; goto done;}
|
|
|
|
if((seg = malloc(len+1)) == NULL)
|
|
|
|
{stat = NC_ENOMEM; goto done;}
|
|
|
|
memcpy(seg,p,len);
|
|
|
|
seg[len] = '\0';
|
|
|
|
nclistpush(segments,seg);
|
|
|
|
seg = NULL; /* avoid mem errors */
|
|
|
|
if(*q) p = q+1; else p = q;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
nullfree(seg);
|
|
|
|
return THROW(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* concat the the segments with each segment preceded by '/' */
|
|
|
|
int
|
|
|
|
nczm_join(NClist* segments, char** pathp)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
int i;
|
|
|
|
NCbytes* buf = NULL;
|
|
|
|
|
|
|
|
if(segments == NULL)
|
|
|
|
{stat = NC_EINVAL; goto done;}
|
|
|
|
if((buf = ncbytesnew())==NULL)
|
|
|
|
{stat = NC_ENOMEM; goto done;}
|
|
|
|
if(nclistlength(segments) == 0)
|
|
|
|
ncbytescat(buf,"/");
|
|
|
|
else for(i=0;i<nclistlength(segments);i++) {
|
|
|
|
const char* seg = nclistget(segments,i);
|
2020-08-18 09:15:47 +08:00
|
|
|
if(seg[0] != '/')
|
|
|
|
ncbytescat(buf,"/");
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
ncbytescat(buf,seg);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if(!stat) {
|
|
|
|
if(pathp) *pathp = ncbytesextract(buf);
|
|
|
|
}
|
|
|
|
ncbytesfree(buf);
|
|
|
|
return THROW(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nczm_concat(const char* prefix, const char* suffix, char** pathp)
|
|
|
|
{
|
|
|
|
NCbytes* buf = ncbytesnew();
|
|
|
|
|
|
|
|
if(prefix == NULL || strlen(prefix)==0) prefix = NCZM_SEP;
|
|
|
|
if(suffix == NULL) suffix = "";
|
|
|
|
ncbytescat(buf,prefix);
|
|
|
|
if(ncbytesget(buf,ncbyteslength(buf)-1) == NCZM_SEP[0])
|
|
|
|
ncbytessetlength(buf,ncbyteslength(buf)-1);
|
|
|
|
if(strlen(suffix) > 0 && suffix[0] != NCZM_SEP[0])
|
|
|
|
ncbytescat(buf,NCZM_SEP);
|
|
|
|
ncbytescat(buf,suffix);
|
|
|
|
if(pathp) *pathp = ncbytesextract(buf);
|
|
|
|
ncbytesfree(buf);
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2021-01-29 11:11:01 +08:00
|
|
|
/* Concat multiple strings, but with no intervening separators */
|
|
|
|
int
|
|
|
|
nczm_appendn(char** resultp, int n, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
NCbytes* buf = ncbytesnew();
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start(args, n);
|
|
|
|
for(i=0;i<n;i++) {
|
|
|
|
char* s = va_arg(args,char*);
|
|
|
|
if(s != NULL) ncbytescat(buf,s);
|
|
|
|
}
|
|
|
|
ncbytesnull(buf);
|
|
|
|
va_end(args);
|
|
|
|
if(resultp) {*resultp = ncbytesextract(buf);}
|
|
|
|
ncbytesfree(buf);
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
/* A segment is defined as a '/' plus characters following up
|
|
|
|
to the end or upto the next '/'
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nczm_divide_at(const char* key, int nsegs, char** prefixp, char** suffixp)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
char* prefix = NULL;
|
|
|
|
char* suffix = NULL;
|
|
|
|
size_t len, i;
|
|
|
|
ptrdiff_t delta;
|
|
|
|
const char* p;
|
|
|
|
int abssegs = (nsegs >= 0 ?nsegs: -nsegs);
|
|
|
|
int presegs = 0;
|
|
|
|
|
|
|
|
/* Special case */
|
|
|
|
if(key == NULL || strlen(key) == 0) goto done;
|
|
|
|
|
|
|
|
p = (key[0] == '/' ? key+1 : key);
|
|
|
|
/* Count number of segments */
|
|
|
|
for(len=0;;) {
|
|
|
|
const char* q = strchr(p,'/');
|
|
|
|
len++;
|
|
|
|
if(q == NULL) break;
|
|
|
|
p = q+1; /* start past leading '/' of next segment */
|
|
|
|
}
|
|
|
|
if(abssegs > len)
|
|
|
|
{stat = NC_EINVAL; goto done;}
|
|
|
|
/* find split point */
|
|
|
|
if(nsegs >= 0)
|
|
|
|
{presegs = abssegs;}
|
|
|
|
else
|
|
|
|
{presegs = (len - abssegs);}
|
|
|
|
|
|
|
|
/* skip past the first presegs segments */
|
|
|
|
for(p=key,i=0;i<presegs;i++) {
|
|
|
|
const char* q = strchr(p+1,'/');
|
|
|
|
if(q == NULL) {p = (p + strlen(p)); break;}
|
|
|
|
else p = q;
|
|
|
|
}
|
|
|
|
/* p should point at the presegs+1 start point */
|
|
|
|
delta = (p-key);
|
|
|
|
if(prefixp) {
|
|
|
|
prefix = malloc(delta+1);
|
|
|
|
memcpy(prefix,key,delta);
|
|
|
|
prefix[delta] = '\0';
|
|
|
|
*prefixp = prefix;
|
|
|
|
}
|
|
|
|
if(suffixp) {
|
|
|
|
suffix = strdup(p);
|
|
|
|
*suffixp = suffix;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nczm_clear(NCZMAP* map)
|
|
|
|
{
|
|
|
|
if(map)
|
|
|
|
nullfree(map->url);
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nczm_isabsolutepath(const char* path)
|
|
|
|
{
|
|
|
|
if(path == NULL) return 0;
|
|
|
|
switch (path[0]) {
|
|
|
|
case '\\': return 1;
|
|
|
|
case '/': return 1;
|
|
|
|
case '\0': break;
|
|
|
|
default:
|
|
|
|
/* Check for windows drive letter */
|
2020-08-18 09:15:47 +08:00
|
|
|
if(NChasdriveletter(path)) return 1;
|
This PR adds EXPERIMENTAL support for accessing data in the
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.
2020-06-29 08:02:47 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2020-08-18 09:15:47 +08:00
|
|
|
|
|
|
|
/* Convert forward slash to backslash ( !localize) or vice-versa (localize)*/
|
|
|
|
int
|
|
|
|
nczm_localize(const char* path, char** localpathp, int localize)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
char* localpath = NULL;
|
|
|
|
char* p;
|
|
|
|
int forward = 1;
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
forward = (localize?0:1);
|
|
|
|
#endif
|
|
|
|
/* If path comes from a url, then it may start with: /x:/...
|
|
|
|
where x is a drive letter. If so, then remove leading / */
|
|
|
|
if(path[0] == '/' && NChasdriveletter(path+1))
|
|
|
|
offset = 1;
|
|
|
|
if((localpath = strdup(path+offset))==NULL) return NC_ENOMEM;
|
|
|
|
|
|
|
|
for(p=localpath;*p;p++) {
|
|
|
|
if(forward && *p == '\\') *p = '/';
|
|
|
|
else if(!forward && *p == '/') *p = '\\';
|
|
|
|
}
|
|
|
|
if(localpathp) {*localpathp = localpath; localpath = NULL;}
|
|
|
|
nullfree(localpath);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert path0 to be:
|
|
|
|
1. absolute -- including drive letters
|
2021-01-29 11:11:01 +08:00
|
|
|
2. forward slashed -- we will convert back to back slash in nczm_fixpath
|
2020-08-18 09:15:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
nczm_canonicalpath(const char* path, char** cpathp)
|
|
|
|
{
|
|
|
|
int ret = NC_NOERR;
|
|
|
|
char* cpath = NULL;
|
|
|
|
char* tmp = NULL;
|
|
|
|
|
|
|
|
if(path == NULL)
|
|
|
|
{cpath = NULL; goto done;}
|
|
|
|
|
|
|
|
/* Process path to make it be windows compatible */
|
|
|
|
if((tmp = NCpathcvt(path))==NULL) {ret = NC_ENOMEM; goto done;}
|
|
|
|
|
|
|
|
/* Fix slashes to be forward for now */
|
|
|
|
if((ret = nczm_localize(tmp,&cpath,!LOCALIZE))) goto done;
|
|
|
|
|
|
|
|
if(cpathp) {*cpathp = cpath; cpath = NULL;}
|
|
|
|
done:
|
|
|
|
nullfree(tmp);
|
|
|
|
nullfree(cpath);
|
|
|
|
return THROW(ret);
|
|
|
|
}
|
2021-01-29 11:11:01 +08:00
|
|
|
|
|
|
|
/* extract the first segment of a path */
|
|
|
|
int
|
|
|
|
nczm_segment1(const char* path, char** seg1p)
|
|
|
|
{
|
|
|
|
int ret = NC_NOERR;
|
|
|
|
char* seg1 = NULL;
|
|
|
|
const char* p = NULL;
|
|
|
|
const char* q = NULL;
|
|
|
|
ptrdiff_t delta;
|
|
|
|
|
|
|
|
if(path == NULL)
|
|
|
|
{seg1 = NULL; goto done;}
|
|
|
|
|
|
|
|
p = path;
|
|
|
|
if(*p == '/') p++; /* skip any leading '/' */
|
|
|
|
q = strchr(p,'/');
|
|
|
|
if(q == NULL) q = p+strlen(p); /* point to stop character */
|
|
|
|
delta = (q-p);
|
|
|
|
if((seg1 = (char*)malloc(delta+1))==NULL)
|
|
|
|
{ret = NC_ENOMEM; goto done;}
|
|
|
|
memcpy(seg1,p,delta);
|
|
|
|
seg1[delta] = '\0';
|
|
|
|
|
|
|
|
if(seg1p) {*seg1p = seg1; seg1 = NULL;}
|
|
|
|
done:
|
|
|
|
nullfree(seg1);
|
|
|
|
return THROW(ret);
|
|
|
|
}
|
|
|
|
|
2021-02-25 04:46:11 +08:00
|
|
|
/*
|
|
|
|
Extract the last segment from path.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
nczm_lastsegment(const char* path, char** lastp)
|
|
|
|
{
|
|
|
|
int ret = NC_NOERR;
|
|
|
|
const char* last = NULL;
|
|
|
|
|
|
|
|
if(path == NULL)
|
|
|
|
{if(lastp) *lastp = NULL; goto done;}
|
|
|
|
|
|
|
|
last = strrchr(path,'/');
|
|
|
|
if(last == NULL) last = path; else last++;
|
|
|
|
|
|
|
|
if(lastp) *lastp = strdup(last);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return THROW(ret);
|
|
|
|
}
|
|
|
|
|
2021-01-29 11:11:01 +08:00
|
|
|
/*
|
|
|
|
Extract the basename from a path.
|
|
|
|
Basename is last segment minus one extension.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
nczm_basename(const char* path, char** basep)
|
|
|
|
{
|
2021-02-25 04:46:11 +08:00
|
|
|
int stat = NC_NOERR;
|
2021-01-29 11:11:01 +08:00
|
|
|
char* base = NULL;
|
2021-02-25 04:46:11 +08:00
|
|
|
char* last = NULL;
|
2021-01-29 11:11:01 +08:00
|
|
|
const char* p = NULL;
|
|
|
|
ptrdiff_t delta;
|
|
|
|
|
2021-02-25 04:46:11 +08:00
|
|
|
if((stat=nczm_lastsegment(path,&last))) goto done;
|
2021-01-29 11:11:01 +08:00
|
|
|
|
2021-02-25 04:46:11 +08:00
|
|
|
if(last == NULL) goto done;
|
|
|
|
p = strrchr(last,'.');
|
|
|
|
if(p == NULL) p = last+strlen(last);
|
|
|
|
delta = (p - last);
|
2021-01-29 11:11:01 +08:00
|
|
|
if((base = (char*)malloc(delta+1))==NULL)
|
2021-02-25 04:46:11 +08:00
|
|
|
{stat = NC_ENOMEM; goto done;}
|
|
|
|
memcpy(base,last,delta);
|
2021-01-29 11:11:01 +08:00
|
|
|
base[delta] = '\0';
|
|
|
|
if(basep) {*basep = base; base = NULL;}
|
|
|
|
done:
|
2021-02-25 04:46:11 +08:00
|
|
|
nullfree(last);
|
2021-01-29 11:11:01 +08:00
|
|
|
nullfree(base);
|
2021-02-25 04:46:11 +08:00
|
|
|
return THROW(stat);
|
2021-01-29 11:11:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* bubble sort a list of strings */
|
|
|
|
void
|
|
|
|
nczm_sortlist(NClist* l)
|
|
|
|
{
|
|
|
|
nczm_sortenvv(nclistlength(l),(char**)nclistcontents(l));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bubble sort a list of strings */
|
|
|
|
void
|
|
|
|
nczm_sortenvv(int n, char** envv)
|
|
|
|
{
|
|
|
|
size_t i, switched;
|
|
|
|
|
|
|
|
if(n <= 1) return;
|
|
|
|
do {
|
|
|
|
switched = 0;
|
|
|
|
for(i=0;i<n-1;i++) {
|
|
|
|
char* ith = envv[i];
|
|
|
|
char* ith1 = envv[i+1];
|
|
|
|
if(strcmp(ith,ith1) > 0) {
|
|
|
|
envv[i] = ith1;
|
|
|
|
envv[i+1] = ith;
|
|
|
|
switched = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(switched);
|
|
|
|
#if 0
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
fprintf(stderr,"sorted: [%d] %s\n",i,(const char*)envv[i]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NCZ_freeenvv(int n, char** envv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char** p;
|
|
|
|
if(envv == NULL) return;
|
|
|
|
if(n < 0)
|
|
|
|
{for(n=0, p = envv; *p; n++); /* count number of strings */}
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
if(envv[i]) free(envv[i]);
|
|
|
|
free(envv);
|
|
|
|
}
|