netcdf-c/include/nc.h
Dennis Heimbigner bf2746b8ea Provide byte-range reading of remote datasets
re: issue https://github.com/Unidata/netcdf-c/issues/1251

Assume that you have the URL to a remote dataset
which is a normal netcdf-3 or netcdf-4 file.

This PR allows the netcdf-c to read that dataset's
contents as a netcdf file using HTTP byte ranges
if the remote server supports byte-range access.

Originally, this PR was set up to access Amazon S3 objects,
but it can also access other remote datasets such as those
provided by a Thredds server via the HTTPServer access protocol.
It may also work for other kinds of servers.

Note that this is not intended as a true production
capability because, as is known, this kind of access to
can be quite slow. In addition, the byte-range IO drivers
do not currently do any sort of optimization or caching.

An additional goal here is to gain some experience with
the Amazon S3 REST protocol.

This architecture and its use documented in
the file docs/byterange.dox.

There are currently two test cases:

1. nc_test/tst_s3raw.c - this does a simple open, check format, close cycle
   for a remote netcdf-3 file and a remote netcdf-4 file.
2. nc_test/test_s3raw.sh - this uses ncdump to investigate some remote
   datasets.

This PR also incorporates significantly changed model inference code
(see the superceded PR https://github.com/Unidata/netcdf-c/pull/1259).

1. It centralizes the code that infers the dispatcher.
2. It adds support for byte-range URLs

Other changes:

1. NC_HDF5_finalize was not being properly called by nc_finalize().
2. Fix minor bug in ncgen3.l
3. fix memory leak in nc4info.c
4. add code to walk the .daprc triples and to replace protocol=
   fragment tag with a more general mode= tag.

Final Note:
Th inference code is still way too complicated. We need to move
to the validfile() model used by netcdf Java, where each
dispatcher is asked if it can process the file. This decentralizes
the inference code. This will be done after all the major new
dispatchers (PIO, Zarr, etc) have been implemented.
2019-01-01 18:27:36 -07:00

90 lines
2.6 KiB
C

/*
* Copyright 2018, University Corporation for Atmospheric Research
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*/
#ifndef _NC_H_
#define _NC_H_
#include "config.h"
#include "netcdf.h"
/* Forward */
struct NCmodel;
/* There's an external ncid (ext_ncid) and an internal ncid
* (int_ncid). The ext_ncid is the ncid returned to the user. If
* the user has opened or created a netcdf-4 file, then the
* ext_ncid is the same as the int_ncid. If he has opened or
* created a netcdf-3 file ext_ncid (which the user sees) is
* different from the int_ncid, which is the ncid returned by the
* netcdf-3 layer, which insists on inventing its own ncids,
* regardless of what is already in use due to previously opened
* netcdf-4 files. The ext_ncid contains the ncid for the root
* group (i.e. group zero). */
/* Common Shared Structure for all Dispatched Objects */
typedef struct NC {
int ext_ncid;
int int_ncid;
struct NC_Dispatch* dispatch;
void* dispatchdata; /*per-'file' data; points to e.g. NC3_INFO data*/
char* path;
int mode; /* as provided to nc_open/nc_create */
struct NCmodel* model; /* as determined by libdispatch/dfile.c */
#ifdef USE_REFCOUNT
int refcount; /* To enable multiple name-based opens */
#endif
} NC;
/*
* Counted string for names and such
*/
typedef struct {
/* all xdr'd */
size_t nchars;
char *cp;
} NC_string;
/* Define functions that are used across multiple dispatchers */
/* Begin defined in string.c */
extern void
free_NC_string(NC_string *ncstrp);
extern int
NC_check_name(const char *name);
extern NC_string *
new_NC_string(size_t slen, const char *str);
extern int
set_NC_string(NC_string *ncstrp, const char *str);
/* End defined in string.c */
extern int
NC_check_id(int ncid, NC **ncpp);
/* Create a pseudo file descriptor that does not
overlap real file descriptors */
extern int nc__pseudofd(void);
/* This function gets a current default create flag */
extern int nc_get_default_format(void);
extern int add_to_NCList(NC*);
extern void del_from_NCList(NC*);/* does not free object */
extern NC* find_in_NCList(int ext_ncid);
extern NC* find_in_NCList_by_name(const char*);
extern void free_NCList(void);/* reclaim whole list */
extern int count_NCList(void); /* return # of entries in NClist */
extern int iterate_NCList(int i,NC**); /* Walk from 0 ...; ERANGE return => stop */
/* Defined in nc.c */
extern void free_NC(NC*);
extern int new_NC(struct NC_Dispatch*, const char*, int, struct NCmodel*, NC**);
/* Defined in nc.c */
extern int ncdebug;
#endif /* _NC_H_ */