netcdf-c/oc2/occompile.c

468 lines
12 KiB
C
Raw Normal View History

2018-12-07 06:47:47 +08:00
/* Copyright 2018, UCAR/Unidata and OPeNDAP, Inc.
See the COPYRIGHT file for more information. */
#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include "ocinternal.h"
#include "ocdebug.h"
#include "ocdump.h"
2013-03-16 05:44:59 +08:00
/* Mnemonic */
#define TOPLEVEL 1
/* Forward */
static OCdata* newocdata(OCnode* pattern);
2024-03-16 01:25:09 +08:00
static off_t ocxdrsize(OCtype etype,int isscalar);
static OCerror occompile1(OCstate*, OCnode*, XXDR*, OCdata**);
static OCerror occompilerecord(OCstate*, OCnode*, XXDR*, OCdata**);
2013-03-16 05:44:59 +08:00
static OCerror occompilefields(OCstate*, OCdata*, XXDR*, int istoplevel);
static OCerror occompileatomic(OCstate*, OCdata*, XXDR*);
static int ocerrorstring(XXDR* xdrs);
2013-03-16 05:44:59 +08:00
static int istoplevel(OCnode* node);
/* Sequence tag constant */
static const char StartOfSequence = '\x5A';
static const char EndOfSequence = '\xA5';
/*
2014-11-22 07:20:44 +08:00
Provide an option that makes a single pass over
the data packet and record pointers into it
to speed up access.
*/
/* Assume we are operating on the datadds tree */
OCerror
occompile(OCstate* state, OCnode* xroot)
{
OCerror ocstat = OC_NOERR;
XXDR* xxdrs;
OCtree* xtree;
OCdata* data;
OCASSERT(state != NULL);
OCASSERT(xroot != NULL);
OCASSERT(xroot->tree != NULL);
OCASSERT(xroot->tree->dxdclass == OCDATADDS);
OCASSERT(xroot->tree->data.data == NULL);
xtree = xroot->tree;
xxdrs = xtree->data.xdrs;
if(xxdrs == NULL) return OCTHROW(OC_EXDR);
ocstat = occompile1(state,xroot,xxdrs,&data);
if(ocstat == OC_NOERR)
xtree->data.data = data;
#ifdef OCDEBUG
{
2017-03-18 07:20:02 +08:00
Ncbytes* buffer = ncbytesnew();
ocdumpdatatree(state,data,buffer,0);
2017-03-18 07:20:02 +08:00
fprintf(stderr,"datatree:\n%s",ncbytescontents(buffer));
ncbytesfree(buffer);
}
#endif
return OCTHROW(ocstat);
}
static OCerror
occompile1(OCstate* state, OCnode* xnode, XXDR* xxdrs, OCdata** datap)
{
OCerror ocstat = OC_NOERR;
size_t i;
OCdata* data = NULL;
size_t nelements = 0;
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
NClist* records = NULL;
/* Allocate instance for this node */
data = newocdata(xnode);
MEMFAIL(data);
/* Capture position(s) */
data->xdroffset = xxdr_getpos(xxdrs);
switch (xnode->octype) {
case OC_Dataset:
case OC_Grid: /* Always scalars */
2013-03-16 05:44:59 +08:00
ocstat = occompilefields(state,data,xxdrs,istoplevel(xnode));
if(ocstat != OC_NOERR) goto fail;
break;
case OC_Structure:
if(xnode->array.rank == 0) {/* scalar */
2013-03-16 05:44:59 +08:00
ocstat = occompilefields(state,data,xxdrs,istoplevel(xnode));
if(ocstat != OC_NOERR) goto fail;
} else { /* dimensioned structure */
unsigned int xdrcount;
fset(data->datamode,OCDT_ARRAY);
/* Determine # of instances */
nelements = octotaldimsize(xnode->array.rank,xnode->array.sizes);
if(nelements == 0) {ocstat = OCTHROW(OC_ENODATA); goto fail;}
/* Validate and skip the leading count field */
if(!xxdr_uint(xxdrs,&xdrcount))
{ocstat = OC_EXDR; goto fail;}
if(xdrcount != nelements)
{ocstat=OCTHROW(OC_EINVALCOORDS); goto fail;}
/* allocate space to capture all the element instances */
This PR adds EXPERIMENTAL support for accessing data in the cloud using a variant of the Zarr protocol and storage format. This enhancement is generically referred to as "NCZarr". The data model supported by NCZarr is netcdf-4 minus the user-defined types and the String type. In this sense it is similar to the CDF-5 data model. More detailed information about enabling and using NCZarr is described in the document NUG/nczarr.md and in a [Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in). WARNING: this code has had limited testing, so do use this version for production work. Also, performance improvements are ongoing. Note especially the following platform matrix of successful tests: Platform | Build System | S3 support ------------------------------------ Linux+gcc | Automake | yes Linux+gcc | CMake | yes Visual Studio | CMake | no Additionally, and as a consequence of the addition of NCZarr, major changes have been made to the Filter API. NOTE: NCZarr does not yet support filters, but these changes are enablers for that support in the future. Note that it is possible (probable?) that there will be some accidental reversions if the changes here did not correctly mimic the existing filter testing. In any case, previously filter ids and parameters were of type unsigned int. In order to support the more general zarr filter model, this was all converted to char*. The old HDF5-specific, unsigned int operations are still supported but they are wrappers around the new, char* based nc_filterx_XXX functions. This entailed at least the following changes: 1. Added the files libdispatch/dfilterx.c and include/ncfilter.h 2. Some filterx utilities have been moved to libdispatch/daux.c 3. A new entry, "filter_actions" was added to the NCDispatch table and the version bumped. 4. An overly complex set of structs was created to support funnelling all of the filterx operations thru a single dispatch "filter_actions" entry. 5. Move common code to from libhdf5 to libsrc4 so that it is accessible to nczarr. Changes directly related to Zarr: 1. Modified CMakeList.txt and configure.ac to support both C and C++ -- this is in support of S3 support via the awd-sdk libraries. 2. Define a size64_t type to support nczarr. 3. More reworking of libdispatch/dinfermodel.c to support zarr and to regularize the structure of the fragments section of a URL. Changes not directly related to Zarr: 1. Make client-side filter registration be conditional, with default off. 2. Hack include/nc4internal.h to make some flags added by Ed be unique: e.g. NC_CREAT, NC_INDEF, etc. 3. cleanup include/nchttp.h and libdispatch/dhttp.c. 4. Misc. changes to support compiling under Visual Studio including: * Better testing under windows for dirent.h and opendir and closedir. 5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags and to centralize error reporting. 6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them. 7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible. Changes Left TO-DO: 1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
data->instances = (OCdata**)calloc(nelements,sizeof(OCdata*));
2014-11-22 07:20:44 +08:00
MEMGOTO(data->instances,ocstat,fail);
data->ninstances = 0;
/* create and fill the element instances */
for(i=0;i<nelements;i++) {
OCdata* instance = newocdata(xnode);
2014-11-22 07:20:44 +08:00
MEMGOTO(instance,ocstat,fail);
fset(instance->datamode,OCDT_ELEMENT);
data->instances[i] = instance;
data->ninstances++;
/* Capture the back link */
instance->container = data;
instance->index = i;
/* capture the current instance position */
instance->xdroffset = xxdr_getpos(xxdrs);
/* Now compile the fields of this instance */
2013-03-16 05:44:59 +08:00
ocstat = occompilefields(state,instance,xxdrs,!TOPLEVEL);
if(ocstat != OC_NOERR) {goto fail;}
}
}
break;
case OC_Sequence:
/* Since we do not know the # records beforehand,
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
use a list to collect the record instances.
*/
fset(data->datamode,OCDT_SEQUENCE);
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
records = nclistnew();
for(nelements=0;;nelements++) {
/* pick up the sequence record begin marker*/
char tmp[sizeof(unsigned int)];
/* extract the tag byte*/
if(!xxdr_opaque(xxdrs,tmp,(off_t)sizeof(tmp)))
{ocstat = OC_EXDR; goto fail;}
if(tmp[0] == StartOfSequence) {
/* Allocate a record instance */
OCdata* record = NULL;
ocstat = occompilerecord(state,xnode,xxdrs,&record);
2014-04-19 09:13:34 +08:00
if(ocstat != OC_NOERR || !record) goto fail;
/* Capture the back link */
record->container = data;
record->index = nelements;
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
nclistpush(records,(void*)record);
record = NULL;
} else if(tmp[0] == EndOfSequence) {
break; /* we are done with the this sequence instance*/
} else {
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
nclog(NCLOGERR,"missing/invalid begin/end record marker\n");
ocstat = OCTHROW(OC_EINVALCOORDS);
goto fail;
}
}
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
OCASSERT(nelements == nclistlength(records));
/* extract the content */
data->ninstances = nelements;
This PR adds EXPERIMENTAL support for accessing data in the cloud using a variant of the Zarr protocol and storage format. This enhancement is generically referred to as "NCZarr". The data model supported by NCZarr is netcdf-4 minus the user-defined types and the String type. In this sense it is similar to the CDF-5 data model. More detailed information about enabling and using NCZarr is described in the document NUG/nczarr.md and in a [Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in). WARNING: this code has had limited testing, so do use this version for production work. Also, performance improvements are ongoing. Note especially the following platform matrix of successful tests: Platform | Build System | S3 support ------------------------------------ Linux+gcc | Automake | yes Linux+gcc | CMake | yes Visual Studio | CMake | no Additionally, and as a consequence of the addition of NCZarr, major changes have been made to the Filter API. NOTE: NCZarr does not yet support filters, but these changes are enablers for that support in the future. Note that it is possible (probable?) that there will be some accidental reversions if the changes here did not correctly mimic the existing filter testing. In any case, previously filter ids and parameters were of type unsigned int. In order to support the more general zarr filter model, this was all converted to char*. The old HDF5-specific, unsigned int operations are still supported but they are wrappers around the new, char* based nc_filterx_XXX functions. This entailed at least the following changes: 1. Added the files libdispatch/dfilterx.c and include/ncfilter.h 2. Some filterx utilities have been moved to libdispatch/daux.c 3. A new entry, "filter_actions" was added to the NCDispatch table and the version bumped. 4. An overly complex set of structs was created to support funnelling all of the filterx operations thru a single dispatch "filter_actions" entry. 5. Move common code to from libhdf5 to libsrc4 so that it is accessible to nczarr. Changes directly related to Zarr: 1. Modified CMakeList.txt and configure.ac to support both C and C++ -- this is in support of S3 support via the awd-sdk libraries. 2. Define a size64_t type to support nczarr. 3. More reworking of libdispatch/dinfermodel.c to support zarr and to regularize the structure of the fragments section of a URL. Changes not directly related to Zarr: 1. Make client-side filter registration be conditional, with default off. 2. Hack include/nc4internal.h to make some flags added by Ed be unique: e.g. NC_CREAT, NC_INDEF, etc. 3. cleanup include/nchttp.h and libdispatch/dhttp.c. 4. Misc. changes to support compiling under Visual Studio including: * Better testing under windows for dirent.h and opendir and closedir. 5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags and to centralize error reporting. 6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them. 7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible. Changes Left TO-DO: 1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
data->instances = nclistextract(records);
2014-11-22 07:20:44 +08:00
MEMGOTO(data,ocstat,fail);
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
nclistfree(records);
records = NULL;
break;
case OC_Atomic:
fset(data->datamode,OCDT_ATOMIC);
ocstat = occompileatomic(state,data,xxdrs);
if(ocstat != OC_NOERR) goto fail;
break;
default:
OCPANIC1("occompile: encountered unexpected node type: %x",xnode->octype);
break;
}
/*ok:*/
2014-11-22 07:20:44 +08:00
if(datap) {
*datap = data;
data = NULL;
}
if(data != NULL)
ocdata_free(state,data);
return OCTHROW(ocstat);
fail:
/* See if we can extract error info from the response */
ocerrorstring(xxdrs);
if(records != NULL) {
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
for(i=0;i<nclistlength(records);i++)
ocdata_free(state,(OCdata*)nclistget(records,i));
nclistfree(records);
}
2014-11-22 07:20:44 +08:00
if(data != NULL)
ocdata_free(state,data);
2014-11-22 07:20:44 +08:00
return OCTHROW(ocstat);
}
static OCerror
occompilerecord(OCstate* state, OCnode* xnode, XXDR* xxdrs, OCdata** recordp)
{
OCerror ocstat = OC_NOERR;
OCdata* record = newocdata(xnode);/* create record record */
MEMFAIL(record);
fset(record->datamode,OCDT_RECORD);
record->pattern = xnode;
/* capture the current record position */
record->xdroffset = xxdr_getpos(xxdrs);
/* Compile the fields of this record */
2013-03-16 05:44:59 +08:00
ocstat = OCTHROW(occompilefields(state,record,xxdrs,!TOPLEVEL));
if(ocstat == OC_NOERR) {
2014-11-22 07:20:44 +08:00
if(recordp) {
*recordp = record;
record = NULL;
}
if(record != NULL)
ocdata_free(state,record);
}
2014-11-22 07:20:44 +08:00
return OCTHROW(ocstat);
}
static OCerror
2013-03-16 05:44:59 +08:00
occompilefields(OCstate* state, OCdata* data, XXDR* xxdrs, int istoplevel)
{
size_t i;
OCerror ocstat = OC_NOERR;
size_t nelements;
OCnode* xnode = data->pattern;
assert(data != NULL);
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
nelements = nclistlength(xnode->subnodes);
if(nelements == 0)
goto done;
data->instances = (OCdata**)malloc(nelements*sizeof(OCdata*));
MEMFAIL(data->instances);
for(i=0;i<nelements;i++) {
OCnode* fieldnode;
OCdata* fieldinstance;
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
fieldnode = (OCnode*)nclistget(xnode->subnodes,i);
ocstat = occompile1(state,fieldnode,xxdrs,&fieldinstance);
if(ocstat != OC_NOERR)
goto fail;
fset(fieldinstance->datamode,OCDT_FIELD);
data->instances[i] = fieldinstance;
data->ninstances++;
/* Capture the back link */
fieldinstance->container = data;
fieldinstance->index = i;
}
2013-03-16 05:44:59 +08:00
/* If top-level, then link the OCnode to the OCdata directly */
if(istoplevel) {
for(i=0;i<nelements;i++) {
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
OCnode* fieldnode = (OCnode*)nclistget(xnode->subnodes,i);
2013-03-16 05:44:59 +08:00
OCdata* fieldinstance = data->instances[i];
fieldnode->data = fieldinstance;
}
}
done:
return OCTHROW(ocstat);
fail:
if(data->instances != NULL) {
for(i=0;i<data->ninstances;i++)
ocdata_free(state,data->instances[i]);
data->ninstances = 0;
}
return OCTHROW(ocstat);
}
static OCerror
occompileatomic(OCstate* state, OCdata* data, XXDR* xxdrs)
{
OCerror ocstat = OC_NOERR;
int i;
2024-03-16 01:25:09 +08:00
off_t xdrsize;
unsigned int xxdrcount;
OCnode* xnode = data->pattern;
int scalar = (xnode->array.rank == 0);
2014-11-22 07:20:44 +08:00
OCASSERT((xnode->octype == OC_Atomic));
if(!scalar) {
/* Use the count from the datadds */
2024-03-16 01:25:09 +08:00
size_t nelements = octotaldimsize(xnode->array.rank,xnode->array.sizes);
/* Get first copy of the dimension count */
if(!xxdr_uint(xxdrs,&xxdrcount)) {ocstat = OC_EXDR; goto fail;}
if(xxdrcount != nelements) {ocstat=OCTHROW(OC_EINVALCOORDS); goto fail;}
if(xnode->etype != OC_String && xnode->etype != OC_URL) {
/* Get second copy of the dimension count */
if(!xxdr_uint(xxdrs,&xxdrcount)) {ocstat = OC_EXDR; goto fail;}
if(xxdrcount != nelements) {ocstat=OCTHROW(OC_EINVALCOORDS); goto fail;}
}
} else { /*scalar*/
xxdrcount = 1;
}
data->xdroffset = xxdr_getpos(xxdrs);
data->ninstances = xxdrcount;
data->xdrsize = ocxdrsize(xnode->etype,scalar);
switch (xnode->etype) {
/* Do the fixed sized, non-packed cases */
case OC_Int16: case OC_UInt16:
case OC_Int32: case OC_UInt32:
case OC_Int64: case OC_UInt64:
case OC_Float32: case OC_Float64:
/* Skip the data */
2024-03-16 01:25:09 +08:00
xxdr_skip(xxdrs,(off_t)data->ninstances*data->xdrsize);
break;
/* Do the fixed sized, possibly packed cases */
case OC_Byte:
case OC_UByte:
case OC_Char:
/* Get the totalsize and round up to multiple of XDRUNIT */
2024-03-16 01:25:09 +08:00
xdrsize = (off_t)data->ninstances*data->xdrsize;
xdrsize = RNDUP(xdrsize);
/* Skip the data */
xxdr_skip(xxdrs,xdrsize);
break;
/* Hard case, because strings are variable length */
case OC_String: case OC_URL:
/* Start by allocating a set of pointers for each string */
data->nstrings = xxdrcount;
data->strings = (off_t*)malloc(sizeof(off_t)*data->nstrings);
/* We need to walk each string, get size, then skip */
for(i=0;i<data->nstrings;i++) {
unsigned int len;
off_t lenz;
data->strings[i] = xxdr_getpos(xxdrs);
/* get exact string length */
if(!xxdr_uint(xxdrs,&len)) {ocstat = OC_EXDR; goto fail;}
lenz = (off_t)len;
lenz = RNDUP(lenz);
/* Skip the data */
xxdr_skip(xxdrs,lenz);
}
break;
default:
OCPANIC1("unexpected etype: %d",xnode->etype);
} /* switch */
/*ok:*/
return OCTHROW(ocstat);
fail:
if(data->strings != NULL)
free(data->strings);
data->strings = NULL;
data->ninstances = 0;
return OCTHROW(ocstat);
}
void
ocdata_free(OCstate* state, OCdata* data)
{
if(data == NULL)
return;
if(data->instances != NULL) {
int i;
for(i=0;i<data->ninstances;i++)
ocdata_free(state,data->instances[i]);
free(data->instances);
}
if(data->strings != NULL)
free(data->strings);
free(data);
}
static OCdata*
newocdata(OCnode* pattern)
{
OCdata* data = (OCdata*)calloc(1,sizeof(OCdata));
MEMCHECK(data,NULL);
data->header.magic = OCMAGIC;
data->header.occlass = OC_Data;
data->pattern = pattern;
return data;
}
2013-03-16 05:44:59 +08:00
static int
istoplevel(OCnode* node)
{
if(node == NULL)
return 1; /* base case */
if(!istoplevel(node->container))
return 0;
switch (node->octype) {
case OC_Dataset: case OC_Grid: case OC_Atomic: return 1;
case OC_Structure:
2014-11-22 07:20:44 +08:00
return (node->array.rank == 0 ? 1 : 0); /* Toplevel if scalar */
2013-03-16 05:44:59 +08:00
case OC_Sequence: default: return 0;
}
return 1;
}
/* XDR representation size depends on if this is scalar or not */
2024-03-16 01:25:09 +08:00
static off_t
ocxdrsize(OCtype etype, int isscalar)
{
switch (etype) {
case OC_Char:
case OC_Byte:
case OC_UByte:
return (isscalar? XDRUNIT : 1);
case OC_Int16:
case OC_UInt16:
case OC_Int32:
case OC_UInt32:
case OC_Float32:
return XDRUNIT;
case OC_Float64:
case OC_Int64:
case OC_UInt64:
return 2*XDRUNIT;
default:
break; /* no simple size */
}
return 0;
}
#define tag "Error {\n"
static int
ocerrorstring(XXDR* xdrs)
{
/* Check to see if the xdrs contains "Error {\n'; assume it is at the beginning of data */
off_t avail = xxdr_getavail(xdrs);
2014-11-22 07:20:44 +08:00
char* data;
if(!xxdr_setpos(xdrs,(off_t)0)) return 0;
data = (char*)malloc((size_t)avail);
MEMCHECK(data,0);
if(!xxdr_opaque(xdrs,data,avail)) {free(data); return 0;}
/* check for error tag at front */
if(ocstrncmp(data,tag,sizeof(tag))==0) {
char* p;
if((p=strchr(data,'}')) != NULL) *(++p)='\0';
Primary change: add dap4 support Specific changes: 1. Add dap4 code: libdap4 and dap4_test. Note that until the d4ts server problem is solved, dap4 is turned off. 2. Modify various files to support dap4 flags: configure.ac, Makefile.am, CMakeLists.txt, etc. 3. Add nc_test/test_common.sh. This centralizes the handling of the locations of various things in the build tree: e.g. where is ncgen.exe located. See nc_test/test_common.sh for details. 4. Modify .sh files to use test_common.sh 5. Obsolete separate oc2 by moving it to be part of netcdf-c. This means replacing code with netcdf-c equivalents. 5. Add --with-testserver to configure.ac to allow override of the servers to be used for --enable-dap-remote-tests. 6. There were multiple versions of nctypealignment code. Try to centralize in libdispatch/doffset.c and include/ncoffsets.h 7. Add a unit test for the ncuri code because of its complexity. 8. Move the findserver code out of libdispatch and into a separate, self contained program in ncdap_test and dap4_test. 9. Move the dispatch header files (nc{3,4}dispatch.h) to .../include because they are now shared by modules. 10. Revamp the handling of TOPSRCDIR and TOPBUILDDIR for shell scripts. 11. Make use of MREMAP if available 12. Misc. minor changes e.g. - #include <config.h> -> #include "config.h" - Add some no-install headers to /include - extern -> EXTERNL and vice versa as needed - misc header cleanup - clean up checking for misc. unix vs microsoft functions 13. Change copyright decls in some files to point to LICENSE file. 14. Add notes to RELEASENOTES.md
2017-03-09 08:01:10 +08:00
nclog(NCLOGERR,"Server error: %s",data);
/* Since important, report to stderr as well */
fprintf(stderr,"Server error: %s",data);
return 1;
}
return 0;
}