Skip to content

Commit

Permalink
Merge branch 'main' into distcheck.dmh
Browse files Browse the repository at this point in the history
  • Loading branch information
WardF committed May 17, 2022
2 parents 72b2567 + 6e8e1c3 commit c9727c2
Show file tree
Hide file tree
Showing 17 changed files with 336 additions and 112 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ This file contains a high-level description of this package's evolution. Release

## 4.8.2 - TBD


* [Bug Fix] Get "make distcheck" to work See [Github #/2343](https://github.com/Unidata/netcdf-c/pull/2343).
* [Enhancement] Allow the read/write of JSON-valued Zarr attributes to allow
for domain specific info such as used by GDAL/Zarr. See [Github #????](https://github.com/Unidata/netcdf-c/pull/????).
* [Enhancement] Turn on the XArray convention for NCZarr files by default. WARNING, this means that the mode should explicitly specify nczarr" or "zarr" even if "xarray" or "noxarray" is specified. See [Github #2257](https://github.com/Unidata/netcdf-c/pull/2257).
* [Enhancement] Update the documentation to match the current filter capabilities See [Github #2249](https://github.com/Unidata/netcdf-c/pull/2249).
* [Enhancement] Support installation of pre-built standard filters into user-specified location. See [Github #2318](https://github.com/Unidata/netcdf-c/pull/2318).
* [Enhancement] Improve filter support. More specifically (1) add nc_inq_filter_avail to check if a filter is available, (2) add the notion of standard filters, (3) cleanup szip support to fix interaction with NCZarr. See [Github #2245](https://github.com/Unidata/netcdf-c/pull/2245).
Expand Down
23 changes: 14 additions & 9 deletions docs/nczarr.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,18 @@ Note that It should be the case that zipping a _file_
format directory tree will produce a file readable by the
_zip_ storage format, and vice-versa.

By default, _mode=zarr_ also supports the XArray _\_ARRAY\_DIMENSIONS_ convention. The _noxarray_ mode tells the library to disable the XArray support.
By default, the XArray convention is supported and used for
both NCZarr files and pure Zarr files. This
means that every variable in the root group whose named dimensions
are also in the root group will have an attribute called
*\_ARRAY\_DIMENSIONS* that stores those dimension names.
The _noxarray_ mode tells the library to disable the XArray support.

The netcdf-c library is capable of inferring additional mode flags based on the flags it finds. Currently we have the following inferences.

- _xarray_ => _zarr_
- _noxarray_ => _zarr_
- _zarr_ => _nczarr_

So for example: ````...#mode=noxarray,zip```` is equivalent to this.
````...#mode=nczarr,zarr,noxarray,zip
So for example: ````...#mode=zarr,zip```` is equivalent to this.
````...#mode=nczarr,zarr,zip
````
<!--
- log=&lt;output-stream&gt;: this control turns on logging output,
Expand Down Expand Up @@ -434,10 +436,13 @@ The value of this attribute is a list of dimension names (strings).
An example might be ````["time", "lon", "lat"]````.
It is essentially equivalent to the ````_NCZARR_ARRAY "dimrefs" list````, except that the latter uses fully qualified names so the referenced dimensions can be anywhere in the dataset.

As of _netcdf-c_ version 4.8.1, The Xarray ''_ARRAY_DIMENSIONS'' attribute is supported.
This attribute will be read/written by default, but can be suppressed if the mode value "noxarray" is specified.
As of _netcdf-c_ version 4.8.2, The Xarray ''_ARRAY_DIMENSIONS'' attribute is supported for both NCZarr and pure Zarr.
If possible, this attribute will be read/written by default,
but can be suppressed if the mode value "noxarray" is specified.
If detected, then these dimension names are used to define shared dimensions.
Note that "noxarray" or "xarray" implies pure zarr format.
The following conditions will cause ''_ARRAY_DIMENSIONS'' to not be written.
* The variable is not in the root group,
* Any dimension referenced by the variable is not in the root group.

# Examples {#nczarr_examples}

Expand Down
4 changes: 2 additions & 2 deletions docs/static-pages/software.html
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ <h2><a id="gliderscope" name="gliderscope">Gliderccope</a></h2>
Dr L. Mun Woo <mun.woo@uwa.edu.au>
at ANFOG (Australian National Facility for Ocean Gliders)
has developed
<a href="http://imos.org.au/facilities/oceangliders/glider-data/gliderscope/">Gliderscope</a>.
<a href="https://imos.org.au/gliderscope">Gliderscope</a>.
Gliderscope is an IMOS (Integrated Marine Observing System)
oceanographic software package allowing users quick easy visualisation
of ocean glider data, via a convenient graphical user interface.
Expand Down Expand Up @@ -2008,7 +2008,7 @@ <h2><a id="netcdf_ninja" name="netcdf_ninja">NetCDF Ninja</a></h2>
<p>
Dr L. Mun Woo of University of Western Australia <mun.woo@uwa.edu.au>
has developed
<a href="http://imos.org.au/facilities/oceangliders/glider-data/netcdfninja/">NetCDF Ninja</a>,
<a href="https://imos.org.au/netcdfninja">NetCDF Ninja</a>,
a graphical user interface that allows users to browse all
the metadata contained in netCDF files, scrutinise the data using an
interactive graphical plot and even make small alterations or export
Expand Down
5 changes: 4 additions & 1 deletion include/ncjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ struct NCJconst {int bval; long long ival; double dval; char* sval;};
extern "C" {
#endif

/* Parse a JSON string */
/* Parse a string to NCjson*/
DLLEXPORT int NCJparse(const char* text, unsigned flags, NCjson** jsonp);

/* Parse a counted string to NCjson*/
DLLEXPORT int NCJparsen(size_t len, const char* text, unsigned flags, NCjson** jsonp);

/* Reclaim a JSON tree */
DLLEXPORT extern void NCJreclaim(NCjson* json);

Expand Down
9 changes: 4 additions & 5 deletions libdispatch/dinfermodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ static const struct MACRODEF {
{"dap4","mode",{"dap4",NULL}},
{"s3","mode",{"s3","nczarr",NULL}},
{"bytes","mode",{"bytes",NULL}},
{"xarray","mode",{"nczarr","zarr","xarray",NULL}},
{"noxarray","mode",{"nczarr","zarr","noxarray",NULL}},
{"zarr","mode",{"nczarr","zarr","xarray",NULL}},
{"xarray","mode",{"zarr", NULL}},
{"noxarray","mode",{"nczarr", "noxarray", NULL}},
{"zarr","mode",{"nczarr","zarr", NULL}},
{NULL,NULL,{NULL}}
};

Expand All @@ -149,9 +149,8 @@ static const struct MODEINFER {
char* inference;
} modeinferences[] = {
{"zarr","nczarr"},
{"zarr","xarray"},
{"xarray","zarr"},
{"noxarray","zarr"},
{"noxarray","nczarr"},
{NULL,NULL}
};

Expand Down
43 changes: 34 additions & 9 deletions libdispatch/ncjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static int NCJyytext(NCJparser*, char* start, size_t pdlen);
static void NCJreclaimArray(struct NCjlist*);
static void NCJreclaimDict(struct NCjlist*);
static int NCJunescape(NCJparser* parser);
static int unescape1(int c);
static int listappend(struct NCjlist* list, NCjson* element);

#ifndef NETCDF_JSON_H
Expand All @@ -109,24 +110,28 @@ static int bytesappendc(NCJbuf* bufp, const char c);

int
NCJparse(const char* text, unsigned flags, NCjson** jsonp)
{
return NCJparsen(strlen(text),text,flags,jsonp);
}

int
NCJparsen(size_t len, const char* text, unsigned flags, NCjson** jsonp)
{
int stat = NCJ_OK;
size_t len;
NCJparser* parser = NULL;
NCjson* json = NULL;

/* Need at least 1 character of input */
if(text == NULL || text[0] == '\0')
if(len == 0 || text == NULL)
{stat = NCJTHROW(NCJ_ERR); goto done;}
if(jsonp == NULL) goto done;
parser = calloc(1,sizeof(NCJparser));
if(parser == NULL)
{stat = NCJTHROW(NCJ_ERR); goto done;}
len = strlen(text);
parser->text = (char*)malloc(len+1+1);
if(parser->text == NULL)
{stat = NCJTHROW(NCJ_ERR); goto done;}
strcpy(parser->text,text);
memcpy(parser->text,text,len);
parser->text[len] = '\0';
parser->text[len+1] = '\0';
parser->pos = &parser->text[0];
Expand Down Expand Up @@ -334,16 +339,21 @@ NCJlex(NCJparser* parser)
c = *parser->pos;
if(c == '\0') {
token = NCJ_EOF;
} else if(c <= ' ' || c == '\177') {
} else if(c <= ' ' || c == '\177') {/* ignore whitespace */
parser->pos++;
continue;
} else if(c == NCJ_ESCAPE) {
parser->pos++;
continue; /* ignore whitespace */
c = *parser->pos;
*parser->pos = unescape1(c);
continue;
} else if(strchr(JSON_WORD, c) != NULL) {
start = parser->pos;
for(;;) {
c = *parser->pos++;
if(c == '\0' || strchr(JSON_WORD,c) == NULL) break; /* end of word */
}
/* Pushback c if not whitespace */
/* Pushback c */
parser->pos--;
count = ((parser->pos) - start);
if(NCJyytext(parser,start,count)) goto done;
Expand Down Expand Up @@ -604,6 +614,21 @@ NCJunescape(NCJparser* parser)
return NCJTHROW(NCJ_OK);
}

/* Unescape a single character */
static int
unescape1(int c)
{
switch (c) {
case 'b': c = '\b'; break;
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
default: c = c; break;/* technically not Json conformant */
}
return c;
}

#ifdef NCJDEBUG
static char*
tokenname(int token)
Expand Down Expand Up @@ -896,7 +921,7 @@ NCJunparseR(const NCjson* json, NCJbuf* buf, unsigned flags)
if(json->list.len > 0 && json->list.contents != NULL) {
int shortlist = 0;
for(i=0;!shortlist && i < json->list.len;i+=2) {
if(i > 0) bytesappendc(buf,NCJ_COMMA);
if(i > 0) {bytesappendc(buf,NCJ_COMMA);bytesappendc(buf,' ');};
NCJunparseR(json->list.contents[i],buf,flags); /* key */
bytesappendc(buf,NCJ_COLON);
bytesappendc(buf,' ');
Expand Down Expand Up @@ -945,7 +970,7 @@ escape(const char* text, NCJbuf* buf)
case '\n': replace = 'n'; break;
case '\r': replace = 'r'; break;
case '\t': replace = 't'; break;
case NCJ_QUOTE: replace = '\''; break;
case NCJ_QUOTE: replace = '\"'; break;
case NCJ_ESCAPE: replace = '\\'; break;
default: break;
}
Expand Down
11 changes: 6 additions & 5 deletions libnczarr/zarr.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,15 @@ applycontrols(NCZ_FILE_INFO_T* zinfo)
}
/* Process the modelist first */
zinfo->controls.mapimpl = NCZM_DEFAULT;
zinfo->controls.flags |= FLAG_XARRAYDIMS; /* Always support XArray convention where possible */
for(i=0;i<nclistlength(modelist);i++) {
const char* p = nclistget(modelist,i);
if(strcasecmp(p,PUREZARRCONTROL)==0) zinfo->controls.flags |= (FLAG_PUREZARR|FLAG_XARRAYDIMS);
else if(strcasecmp(p,XARRAYCONTROL)==0) zinfo->controls.flags |= (FLAG_XARRAYDIMS|FLAG_PUREZARR); /*xarray=>zarr*/
else if(strcasecmp(p,NOXARRAYCONTROL)==0) {
if(strcasecmp(p,PUREZARRCONTROL)==0)
zinfo->controls.flags |= (FLAG_PUREZARR);
else if(strcasecmp(p,XARRAYCONTROL)==0)
zinfo->controls.flags |= FLAG_PUREZARR;
else if(strcasecmp(p,NOXARRAYCONTROL)==0)
noflags |= FLAG_XARRAYDIMS;
zinfo->controls.flags |= FLAG_PUREZARR; /*noxarray=>zarr*/
}
else if(strcasecmp(p,"zip")==0) zinfo->controls.mapimpl = NCZM_ZIP;
else if(strcasecmp(p,"file")==0) zinfo->controls.mapimpl = NCZM_FILE;
else if(strcasecmp(p,"s3")==0) zinfo->controls.mapimpl = NCZM_S3;
Expand Down
Loading

0 comments on commit c9727c2

Please sign in to comment.