netcdf-c/nczarr_test/tst_notzarr.c
Dennis Heimbigner 5c07ebfd11 Check at nc_open if file appears to be in NCZarr/Zarr format.
re: Issue https://github.com/Unidata/netcdf-c/issues/2656

Charlie Zender notes that *nc_open()* does not immediately detect that the given path refers to a file not in zarr format. Rather it fails later when trying to read the (meta-)data.

The reason is that the Zarr format is highly decentralized. There is no easily testable magic number or superblock to look for. In effect the only way to see if a directory is Zarr is to successfully read it.

It is possible to heuristically detect that a path refers to an NCZarr/Zarr file by doing a breadth-first search of the file tree starting at the given path. If the search encounters a file whose name starts with ".z", then assume it is a legitimate NCZarr/Zarr file. Of course, this test could be costly. One hopes that in practice that it is not.

In addition to this fix, a corresponding test case was added.

## Other Changes

re: PR https://github.com/Unidata/netcdf-c/pull/2529

There was an error under Cygwin for this PR that is fixed in this PR. The fix was to convert all *noinst_* references to *check_*.
2023-03-13 13:24:14 -06:00

32 lines
680 B
C

/* This is part of the netCDF package.
Copyright 2018 University Corporation for Atmospheric Research/Unidata
See COPYRIGHT file for conditions of use.
Test nczarr filter loading
Author: Dennis Heimbigner
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "netcdf.h"
#define ERR(r) {fprintf(stderr,"fail: line %d: (%d) %s\n",__LINE__,(r),nc_strerror((r)));}
int
main(int argc, char **argv)
{
int ret = NC_NOERR;
int ncid;
if(argc < 2) {
fprintf(stderr,"Usage: tst_notzarr <url>\n");
exit(1);
}
ret = nc_open(argv[1],NC_NETCDF4,&ncid);
printf("%d",ret);
if(ret == NC_NOERR) nc_close(ncid);
exit(0);
}