mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-12-21 08:39:46 +08:00
9f78be8bb8
A number of other packages that read/write Zarr insert attributes whose value is a dictionary containing specialized information. An example is the GDAL Driver convention (see https://gdal.org/drivers/raster/zarr.html). In order to handle such attributes, this PR enforces a special convention. It applies to both pure Zarr an NCZarr format as written by the netdf-c library. The convention is as follows: ## Reading Suppose an attribute is read from *.zattrs* and it has a JSON value that is a a dictionary. In this case, the JSON dictionary is converted to a string value. It then appears in the netcdf-c API as if it is a character valued attribute of the same name, and whose value is the "stringified" dictionary. # Writing Suppose an attribute is of type character and its *value* *looks like* a JSON dictionary. In this case, it is parsed to JSON and written as the value of the attribute in the NCZarr file. Here the *value* is the concatenation of all the characters in the attributes netcdf-c value. The term "looks like" means that the *value*'s first character is "{", its last value is "}", and it can be successfully parsed by a JSON parser. A test case, *nczarr_test/run_jsonconventions.sh* was also added. ## Misc. Unrelated Changes 1. Fix an error in nc_test4/tst_broken_files.c 2. Modify the internal JSON parser API. 3. Modify the nczarr_test/zisjson program is modified to support this convention.
32 lines
809 B
Bash
Executable File
32 lines
809 B
Bash
Executable File
#!/bin/sh
|
|
|
|
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
|
|
. ../test_common.sh
|
|
|
|
. "$srcdir/test_nczarr.sh"
|
|
|
|
# This shell script tests support for:
|
|
# read/write using json convention
|
|
|
|
set -e
|
|
|
|
testcase() {
|
|
zext=$1
|
|
|
|
echo "*** Test: write then read using json convention"
|
|
fileargs tmp_jsonconvention "mode=nczarr,$zext"
|
|
deletemap $zext $file
|
|
${NCGEN} -4 -b -o "$fileurl" $srcdir/ref_jsonconvention.cdl
|
|
${NCDUMP} $fileurl > tmp_jsonconvention_${zext}.cdl
|
|
# remove '\n' from ref file before comparing
|
|
rm -f tmp_jsonconvention.cdl
|
|
sed -e 's|\\n||g' < ${srcdir}/ref_jsonconvention.cdl > tmp_jsonconvention.cdl
|
|
diff -b tmp_jsonconvention.cdl tmp_jsonconvention_${zext}.cdl
|
|
}
|
|
|
|
testcase file
|
|
if test "x$FEATURE_NCZARR_ZIP" = xyes ; then testcase zip; fi
|
|
if test "x$FEATURE_S3TESTS" = xyes ; then testcase s3; fi
|
|
|
|
exit 0
|