netcdf-c/include/ncconfigure.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

186 lines
3.1 KiB
C

/*
* Copyright 2018 University Corporation for Atmospheric
* Research/Unidata. See COPYRIGHT file for more info.
*
* This header file is for the parallel I/O functions of netCDF.
*
*/
/* "$Id: netcdf_par.h,v 1.1 2010/06/01 15:46:49 ed Exp $" */
#ifndef NCCONFIGURE_H
#define NCCONFIGURE_H 1
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
/*
This is included in bottom
of config.h. It is where,
typically, alternatives to
missing functions should be
defined and missing types defined.
*/
#ifdef _WIN32
#ifndef HAVE_SSIZE_T
#include <basetsd.h>
typedef SSIZE_T ssize_t;
#define HAVE_SSIZE_T 1
#endif
#endif
/*Warning: Cygwin with -ansi does not define these functions
in its headers.*/
#ifndef _WIN32
#if __STDC__ == 1 /*supposed to be same as -ansi flag */
#if defined(__cplusplus)
extern "C" {
#endif
/* WARNING: in some systems, these functions may be defined as macros, so check */
#ifndef strdup
#ifndef HAVE_STRDUP
char* strdup(const char*);
#define HAVE_STRDUP
#endif
#endif
#ifndef HAVE_STRLCAT
#ifndef strlcat
size_t strlcat(char*,const char*,size_t);
#endif
#endif
#ifndef HAVE_SNPRINTF
#ifndef snprintf
int snprintf(char*, size_t, const char*, ...);
#endif
#endif
#ifndef HAVE_STRCASECMP
#ifndef strcasecmp
extern int strcasecmp(const char*, const char*);
#endif
#endif
#ifndef HAVE_STRTOLL
#ifndef strtoll
long long int strtoll(const char*, char**, int);
#endif
#endif
#ifndef HAVE_STRTOULL
#ifndef strtoull
unsigned long long int strtoull(const char*, char**, int);
#endif
#endif
#if defined(__cplusplus)
}
#endif
#endif /*STDC*/
#else /*_WIN32*/
#ifndef HAVE_STRLCAT
#define strlcat(d,s,n) strcat_s((d),(n),(s))
#endif
#ifndef __MINGW32__
#ifndef strcasecmp
#define strcasecmp _stricmp
#endif
#ifndef strncasecmp
#define strncasecmp _strnicmp
#endif
#ifndef snprintf
#if _MSC_VER<1900
#define snprintf _snprintf
#endif
#endif
#ifndef fileno
#define fileno(f) _fileno(f)
#endif
#endif /*__MINGW32__*/
#endif /*_WIN32*/
/* handle null arguments */
#ifndef nulldup
#define nulldup(s) ((s)==NULL?NULL:strdup(s))
#endif
#ifndef nulllen
#define nulllen(s) ((s)==NULL?0:strlen(s))
#endif
#ifndef nullfree
#define nullfree(s) {if((s)!=NULL) {free(s);} else {}}
#endif
#ifndef HAVE_UCHAR
typedef unsigned char uchar;
#endif
#ifndef HAVE_LONGLONG
typedef long long longlong;
typedef unsigned long long ulonglong;
#endif
#ifndef HAVE_USHORT
typedef unsigned short ushort;
#endif
#ifndef HAVE_UINT
typedef unsigned int uint;
#endif
#ifndef HAVE_UINT64
typedef unsigned long long uint64;
#endif
#ifndef HAVE_UINT64_T
typedef unsigned long long uint64_t;
#endif
#ifndef _WIN32
#ifndef HAVE_UINTPTR_T
#if SIZEOF_VOIDP == 8
#define uintptr_t unsigned long
#else
#define uintptr_t unsigned int
#endif
#endif
#endif
#ifndef HAVE_SIZE64_T
typedef unsigned long long size64_t;
#endif
#ifndef HAVE_PTRDIFF_T
typedef long ptrdiff_t;
#endif
/* Provide a fixed size alternative to off_t or off64_t */
typedef long long fileoffset_t;
#ifndef NC_UNUSED
#define NC_UNUSED(var) (void)var
#endif
#endif /* NCCONFIGURE_H */