netcdf-c/libnczarr/zdebug.h
Dennis Heimbigner 231ae96c4b Add support for Zarr string type to NCZarr
* re: https://github.com/Unidata/netcdf-c/pull/2278
* re: https://github.com/Unidata/netcdf-c/issues/2485
* re: https://github.com/Unidata/netcdf-c/issues/2474

This PR subsumes PR https://github.com/Unidata/netcdf-c/pull/2278.
Actually is a bit an omnibus covering several issues.

## PR https://github.com/Unidata/netcdf-c/pull/2278
Add support for the Zarr string type.
Zarr strings are restricted currently to be of fixed size.
The primary issue to be addressed is to provide a way for user to
specify the size of the fixed length strings. This is handled by providing
the following new attributes special:
1. **_nczarr_default_maxstrlen** —
This is an attribute of the root group. It specifies the default
maximum string length for string types. If not specified, then
it has the value of 64 characters.
2. **_nczarr_maxstrlen** —
This is a per-variable attribute. It specifies the maximum
string length for the string type associated with the variable.
If not specified, then it is assigned the value of
**_nczarr_default_maxstrlen**.

This PR also requires some hacking to handle the existing netcdf-c NC_CHAR
type, which does not exist in zarr. The goal was to choose numpy types for
both the netcdf-c NC_STRING type and the netcdf-c NC_CHAR type such that
if a pure zarr implementation read them, it would still work and an
NC_CHAR type would be handled by zarr as a string of length 1.

For writing variables and NCZarr attributes, the type mapping is as follows:
* "|S1" for NC_CHAR.
* ">S1" for NC_STRING && MAXSTRLEN==1
* ">Sn" for NC_STRING && MAXSTRLEN==n

Note that it is a bit of a hack to use endianness, but it should be ok since for
string/char, the endianness has no meaning.

For reading attributes with pure zarr (i.e. with no nczarr
atribute types defined), they will always be interpreted as of
type NC_CHAR.

## Issue: https://github.com/Unidata/netcdf-c/issues/2474
This PR partly fixes this issue because it provided more
comprehensive support for Zarr attributes that are JSON valued expressions.
This PR still does not address the problem in that issue where the
_ARRAY_DIMENSION attribute is incorrectly set. Than can only be
fixed by the creator of the datasets.

## Issue: https://github.com/Unidata/netcdf-c/issues/2485
This PR also fixes the scalar failure shown in this issue.
It generally cleans up scalar handling.
It also adds a note to the documentation describing that
NCZarr supports scalars while Zarr does not and also how
scalar interoperability is achieved.

## Misc. Other Changes
1. Convert the nczarr special attributes and keys to be all lower case. So "_NCZARR_ATTR" now used "_nczarr_attr. Support back compatibility for the upper case names.
2. Cleanup my too-clever-by-half handling of scalars in libnczarr.
2022-08-27 20:21:13 -06:00

85 lines
3.0 KiB
C

/*********************************************************************
* Copyright 2018, UCAR/Unidata
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*********************************************************************/
#ifndef ZDEBUG_H
#define ZDEBUG_H
#undef ZDEBUG /* general debug */
#undef ZDEBUG1 /* detailed debug */
#define ZCATCH /* Warning: significant performance impact */
#define ZTRACING /* Warning: significant performance impact */
#include "ncexternl.h"
#include "nclog.h"
#ifdef LOGGING
#define ZLOG(tag,...) nclog(tag,__VA_ARGS__)
#else
#define ZLOG(tag,...)
#endif
#ifdef ZCATCH
/* Place breakpoint on zbreakpoint to catch errors close to where they occur*/
#define THROW(e) zthrow((e),__FILE__, __func__, __LINE__)
#define REPORT(e,msg) zreport((e),(msg),__FILE__, __func__, __LINE__)
#define ZCHECK(e) if((e)) {THROW(stat); goto done;} else {}
EXTERNL int zbreakpoint(int err);
EXTERNL int zthrow(int err, const char* fname, const char* fcn, int line);
EXTERNL int zreport(int err, const char* msg, const char* fname, const char* fcn, int line);
#else
#define ZCHECK(e) {if((e)) {goto done;}}
#define THROW(e) (e)
#define REPORT(e,msg) (e)
#endif
#ifdef ZTRACING
#define ZTRACE(level,fmt,...) nctrace((level),__func__,fmt,##__VA_ARGS__)
#define ZTRACEMORE(level,fmt,...) nctracemore((level),fmt,##__VA_ARGS__)
#define ZUNTRACE(e) ncuntrace(__func__,THROW(e),NULL)
#define ZUNTRACEX(e,fmt,...) ncuntrace(__func__,THROW(e),fmt,##__VA_ARGS__)
#else
#define ZTRACE(level,fmt,...)
#define ZTRACEMORE(level,fmt,...)
#define ZUNTRACE(e) (e)
#define ZUNTRACEX(e,fmt,...) (e)
#endif
/* printers */
EXTERNL void nczprint_reclaim(void);
EXTERNL char* nczprint_slice(NCZSlice);
EXTERNL char* nczprint_slices(int rank, const NCZSlice*);
EXTERNL char* nczprint_slab(int rank, const NCZSlice*);
EXTERNL char* nczprint_odom(const NCZOdometer*);
EXTERNL char* nczprint_chunkrange(const NCZChunkRange);
EXTERNL char* nczprint_projection(const NCZProjection);
EXTERNL char* nczprint_sliceprojections(const NCZSliceProjections);
EXTERNL char* nczprint_allsliceprojections(int r, const NCZSliceProjections* slp);
EXTERNL char* nczprint_slicex(const NCZSlice slice, int raw);
EXTERNL char* nczprint_slicesx(int rank, const NCZSlice* slices, int raw);
EXTERNL char* nczprint_projectionx(const NCZProjection proj, int raw);
EXTERNL char* nczprint_sliceprojectionsx(const NCZSliceProjections slp, int raw);
EXTERNL char* nczprint_vector(size_t,const size64_t*);
EXTERNL char* nczprint_idvector(size_t,const int*);
EXTERNL char* nczprint_paramvector(size_t,const unsigned*);
EXTERNL char* nczprint_sizevector(size_t,const size_t*);
EXTERNL char* nczprint_envv(const char** envv);
EXTERNL void zdumpcommon(const struct Common*);
/* Define the possible unit tests (powers of 2) */
#define UTEST_RANGE 1
#define UTEST_WALK 2
#define UTEST_TRANSFER 4
#define UTEST_WHOLECHUNK 8
struct ZUTEST {
int tests;
void (*print)(int sort,...);
};
EXTERNL struct ZUTEST* zutest;
#endif /*ZDEBUG_H*/