diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ccc2646f7..df9af1a231 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,8 +267,6 @@ SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_SOURCE_DIR}/libsrc) # End Compiler Configuration ################################ - - ## # Configuration for post-install RPath # Adapted from http://www.cmake.org/Wiki/CMake_RPATH_handling diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 450c31644c..dd58e56774 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -12,6 +12,7 @@ reading and writing. See the file docs/filters.md. ## 4.5.1 - TBD * [Enhancement] Added an option to enable strict null-byte padding for headers; this padding was specified in the spec but was not enforced. Enabling this option will allow you to check your files, as it will return an E_NULLPAD error. It is possible for these files to have been written by older versions of libnetcdf. There is no effective problem caused by this lack of null padding, so enabling these options is informational only. The options for `configure` and `cmake` are `--enable-strict-null-byte-header-padding` and `-DENABLE_STRICT_NULL_BYTE_HEADER_PADDING`, respectively. See [Github #657](https://github.com/Unidata/netcdf-c/issues/657) for more information. +* Corrected a number of memory issues identified in `ncgen`. See [GitHub #558 for more information](https://github.com/Unidata/netcdf-c/pull/558). * [Enhancement] Reverted behavior/handling of out-of-range attribute values to pre-4.5.0 default. See [Github #512](https://github.com/Unidata/netcdf-c/issues/512) for more information. * [Bug] Fixed error in tst_parallel2.c. See [Github #545](https://github.com/Unidata/netcdf-c/issues/545) for more information. * [Bug] Fixed handling of corrupt files + proper offset handling for hdf5 files. See [Github #552](https://github.com/Unidata/netcdf-c/issues/552) for more information. diff --git a/cf b/cf index d1da1ee209..f8a36def85 100644 --- a/cf +++ b/cf @@ -3,6 +3,7 @@ DB=1 #X=-x FAST=1 +#MEM=1 HDF5=1 DAP=1 @@ -22,8 +23,9 @@ fi CFLAGS="" #CFLAGS="-Wall -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unused-parameter -Wconversion ${CFLAGS}" CFLAGS="-Wall -Wno-unused-but-set-variable -Wno-unused-variable -Wno-unused-parameter -Wno-char-subscripts -Wno-pointer-sign -Wno-format ${CFLAGS}" -#CFLAGS="-Wall ${CFLAGS}" -#CFLAGS="-Wconversion" +if test "x$MEM" = x1 ; then +CFLAGS="-fsanitize=address -fno-omit-frame-pointer ${CFLAGS}" +fi stddir="/usr/local" PREFIX=/usr/local diff --git a/docs/OPeNDAP.dox b/docs/OPeNDAP.dox index 59f383953c..7b17a09409 100644 --- a/docs/OPeNDAP.dox +++ b/docs/OPeNDAP.dox @@ -1,4 +1,5 @@ -/*! \page dap2 DAP2 Support +/*! +\page dap2 DAP2 Support \tableofcontents @@ -35,7 +36,7 @@ See the following pages for more information. - \subpage var_dim_trans - \subpage var_name_trans -\page dap_accessing_data Accessing OPeNDAP Data +\section dap_accessing_data Accessing OPeNDAP Data In order to access an OPeNDAP data source through the netCDF API, the file name normally used is replaced with a URL with a specific @@ -177,13 +178,13 @@ variables: } \endcode -\page dap_to_netcdf DAP to NetCDF Translation Rules +\section dap_to_netcdf DAP to NetCDF Translation Rules Currently only one translation available: DAP 2 Protocol to netCDF-3. There used to be a DAP 2 Protocol to netCDF-4 translation but that has been removed until the DAP4 protocol is available. -\section nc3_trans_rules netCDF-3 Translation Rules +\subsection nc3_trans_rules netCDF-3 Translation Rules The current default translation code translates the OPeNDAP protocol to netCDF-3 (classic). This netCDF-3 translation converts an OPeNDAP @@ -225,7 +226,7 @@ Dataset { } D1; \endcode -\section var_def Variable Definition +\subsection var_def Variable Definition The set of netCDF variables is derived from the fields with primitive base types as they occur in Sequences, Grids, and Structures. The @@ -244,7 +245,7 @@ within grids are left out in order to mimic the behavior of libnc-dap. lon \endcode -\page dap2_reserved_keywords DAP2 Reserved Keywords +\section dap2_reserved_keywords DAP2 Reserved Keywords In the OPeNDAP DAP2 protocol, there are a number of reserved keywords. These keywords are case insensitive and if you use one as a netCDF variable name, you may encounter odd behavior such as case changes (depending on the client DDS/DAS parser). The list of reserved keywords as used by the netCDF-C library parser are as follows: @@ -272,7 +273,7 @@ In the OPeNDAP DAP2 protocol, there are a number of reserved keywords. These ke - program -\page var_dim_trans Variable Dimension Translation +\section var_dim_trans Variable Dimension Translation A variable's rank is determined from three sources. - The variable has the dimensions associated with the field it @@ -287,7 +288,7 @@ containers is a DAP DDS Sequence. This is discussed more fully below. If the type of the netCDF variable is char, then an extra string dimension is added as the last dimension. -\section dim_trans Dimension translation +\subsection dim_trans Dimension translation For dimensions, the rules are as follows. @@ -366,7 +367,7 @@ dimensions: S1.FS2.f2_0 = 2 ; \endcode -\page var_name_trans Variable Name Translation +\section var_name_trans Variable Name Translation The steps for variable name translation are as follows. @@ -435,7 +436,7 @@ int S1.FS2.f1(lat, lat) ; Note that this is incorrect because it dimensions S1.FS2.f1(2,2) rather than S1.FS2.f1(2,3). -\section dap_translation Translating DAP DDS Sequences +\subsection dap_translation Translating DAP DDS Sequences Any variable (as determined above) that is contained directly or indirectly by a Sequence is subject to revision of its rank using the @@ -552,7 +553,7 @@ performance. Currently, a limited set of client parameters is recognized. Parameters not listed here are ignored, but no error is -signalled. +signalled. All names are case insensitive. Parameter Name Legal Values Semantics - "log" | "log=" - Turn on logging and send the log output to @@ -568,10 +569,11 @@ Parameter Name Legal Values Semantics enabled, then this can be helpful in checking to see the access behavior of the netCDF code. - "stringlength=NN" - Specify the default string length to use for - string dimensions. The default is 64. + string dimensions. The default is 64. The name "maxstrlen" is an + alias for "stringlength". - "stringlength_=NN" - Specify the default string length to use for a string dimension for the specified variable. The default is - 64. + 64. The name "maxstrlen_" is an alias for "stringlength_". - "cache" - This enables caching. - "cachelimit=NN" - Specify the maximum amount of space allowed for the cache. diff --git a/include/nc4internal.h b/include/nc4internal.h index bb1b889176..53375082c0 100644 --- a/include/nc4internal.h +++ b/include/nc4internal.h @@ -102,6 +102,12 @@ typedef enum {VAR, DIM, ATT} NC_OBJ_T; * as the netCDF dimid. */ #define NC_DIMID_ATT_NAME "_Netcdf4Dimid" +/** This is the name of the class HDF5 dimension scale attribute. */ +#define HDF5_DIMSCALE_CLASS_ATT_NAME "CLASS" + +/** This is the name of the name HDF5 dimension scale attribute. */ +#define HDF5_DIMSCALE_NAME_ATT_NAME "NAME" + /* Boolean type, to make the code easier to read */ typedef enum {NC_FALSE = 0, NC_TRUE = 1} nc_bool_t; @@ -126,7 +132,7 @@ typedef struct NC_DIM_INFO nc_bool_t unlimited; /* True if the dimension is unlimited */ nc_bool_t extended; /* True if the dimension needs to be extended */ nc_bool_t too_long; /* True if len is too big to fit in local size_t. */ - hid_t hdf_dimscaleid; + hid_t hdf_dimscaleid; /* Non-zero if a DIM_WITHOUT_VARIABLE dataset is in use (no coord var). */ HDF5_OBJID_T hdf5_objid; struct NC_VAR_INFO *coord_var; /* The coord var, if it exists. */ } NC_DIM_INFO_T; @@ -344,6 +350,7 @@ int nc4_convert_type(const void *src, void *dest, /* These functions do HDF5 things. */ int rec_detach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid); int rec_reattach_scales(NC_GRP_INFO_T *grp, int dimid, hid_t dimscaleid); +int delete_existing_dimscale_dataset(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T *dim); int nc4_open_var_grp2(NC_GRP_INFO_T *grp, int varid, hid_t *dataset); int nc4_put_vara(NC *nc, int ncid, int varid, const size_t *startp, const size_t *countp, nc_type xtype, int is_long, void *op); diff --git a/include/nc_tests.h b/include/nc_tests.h index 613298e05d..d89b915d9c 100644 --- a/include/nc_tests.h +++ b/include/nc_tests.h @@ -1,11 +1,12 @@ -/** \internal -\file -Common includes, defines, etc., for test code in the libsrc4 and -nc_test4 directories. - -This is part of the netCDF package. Copyright 2005 University -Corporation for Atmospheric Research/Unidata. See \ref copyright file -for conditions of use. +/* This is part of the netCDF package. Copyright 2005 University + * Corporation for Atmospheric Research/Unidata. See \ref copyright + * file for conditions of use. */ +/** @internal @file + * + * Common includes, defines, etc., for test code in the libsrc4 and + * nc_test4 directories. + * + * @author Ed Hartnett, Denis Heimbigner, Ward Fisher */ #ifndef _NC_TESTS_H @@ -22,8 +23,10 @@ for conditions of use. #include "netcdf.h" //#include "err_macros.h" +/** NC_MAX_DIMS for tests. Allows different NC_MAX_DIMS values + * without breaking this test with a heap or stack overflow. */ +#define NC_TESTS_MAX_DIMS 1024 -#define NC_TESTS_MAX_DIMS 1024 /**< NC_MAX_DIMS for tests. Allows different NC_MAX_DIMS values without breaking this test with a heap or stack overflow. */ #define MAX_NUM_FORMATS 5 /**< Max number of available binary formats. */ /** Useful define for tests. */ @@ -38,6 +41,7 @@ for conditions of use. #define ONE_TWENTY_EIGHT_MEG (SIXTEEN_MEG * 8) #define TEST_VAL_42 42 #define BAD_NAME "dd//d/ " +#define NUM_NETCDF_TYPES 12 /** \} */ #ifdef USE_PNETCDF diff --git a/include/netcdf.h b/include/netcdf.h index fac6f63d8e..6d9ca157be 100644 --- a/include/netcdf.h +++ b/include/netcdf.h @@ -254,11 +254,14 @@ These maximums are not used for netCDF-4/HDF5 files unless they were created with the ::NC_CLASSIC_MODEL flag. As a rule, NC_MAX_VAR_DIMS <= NC_MAX_DIMS. + +NOTE: The NC_MAX_DIMS, NC_MAX_ATTRS, and NC_MAX_VARS limits + are *not* enforced after version 4.5.0 */ /**@{*/ -#define NC_MAX_DIMS 1024 -#define NC_MAX_ATTRS 8192 -#define NC_MAX_VARS 8192 +#define NC_MAX_DIMS 1024 /* not enforced after 4.5.0 */ +#define NC_MAX_ATTRS 8192 /* not enforced after 4.5.0 */ +#define NC_MAX_VARS 8192 /* not enforced after 4.5.0 */ #define NC_MAX_NAME 256 #define NC_MAX_VAR_DIMS 1024 /**< max per variable dimensions */ /**@}*/ diff --git a/libdap2/ncd2dispatch.c b/libdap2/ncd2dispatch.c index eb8a2b7cff..24b18655af 100644 --- a/libdap2/ncd2dispatch.c +++ b/libdap2/ncd2dispatch.c @@ -201,6 +201,7 @@ NCD2_initialize(void) int NCD2_finalize(void) { + curl_global_cleanup(); return NC_NOERR; } @@ -1193,6 +1194,7 @@ constrainable(NCURI* durl) return 0; } +/* Lookup a parameter key; case insensitive */ static const char* paramlookup(NCDAPCOMMON* state, const char* key) { @@ -1261,21 +1263,29 @@ applyclientparams(NCDAPCOMMON* nccomm) /* allow embedded _ */ value = paramlookup(nccomm,"stringlength"); + if(value == NULL) + value = paramlookup(nccomm,"maxstrlen"); if(value != NULL && strlen(value) != 0) { if(sscanf(value,"%d",&len) && len > 0) dfaltstrlen = len; - } + } nccomm->cdf.defaultstringlength = dfaltstrlen; /* String dimension limits apply to variables */ for(i=0;icdf.ddsroot->tree->varnodes);i++) { CDFnode* var = (CDFnode*)nclistget(nccomm->cdf.ddsroot->tree->varnodes,i); - /* Define the client param stringlength for this variable*/ - var->maxstringlength = 0; /* => use global dfalt */ - strncpy(tmpname,"stringlength_",sizeof(tmpname)); + /* Define the client param stringlength/maxstrlen for this variable*/ + /* create the variable path name */ pathstr = makeocpathstring(conn,var->ocnode,"."); - strlcat(tmpname,pathstr,sizeof(tmpname)); - nullfree(pathstr); + var->maxstringlength = 0; /* => use global dfalt */ + strcpy(tmpname,"stringlength_"); + strncat(tmpname,pathstr,NC_MAX_NAME); value = paramlookup(nccomm,tmpname); + if(value == NULL) { + strcpy(tmpname,"maxstrlen_"); + strncat(tmpname,pathstr,NC_MAX_NAME); + value = paramlookup(nccomm,tmpname); + } + nullfree(pathstr); if(value != NULL && strlen(value) != 0) { if(sscanf(value,"%d",&len) && len > 0) var->maxstringlength = len; } diff --git a/libdap4/d4file.c b/libdap4/d4file.c index 6574efe0eb..a16053f55c 100644 --- a/libdap4/d4file.c +++ b/libdap4/d4file.c @@ -90,6 +90,9 @@ NCD4_open(const char * path, int mode, { char tmpname[NC_MAX_NAME]; + /* Guarantee tmpname is a legitimate string */ + tmpname[0] = '\0'; + /* Create fake file name: exact name must be unique, but is otherwise irrelevant because we are using NC_DISKLESS */ @@ -122,7 +125,7 @@ NCD4_open(const char * path, int mode, nc_set_default_format(old,&new); /* restore */ d4info->substrate.realfile = ((ncflags & NC_DISKLESS) == 0); d4info->substrate.filename = strdup(tmpname); - if(tmpname == NULL) ret = NC_ENOMEM; + if(d4info->substrate.filename == NULL) ret = NC_ENOMEM; d4info->substrate.nc4id = ncid; } if(ret != NC_NOERR) goto done; diff --git a/libdap4/ncd4.h b/libdap4/ncd4.h index 2995edd2e3..5651732746 100644 --- a/libdap4/ncd4.h +++ b/libdap4/ncd4.h @@ -41,11 +41,6 @@ defined here, including function-like #defines. /* Clear empty structure alignment space; Potentially costly, but probably less than CLEARMEM */ #define CLEARSTRUCT -/**************************************************/ -/* Global state */ - -extern NCD4globalstate* NCD4_globalstate; - /**************************************************/ #undef nullfree diff --git a/libdap4/ncd4dispatch.c b/libdap4/ncd4dispatch.c index b374af2151..ddecd68475 100644 --- a/libdap4/ncd4dispatch.c +++ b/libdap4/ncd4dispatch.c @@ -34,9 +34,6 @@ static NC_Dispatch NCD4_dispatch_base; NC_Dispatch* NCD4_dispatch_table = NULL; /* moved here from ddispatch.c */ -/* Collect global state info in one place */ -NCD4globalstate* NCD4_globalstate = NULL; - /* Forward */ static int globalinit(void); @@ -63,6 +60,7 @@ NCD4_initialize(void) int NCD4_finalize(void) { + curl_global_cleanup(); return THROW(NC_NOERR); } diff --git a/libdap4/ncd4types.h b/libdap4/ncd4types.h index 993faff813..fa74110f46 100644 --- a/libdap4/ncd4types.h +++ b/libdap4/ncd4types.h @@ -42,7 +42,6 @@ typedef enum NCD4mode NCD4mode; typedef enum NCD4translation NCD4translation; typedef struct NCD4curl NCD4curl; typedef struct NCD4meta NCD4meta; -typedef struct NCD4globalstate NCD4globalstate; typedef struct NCD4node NCD4node; typedef struct NCD4params NCD4params; diff --git a/libdispatch/dtype.c b/libdispatch/dtype.c index 75b71376ba..82fafb475d 100644 --- a/libdispatch/dtype.c +++ b/libdispatch/dtype.c @@ -41,7 +41,12 @@ type). Read attributes of the new type with nc_get_att (see /** \ingroup user_types -Learn if two types are equal +Learn if two types are equal. + +\note User-defined types in netCDF-4/HDF5 files must be committed to +the file before nc_inq_type_equal() will work on the type. For +uncommitted user-defined types, nc_inq_type_equal() will return +::NC_EHDFERR. Commit types to the file with a call to nc_enddef(). \param ncid1 \ref ncid of first typeid. \param typeid1 First typeid. @@ -54,8 +59,11 @@ the two types are equal, a zero if they are not equal. \returns ::NC_EBADID Bad \ref ncid. \returns ::NC_EBADTYPE Bad type id. \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled. -\returns ::NC_EHDFERR An error was reported by the HDF5 layer. -\author Dennis Heimbigner, Ward Fisher +\returns ::NC_EHDFERR An error was reported by the HDF5 layer. This +will occur if either of the types have not been committed to the file +(with an nc_enddef()). + +\author Dennis Heimbigner, Ward Fisher, Ed Hartnett */ int nc_inq_type_equal(int ncid1, nc_type typeid1, int ncid2, diff --git a/libdispatch/dutil.c b/libdispatch/dutil.c index bb612c94c1..7ec8625a6e 100644 --- a/libdispatch/dutil.c +++ b/libdispatch/dutil.c @@ -209,7 +209,7 @@ NC_mktmp(const char* base) cvtpath = NCpathcvt(base); strncpy(tmp,cvtpath,sizeof(tmp)); nullfree(cvtpath); - strncat(tmp, "XXXXXX", sizeof(tmp)); + strncat(tmp, "XXXXXX", sizeof(tmp) - strlen(tmp) - 1); #ifdef HAVE_MKSTEMP /* Note Potential problem: old versions of this function diff --git a/libdispatch/ncuri.c b/libdispatch/ncuri.c index 83a065bb4f..09584274da 100644 --- a/libdispatch/ncuri.c +++ b/libdispatch/ncuri.c @@ -658,14 +658,16 @@ ncuriremoveparam(NCURI* uri, const char* key) #endif -/* Internal version of lookup; returns the paired index of the key */ +/* Internal version of lookup; returns the paired index of the key; + case insensitive + */ static int ncfind(char** params, const char* key) { int i; char** p; for(i=0,p=params;*p;p+=2,i++) { - if(strcmp(key,*p)==0) return i; + if(strcasecmp(key,*p)==0) return i; } return -1; } @@ -911,7 +913,8 @@ collectprefixparams(char* text, char** nextp) for(;;) { char* p; char* q; /* by construction, here we are at an LBRACKET: compress it out */ - for(p=sp,q=sp+1;(*p++=*q++);); + for(p=sp,q=sp+1;(*p++=*q++);) + ; /* locate the next RRACKET */ ep = nclocate(sp,RBRACKETSTR); if(ep == NULL) break;/* we are done */ diff --git a/libsrc/Makefile.am b/libsrc/Makefile.am index 56727431d4..bd0e8415c9 100644 --- a/libsrc/Makefile.am +++ b/libsrc/Makefile.am @@ -37,12 +37,12 @@ noinst_LTLIBRARIES = libnetcdf3.la # These files are cleaned on developer workstations (and then rebuilt # with m4), but they are included in the distribution so that the user # does not have to have m4. -MAINTAINERCLEANFILES = $(man_MANS) attrx.c ncx.c putgetx.c +MAINTAINERCLEANFILES = $(man_MANS) attr.c ncx.c putget.c EXTRA_DIST = attr.m4 ncx.m4 putget.m4 $(man_MANS) CMakeLists.txt XGetopt.c # This tells make how to turn .m4 files into .c files. .m4.c: - m4 $(AM_M4FLAGS) $(M4FLAGS) -s $< > $(top_srcdir)/libsrc/$@ + m4 $(AM_M4FLAGS) $(M4FLAGS) -s $< > $(top_srcdir)/libsrc/$(@F) # The C API man page. man_MANS = netcdf.3 diff --git a/libsrc4/nc4dim.c b/libsrc4/nc4dim.c index 3037318303..0841de3c80 100644 --- a/libsrc4/nc4dim.c +++ b/libsrc4/nc4dim.c @@ -1,3 +1,6 @@ +/* Copyright 2003-2018, University Corporation for Atmospheric + * Research. See the COPYRIGHT file for copying and redistribution + * conditions. */ /** * @file * @internal This file is part of netcdf-4, a netCDF-like interface @@ -6,9 +9,6 @@ * * This file handles the nc4 dimension functions. * - * Copyright 2003-5, University Corporation for Atmospheric Research. See - * the COPYRIGHT file for copying and redistribution conditions. - * * @author Ed Hartnett */ @@ -103,8 +103,7 @@ NC4_def_dim(int ncid, const char *name, size_t len, int *idp) /* Find our global metadata structure. */ if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5))) return retval; - - assert(h5 && nc /*& grp*/); + assert(h5 && nc && grp); /* If the file is read-only, return an error. */ if (h5->no_write) @@ -327,9 +326,7 @@ NC4_rename_dim(int ncid, int dimid, const char *name) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5))) return retval; - - assert(nc); - assert(h5 && grp); + assert(nc && h5 && grp); /* Trying to write to a read-only file? No way, Jose! */ if (h5->no_write) @@ -352,33 +349,30 @@ NC4_rename_dim(int ncid, int dimid, const char *name) return NC_EBADDIM; dim = tmp_dim; - /* Check for renaming dimension w/o variable */ + /* Check for renaming dimension w/o variable. */ if (dim->hdf_dimscaleid) { /* Sanity check */ assert(!dim->coord_var); + LOG((3, "dim %s is a dim without variable", dim->name)); - /* Close the HDF5 dataset */ - if (H5Dclose(dim->hdf_dimscaleid) < 0) - return NC_EHDFERR; - dim->hdf_dimscaleid = 0; - - /* Now delete the dataset (it will be recreated later, if necessary) */ - if (H5Gunlink(grp->hdf_grpid, dim->name) < 0) - return NC_EDIMMETA; + /* Delete the dimscale-only dataset. */ + if ((retval = delete_existing_dimscale_dataset(grp, dimid, dim))) + return retval; } /* Give the dimension its new name in metadata. UTF8 normalization * has been done. */ - if(dim->name) - free(dim->name); + assert(dim->name); + free(dim->name); if (!(dim->name = malloc((strlen(norm_name) + 1) * sizeof(char)))) return NC_ENOMEM; strcpy(dim->name, norm_name); - dim->hash = hash_fast(norm_name, strlen(norm_name)); + LOG((3, "dim is now named %s", dim->name)); - /* Check if dimension was a coordinate variable, but names are different now */ + /* Check if dimension was a coordinate variable, but names are + * different now */ if (dim->coord_var && strcmp(dim->name, dim->coord_var->name)) { /* Break up the coordinate variable */ @@ -386,24 +380,24 @@ NC4_rename_dim(int ncid, int dimid, const char *name) return retval; } - /* Check if dimension should become a coordinate variable */ + /* Check if dimension should become a coordinate variable. */ if (!dim->coord_var) { NC_VAR_INFO_T *var; - /* Attempt to find a variable with the same name as the dimension in - * the current group. */ + /* Attempt to find a variable with the same name as the + * dimension in the current group. */ if ((retval = nc4_find_var(grp, dim->name, &var))) return retval; - /* Check if we found a variable and the variable has the dimension in - * index 0. */ + /* Check if we found a variable and the variable has the + * dimension in index 0. */ if (var && var->dim[0] == dim) { /* Sanity check */ assert(var->dimids[0] == dim->dimid); - /* Reform the coordinate variable */ + /* Reform the coordinate variable. */ if ((retval = nc4_reform_coord_var(grp, var, dim))) return retval; } diff --git a/libsrc4/nc4grp.c b/libsrc4/nc4grp.c index 7ea43357d5..a422fd729c 100644 --- a/libsrc4/nc4grp.c +++ b/libsrc4/nc4grp.c @@ -1,14 +1,13 @@ +/* Copyright 2005-2018, University Corporation for Atmospheric + * Research. See COPYRIGHT file for copying and redistribution + * conditions. */ /** * @file * @internal This file is part of netcdf-4, a netCDF-like interface * for HDF5, or a HDF5 backend for netCDF, depending on your point of * view. * - * This file handles the nc4 groups. - * - * Copyright 2005, University Corporation for Atmospheric Research. See - * netcdf-4/docs/COPYRIGHT file for copying and redistribution - * conditions. + * This file handles groups. * * @author Ed Hartnett */ @@ -16,7 +15,7 @@ #include "nc4dispatch.h" /** - * @internal Create a group. It's ncid is returned in the new_ncid + * @internal Create a group. Its ncid is returned in the new_ncid * pointer. * * @param parent_ncid Parent group. @@ -42,8 +41,7 @@ NC4_def_grp(int parent_ncid, const char *name, int *new_ncid) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(parent_ncid, &grp, &h5))) return retval; - if (!h5) - return NC_ENOTNC4; + assert(h5); /* Check and normalize the name. */ if ((retval = nc4_check_name(name, norm_name))) @@ -103,22 +101,22 @@ NC4_rename_grp(int grpid, const char *name) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(grpid, &grp, &h5))) return retval; - if (!h5) - return NC_ENOTNC4; + assert(h5); if (h5->no_write) return NC_EPERM; /* attempt to write to a read-only file */ /* Do not allow renaming the root group */ - if(grp->parent == NULL) + if (grp->parent == NULL) return NC_EBADGRPID; /* Check and normalize the name. */ if ((retval = nc4_check_name(name, norm_name))) return retval; - /* Check that this name is not in use as a var, grp, or type. */ - if ((retval = nc4_check_dup_name(grp, norm_name))) + /* Check that this name is not in use as a var, grp, or type in the + * parent group (i.e. the group that grp is in). */ + if ((retval = nc4_check_dup_name(grp->parent, norm_name))) return retval; /* If it's not in define mode, switch to define mode. */ @@ -184,10 +182,7 @@ NC4_inq_ncid(int ncid, const char *name, int *grp_ncid) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(ncid, &grp, &h5))) return retval; - - /* Groups only work with netCDF-4/HDF5 files... */ - if (!h5) - return NC_ENOTNC4; + assert(h5); /* Normalize name. */ if ((retval = nc4_normalize_name(name, norm_name))) @@ -231,14 +226,7 @@ NC4_inq_grps(int ncid, int *numgrps, int *ncids) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(ncid, &grp, &h5))) return retval; - - /* For netCDF-3 files, just report zero groups. */ - if (!h5) - { - if (numgrps) - *numgrps = 0; - return NC_NOERR; - } + assert(h5); /* Count the number of groups in this group. */ for (g = grp->children; g; g = g->l.next) @@ -283,13 +271,11 @@ NC4_inq_grpname(int ncid, char *name) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(ncid, &grp, &h5))) return retval; + assert(h5); + + /* Copy the name. */ if (name) - { - if (!h5) - strcpy(name, "/"); - else - strcpy(name, grp->name); - } + strcpy(name, grp->name); return NC_NOERR; } @@ -388,11 +374,8 @@ NC4_inq_grp_parent(int ncid, int *parent_ncid) /* Find info for this file and group. */ if ((retval = nc4_find_grp_h5(ncid, &grp, &h5))) return retval; - - /* Groups only work with netCDF-4/HDF5 files... */ - if (!h5) - return NC_ENOGRP; - + assert(h5); + /* Set the parent ncid, if there is one. */ if (grp->parent) { @@ -434,6 +417,7 @@ NC4_inq_grp_full_ncid(int ncid, const char *full_name, int *grp_ncid) /* Find info for this file and group, and set pointer to each. */ if ((ret = nc4_find_grp_h5(ncid, &grp, &h5))) return ret; + assert(h5); /* Copy full_name because strtok messes with the value it works * with, and we don't want to mess up full_name. */ @@ -503,29 +487,17 @@ NC4_inq_varids(int ncid, int *nvars, int *varids) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(ncid, &grp, &h5))) return retval; + assert(h5); - if (!h5) + /* This is a netCDF-4 group. Round up them doggies and count + * 'em. The list is in correct (i.e. creation) order. */ + for (i=0; i < grp->vars.nelems; i++) { - /* If this is a netcdf-3 file, there is only one group, the root - * group, and its vars have ids 0 thru nvars - 1. */ - if ((retval = NC4_inq(ncid, NULL, &num_vars, NULL, NULL))) - return retval; + var = grp->vars.value[i]; + if (!var) continue; if (varids) - for (v = 0; v < num_vars; v++) - varids[v] = v; - } - else - { - /* This is a netCDF-4 group. Round up them doggies and count - * 'em. The list is in correct (i.e. creation) order. */ - for (i=0; i < grp->vars.nelems; i++) - { - var = grp->vars.value[i]; - if (!var) continue; - if (varids) - varids[num_vars] = var->varid; - num_vars++; - } + varids[num_vars] = var->varid; + num_vars++; } /* If the user wants to know how many vars in the group, tell @@ -584,44 +556,32 @@ NC4_inq_dimids(int ncid, int *ndims, int *dimids, int include_parents) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(ncid, &grp, &h5))) return retval; + assert(h5); - if (!h5) - { - /* If this is a netcdf-3 file, then the dimids are going to be 0 - * thru ndims-1, so just provide them. */ - if ((retval = NC4_inq(ncid, &num, NULL, NULL, NULL))) - return retval; - if (dimids) - for (d = 0; d < num; d++) - dimids[d] = d; - } - else + /* First count them. */ + for (dim = grp->dim; dim; dim = dim->l.next) + num++; + if (include_parents) + for (g = grp->parent; g; g = g->parent) + for (dim = g->dim; dim; dim = dim->l.next) + num++; + + /* If the user wants the dimension ids, get them. */ + if (dimids) { - /* First count them. */ + int n = 0; + + /* Get dimension ids from this group. */ for (dim = grp->dim; dim; dim = dim->l.next) - num++; + dimids[n++] = dim->dimid; + + /* Get dimension ids from parent groups. */ if (include_parents) - for (g = grp->parent; g; g = g->parent) - for (dim = g->dim; dim; dim = dim->l.next) - num++; + for (g = grp->parent; g; g = g->parent) + for (dim = g->dim; dim; dim = dim->l.next) + dimids[n++] = dim->dimid; - /* If the user wants the dimension ids, get them. */ - if (dimids) - { - int n = 0; - - /* Get dimension ids from this group. */ - for (dim = grp->dim; dim; dim = dim->l.next) - dimids[n++] = dim->dimid; - - /* Get dimension ids from parent groups. */ - if (include_parents) - for (g = grp->parent; g; g = g->parent) - for (dim = g->dim; dim; dim = dim->l.next) - dimids[n++] = dim->dimid; - - qsort(dimids, num, sizeof(int), int_cmp); - } + qsort(dimids, num, sizeof(int), int_cmp); } /* If the user wants the number of dims, give it. */ diff --git a/libsrc4/nc4internal.c b/libsrc4/nc4internal.c index 41d0d7ba3a..e97b43e077 100644 --- a/libsrc4/nc4internal.c +++ b/libsrc4/nc4internal.c @@ -93,6 +93,11 @@ nc4_hdf5_initialize(void) * * @return ::NC_NOERR No error. * @return ::NC_EMAXNAME Name too long. +<<<<<<< HEAD + * @return ::NC_EINVAL NULL given for name. +======= + * @return ::NC_EINVAL Invalid parameter. +>>>>>>> 986673ff49ddb82663b4ba470035e4079aa05b83 * @author Dennis Heimbigner */ int @@ -100,6 +105,16 @@ nc4_check_name(const char *name, char *norm_name) { char *temp; int retval; + + /* Check for NULL. */ + if (!name) + return NC_EINVAL; + + assert(norm_name); + + /* Check for NULL. */ + if (!name) + return NC_EINVAL; /* Check the length. */ if (strlen(name) > NC_MAX_NAME) @@ -1526,7 +1541,9 @@ nc4_rec_grp_del(NC_GRP_INFO_T **list, NC_GRP_INFO_T *grp) while (dim) { LOG((4, "%s: deleting dim %s", __func__, dim->name)); - /* Close HDF5 dataset associated with this dim. */ + /* If this is a dim without a coordinate variable, then close + * the HDF5 DIM_WITHOUT_VARIABLE dataset associated with this + * dim. */ if (dim->hdf_dimscaleid && H5Dclose(dim->hdf_dimscaleid) < 0) return NC_EHDFERR; d = dim->l.next; @@ -1620,7 +1637,12 @@ nc4_att_list_del(NC_ATT_INFO_T **list, NC_ATT_INFO_T *att) /** * @internal Break a coordinate variable to separate the dimension and - * the variable. + * the variable. + * + * This is called from nc_rename_dim() and nc_rename_var(). In some + * renames, the coord variable must stay, but it is no longer a coord + * variable. This function changes a coord var into an ordinary + * variable. * * @param grp Pointer to group info struct. * @param coord_var Pointer to variable info struct. @@ -1628,7 +1650,7 @@ nc4_att_list_del(NC_ATT_INFO_T **list, NC_ATT_INFO_T *att) * * @return ::NC_NOERR No error. * @return ::NC_ENOMEM Out of memory. - * @author Quincey Koziol + * @author Quincey Koziol, Ed Hartnett */ int nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T *dim) @@ -1636,10 +1658,11 @@ nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T int retval = NC_NOERR; /* Sanity checks */ - assert(dim->coord_var == coord_var); - assert(coord_var->dim[0] == dim); - assert(coord_var->dimids[0] == dim->dimid); - assert(0 == dim->hdf_dimscaleid); + assert(grp && coord_var && dim && dim->coord_var == coord_var && + coord_var->dim[0] == dim && coord_var->dimids[0] == dim->dimid && + !dim->hdf_dimscaleid); + LOG((3, "%s dim %s was associated with var %s, but now has different name", + __func__, dim->name, coord_var->name)); /* If we're replacing an existing dimscale dataset, go to * every var in the file and detach this dimension scale. */ @@ -1647,17 +1670,23 @@ nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T dim->dimid, coord_var->hdf_datasetid))) return retval; - /* Allow attached dimscales to be tracked on the [former] coordinate variable */ + /* Allow attached dimscales to be tracked on the [former] + * coordinate variable */ if (coord_var->ndims) { - /* Coordinate variables shouldn't have dimscales attached */ - assert(NULL == coord_var->dimscale_attached); + /* Coordinate variables shouldn't have dimscales attached. */ + assert(!coord_var->dimscale_attached); /* Allocate space for tracking them */ - if (NULL == (coord_var->dimscale_attached = calloc(coord_var->ndims, sizeof(nc_bool_t)))) + if (!(coord_var->dimscale_attached = calloc(coord_var->ndims, + sizeof(nc_bool_t)))) return NC_ENOMEM; } + /* Remove the atts that go with being a coordinate var. */ + /* if ((retval = remove_coord_atts(coord_var->hdf_datasetid))) */ + /* return retval; */ + /* Detach dimension from variable */ coord_var->dimscale = NC_FALSE; dim->coord_var = NULL; @@ -1669,9 +1698,54 @@ nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T return NC_NOERR; } +/** + * @internal Delete an existing dimscale-only dataset. + * + * A dimscale-only HDF5 dataset is created when a dim is defined + * without an accompanying coordinate variable. + * + * Sometimes, during renames, or late creation of variables, an + * existing, dimscale-only dataset must be removed. This means + * detatching all variables that use the dataset, then closing and + * unlinking it. + * + * @param grp The grp of the dimscale-only dataset to be deleted, or a + * higher group in the heirarchy (ex. root group). + * @param dim Pointer to the dim with the dimscale-only dataset to be + * deleted. + * + * @return ::NC_NOERR No error. + * @return ::NC_EHDFERR HDF5 error. + * @author Ed Hartnett + */ +int +delete_existing_dimscale_dataset(NC_GRP_INFO_T *grp, int dimid, NC_DIM_INFO_T *dim) +{ + int retval; + + assert(grp && dim); + LOG((2, "%s: deleting dimscale dataset %s dimid %d", __func__, dim->name, + dimid)); + + /* Detach dimscale from any variables using it */ + if ((retval = rec_detach_scales(grp, dimid, dim->hdf_dimscaleid)) < 0) + return retval; + + /* Close the HDF5 dataset */ + if (H5Dclose(dim->hdf_dimscaleid) < 0) + return NC_EHDFERR; + dim->hdf_dimscaleid = 0; + + /* Now delete the dataset. */ + if (H5Gunlink(grp->hdf_grpid, dim->name) < 0) + return NC_EHDFERR; + + return NC_NOERR; +} + /** * @internal Reform a coordinate variable from a dimension and a - * variable + * variable. * * @param grp Pointer to group info struct. * @param var Pointer to variable info struct. @@ -1683,8 +1757,12 @@ nc4_break_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *coord_var, NC_DIM_INFO_T int nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim) { + int need_to_reattach_scales = 0; int retval = NC_NOERR; + assert(grp && var && dim); + LOG((3, "%s: dim->name %s var->name %s", __func__, dim->name, var->name)); + /* Detach dimscales from the [new] coordinate variable */ if(var->dimscale_attached) { @@ -1694,6 +1772,7 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim) /* Loop over all dimensions for variable */ for (d = 0; d < var->ndims && !finished; d++) + { /* Is there a dimscale attached to this axis? */ if(var->dimscale_attached[d]) { @@ -1704,6 +1783,7 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim) NC_DIM_INFO_T *dim1; for (dim1 = g->dim; dim1 && !finished; dim1 = dim1->l.next) + { if (var->dimids[d] == dim1->dimid) { hid_t dim_datasetid; /* Dataset ID for dimension */ @@ -1713,24 +1793,36 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim) dim_datasetid = dim1->coord_var->hdf_datasetid; else dim_datasetid = dim1->hdf_dimscaleid; - assert(dim_datasetid > 0); - if (H5DSdetach_scale(var->hdf_datasetid, dim_datasetid, d) < 0) - BAIL(NC_EHDFERR); + + /* dim_datasetid may be 0 in some cases when + * renames of dims and vars are happening. In + * this case, the scale has already been + * detached. */ + if (dim_datasetid > 0) + { + LOG((3, "detaching scale from %s", var->name)); + if (H5DSdetach_scale(var->hdf_datasetid, dim_datasetid, d) < 0) + BAIL(NC_EHDFERR); + } var->dimscale_attached[d] = NC_FALSE; if (dims_detached++ == var->ndims) finished++; } + } } } + } /* next variable dimension */ /* Release & reset the array tracking attached dimscales */ free(var->dimscale_attached); var->dimscale_attached = NULL; + need_to_reattach_scales++; } - /* Use variable's dataset ID for the dimscale ID */ + /* Use variable's dataset ID for the dimscale ID. */ if (dim->hdf_dimscaleid && grp != NULL) { + LOG((3, "closing and unlinking dimscale dataset %s", dim->name)); if (H5Dclose(dim->hdf_dimscaleid) < 0) BAIL(NC_EHDFERR); dim->hdf_dimscaleid = 0; @@ -1746,7 +1838,7 @@ nc4_reform_coord_var(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, NC_DIM_INFO_T *dim) dim->coord_var = var; /* Check if this variable used to be a coord. var */ - if (var->was_coord_var && grp != NULL) + if (need_to_reattach_scales || (var->was_coord_var && grp != NULL)) { /* Reattach the scale everywhere it is used. */ /* (Recall that netCDF dimscales are always 1-D) */ diff --git a/libsrc4/nc4type.c b/libsrc4/nc4type.c index 186e311dd1..43dc524f03 100644 --- a/libsrc4/nc4type.c +++ b/libsrc4/nc4type.c @@ -104,7 +104,11 @@ NC4_inq_type_equal(int ncid1, nc_type typeid1, int ncid2, /* Are the two types equal? */ if (equalp) - *equalp = (int)H5Tequal(type1->native_hdf_typeid, type2->native_hdf_typeid); + { + if ((retval = H5Tequal(type1->native_hdf_typeid, type2->native_hdf_typeid)) < 0) + return NC_EHDFERR; + *equalp = 1 ? retval : 0; + } return NC_NOERR; } @@ -133,6 +137,7 @@ NC4_inq_typeid(int ncid, const char *name, nc_type *typeidp) char *norm_name; int i, retval; + /* Handle atomic types. */ for (i = 0; i < NUM_ATOMIC_TYPES; i++) if (!strcmp(name, atomic_name[i])) { @@ -144,10 +149,7 @@ NC4_inq_typeid(int ncid, const char *name, nc_type *typeidp) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(ncid, &grp, &h5))) return retval; - - /* Must be a netCDF-4 file. */ - if (!h5) - return NC_ENOTNC4; + assert(h5 && grp); /* If the first char is a /, this is a fully-qualified * name. Otherwise, this had better be a local name (i.e. no / in @@ -215,9 +217,10 @@ NC4_inq_typeids(int ncid, int *ntypes, int *typeids) /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(ncid, &grp, &h5))) return retval; + assert(h5 && grp); - /* If this is a netCDF-4 file, count types. */ - if (h5 && grp->type) + /* Count types. */ + if (grp->type) for (type = grp->type; type; type = type->l.next) { if (typeids) @@ -271,10 +274,7 @@ add_user_type(int ncid, size_t size, const char *name, nc_type base_typeid, /* Find group metadata. */ if ((retval = nc4_find_grp_h5(ncid, &grp, &h5))) return retval; - - /* Only netcdf-4 files! */ - if (!h5) - return NC_ENOTNC4; + assert(h5 && grp); /* Turn on define mode if it is not on. */ if (!(h5->cmode & NC_INDEF)) @@ -632,8 +632,9 @@ find_nc4_file(int ncid, NC **nc) NC_HDF5_FILE_INFO_T* h5; /* Find file metadata. */ - if (!((*nc) = nc4_find_nc_file(ncid,&h5))) + if (!((*nc) = nc4_find_nc_file(ncid, &h5))) return NC_EBADID; + assert(h5); if (h5->cmode & NC_CLASSIC_MODEL) return NC_ESTRICTNC3; diff --git a/libsrc4/nc4var.c b/libsrc4/nc4var.c index 7cb3f2ad12..8f8fd74277 100644 --- a/libsrc4/nc4var.c +++ b/libsrc4/nc4var.c @@ -655,19 +655,23 @@ NC4_def_var(int ncid, const char *name, nc_type xtype, { var->dimscale = NC_TRUE; dim->coord_var = var; - - /* Use variable's dataset ID for the dimscale ID */ + + /* Use variable's dataset ID for the dimscale ID. So delete + * the HDF5 DIM_WITHOUT_VARIABLE dataset that was created for + * this dim. */ if (dim->hdf_dimscaleid) { /* Detach dimscale from any variables using it */ if ((retval = rec_detach_scales(grp, dimidsp[d], dim->hdf_dimscaleid)) < 0) BAIL(retval); - + + /* Close the HDF5 DIM_WITHOUT_VARIABLE dataset. */ if (H5Dclose(dim->hdf_dimscaleid) < 0) BAIL(NC_EHDFERR); dim->hdf_dimscaleid = 0; - - /* Now delete the dataset (it will be recreated later, if necessary) */ + + /* Now delete the DIM_WITHOUT_VARIABLE dataset (it will be + * recreated later, if necessary). */ if (H5Gunlink(grp->hdf_grpid, dim->name) < 0) BAIL(NC_EDIMMETA); } @@ -683,7 +687,7 @@ NC4_def_var(int ncid, const char *name, nc_type xtype, } /* Determine default chunksizes for this variable. (Even for - * variables which may be contiguous. */ + * variables which may be contiguous.) */ LOG((4, "allocating array of %d size_t to hold chunksizes for var %s", var->ndims, var->name)); if (var->ndims) @@ -740,8 +744,12 @@ NC4_def_var(int ncid, const char *name, nc_type xtype, } /** - * @internal Get all the information about a variable. Pass NULL for whatever - * you don't care about. + * @internal Get all the information about a variable. Pass NULL for + * whatever you don't care about. This is the internal function called + * by nc_inq_var(), nc_inq_var_deflate(), nc_inq_var_fletcher32(), + * nc_inq_var_chunking(), nc_inq_var_chunking_ints(), + * nc_inq_var_fill(), nc_inq_var_endian(), nc_inq_var_filter(), and + * nc_inq_var_szip(). * * @param ncid File ID. * @param varid Variable ID. @@ -1558,15 +1566,14 @@ NC4_rename_var(int ncid, int varid, const char *name) if (!name) return NC_EINVAL; - + LOG((2, "%s: ncid 0x%x varid %d name %s", __func__, ncid, varid, name)); /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5))) return retval; - - assert(h5); + assert(h5 && grp && h5); /* Is the new name too long? */ if (strlen(name) > NC_MAX_NAME) @@ -1604,9 +1611,19 @@ NC4_rename_var(int ncid, int varid, const char *name) return NC_ENOTINDEFINE; /* Change the HDF5 file, if this var has already been created - there. */ + there. Should we check here to ensure there is not already a + dimscale dataset of name name??? */ if (var->created) { + /* Is there an existing dimscale-only dataset of this name? If + * so, it must be deleted. */ + if (var->ndims && var->dim[0]->hdf_dimscaleid) + { + if ((retval = delete_existing_dimscale_dataset(grp, var->dim[0]->dimid, var->dim[0]))) + return retval; + } + + LOG((3, "Moving dataset %s to %s", var->name, name)); if (H5Gmove(grp->hdf_grpid, var->name, name) < 0) BAIL(NC_EHDFERR); } @@ -1617,6 +1634,7 @@ NC4_rename_var(int ncid, int varid, const char *name) return NC_ENOMEM; strcpy(var->name, name); var->hash = nn_hash; + LOG((3, "var is now %s", var->name)); /* Check if this was a coordinate variable previously, but names are different now */ if (var->dimscale && strcmp(var->name, var->dim[0]->name)) diff --git a/nc_test4/CMakeLists.txt b/nc_test4/CMakeLists.txt index 2a2bf31ef9..94538ad17f 100644 --- a/nc_test4/CMakeLists.txt +++ b/nc_test4/CMakeLists.txt @@ -9,7 +9,8 @@ SET(NC4_TESTS tst_dims tst_dims2 tst_dims3 tst_files tst_files4 cdm_sea_soundings tst_vl tst_atts1 tst_atts2 tst_vars2 tst_files5 tst_files6 tst_sync tst_h_strbug tst_h_refs tst_h_scalar tst_rename tst_h5_endians tst_atts_string_rewrite tst_put_vars_two_unlim_dim - tst_hdf5_file_compat tst_fill_attr_vanish tst_rehash tst_filterparser) + tst_hdf5_file_compat tst_fill_attr_vanish tst_rehash tst_filterparser + tst_types) # Note, renamegroup needs to be compiled before run_grp_rename diff --git a/nc_test4/Makefile.am b/nc_test4/Makefile.am index 3bcb00d6ca..7c9fe6e4e2 100644 --- a/nc_test4/Makefile.am +++ b/nc_test4/Makefile.am @@ -25,7 +25,7 @@ tst_fillbug tst_xplatform tst_xplatform2 tst_endian_fill tst_atts \ t_type cdm_sea_soundings tst_camrun tst_vl tst_atts1 tst_atts2 \ tst_vars2 tst_files5 tst_files6 tst_sync tst_h_scalar tst_rename \ tst_h5_endians tst_atts_string_rewrite tst_hdf5_file_compat \ -tst_fill_attr_vanish tst_rehash tst_filterparser tst_bug324 +tst_fill_attr_vanish tst_rehash tst_filterparser tst_bug324 tst_types # Temporary I hope if !ISCYGWIN @@ -97,6 +97,7 @@ check_PROGRAMS += tst_interops2 tst_chunk_hdf4 tst_h4_lendian if BUILD_UTILITIES # This test script depends on ncdump. TESTS += tst_interops2 tst_formatx_hdf4.sh +tst_formatx_hdf4.log: tst_interops2.log endif # BUILD_UTILITIES TESTS += run_chunk_hdf4.sh tst_h4_lendian diff --git a/nc_test4/run_par_test.sh b/nc_test4/run_par_test.sh index 5c5ab5b759..d1135c44a5 100755 --- a/nc_test4/run_par_test.sh +++ b/nc_test4/run_par_test.sh @@ -36,3 +36,4 @@ echo echo "Parallel I/O test for Collective I/O, contributed by HDF Group." mpiexec -n 1 ./tst_simplerw_coll_r mpiexec -n 2 ./tst_simplerw_coll_r +mpiexec -n 4 ./tst_simplerw_coll_r diff --git a/nc_test4/tst_grps.c b/nc_test4/tst_grps.c index 2cadc038d5..ddd9d6009e 100644 --- a/nc_test4/tst_grps.c +++ b/nc_test4/tst_grps.c @@ -3,7 +3,8 @@ See COPYRIGHT file for conditions of use. Test netcdf-4 group code. - $Id: tst_grps.c,v 1.37 2010/04/07 15:21:28 ed Exp $ + + Ed Hartnett */ #include @@ -11,13 +12,17 @@ #include "netcdf.h" #define FILE_NAME "tst_grps.nc" +#define FILE_NAME_CLASSIC "tst_grps_classic.nc" +#define FILE_NAME_CLASSIC_MODEL "tst_grps_classic_model.nc" #define DIM1_NAME "kingdom" #define DIM1_LEN 3 #define DIM2_NAME "year" #define DIM2_LEN 5 #define VAR1_NAME "Number_of_Beheadings_in_Family" #define DYNASTY "Tudor" +#define HENRY_IV "Henry_IV" #define HENRY_VII "Henry_VII" +#define HENRY_VIII "Henry_VIII" #define MARGARET "Margaret" #define JAMES_V_OF_SCOTLAND "James_V_of_Scotland" #define MARY_I_OF_SCOTLAND "Mary_I_of_Scotland" @@ -31,15 +36,21 @@ main(int argc, char **argv) printf("\n*** Testing netcdf-4 group functions.\n"); printf("*** testing simple group create..."); { - int ncid; + int ncid, ncid2; char name_in[NC_MAX_NAME + 1]; int henry_vii_id; + int henry_viii_id; int grpid_in[MAX_SIBLING_GROUPS], varids_in[MAX_SIBLING_GROUPS]; - int dimids_in[MAX_SIBLING_GROUPS], nvars_in, ndims_in, ncid_in; + int nvars_in, ncid_in; int parent_ncid; char name_out[NC_MAX_NAME + 1]; int num_grps; + /* Create a netCDF classic file. Groups will not be allowed. */ + if (nc_create(FILE_NAME_CLASSIC, 0, &ncid2)) ERR; + if (nc_def_grp(ncid2, name_out, &henry_vii_id) != NC_ENOTNC4) ERR; + if (nc_close(ncid2)) ERR; + /* Create a file with one group, a group to contain data about * Henry VII. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; @@ -47,7 +58,16 @@ main(int argc, char **argv) /* This should also work as simple "is this the root group" test */ if (nc_inq_grp_parent(ncid, NULL) != NC_ENOGRP) ERR; strcpy(name_out, HENRY_VII); + + /* These will not work. */ + if (nc_def_grp(ncid + TEST_VAL_42, name_out, &henry_vii_id) != NC_EBADID) ERR; + if (nc_def_grp(ncid, NULL, &henry_vii_id) != NC_EINVAL) ERR; + if (nc_def_grp(ncid, BAD_NAME, &henry_vii_id) != NC_EBADNAME) ERR; + + /* Define the group. */ if (nc_def_grp(ncid, name_out, &henry_vii_id)) ERR; + + /* Check it out. */ if (nc_inq_grp_parent(henry_vii_id, &parent_ncid)) ERR; if (parent_ncid != ncid) ERR; if (nc_inq_ncid(ncid, HENRY_VII, &ncid_in)) ERR; @@ -69,10 +89,77 @@ main(int argc, char **argv) if (strcmp(name_in, HENRY_VII)) ERR; if (nc_inq_varids(grpid_in[0], &nvars_in, varids_in)) ERR; if (nvars_in != 0) ERR; - if (nc_inq_varids(grpid_in[0], &ndims_in, dimids_in)) ERR; - if (ndims_in != 0) ERR; + if (nc_inq_varids(grpid_in[0], NULL, varids_in)) ERR; + if (nc_inq_varids(grpid_in[0], &nvars_in, NULL)) ERR; + if (nc_inq_varids(grpid_in[0], NULL, NULL)) ERR; + if (nc_inq_ncid(ncid, HENRY_VII, &ncid_in)) ERR; if (ncid_in != grpid_in[0]) ERR; + + /* These should fail - file is read-only. */ + if (nc_def_grp(ncid, HENRY_VIII, &henry_viii_id) != NC_EPERM) ERR; + if (nc_rename_grp(grpid_in[0], HENRY_VIII) != NC_EPERM) ERR; + + /* Close the file. */ + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; + printf("*** testing simple group rename..."); + { + int ncid, ncid2; + int grpid_in; + char name_in[NC_MAX_NAME + 1]; + int henry_vii_id; + + /* Create a classic model file. No groups will be allowed. */ + if (nc_create(FILE_NAME_CLASSIC_MODEL, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid2)) ERR; + if (nc_def_grp(ncid2, HENRY_VII, &henry_vii_id) != NC_ESTRICTNC3) ERR; + if (nc_def_var(ncid2, HENRY_IV, NC_INT, 0, NULL, NULL)); + if (nc_close(ncid2)) ERR; + + /* Create a file with one group, a group to contain data about + * Henry VII. */ + if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; + if (nc_def_var(ncid, HENRY_IV, NC_INT, 0, NULL, NULL)); + + /* Turn off define mode. It will automatically be turned back on + * when nc_def_grp is called. */ + if (nc_enddef(ncid)) ERR; + if (nc_def_grp(ncid, HENRY_VII, &henry_vii_id)) ERR; + + /* Check it out. */ + if (nc_inq_grpname(henry_vii_id, name_in)) ERR; + if (strcmp(name_in, HENRY_VII)) ERR; + + /* These will not work. */ + if (nc_rename_grp(henry_vii_id, BAD_NAME) != NC_EBADNAME) ERR; + if (nc_rename_grp(henry_vii_id, HENRY_IV) != NC_ENAMEINUSE) ERR; + if (nc_rename_grp(ncid, HENRY_IV) != NC_EBADGRPID) ERR; + + /* Rename the group. */ + if (nc_rename_grp(henry_vii_id, HENRY_VIII)) ERR; + + /* Check it out. */ + if (nc_inq_grpname(henry_vii_id, name_in)) ERR; + if (strcmp(name_in, HENRY_VIII)) ERR; + + /* Close the file. */ + if (nc_close(ncid)) ERR; + + /* Re-open the file. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + + /* Check it out. */ + if (nc_inq_grps(ncid, NULL, &grpid_in)) ERR; + if (nc_inq_grpname(grpid_in, name_in)) ERR; + if (strcmp(name_in, HENRY_VIII)) ERR; + + /* Rename it. */ + if (nc_rename_grp(grpid_in, HENRY_VII)) ERR; + if (nc_inq_grpname(grpid_in, name_in)) ERR; + if (strcmp(name_in, HENRY_VII)) ERR; + + /* Close the file. */ if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; @@ -121,6 +208,9 @@ main(int argc, char **argv) if (nc_def_var(henry_vii_id, VAR_NAME2, NC_INT64, NDIMS_IN_VAR, &dimid1, &varid2)) ERR; if (nc_def_var(henry_vii_id, VAR_NAME3, NC_INT64, NDIMS_IN_VAR, &dimid2, &varid3)) ERR; + /* These won't work. */ + if (nc_inq_ncid(ncid + TEST_VAL_42, HENRY_VII, &grpid_in) != NC_EBADID) ERR; + /* Check it out. Find the group by name. */ if (nc_inq_ncid(ncid, HENRY_VII, &grpid_in)) ERR; @@ -220,15 +310,26 @@ main(int argc, char **argv) printf("*** testing simple nested group creates..."); { + char root_name[] = "/"; int ncid, grp_ncid; int henry_vii_id, margaret_id, james_v_of_scotland_id, mary_i_of_scotland_id; - int james_i_of_england_id; char name_in[NC_MAX_NAME + 1]; char full_name[NC_MAX_NAME * 10], full_name_in[NC_MAX_NAME * 10]; + char full_name_in1[NC_MAX_NAME * 10]; + char wrong_name[NC_MAX_NAME * 10]; int grpid_in[MAX_SIBLING_GROUPS]; int grp_in; + int grp_in2; int num_grps; - size_t len; + size_t len, len1; + + /* This name is wrong. */ + strcpy(wrong_name, "/"); + strcat(wrong_name, HENRY_VII); + strcpy(wrong_name, "/"); + strcat(wrong_name, MARGARET); + strcpy(wrong_name, "/"); + strcat(wrong_name, MARGARET); /* Create a file with some nested groups in it, suitable * to storing information about the Tudor dynasty of England. */ @@ -237,16 +338,37 @@ main(int argc, char **argv) if (nc_def_grp(henry_vii_id, MARGARET, &margaret_id)) ERR; if (nc_def_grp(margaret_id, JAMES_V_OF_SCOTLAND, &james_v_of_scotland_id)) ERR; if (nc_def_grp(james_v_of_scotland_id, MARY_I_OF_SCOTLAND, &mary_i_of_scotland_id)) ERR; - if (nc_def_grp(mary_i_of_scotland_id, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, &james_i_of_england_id)) ERR; + /* nc_def_grp will accept NULL as ID pointer. Group will be + * created, but ID not returned. */ + if (nc_def_grp(mary_i_of_scotland_id, JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND, NULL)) ERR; strcpy(full_name, "/"); if (nc_inq_grpname_full(ncid, &len, full_name_in)) ERR; if (len != 1 || strcmp(full_name_in, full_name)) ERR; if (nc_inq_grpname_len(ncid, &len)) ERR; if (len != 1) ERR; + + /* These won't work. */ + if (nc_inq_grp_full_ncid(ncid + TEST_VAL_42, full_name, &grp_in) != NC_EBADID) ERR; + if (nc_inq_grp_full_ncid(ncid, NULL, &grp_in) != NC_EINVAL) ERR; + + /* Get the ncid from the full name. */ if (nc_inq_grp_full_ncid(ncid, full_name, &grp_in)) ERR; if (grp_in != ncid) ERR; + /* Works (pretty pointlessly) with NULL for ID pointer. */ + if (nc_inq_grp_full_ncid(ncid, full_name, NULL)) ERR; + + /* Get the root group ID from '/'. */ + if (nc_inq_grp_full_ncid(ncid, root_name, &grp_in2)) ERR; + if (grp_in2 != ncid) ERR; + + /* But the root group does not exist within another group. */ + if (nc_inq_grp_full_ncid(mary_i_of_scotland_id, root_name, &grp_in2) != NC_ENOGRP) ERR; + + /* This name is wrong. */ + if (nc_inq_grp_full_ncid(ncid, wrong_name, &grp_in2) != NC_ENOGRP) ERR; + if (nc_inq_grp_ncid(ncid, HENRY_VII, NULL)) ERR; if (nc_inq_grp_ncid(ncid, HENRY_VII, &grp_ncid)) ERR; if (nc_inq_grps(ncid, &num_grps, NULL)) ERR; @@ -254,6 +376,7 @@ main(int argc, char **argv) if (nc_inq_grps(ncid, NULL, grpid_in)) ERR; if (nc_inq_grpname(grpid_in[0], name_in)) ERR; if (strcmp(name_in, HENRY_VII)) ERR; + if (nc_inq_grpname(grpid_in[0], NULL)) ERR; if (grpid_in[0] != grp_ncid) ERR; strcat(full_name, HENRY_VII); if (nc_inq_grpname_full(grpid_in[0], &len, full_name_in)) ERR; @@ -261,6 +384,9 @@ main(int argc, char **argv) if (nc_inq_grp_full_ncid(ncid, full_name, &grp_in)) ERR; if (grp_in != grpid_in[0]) ERR; + /* Also works with NULL last param. */ + if (nc_inq_grp_full_ncid(ncid, full_name, NULL)) ERR; + if (nc_inq_grp_ncid(grpid_in[0], MARGARET, &grp_ncid)) ERR; if (nc_inq_grps(grpid_in[0], &num_grps, grpid_in)) ERR; if (num_grps != 1) ERR; @@ -312,6 +438,11 @@ main(int argc, char **argv) if (len != strlen(full_name) || strcmp(full_name_in, full_name)) ERR; if (nc_inq_grp_full_ncid(ncid, full_name, &grp_in)) ERR; if (grp_in != grpid_in[0]) ERR; + if (nc_inq_grpname_full(grpid_in[0], NULL, NULL)) ERR; + if (nc_inq_grpname_full(grpid_in[0], &len1, NULL)) ERR; + if (len1 != strlen(full_name)) ERR; + if (nc_inq_grpname_full(grpid_in[0], &len, full_name_in1)) ERR; + if (strcmp(full_name_in1, full_name)) ERR; if (nc_close(ncid)) ERR; diff --git a/nc_test4/tst_rename.c b/nc_test4/tst_rename.c index 6c12d645d8..87ba17ea35 100644 --- a/nc_test4/tst_rename.c +++ b/nc_test4/tst_rename.c @@ -1,167 +1,398 @@ /* - * Demonstrate netcdf-4 rename bug. + * Test renames of vars and dims. It's a surprisingly tricky business. + * + * Quincey Koziol, Ed Hartnett */ -#include -#include -#include -#include - -/* On error, prints line number and file of test program. */ -#define ERR do { \ -fflush(stdout); \ -fprintf(stderr, "Unexpected result, %s, line: %d\n", \ - __FILE__, __LINE__); \ -return 2; \ -} while (0) - -#define FILE_NAME3 "tst_rnfix3.nc" -#define FILE_NAME4 "tst_rnfix4.nc" -#define ODIM_NAME "lat" /* name for coord dim */ -#define NDIM_NAME "tal" /* new name for coord dim */ -#define OVAR_NAME "lat" /* name for coord var */ -#define NVAR_NAME "tal" /* new name for coord var */ -#define OVAR2_NAME "rh" /* name for non-coord var that uses coord dim */ -#define VAR_RANK 1 /* all vars in this test are of same rank */ -#define DIM_LEN 2 /* all dims in this test are of same len */ +#include "nc_tests.h" +#include "err_macros.h" + +#define FILE_NAME3 "tst_rename_fix3.nc" +#define FILE_NAME4 "tst_rename_fix4.nc" +#define ODIM_NAME "lat" /* name for coord dim */ +#define LAT "lat" +#define TAL "tal" +#define TAL1 "tal1" +#define TAL2 "tal2" +#define RH "rh" +#define NDIM_NAME "tal" /* new name for coord dim */ +#define OVAR_NAME "lat" /* name for coord var */ +#define NVAR_NAME "tal" /* new name for coord var */ +#define OVAR2_NAME "rh" /* name for non-coord var that uses coord dim */ +#define VAR_RANK 1 /* all vars in this test are of same rank */ +#define DIM_LEN 2 /* all dims in this test are of same len */ + +/* Test data. */ +int lats[DIM_LEN] = {-90, 90}; +float rh[DIM_LEN] = {0.25, 0.75}; /* For renaming tests. Create small test file of specified format * with a coordinate dimension, corresponding coordinate variable, and - * a non-coordinate variable that uses the coordinate dimension. - */ + * a non-coordinate variable that uses the coordinate dimension. */ int -create_test_file( - char *path, /* filename */ - int format /* NC_FORMAT_CLASSIC, NC_FORMAT_64BIT, - NC_FORMAT_NETCDF4, or NC_FORMAT_NETCDF4_CLASSIC */ - ) +create_test_file(char *path, int format) { - int ncid, dimid, varid, var2id; - int dims[VAR_RANK]; - int lats[DIM_LEN] = {-90, 90}; - float rh[DIM_LEN] = {0.25, 0.75}; - switch (format) { - case (NC_FORMAT_CLASSIC): - if (nc_create(path, 0, &ncid)) ERR; - break; - case (NC_FORMAT_64BIT_OFFSET): - if (nc_create(path, NC_64BIT_OFFSET, &ncid)) ERR; - break; - case (NC_FORMAT_NETCDF4): - if (nc_create(path, NC_NETCDF4, &ncid)) ERR; - break; - case(NC_FORMAT_NETCDF4_CLASSIC): - if (nc_create(path, NC_NETCDF4 | NC_CLASSIC_MODEL, &ncid)) ERR; - break; - default: - ERR; - return NC_ENOTNC; - } - if (nc_def_dim(ncid, ODIM_NAME, DIM_LEN, &dimid)) ERR; - dims[0] = dimid; - if (nc_def_var(ncid, OVAR_NAME, NC_INT, VAR_RANK, dims, &varid)) ERR; - if (nc_def_var(ncid, OVAR2_NAME, NC_FLOAT, VAR_RANK, dims, &var2id)) ERR; - if (nc_enddef(ncid)) ERR; /* not necessary for netCDF-4 files */ - if (nc_put_var_int(ncid, varid, lats)) ERR; - if (nc_put_var_float(ncid, var2id, rh)) ERR; - if (nc_close(ncid)) ERR; - return 0; + int ncid, varid, var2id; + int dims[VAR_RANK]; + + if (nc_set_default_format(format, NULL)) ERR; + if (nc_create(path, 0, &ncid)) ERR; + if (nc_def_dim(ncid, LAT, DIM_LEN, &dims[0])) ERR; + if (nc_def_var(ncid, LAT, NC_INT, VAR_RANK, dims, &varid)) ERR; + if (nc_def_var(ncid, RH, NC_FLOAT, VAR_RANK, dims, &var2id)) ERR; + if (nc_enddef(ncid)) ERR; /* not necessary for netCDF-4 files */ + if (nc_put_var_int(ncid, varid, lats)) ERR; + if (nc_put_var_float(ncid, var2id, rh)) ERR; + if (nc_close(ncid)) ERR; + return 0; } - + +/* Check the file that was produced by create_test_file(). Only the + * names have been changed... */ +int +check_file(int ncid, char *var0_name, char *var1_name, char *dim_name) +{ + int varid; + int var2id; + int dimid; + int lats_in[DIM_LEN]; + float rh_in[DIM_LEN]; + int ii; + + /* printf("checking for vars %s and %s, dim %s\n", var0_name, var1_name, */ + /* dim_name); */ + + /* Check vars. Ids will change because of rename. */ + if (nc_inq_varid(ncid, var0_name, &varid)) ERR; + if (nc_inq_varid(ncid, var1_name, &var2id)) ERR; + + /* Check dim. */ + if (nc_inq_dimid(ncid, dim_name, &dimid)) ERR; + if (dimid != 0) ERR; + + /* Check the lats. */ + if (nc_get_var_int(ncid, varid, lats_in)) ERR; + for (ii = 0; ii < DIM_LEN; ii++) + if (lats_in[ii] != lats[ii]) + ERR; + + /* Check the RH. */ + if (nc_get_var_float(ncid, var2id, rh_in)) ERR; + for (ii = 0; ii < DIM_LEN; ii++) + if (rh_in[ii] != rh[ii]) + ERR; + + return 0; +} + +/* Check the file created in Charlie Zender's test. See github + * #597. */ +int +check_charlies_file(char *file, char *dim_name, char *var_name) +{ + int ncid; + int varid, dimid; + + if (nc_open(file, 0, &ncid)) ERR; + if (nc_inq_varid(ncid, var_name, &varid)) ERR; + if (nc_inq_dimid(ncid, dim_name, &dimid)) ERR; + if (varid || dimid) ERR; + if (nc_close(ncid)) ERR; + return NC_NOERR; +} + int main(int argc, char **argv) { #define NUM_FORMATS 2 - int formats[NUM_FORMATS] = {NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC}; - char *fmt_names[] = {"netCDF-4", "netCDF-4 classic model"}; - char *file_names[] = {FILE_NAME3, FILE_NAME4}; - int format; + int formats[NUM_FORMATS] = {NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC}; + char *fmt_names[] = {"netCDF-4", "netCDF-4 classic model"}; + char *file_names[] = {FILE_NAME3, FILE_NAME4}; + int format; - fprintf(stderr,"*** Testing netcdf rename bugs and fixes.\n"); + fprintf(stderr,"*** Testing netcdf rename bugs and fixes.\n"); + nc_set_log_level(5); - for(format = 0; format < NUM_FORMATS; format++) - { + for (format = 0; format < NUM_FORMATS; format++) + /* for (format = 0; format < 1; format++) */ + { int ncid, dimid, varid, var2id; int lats[DIM_LEN] = {-90, 90}; int lats_in[DIM_LEN]; float rh[DIM_LEN] = {0.25, 0.75}; float rh_in[DIM_LEN]; int ii; - - fprintf(stderr,"*** Test renaming coordinate variable and its dimension for %s...\n", - fmt_names[format]); - if (create_test_file(file_names[format], formats[format])) ERR; - if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; - if (nc_inq_dimid(ncid, ODIM_NAME, &dimid)) ERR; - if (nc_inq_varid(ncid, OVAR_NAME, &varid)) ERR; - if (nc_inq_varid(ncid, OVAR2_NAME, &var2id)) ERR; - if (nc_redef(ncid)) ERR; /* omitting this and nc_enddef call eliminates bug */ - if (nc_rename_dim(ncid, dimid, NDIM_NAME)) ERR; - if (nc_rename_var(ncid, varid, NVAR_NAME)) ERR; - if (nc_enddef(ncid)) ERR; - if (nc_get_var_int(ncid, varid, lats_in)) ERR; - for (ii = 0; ii < DIM_LEN; ii++) { - if (lats_in[ii] != lats[ii]) - fprintf(stderr, "\tlats_in[%d] is %d, should be %d\n", ii, lats_in[ii], lats[ii]); + + fprintf(stderr,"*** Test Charlie's test for renaming..."); + { +#define CHARLIE_TEST_FILE "tst_charlie_rename_coord_dim.nc" +#define LON "lon" +#define LONGITUDE "longitude" +#define DIM1_LEN 4 +#define NDIM1 1 + int ncid, dimid, varid; + float data[DIM1_LEN] = {0, 90.0, 180.0, 270.0}; + + /* Create a nice, simple file. This file will contain one + * dataset, "lon", which is a dimscale. */ + if (nc_create(CHARLIE_TEST_FILE, NC_NETCDF4, &ncid)) ERR; + if (nc_def_dim(ncid, LON, DIM1_LEN, &dimid)) ERR; + if (nc_def_var(ncid, LON, NC_FLOAT, NDIM1, &dimid, &varid)) ERR; + if (nc_enddef(ncid)) ERR; + if (nc_put_var_float(ncid, varid, data)) ERR; + if (nc_close(ncid)) ERR; + + /* Check the file. */ + if (check_charlies_file(CHARLIE_TEST_FILE, LON, LON)) ERR; + + /* Open the file and rename the dimension. This will cause + * lon to stop being a coord var and dimscale, and create a + * new dimscale without var dataset "longitude". Dataset + * "lon" will point to "longitude" as its dimscale. */ + if (nc_open(CHARLIE_TEST_FILE, NC_WRITE, &ncid)) ERR; + if (nc_redef(ncid)) ERR; + if (nc_rename_dim(ncid, 0, LONGITUDE)) ERR; + if (nc_enddef(ncid)) ERR; + if (nc_close(ncid)) ERR; + + /* Reopen the file to check. */ + if (check_charlies_file(CHARLIE_TEST_FILE, LONGITUDE, LON)) ERR; + + /* Open the file and rename the variable. This will remove + * the dimscale-only dataset "longitude" and rename the + * extisting dataset "lon" to "longitude". Variable + * "longitude" will become a coordinate var. */ + /* if (nc_open(CHARLIE_TEST_FILE, NC_WRITE, &ncid)) ERR; */ + /* if (nc_redef(ncid)) ERR; */ + /* if (nc_rename_var(ncid, 0, LONGITUDE)) ERR; */ + /* if (nc_enddef(ncid)) ERR; */ + /* if (nc_close(ncid)) ERR; */ + + /* Reopen the file to check. */ + /* if (check_charlies_file(CHARLIE_TEST_FILE, LONGITUDE, LONGITUDE)) ERR; */ } - if (nc_get_var_float(ncid, var2id, rh_in)) ERR; - for (ii = 0; ii < DIM_LEN; ii++) { - if (rh_in[ii] != rh[ii]) - fprintf(stderr, "\trh_in[%d] is %g, should be %g\n", ii, rh_in[ii], rh[ii]); + SUMMARIZE_ERR; + + printf("*** testing renaming before enddef for %s...", fmt_names[format]); + { + int ncid, varid, var2id; + int dimid; + + if (nc_set_default_format(formats[format], NULL)) ERR; + if (nc_create(file_names[format], 0, &ncid)) ERR; + if (nc_def_dim(ncid, LAT, DIM_LEN, &dimid)) ERR; + if (nc_def_var(ncid, LAT, NC_INT, VAR_RANK, &dimid, &varid)) ERR; + if (nc_def_var(ncid, RH, NC_FLOAT, VAR_RANK, &dimid, &var2id)) ERR; + + /* Now rename the dim. */ + if (nc_rename_dim(ncid, dimid, TAL)) ERR; + if (nc_rename_var(ncid, varid, TAL)) ERR; + + if (nc_enddef(ncid)) ERR; /* not necessary for netCDF-4 files */ + if (nc_put_var_int(ncid, varid, lats)) ERR; + if (nc_put_var_float(ncid, var2id, rh)) ERR; + if (nc_close(ncid)) ERR; + + /* Reopen and check. */ + if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; + if (check_file(ncid, TAL, RH, TAL)) ERR; + if (nc_close(ncid)) ERR; } - if (nc_close(ncid)) ERR; - - fprintf(stderr,"*** Test renaming just coordinate variable for %s...\n", - fmt_names[format]); - if (create_test_file(file_names[format], formats[format])) ERR; - if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; - if (nc_inq_dimid(ncid, ODIM_NAME, &dimid)) ERR; - if (nc_inq_varid(ncid, OVAR_NAME, &varid)) ERR; - if (nc_inq_varid(ncid, OVAR2_NAME, &var2id)) ERR; - if (nc_redef(ncid)) ERR; /* omitting this and nc_enddef call eliminates bug */ - /* if (nc_rename_dim(ncid, dimid, NDIM_NAME)) ERR; */ - if (nc_rename_var(ncid, varid, NVAR_NAME)) ERR; - if (nc_enddef(ncid)) ERR; - if (nc_get_var_int(ncid, varid, lats_in)) ERR; - for (ii = 0; ii < DIM_LEN; ii++) { - if (lats_in[ii] != lats[ii]) - fprintf(stderr, "\tlats_in[%d] is %d, should be %d\n", ii, lats_in[ii], lats[ii]); + SUMMARIZE_ERR; + + printf("*** testing renaming after enddef for %s...", fmt_names[format]); + { + int ncid, varid, var2id; + int dimid; + + if (nc_set_default_format(formats[format], NULL)) ERR; + if (nc_create(file_names[format], 0, &ncid)) ERR; + if (nc_def_dim(ncid, LAT, DIM_LEN, &dimid)) ERR; + if (nc_def_var(ncid, TAL1, NC_INT, VAR_RANK, &dimid, &varid)) ERR; + if (nc_def_var(ncid, RH, NC_FLOAT, VAR_RANK, &dimid, &var2id)) ERR; + if (nc_enddef(ncid)) ERR; + if (nc_redef(ncid)) ERR; + + if (nc_rename_var(ncid, varid, TAL2)) ERR; + if (nc_rename_dim(ncid, dimid, TAL)) ERR; + if (nc_enddef(ncid)) ERR; + + if (nc_put_var_int(ncid, varid, lats)) ERR; + if (nc_put_var_float(ncid, var2id, rh)) ERR; + if (nc_close(ncid)) ERR; + + /* Reopen and check. */ + if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; + if (check_file(ncid, TAL2, RH, TAL)) ERR; + if (nc_close(ncid)) ERR; } - if (nc_get_var_float(ncid, var2id, rh_in)) ERR; - for (ii = 0; ii < DIM_LEN; ii++) { - if (rh_in[ii] != rh[ii]) - fprintf(stderr, "\trh_in[%d] is %g, should be %g\n", ii, rh_in[ii], rh[ii]); + SUMMARIZE_ERR; + printf("*** testing more renaming after enddef for %s...", fmt_names[format]); + { + int ncid, varid, var2id; + int dimid; + + /* This will create a HDF5 file with two datasets, RH, and + * LAT. LAT is a dimscale. RH points to dimscale LAT. Life is + * so simple. */ + if (nc_set_default_format(formats[format], NULL)) ERR; + if (nc_create(file_names[format], 0, &ncid)) ERR; + if (nc_def_dim(ncid, LAT, DIM_LEN, &dimid)) ERR; + if (nc_def_var(ncid, LAT, NC_INT, VAR_RANK, &dimid, &varid)) ERR; + if (nc_def_var(ncid, RH, NC_FLOAT, VAR_RANK, &dimid, &var2id)) ERR; + if (nc_enddef(ncid)) ERR; + if (nc_redef(ncid)) ERR; + + /* This will cause dataset LAT to be renamed TAL. It will no + * longer be a dimscale. Dataset LAT will be created as a + * dimscale without a variable. Datasets RH and TAL will + * re-point to (new) dimscale LAT. */ + if (nc_rename_var(ncid, varid, TAL)) ERR; + if (nc_enddef(ncid)) ERR; + + if (nc_redef(ncid)) ERR; + + /* This will cause dimscale-only dataset LAT to be + * deleted. Existing dataset TAL will become the dimscale + * dataset. Dataset RH will re-point to dimscale TAL. */ + if (nc_rename_dim(ncid, dimid, TAL)) ERR; + if (nc_enddef(ncid)) ERR; + + /* Varids have changed, so get them again. */ + if (nc_inq_varid(ncid, TAL, &varid)) ERR; + if (nc_inq_varid(ncid, RH, &var2id)) ERR; + + /* Write some data. */ + if (nc_put_var_int(ncid, varid, lats)) ERR; + if (nc_put_var_float(ncid, var2id, rh)) ERR; + if (nc_close(ncid)) ERR; + + /* Reopen and check. */ + if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; + if (check_file(ncid, TAL, RH, TAL)) ERR; + if (nc_close(ncid)) ERR; } - if (nc_close(ncid)) ERR; + SUMMARIZE_ERR; + + printf("*** testing renaming after enddef for %s...", fmt_names[format]); + { + int ncid, varid, var2id; + int dimid; + + if (nc_set_default_format(formats[format], NULL)) ERR; + if (nc_create(file_names[format], 0, &ncid)) ERR; + if (nc_def_dim(ncid, LAT, DIM_LEN, &dimid)) ERR; + if (nc_def_var(ncid, LAT, NC_INT, VAR_RANK, &dimid, &varid)) ERR; + if (nc_def_var(ncid, RH, NC_FLOAT, VAR_RANK, &dimid, &var2id)) ERR; + if (nc_enddef(ncid)) ERR; /* not necessary for netCDF-4 files */ + if (nc_redef(ncid)) ERR; /* not necessary for netCDF-4 files */ + /* Now rename the dim. */ + if (nc_rename_dim(ncid, dimid, TAL)) ERR; + if (nc_rename_var(ncid, varid, TAL)) ERR; + if (nc_enddef(ncid)) ERR; /* not necessary for netCDF-4 files */ + + if (nc_put_var_int(ncid, varid, lats)) ERR; + if (nc_put_var_float(ncid, var2id, rh)) ERR; + if (nc_close(ncid)) ERR; + + /* Reopen and check. */ + if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; + /* if (check_file(ncid, LAT, RH, TAL)) ERR; */ + /* if (check_file(ncid, TAL, RH, TAL)) ERR; */ + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; - fprintf(stderr,"*** Test renaming just coordinate dimension for %s...\n", - fmt_names[format]); - if (create_test_file(file_names[format], formats[format])) ERR; - if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; - if (nc_inq_dimid(ncid, ODIM_NAME, &dimid)) ERR; - if (nc_inq_varid(ncid, OVAR_NAME, &varid)) ERR; - if (nc_inq_varid(ncid, OVAR2_NAME, &var2id)) ERR; - if (nc_redef(ncid)) ERR; /* omitting this and nc_enddef call eliminates bug */ - if (nc_rename_dim(ncid, dimid, NDIM_NAME)) ERR; - /* if (nc_rename_var(ncid, varid, NVAR_NAME)) ERR; */ - if (nc_enddef(ncid)) ERR; - if (nc_get_var_int(ncid, varid, lats_in)) ERR; - for (ii = 0; ii < DIM_LEN; ii++) { - if (lats_in[ii] != lats[ii]) - fprintf(stderr, "\tlats_in[%d] is %d, should be %d\n", ii, lats_in[ii], lats[ii]); + printf("*** testing renaming after enddef for %s...", fmt_names[format]); + { + /* Create a file with datasets LAT, RH. LAT is a dimscale. RH + * points to LAT. */ + if (create_test_file(file_names[format], formats[format])) ERR; + if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; + if (nc_inq_dimid(ncid, LAT, &dimid)) ERR; + if (nc_inq_varid(ncid, LAT, &varid)) ERR; + if (nc_inq_varid(ncid, RH, &var2id)) ERR; + if (check_file(ncid, LAT, RH, LAT)) ERR; + if (nc_redef(ncid)) ERR; + + /* Rename the dim. This creates new dataset TAL. LAT is no + * longer a dimscale. RH is repointed to TAL. LAT is pointed + * to TAL. */ + if (nc_rename_dim(ncid, dimid, TAL)) ERR; + if (nc_enddef(ncid)) ERR; + if (nc_redef(ncid)) ERR; + + /* Rename the var. This will remove dimscale-only dataset + * TAL. LAT will become a dimscale. RH will point to LAT. */ + if (nc_rename_var(ncid, varid, TAL)) ERR; + if (nc_enddef(ncid)) ERR; + /* if (check_file(ncid, LAT, RH, TAL)) ERR; */ + if (nc_close(ncid)) ERR; + + if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; + /* if (check_file(ncid, LAT, RH, TAL)) ERR; */ + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; + + fprintf(stderr,"*** Test renaming just coordinate variable for %s...", + fmt_names[format]); + { + if (create_test_file(file_names[format], formats[format])) ERR; + if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; + if (nc_inq_dimid(ncid, ODIM_NAME, &dimid)) ERR; + if (nc_inq_varid(ncid, OVAR_NAME, &varid)) ERR; + if (nc_inq_varid(ncid, OVAR2_NAME, &var2id)) ERR; + if (nc_redef(ncid)) ERR; /* omitting this and nc_enddef call eliminates bug */ + /* if (nc_rename_dim(ncid, dimid, NDIM_NAME)) ERR; */ + if (nc_rename_var(ncid, varid, NVAR_NAME)) ERR; + if (nc_enddef(ncid)) ERR; + if (nc_get_var_int(ncid, varid, lats_in)) ERR; + for (ii = 0; ii < DIM_LEN; ii++) { + if (lats_in[ii] != lats[ii]) + fprintf(stderr, "\tlats_in[%d] is %d, should be %d\n", ii, lats_in[ii], lats[ii]); + } + if (nc_get_var_float(ncid, var2id, rh_in)) ERR; + for (ii = 0; ii < DIM_LEN; ii++) { + if (rh_in[ii] != rh[ii]) + fprintf(stderr, "\trh_in[%d] is %g, should be %g\n", ii, rh_in[ii], rh[ii]); + } + if (nc_close(ncid)) ERR; } - if (nc_get_var_float(ncid, var2id, rh_in)) ERR; - for (ii = 0; ii < DIM_LEN; ii++) { - if (rh_in[ii] != rh[ii]) - fprintf(stderr, "\trh_in[%d] is %g, should be %g\n", ii, rh_in[ii], rh[ii]); + SUMMARIZE_ERR; + + fprintf(stderr,"*** Test renaming just coordinate dimension for %s...", + fmt_names[format]); + { + if (create_test_file(file_names[format], formats[format])) ERR; + if (nc_open(file_names[format], NC_WRITE, &ncid)) ERR; + if (nc_inq_dimid(ncid, ODIM_NAME, &dimid)) ERR; + if (nc_inq_varid(ncid, OVAR_NAME, &varid)) ERR; + if (nc_inq_varid(ncid, OVAR2_NAME, &var2id)) ERR; + if (nc_redef(ncid)) ERR; /* omitting this and nc_enddef call eliminates bug */ + if (nc_rename_dim(ncid, dimid, NDIM_NAME)) ERR; + /* if (nc_rename_var(ncid, varid, NVAR_NAME)) ERR; */ + if (nc_enddef(ncid)) ERR; + if (nc_get_var_int(ncid, varid, lats_in)) ERR; + for (ii = 0; ii < DIM_LEN; ii++) { + if (lats_in[ii] != lats[ii]) + fprintf(stderr, "\tlats_in[%d] is %d, should be %d\n", ii, lats_in[ii], lats[ii]); + } + if (nc_get_var_float(ncid, var2id, rh_in)) ERR; + for (ii = 0; ii < DIM_LEN; ii++) { + if (rh_in[ii] != rh[ii]) + fprintf(stderr, "\trh_in[%d] is %g, should be %g\n", ii, rh_in[ii], rh[ii]); + } + if (nc_close(ncid)) ERR; } - if (nc_close(ncid)) ERR; + SUMMARIZE_ERR; - if (formats[format] == NC_FORMAT_NETCDF4) { - printf("*** Test renaming attribute in sub-group for %s...\n", + if (formats[format] == NC_FORMAT_NETCDF4) + { + printf("*** Test renaming attribute in sub-group for %s...", fmt_names[format]); - { + { #define DIMNAME "lon" #define VARNAME "lon" #define G1_VARNAME "lon" @@ -199,16 +430,16 @@ main(int argc, char **argv) if (nc_enddef (ncid)) ERR; /* write variable data */ { - float lon_data[4] = {0, 90, 180, 270}; - size_t start[] = {0}; - size_t count[] = {4}; - if (nc_put_vara(ncid, lon_var, start, count, lon_data)) ERR; + float lon_data[4] = {0, 90, 180, 270}; + size_t start[] = {0}; + size_t count[] = {4}; + if (nc_put_vara(ncid, lon_var, start, count, lon_data)) ERR; } { - float g1_lon_data[4] = {0, 90, 180, 270}; - size_t start[] = {0}; - size_t count[] = {4}; - if (nc_put_vara(g1_grp, g1_lon_var, start, count, g1_lon_data)) ERR; + float g1_lon_data[4] = {0, 90, 180, 270}; + size_t start[] = {0}; + size_t count[] = {4}; + if (nc_put_vara(g1_grp, g1_lon_var, start, count, g1_lon_data)) ERR; } if (nc_close(ncid)) ERR; @@ -223,17 +454,17 @@ main(int argc, char **argv) has expected value */ { - if (nc_open(file_names[format], NC_NOWRITE, &ncid)) ERR; - if (nc_inq_grp_ncid(ncid, GRP_NAME, &g1_grp)) ERR; - if (nc_inq_varid(g1_grp, VARNAME, &g1_lon_var)) ERR; - if (nc_get_att_text(g1_grp, g1_lon_var, NEW_NAME, data_in)) ERR; - if (strncmp(CONTENTS, data_in, strlen(CONTENTS))) ERR; - if (nc_close(ncid)) ERR; + if (nc_open(file_names[format], NC_NOWRITE, &ncid)) ERR; + if (nc_inq_grp_ncid(ncid, GRP_NAME, &g1_grp)) ERR; + if (nc_inq_varid(g1_grp, VARNAME, &g1_lon_var)) ERR; + if (nc_get_att_text(g1_grp, g1_lon_var, NEW_NAME, data_in)) ERR; + if (strncmp(CONTENTS, data_in, strlen(CONTENTS))) ERR; + if (nc_close(ncid)) ERR; } free(data_in); - } + } + SUMMARIZE_ERR; } - } - - return(0); + } /* next format */ + FINAL_RESULTS; } diff --git a/nc_test4/tst_simplerw_coll_r.c b/nc_test4/tst_simplerw_coll_r.c index 098db49c37..51d3dbb7a7 100644 --- a/nc_test4/tst_simplerw_coll_r.c +++ b/nc_test4/tst_simplerw_coll_r.c @@ -1,28 +1,19 @@ -/* Copyright 2007-2011, UCAR/Unidata. See COPYRIGHT file for copying - and redistribution conditions. - - This is part of the netCDF package. - - This is a benchmarking program for netCDF-4 parallel I/O. -*/ - -/* Defining USE_MPE causes the MPE trace library to be used (and you - * must also relink with -llmpe -lmpe). This causes clog2 output to be - * written, which can be converted to slog2 (by the program - * clog2TOslog2) and then used in the analysis program jumpshot. */ -/*#define USE_MPE 1*/ - -#include -#include -#include -#include -#include - -#ifdef USE_MPE -#include -#endif /* USE_MPE */ - -#define FILE_NAME "tst_parallel4_simplerw_coll.nc" +/* Copyright 2007-2011, UCAR/Unidata. See COPYRIGHT file for copying + * and redistribution conditions. + * + * This is part of the netCDF package. + * + * This test is for parallel IO and the collective access of metadata + * with HDF5. + * + * Ward Fisher, Ed Hartnett + */ + +#include "config.h" +#include "nc_tests.h" +#include "err_macros.h" + +#define TEST_NAME "tst_parallel4_simplerw_coll" #define NDIMS 3 #define DIMSIZE 16 #define NUM_SLABS 16 @@ -30,220 +21,396 @@ #define DIM2_NAME "x" #define DIM3_NAME "y" #define VAR_NAME "Bond_James_Bond" -#define ERR do { \ -fflush(stdout); /* Make sure our stdout is synced with stderr. */ \ -fprintf(stderr, "Sorry! Unexpected result, %s, line: %d\n", \ - __FILE__, __LINE__); \ -return 2; \ -} while (0) +#define NUM_FILL_TEST_RUNS 3 int main(int argc, char **argv) { - /* MPI stuff. */ - int mpi_namelen; - char mpi_name[MPI_MAX_PROCESSOR_NAME]; - int mpi_size, mpi_rank; - MPI_Comm comm = MPI_COMM_WORLD; - MPI_Info info = MPI_INFO_NULL; - double start_time = 0, total_time; - - /* Netcdf-4 stuff. */ - int ncid, varid, dimids[NDIMS]; - size_t start[NDIMS] = {0, 0, 0}; - size_t count[NDIMS] = {1, DIMSIZE, DIMSIZE}; - int data[DIMSIZE * DIMSIZE], data_in[DIMSIZE * DIMSIZE]; - int j, i, ret; - - char file_name[NC_MAX_NAME + 1]; - int ndims_in, nvars_in, natts_in, unlimdimid_in; - -#ifdef USE_MPE - int s_init, e_init, s_define, e_define, s_write, e_write, s_close, e_close; -#endif /* USE_MPE */ - - /* Initialize MPI. */ - MPI_Init(&argc,&argv); - MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); - MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); - MPI_Get_processor_name(mpi_name, &mpi_namelen); - /*printf("mpi_name: %s size: %d rank: %d\n", mpi_name, mpi_size, mpi_rank);*/ -//#if 0 - /* Must be able to evenly divide my slabs between processors. */ - if (NUM_SLABS % mpi_size != 0) - { - if (!mpi_rank) printf("NUM_SLABS (%d) is not evenly divisible by mpi_size(%d)\n", - NUM_SLABS, mpi_size); - ERR; - } - -#ifdef USE_MPE - MPE_Init_log(); - s_init = MPE_Log_get_event_number(); - e_init = MPE_Log_get_event_number(); - s_define = MPE_Log_get_event_number(); - e_define = MPE_Log_get_event_number(); - s_write = MPE_Log_get_event_number(); - e_write = MPE_Log_get_event_number(); - s_close = MPE_Log_get_event_number(); - e_close = MPE_Log_get_event_number(); - s_open = MPE_Log_get_event_number(); - e_open = MPE_Log_get_event_number(); - MPE_Describe_state(s_init, e_init, "Init", "red"); - MPE_Describe_state(s_define, e_define, "Define", "yellow"); - MPE_Describe_state(s_write, e_write, "Write", "green"); - MPE_Describe_state(s_close, e_close, "Close", "purple"); - MPE_Describe_state(s_open, e_open, "Open", "blue"); - MPE_Start_log(); - MPE_Log_event(s_init, 0, "start init"); -#endif /* USE_MPE */ - -/* if (!mpi_rank) */ -/* { */ -/* printf("\n*** Testing parallel I/O some more.\n"); */ -/* printf("*** writing a %d x %d x %d file from %d processors...\n", */ -/* NUM_SLABS, DIMSIZE, DIMSIZE, mpi_size); */ -/* } */ - - /* We will write the same slab over and over. */ - for (i = 0; i < DIMSIZE * DIMSIZE; i++) - data[i] = mpi_rank; - -#ifdef USE_MPE - MPE_Log_event(e_init, 0, "end init"); - MPE_Log_event(s_define, 0, "start define file"); -#endif /* USE_MPE */ - - /* Create a parallel netcdf-4 file. */ - if (nc_create_par(FILE_NAME, NC_NETCDF4|NC_MPIIO, comm, info, &ncid)) ERR; - - /* A global attribute holds the number of processors that created - * the file. */ - if (nc_put_att_int(ncid, NC_GLOBAL, "num_processors", NC_INT, 1, &mpi_size)) ERR; - - /* Create three dimensions. */ - if (nc_def_dim(ncid, DIM1_NAME, NUM_SLABS, dimids)) ERR; - if (nc_def_dim(ncid, DIM2_NAME, DIMSIZE, &dimids[1])) ERR; - if (nc_def_dim(ncid, DIM3_NAME, DIMSIZE, &dimids[2])) ERR; - - /* Create one var. */ - if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIMS, dimids, &varid)) ERR; - - /* Write metadata to file. */ - if (nc_enddef(ncid)) ERR; - -#ifdef USE_MPE - MPE_Log_event(e_define, 0, "end define file"); - if (mpi_rank) - sleep(mpi_rank); -#endif /* USE_MPE */ - -/* if (nc_var_par_access(ncid, varid, NC_COLLECTIVE)) ERR;*/ -/* if (nc_var_par_access(ncid, varid, NC_INDEPENDENT)) ERR;*/ - - if (!mpi_rank) - start_time = MPI_Wtime(); - - /* Write all the slabs this process is responsible for. */ - for (i = 0; i < NUM_SLABS / mpi_size; i++) - { - start[0] = NUM_SLABS / mpi_size * mpi_rank + i; - -#ifdef USE_MPE - MPE_Log_event(s_write, 0, "start write slab"); -#endif /* USE_MPE */ - - /* Write one slab of data. */ - if (nc_put_vara_int(ncid, varid, start, count, data)) ERR; - -#ifdef USE_MPE - MPE_Log_event(e_write, 0, "end write file"); -#endif /* USE_MPE */ - } - - if (!mpi_rank) - { - total_time = MPI_Wtime() - start_time; -/* printf("num_proc\ttime(s)\n");*/ - printf("%d\t%g\t%g\n", mpi_size, total_time, DIMSIZE * DIMSIZE * NUM_SLABS * sizeof(int) / total_time); - } - -#ifdef USE_MPE - MPE_Log_event(s_close, 0, "start close file"); -#endif /* USE_MPE */ - - /* Close the netcdf file. */ - if (nc_close(ncid)) ERR; - -//#endif -#ifdef USE_MPE - MPE_Log_event(e_close, 0, "end close file"); -#endif /* USE_MPE */ - - /* Reopen the file and check it. */ - if ((ret = nc_open_par(FILE_NAME, NC_NOWRITE|NC_MPIIO, comm, info, &ncid))) - { - printf("ret = %d\n", ret); - return -1; - } - if (nc_inq(ncid, &ndims_in, &nvars_in, &natts_in, &unlimdimid_in)) ERR; - if (ndims_in != NDIMS || nvars_in != 1 || natts_in != 1 || - unlimdimid_in != -1) ERR; - - /* Read all the slabs this process is responsible for. */ - for (i = 0; i < NUM_SLABS / mpi_size; i++) - { - start[0] = NUM_SLABS / mpi_size * mpi_rank + i; - -#ifdef USE_MPE - MPE_Log_event(s_read, 0, "start read slab"); -#endif /* USE_MPE */ - - if(mpi_rank == 0) { -for(j=0; j<3;j++) -count[j] = 0; - - } - if (nc_var_par_access(ncid, varid, NC_COLLECTIVE)) ERR; - /* Read one slab of data. */ - if (nc_get_vara_int(ncid, varid, start, count, data_in)) ERR; - -if(mpi_rank != 0) { - /* Check data. */ - for (j = 0; j < DIMSIZE * DIMSIZE; j++) - if (data_in[j] != mpi_rank) - { - ERR; - break; - } -} - -#ifdef USE_MPE - MPE_Log_event(e_read, 0, "end read file"); -#endif /* USE_MPE */ - } - -#ifdef USE_MPE - MPE_Log_event(s_close, 0, "start close file"); -#endif /* USE_MPE */ - - /* Close the netcdf file. */ - if (nc_close(ncid)) ERR; - -#ifdef USE_MPE - MPE_Log_event(e_close, 0, "end close file"); -#endif /* USE_MPE */ - - /* Delete this large file. */ - // remove(file_name); - - /* Shut down MPI. */ - MPI_Finalize(); - -/* if (!mpi_rank) */ -/* { */ -/* SUMMARIZE_ERR; */ -/* FINAL_RESULTS; */ -/* } */ - return 0; + int mpi_namelen; + char mpi_name[MPI_MAX_PROCESSOR_NAME]; + int mpi_size, mpi_rank; + MPI_Comm comm = MPI_COMM_WORLD; + MPI_Info info = MPI_INFO_NULL; + double start_time = 0, total_time; + int mpi_size_in; +#define NUM_TEST_TYPES 11 + nc_type test_type[NUM_TEST_TYPES] = {NC_BYTE, NC_CHAR, NC_SHORT, NC_INT, NC_FLOAT, NC_DOUBLE, + NC_UBYTE, NC_USHORT, NC_UINT, NC_INT64, NC_UINT64}; + int tt, fv; + int j, i, k, ret; + + /* Initialize MPI. */ + MPI_Init(&argc,&argv); + MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); + MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); + MPI_Get_processor_name(mpi_name, &mpi_namelen); + + /* Must be able to evenly divide my slabs between processors. */ + if (NUM_SLABS % mpi_size) + { + if (!mpi_rank) + printf("NUM_SLABS (%d) is not evenly divisible by mpi_size(%d)\n", + NUM_SLABS, mpi_size); + ERR; + } + + if (!mpi_rank) + printf("\n*** Testing parallel I/O some more.\n"); + + /* Test for different fill value settings. */ + for (fv = 0; fv < NUM_FILL_TEST_RUNS; fv++) + { + /* Test for different netCDF types. */ + for (tt = 0; tt < NUM_TEST_TYPES; tt++) + { + char file_name[NC_MAX_NAME + 1]; + int fill_mode_in; + void *data, *data_in; + void *fill_value, *fill_value_in; + size_t type_size; + size_t write_start[NDIMS] = {0, 0, 1}; + size_t write_count[NDIMS] = {1, DIMSIZE, DIMSIZE - 1}; + size_t read_start[NDIMS] = {0, 0, 0}; + size_t read_count[NDIMS] = {1, DIMSIZE, DIMSIZE}; + int ncid, varid, dimids[NDIMS]; + int ndims_in, nvars_in, natts_in, unlimdimid_in; + + /* Fill values to be expected. */ + signed char byte_expected_fill_value; + unsigned char char_expected_fill_value; + short short_expected_fill_value; + int int_expected_fill_value; + float float_expected_fill_value; + double double_expected_fill_value; + unsigned char ubyte_expected_fill_value; + unsigned short ushort_expected_fill_value; + unsigned int uint_expected_fill_value; + long long int int64_expected_fill_value; + unsigned long long int uint64_expected_fill_value; + + /* Fill values used when writing. */ + signed char byte_fill_value = -TEST_VAL_42; + unsigned char char_fill_value = 'x'; + short short_fill_value = TEST_VAL_42 * 100; + int int_fill_value = TEST_VAL_42 * 1000; + float float_fill_value = TEST_VAL_42 * 1000; + double double_fill_value = TEST_VAL_42 * 1000; + unsigned char ubyte_fill_value = TEST_VAL_42; + unsigned short ushort_fill_value = TEST_VAL_42 * 100; + unsigned int uint_fill_value = TEST_VAL_42 * 1000; + long long int int64_fill_value = TEST_VAL_42 * 1000; + unsigned long long int uint64_fill_value = TEST_VAL_42 * 1000; + + /* Fill values read in. */ + signed char byte_fill_value_in; + unsigned char char_fill_value_in; + short short_fill_value_in; + int int_fill_value_in; + float float_fill_value_in; + double double_fill_value_in; + unsigned char ubyte_fill_value_in; + unsigned short ushort_fill_value_in; + unsigned int uint_fill_value_in; + long long int int64_fill_value_in; + unsigned long long int uint64_fill_value_in; + + /* Data to write and read. */ + signed char byte_data[DIMSIZE * DIMSIZE], byte_data_in[DIMSIZE * DIMSIZE]; + unsigned char char_data[DIMSIZE * DIMSIZE], char_data_in[DIMSIZE * DIMSIZE]; + short short_data[DIMSIZE * DIMSIZE], short_data_in[DIMSIZE * DIMSIZE]; + int int_data[DIMSIZE * DIMSIZE], int_data_in[DIMSIZE * DIMSIZE]; + float float_data[DIMSIZE * DIMSIZE], float_data_in[DIMSIZE * DIMSIZE]; + double double_data[DIMSIZE * DIMSIZE], double_data_in[DIMSIZE * DIMSIZE]; + unsigned char ubyte_data[DIMSIZE * DIMSIZE], ubyte_data_in[DIMSIZE * DIMSIZE]; + unsigned short ushort_data[DIMSIZE * DIMSIZE], ushort_data_in[DIMSIZE * DIMSIZE]; + unsigned int uint_data[DIMSIZE * DIMSIZE], uint_data_in[DIMSIZE * DIMSIZE]; + long long int int64_data[DIMSIZE * DIMSIZE], int64_data_in[DIMSIZE * DIMSIZE]; + unsigned long long int uint64_data[DIMSIZE * DIMSIZE], uint64_data_in[DIMSIZE * DIMSIZE]; + + if (!mpi_rank) + printf("*** writing a %d x %d x %d file from %d processors for fill value test %d type %d...\n", + NUM_SLABS, DIMSIZE, DIMSIZE, mpi_size, fv, test_type[tt]); + + /* Initialize test data. */ + switch(test_type[tt]) + { + case NC_BYTE: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + byte_data[i] = mpi_rank; + data = byte_data; + data_in = byte_data_in; + byte_expected_fill_value = fv ? byte_fill_value : NC_FILL_BYTE; + fill_value = &byte_expected_fill_value; + fill_value_in = &byte_fill_value_in; + break; + case NC_CHAR: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + char_data[i] = mpi_rank; + data = char_data; + data_in = char_data_in; + char_expected_fill_value = fv ? char_fill_value : NC_FILL_CHAR; + fill_value = &char_expected_fill_value; + fill_value_in = &char_fill_value_in; + break; + case NC_SHORT: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + short_data[i] = mpi_rank; + data = short_data; + data_in = short_data_in; + short_expected_fill_value = fv ? short_fill_value : NC_FILL_SHORT; + fill_value = &short_expected_fill_value; + fill_value_in = &short_fill_value_in; + break; + case NC_INT: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + int_data[i] = mpi_rank; + data = int_data; + data_in = int_data_in; + int_expected_fill_value = fv ? int_fill_value : NC_FILL_INT; + fill_value = &int_expected_fill_value; + fill_value_in = &int_fill_value_in; + break; + case NC_FLOAT: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + float_data[i] = mpi_rank; + data = float_data; + data_in = float_data_in; + float_expected_fill_value = fv ? float_fill_value : NC_FILL_FLOAT; + fill_value = &float_expected_fill_value; + fill_value_in = &float_fill_value_in; + break; + case NC_DOUBLE: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + double_data[i] = mpi_rank; + data = double_data; + data_in = double_data_in; + double_expected_fill_value = fv ? double_fill_value : NC_FILL_DOUBLE; + fill_value = &double_expected_fill_value; + fill_value_in = &double_fill_value_in; + break; + case NC_UBYTE: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + ubyte_data[i] = mpi_rank; + data = ubyte_data; + data_in = ubyte_data_in; + ubyte_expected_fill_value = fv ? ubyte_fill_value : NC_FILL_UBYTE; + fill_value = &ubyte_expected_fill_value; + fill_value_in = &ubyte_fill_value_in; + break; + case NC_USHORT: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + ushort_data[i] = mpi_rank; + data = ushort_data; + data_in = ushort_data_in; + ushort_expected_fill_value = fv ? ushort_fill_value : NC_FILL_USHORT; + fill_value = &ushort_expected_fill_value; + fill_value_in = &ushort_fill_value_in; + break; + case NC_UINT: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + uint_data[i] = mpi_rank; + data = uint_data; + data_in = uint_data_in; + uint_expected_fill_value = fv ? uint_fill_value : NC_FILL_UINT; + fill_value = &uint_expected_fill_value; + fill_value_in = &uint_fill_value_in; + break; + case NC_INT64: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + int64_data[i] = mpi_rank; + data = int64_data; + data_in = int64_data_in; + int64_expected_fill_value = fv ? int64_fill_value : NC_FILL_INT64; + fill_value = &int64_expected_fill_value; + fill_value_in = &int64_fill_value_in; + break; + case NC_UINT64: + for (i = 0; i < DIMSIZE * DIMSIZE; i++) + uint64_data[i] = mpi_rank; + data = uint64_data; + data_in = uint64_data_in; + uint64_expected_fill_value = fv ? uint64_fill_value : NC_FILL_UINT64; + fill_value = &uint64_expected_fill_value; + fill_value_in = &uint64_fill_value_in; + break; + } + + /* Create a file name. */ + sprintf(file_name, "%s_type_%d_fv_%d.nc", TEST_NAME, test_type[tt], fv); + + /* Create a parallel netcdf-4 file. */ + if (nc_create_par(file_name, NC_NETCDF4|NC_MPIIO, comm, info, &ncid)) ERR; + + /* Get the type len. */ + if (nc_inq_type(ncid, test_type[tt], NULL, &type_size)) ERR; + + /* A global attribute holds the number of processors that created + * the file. */ + if (nc_put_att_int(ncid, NC_GLOBAL, "num_processors", NC_INT, 1, &mpi_size)) ERR; + + /* Create three dimensions. */ + if (nc_def_dim(ncid, DIM1_NAME, NUM_SLABS, dimids)) ERR; + if (nc_def_dim(ncid, DIM2_NAME, DIMSIZE, &dimids[1])) ERR; + if (nc_def_dim(ncid, DIM3_NAME, DIMSIZE, &dimids[2])) ERR; + + /* Create one var. */ + if (nc_def_var(ncid, VAR_NAME, test_type[tt], NDIMS, dimids, &varid)) ERR; + if (nc_put_att_int(ncid, varid, "var_num_processors", NC_INT, 1, &mpi_size)) ERR; + if (fv == 1) + { + if (nc_def_var_fill(ncid, varid, NC_FILL, fill_value)) ERR; + if (nc_inq_var_fill(ncid, varid, &fill_mode_in, fill_value_in)) ERR; + if (fill_mode_in != NC_FILL) ERR; + if (memcmp(fill_value_in, fill_value, type_size)) ERR; + } + else if (fv == 2) + { + if (nc_def_var_fill(ncid, varid, NC_NOFILL, NULL)) ERR; + if (nc_inq_var_fill(ncid, varid, &fill_mode_in, NULL)) ERR; + if (!fill_mode_in) ERR; /* nofill will be true */ + } + + /* Write metadata to file. */ + if (nc_enddef(ncid)) ERR; + + /* Change access mode to collective, then back to independent. */ + if (nc_var_par_access(ncid, varid, NC_COLLECTIVE)) ERR; + if (nc_var_par_access(ncid, varid, NC_INDEPENDENT)) ERR; + + if (!mpi_rank) + start_time = MPI_Wtime(); + + /* Write all the slabs this process is responsible for. */ + for (i = 0; i < NUM_SLABS / mpi_size; i++) + { + write_start[0] = NUM_SLABS / mpi_size * mpi_rank + i; + + /* Write one slab of data. Due to start/count settings, + * every 16th value will be a fill value. */ + if (nc_put_vara(ncid, varid, write_start, write_count, data)) ERR; + } + + /* On rank 0, keep track of time. */ + if (!mpi_rank) + { + total_time = MPI_Wtime() - start_time; + printf("%d\t%g\t%g\n", mpi_size, total_time, DIMSIZE * DIMSIZE * NUM_SLABS * + sizeof(int) / total_time); + } + + /* Close the netcdf file. */ + if (nc_close(ncid)) ERR; + + /* Reopen the file and check it. */ + if ((ret = nc_open_par(file_name, NC_NOWRITE|NC_MPIIO, comm, info, &ncid))) ERR; + if (nc_inq(ncid, &ndims_in, &nvars_in, &natts_in, &unlimdimid_in)) ERR; + if (ndims_in != NDIMS || nvars_in != 1 || natts_in != 1 || + unlimdimid_in != -1) ERR; + + /* Check the attributes. */ + if (nc_get_att_int(ncid, NC_GLOBAL, "num_processors", &mpi_size_in)) ERR; + if (mpi_size_in != mpi_size) ERR; + if (nc_get_att_int(ncid, 0, "var_num_processors", &mpi_size_in)) ERR; + if (mpi_size_in != mpi_size) ERR; + if (fv == 1) + { + if (nc_inq_var_fill(ncid, varid, &fill_mode_in, fill_value_in)) ERR; + if (fill_mode_in != NC_FILL) ERR; + if (memcmp(fill_value_in, fill_value, type_size)) ERR; + } + + /* Read all the slabs this process is responsible for. */ + for (i = 0; i < NUM_SLABS / mpi_size; i++) + { + read_start[0] = NUM_SLABS / mpi_size * mpi_rank + i; + /* printf("mpi_rank %d i %d read_start[0] %ld\n", mpi_rank, i, read_start[0]); */ + + /* Read one slab of data. */ + if (nc_get_vara(ncid, varid, read_start, read_count, data_in)) ERR; + + /* Check data. For the third fill value test, fill is + * turned off. So don't bother testing the values where k + * is zero. */ + /* printf("mpi_rank %d fv %d i %d j %d k %d int_data_in[j * k] %d int_expected_fill_value %d " */ + /* "expected_value %d\n", mpi_rank, fv, i, j, k, int_data_in[j * k], */ + /* int_expected_fill_value, expected_value); */ + switch (test_type[tt]) + { + case NC_BYTE: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (byte_data_in[j * DIMSIZE + k] != (signed char)(k ? mpi_rank : byte_expected_fill_value)) ERR; + break; + case NC_SHORT: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (short_data_in[j * DIMSIZE + k] != (short)(k ? mpi_rank : short_expected_fill_value)) ERR; + break; + case NC_INT: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (int_data_in[j * DIMSIZE + k] != (int)(k ? mpi_rank : int_expected_fill_value)) ERR; + break; + case NC_FLOAT: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (float_data_in[j * DIMSIZE + k] != (float)(k ? mpi_rank : float_expected_fill_value)) ERR; + break; + case NC_DOUBLE: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (double_data_in[j * DIMSIZE + k] != (double)(k ? mpi_rank : double_expected_fill_value)) ERR; + break; + case NC_UBYTE: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (ubyte_data_in[j * DIMSIZE + k] != (unsigned char)(k ? mpi_rank : ubyte_expected_fill_value)) ERR; + break; + case NC_USHORT: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (ushort_data_in[j * DIMSIZE + k] != (unsigned short)(k ? mpi_rank : ushort_expected_fill_value)) ERR; + break; + case NC_UINT: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (uint_data_in[j * DIMSIZE + k] != (unsigned int)(k ? mpi_rank : uint_expected_fill_value)) ERR; + break; + case NC_INT64: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (int64_data_in[j * DIMSIZE + k] != (long long int)(k ? mpi_rank : int64_expected_fill_value)) ERR; + break; + case NC_UINT64: + for (j = 0; j < DIMSIZE; j++) + for (k = 0; k < DIMSIZE; k++) + if (fv < 2 || k) + if (uint64_data_in[j * DIMSIZE + k] != (unsigned long long int)(k ? mpi_rank : uint64_expected_fill_value)) ERR; + break; + } + } /* next slab */ + + /* Close the netcdf file. */ + if (nc_close(ncid)) ERR; + + if (!mpi_rank) + SUMMARIZE_ERR; + } /* next test type */ + } /* next fill value test run */ + + /* Shut down MPI. */ + MPI_Finalize(); + + if (!mpi_rank) + FINAL_RESULTS; + return 0; } diff --git a/nc_test4/tst_types.c b/nc_test4/tst_types.c index f12f7f2b43..def4a0419c 100644 --- a/nc_test4/tst_types.c +++ b/nc_test4/tst_types.c @@ -1,333 +1,395 @@ -/* Test program for types. */ -#include -#include - -/* This macro prints an error message and exits. */ -#define BAIL(e) do { \ -fprintf(stderr, "Error in file %s, line %d.\n%s\n", \ -__FILE__, __LINE__, nc_strerror(e)); \ -return 2; \ -} while (0) - -/* This macro keep track of the number of errors and prints an error - * message. */ -#define ERR do { \ -fprintf(stderr, "Error in file %s, line %d.\n", __FILE__, __LINE__); \ -errors++; \ -} while (0) - +/* This is part of the netCDF package. + Copyright 2005 University Corporation for Atmospheric Research/Unidata + See COPYRIGHT file for conditions of use. + + Test netcdf-4 types. + + Ed Hartnett +*/ + +#include "config.h" +#include "nc_tests.h" +#include "err_macros.h" + #define MAX_VARNAME 20 #define NUM_TYPES 6 #define NUM_DIMS 1 #define SIZE 5 #define STRIDE_SIZE 2 -#define FILENAME "test.nc" - -#define CLEAN_INPUT_BUFFERS \ - for (i=0; i./tmp_testurl 2> ./errtmp_testurl if test "x${SHOW}" = x1 ; then cat ./tmp_testurl ; fi + +# Test that maxstrlen works as alias for stringlength +echo "***Testing maxstrlen=stringlength alias" +buildurl $STRLEN "" +# Invoke ncdump to extract the URL +echo "command: ${NCDUMP} -h $url" +${NCDUMP} "$url" >./tmp_testurl 2> ./errtmp_testurl +if test "x${SHOW}" = x1 ; then cat ./tmp_testurl ; fi +# Look for the value of maxStrlen in output cdl +if ! fgrep -i "maxstrlen = 16" ./tmp_testurl ; then +echo "***Fail: maxStrlen not recognized" +fgrep -i "maxstrlen16 = 16" ./tmp_testurl > ./errtmp_testurl +fi + fi locreset @@ -90,5 +105,3 @@ if test "x$pass" = x0 ; then fi echo "***PASS" exit 0 - - diff --git a/ncgen/bindata.c b/ncgen/bindata.c index 741cb601e6..7dd2d57c2b 100644 --- a/ncgen/bindata.c +++ b/ncgen/bindata.c @@ -86,7 +86,7 @@ bin_constant(Generator* generator, Symbol* sym, NCConstant* con, Bytebuffer* buf char* nil = NULL; bbAppendn(buf,(void*)&nil,sizeof(nil)); } else { - ptr = (char*)malloc(len+1); + ptr = (char*)ecalloc(len+1); memcpy(ptr,con->value.stringv.stringv,len); ptr[len] = '\0'; bbAppendn(buf,(void*)&ptr,sizeof(ptr)); diff --git a/ncgen/bytebuffer.c b/ncgen/bytebuffer.c index fd68dc630b..8613d09c63 100644 --- a/ncgen/bytebuffer.c +++ b/ncgen/bytebuffer.c @@ -28,14 +28,14 @@ bbFail(void) fflush(stdout); fprintf(stderr,"bytebuffer failure\n"); fflush(stderr); - if(bbdebug) exit(1); + if(bbdebug) abort(); return FALSE; } Bytebuffer* bbNew(void) { - Bytebuffer* bb = (Bytebuffer*)emalloc(sizeof(Bytebuffer)); + Bytebuffer* bb = (Bytebuffer*)malloc(sizeof(Bytebuffer)); if(bb == NULL) return (Bytebuffer*)bbFail(); bb->alloc=0; bb->length=0; @@ -53,7 +53,7 @@ bbSetalloc(Bytebuffer* bb, const unsigned int sz0) if(sz <= 0) {sz = (bb->alloc?2*bb->alloc:DEFAULTALLOC);} else if(bb->alloc >= sz) return TRUE; else if(bb->nonextendible) return bbFail(); - newcontent=(char*)ecalloc(sz,sizeof(char)); + newcontent=(char*)calloc(sz,sizeof(char)); if(bb->alloc > 0 && bb->length > 0 && bb->content != NULL) { memcpy((void*)newcontent,(void*)bb->content,sizeof(char)*bb->length); } @@ -250,7 +250,7 @@ bbTailpeek(Bytebuffer* bb, char* pelem) char* bbDup(const Bytebuffer* bb) { - char* result = (char*)emalloc(bb->length+1); + char* result = (char*)malloc(bb->length+1); memcpy((void*)result,(const void*)bb->content,bb->length); result[bb->length] = '\0'; /* just in case it is a string*/ return result; diff --git a/ncgen/cdfdata.c b/ncgen/cdfdata.c index 45a8eb7642..95a78043c4 100644 --- a/ncgen/cdfdata.c +++ b/ncgen/cdfdata.c @@ -323,7 +323,7 @@ genbin_vlenconstants(List* vlenconstants) /* Prepare a place to store vlen constants */ nvlen = listlength(vlenconstants); if(nvlen == 0) return; - vlendata = (struct Vlendata*)emalloc(sizeof(struct Vlendata)*nvlen+1); + vlendata = (struct Vlendata*)ecalloc(sizeof(struct Vlendata)*nvlen+1); memset((void*)vlendata,0,sizeof(struct Vlendata)*nvlen+1); for(i=0;ivalue.stringv.len; - tmp.stringv.stringv = (char*)malloc(src->value.stringv.len+1); + tmp.stringv.stringv = (char*)ecalloc(src->value.stringv.len+1); memcpy((void*)tmp.stringv.stringv, (void*)src->value.stringv.stringv, tmp.stringv.len); @@ -549,7 +549,7 @@ case CASE(NC_OPAQUE,NC_DOUBLE): tmp.doublev = *(double*)bytes; break; case CASE(NC_OPAQUE,NC_OPAQUE): - tmp.opaquev.stringv = (char*)malloc(src->value.opaquev.len+1); + tmp.opaquev.stringv = (char*)ecalloc(src->value.opaquev.len+1); memcpy(tmp.opaquev.stringv,src->value.opaquev.stringv,src->value.opaquev.len); tmp.opaquev.len = src->value.opaquev.len; tmp.opaquev.stringv[tmp.opaquev.len] = '\0'; @@ -590,7 +590,7 @@ setprimlength(NCConstant* prim, unsigned long len) prim->value.stringv.len = len; } else {/* prim->value.stringv.len > srcov->len*/ char* s; - s = (char*)emalloc(len+1); + s = (char*)ecalloc(len+1); memset(s,NC_FILL_CHAR,len); s[len] = '\0'; memcpy(s,prim->value.stringv.stringv,prim->value.stringv.len); @@ -609,7 +609,7 @@ setprimlength(NCConstant* prim, unsigned long len) prim->value.opaquev.len = len; } else {/* prim->value.opaquev.len < len => expand*/ char* s; - s = (char*)emalloc(len+1); + s = (char*)ecalloc(len+1); memset(s,'0',len); memcpy(s,prim->value.opaquev.stringv,prim->value.opaquev.len); s[len] = '\0'; diff --git a/ncgen/data.c b/ncgen/data.c index c564ab416f..89ff41573e 100644 --- a/ncgen/data.c +++ b/ncgen/data.c @@ -84,7 +84,7 @@ Datasrc* allocdatasrc(void) { Datasrc* src; - src = emalloc(sizeof(Datasrc)); + src = ecalloc(sizeof(Datasrc)); src->data = NULL; src->index = 0; src->length = 0; @@ -274,13 +274,13 @@ cloneconstant(NCConstant* con) char* s; switch (newcon.nctype) { case NC_STRING: - s = (char*)emalloc(newcon.value.stringv.len+1); + s = (char*)ecalloc(newcon.value.stringv.len+1); memcpy(s,newcon.value.stringv.stringv,newcon.value.stringv.len); s[newcon.value.stringv.len] = '\0'; newcon.value.stringv.stringv = s; break; case NC_OPAQUE: - s = (char*)emalloc(newcon.value.opaquev.len+1); + s = (char*)ecalloc(newcon.value.opaquev.len+1); memcpy(s,newcon.value.opaquev.stringv,newcon.value.opaquev.len); s[newcon.value.opaquev.len] = '\0'; newcon.value.opaquev.stringv = s; @@ -675,7 +675,7 @@ indented(int n) { char* indentation; if(dent == NULL) { - dent = (char*)emalloc(INDENTMAX+1); + dent = (char*)ecalloc(INDENTMAX+1); memset((void*)dent,' ',INDENTMAX); dent[INDENTMAX] = '\0'; } @@ -688,22 +688,13 @@ void dlextend(Datalist* dl) { size_t newalloc; - newalloc = (dl->alloc > 0?2*dl->alloc:1); - dlsetalloc(dl,newalloc); -} - -void -dlsetalloc(Datalist* dl, size_t newalloc) -{ - NCConstant* newdata; - if(newalloc <= 0) newalloc = 1; - if(dl->alloc > 0) - newdata = (NCConstant*)erealloc((void*)dl->data,sizeof(NCConstant)*newalloc); - else { - newdata = (NCConstant*)emalloc(sizeof(NCConstant)*newalloc); - memset((void*)newdata,0,sizeof(NCConstant)*newalloc); - } + NCConstant* newdata = NULL; + newalloc = (dl->alloc > 0?2*dl->alloc:2); + newdata = (NCConstant*)ecalloc(newalloc*sizeof(NCConstant)); + if(dl->length > 0) + memcpy(newdata,dl->data,sizeof(NCConstant)*dl->length); dl->alloc = newalloc; + nullfree(dl->data); dl->data = newdata; } @@ -714,9 +705,9 @@ builddatalist(int initial) Datalist* ci; if(initial <= 0) initial = DATALISTINIT; initial++; /* for header*/ - ci = (Datalist*)emalloc(sizeof(Datalist)); + ci = (Datalist*)ecalloc(sizeof(Datalist)); memset((void*)ci,0,sizeof(Datalist)); /* only clear the hdr*/ - ci->data = (NCConstant*)emalloc(sizeof(NCConstant)*initial); + ci->data = (NCConstant*)ecalloc(sizeof(NCConstant)*initial); memset((void*)ci->data,0,sizeof(NCConstant)*initial); ci->alloc = initial; ci->length = 0; @@ -726,7 +717,8 @@ builddatalist(int initial) void dlappend(Datalist* dl, NCConstant* constant) { - if(dl->length >= dl->alloc) dlextend(dl); + if(dl->length >= dl->alloc) + dlextend(dl); if(constant == NULL) constant = &nullconstant; dl->data[dl->length++] = *constant; } diff --git a/ncgen/debug.c b/ncgen/debug.c index 468986f7b6..b20bd0665c 100644 --- a/ncgen/debug.c +++ b/ncgen/debug.c @@ -1,9 +1,7 @@ -/********************************************************************* - * Copyright 2009, UCAR/Unidata - * See netcdf/COPYRIGHT file for copying and redistribution conditions. - *********************************************************************/ -/* $Id: debug.c,v 1.2 2010/05/24 19:59:57 dmh Exp $ */ -/* $Header: /upc/share/CVS/netcdf-3/ncgen/debug.c,v 1.2 2010/05/24 19:59:57 dmh Exp $ */ +/* +Copyright (c) 1998-2017 University Corporation for Atmospheric Research/Unidata +See LICENSE.txt for license information. +*/ #include "includes.h" @@ -26,21 +24,23 @@ void fdebug(const char *fmt, ...) /**************************************************/ /* Support debugging of memory*/ -/* Also guarantee that calloc zeros memory*/ -void* -chkcalloc(size_t size, size_t nelems) + +void +chkfree(void* memory) { - return chkmalloc(size*nelems); + if(memory == NULL) { + panic("free: null memory"); + } + free(memory); } void* -chkmalloc(size_t size) +chkcalloc(size_t size) { void* memory = calloc(size,1); /* use calloc to zero memory*/ if(memory == NULL) { panic("malloc:out of memory"); } - memset(memory,0,size); return memory; } @@ -54,10 +54,16 @@ chkrealloc(void* ptr, size_t size) return memory; } -void -chkfree(void* mem) +char* +chkstrdup(const char* s) { - if(mem != NULL) free(mem); + char* dup = strdup(s); + if(s == NULL) { + panic("strdup: null argument"); + } + if(dup == NULL) { + panic("strdup: out of memory"); + } } int diff --git a/ncgen/debug.h b/ncgen/debug.h index 60ec1e4e8b..bf183aae62 100644 --- a/ncgen/debug.h +++ b/ncgen/debug.h @@ -43,18 +43,22 @@ extern void fdebug(const char *fmt, ...); extern int panic(const char* fmt, ...); /* -Provide wrapped versions of calloc and malloc. -The wrapped version panics if memory is exhausted. +Provide wrapped versions of XXXalloc for debugging/ +The wrapped version: +1. fails if size is zero or memory is NULL +2. fails if memory is exhausted. +3. zeros all allocated memory. */ -#define ecalloc(x,y) chkcalloc(x,y) -#define emalloc(x) chkmalloc(x) +#define ecalloc(x) chkcalloc(x) /*note only single arg */ #define erealloc(p,x) chkrealloc(p,x) #define efree(x) chkfree(x) -extern void* chkcalloc(size_t, size_t); -extern void* chkmalloc(size_t); +#define estrdup(x) chkstrdup(x) +extern void* chkcalloc(size_t); extern void* chkrealloc(void*,size_t); extern void chkfree(void*); +extern char* chkstrdup(const char* s); + #define MEMCHECK(var,throw) {if((var)==NULL) return (throw);} #endif /*NCGEN_DEBUG_H*/ diff --git a/ncgen/escapes.c b/ncgen/escapes.c index 3211728b3d..a5e66bcc2f 100644 --- a/ncgen/escapes.c +++ b/ncgen/escapes.c @@ -169,7 +169,7 @@ initcodify(void) idtlen = strlen("DIGIT_n_"); /* initial digit template */ hexlen = strlen("_XHH"); /* template for hex of non-ASCII bytes */ for(i = 0; i < 128; i++) { - rp = emalloc(2); + rp = ecalloc(2); rp[0] = i; rp[1] = '\0'; repls[i] = rp; @@ -180,7 +180,7 @@ initcodify(void) repls[j] = ctable[i].s; } for(i = 128; i < 256; i++) { - rp = emalloc(hexlen+1); + rp = ecalloc(hexlen+1); snprintf(rp, hexlen+1, "_X%2.2X", i); /* need to include null*/ rp[hexlen] = '\0'; repls[i] = rp; @@ -460,7 +460,7 @@ f77quotestring(Bytebuffer* databuf) return; } - s = (unsigned char*)emalloc(slen+1); + s = (unsigned char*)ecalloc(slen+1); memcpy((void*)s,bbContents(databuf),slen); s[slen] = '\0'; bbClear(databuf); diff --git a/ncgen/genbin.c b/ncgen/genbin.c index e107a50cad..1a5ca15f61 100644 --- a/ncgen/genbin.c +++ b/ncgen/genbin.c @@ -383,6 +383,7 @@ genbin_defineattr(Symbol* asym) Bytebuffer* databuf = bbNew(); generator_reset(bin_generator,NULL); generate_attrdata(asym,bin_generator,(Writer)genbin_write,databuf); + bbFree(databuf); } @@ -395,6 +396,7 @@ genbin_definevardata(Symbol* vsym) databuf = bbNew(); generator_reset(bin_generator,NULL); generate_vardata(vsym,bin_generator,(Writer)genbin_write,databuf); + bbFree(databuf); } static int @@ -457,7 +459,7 @@ static int genbin_writeattr(Generator* generator, Symbol* asym, Bytebuffer* databuf, int rank, size_t* start, size_t* count) { - int stat; + int stat = NC_NOERR; size_t len; Datalist* list; int varid, grpid, typid; diff --git a/ncgen/genc.c b/ncgen/genc.c index 58eaf4e81d..cbec6c9562 100644 --- a/ncgen/genc.c +++ b/ncgen/genc.c @@ -512,11 +512,11 @@ genc_definespecialattributes(Symbol* vsym) if(special->flags & _FILTER_FLAG) { /* Special check for alternate way to specify _Deflate */ if(special->_FilterID == ZIP_ID) { - unsigned int level; + int level; if(special->nparams == 0 || special->_FilterParams == NULL) level = 9; /* default */ else - level = special->_FilterParams[0]; + level = (int)special->_FilterParams[0]; if(level < 0 || level > 9) derror("Illegal deflate level"); else { @@ -525,7 +525,7 @@ genc_definespecialattributes(Symbol* vsym) groupncid(vsym->container), varncid(vsym), (special->_Shuffle == 1?"NC_SHUFFLE":"NC_NOSHUFFLE"), - (level >= 0?1:0), + 1, level); codedump(stmt); } diff --git a/ncgen/genchar.c b/ncgen/genchar.c index 17682246d6..7a96ff0694 100644 --- a/ncgen/genchar.c +++ b/ncgen/genchar.c @@ -253,7 +253,7 @@ gen_leafchararray(Dimset* dimset, int dimindex, Datalist* data, } } if(cccount > 1) { - char* accum = (char*)malloc(cccount+1); + char* accum = (char*)ecalloc(cccount+1); int len = 0; Datalist* newlist = builddatalist(datalistlen(data)); int lineno = 0; @@ -338,13 +338,13 @@ gen_leafchararray(Dimset* dimset, int dimindex, Datalist* data, static NCConstant* makeconst(int lineno, int len, char* str) { - NCConstant* con = (NCConstant*)malloc(sizeof(NCConstant)); + NCConstant* con = (NCConstant*)ecalloc(sizeof(NCConstant)); con->nctype = NC_STRING; con->lineno = lineno; con->filled = 0; con->value.stringv.len = len; /* We cannot use strdup because str might have embedded nuls */ - con->value.stringv.stringv = (char*)malloc(len+1); + con->value.stringv.stringv = (char*)ecalloc(len+1); memcpy((void*)con->value.stringv.stringv,(void*)str,len); con->value.stringv.stringv[len] = '\0'; return con; diff --git a/ncgen/generate.c b/ncgen/generate.c index 9c2449ea6b..73f234d4ea 100644 --- a/ncgen/generate.c +++ b/ncgen/generate.c @@ -450,7 +450,7 @@ normalizeopaquelength(NCConstant* prim, unsigned long nbytes) prim->value.opaquev.len = nnibs; } else {/* prim->value.opaquev.len < nnibs => expand*/ char* s; - s = (char*)emalloc(nnibs+1); + s = (char*)ecalloc(nnibs+1); memset(s,'0',nnibs); /* Fill with '0' characters */ memcpy(s,prim->value.opaquev.stringv,prim->value.opaquev.len); s[nnibs] = '\0'; diff --git a/ncgen/generr.c b/ncgen/generr.c index 2770b5d3d6..98d82918a5 100644 --- a/ncgen/generr.c +++ b/ncgen/generr.c @@ -116,7 +116,7 @@ semerror(lno,fmt,va_alist) const int lno; const char* fmt; va_dcl vastart(argv,fmt); (void)fprintf(stderr,"%s: %s line %d: ", progname, cdlname, lno); vderror(fmt,argv); - exit(1); /* immediately fatal */ + finalize_netcdf(1); /* immediately fatal */ } /* Capture potential version errors */ diff --git a/ncgen/genjjni.c b/ncgen/genjjni.c index a47558656b..7cc3910697 100644 --- a/ncgen/genjjni.c +++ b/ncgen/genjjni.c @@ -1541,7 +1541,7 @@ jname(Symbol* sym) /* Attribute name must be prefixed with the cname of the*/ /* associated variable*/ char* lname; - lname = (char*)emalloc(strlen(sym->att.var->name) + lname = (char*)ecalloc(strlen(sym->att.var->name) +strlen(sym->name) +1+1); lname[0] = '\0'; diff --git a/ncgen/genlib.c b/ncgen/genlib.c index 98e845bb16..ff27dd7b70 100644 --- a/ncgen/genlib.c +++ b/ncgen/genlib.c @@ -116,7 +116,7 @@ topfqn(Symbol* sym) parentfqn = parent->fqn; fqnname = fqnescape(sym->name); - fqn = (char*)malloc(strlen(fqnname) + strlen(parentfqn) + 1 + 1); + fqn = (char*)ecalloc(strlen(fqnname) + strlen(parentfqn) + 1 + 1); strcpy(fqn,parentfqn); strcat(fqn,"/"); strcat(fqn,fqnname); @@ -151,7 +151,7 @@ nestedfqn(Symbol* sym) assert(parent->fqn != NULL); fqnname = fqnescape(sym->name); - fqn = (char*)malloc(strlen(fqnname) + strlen(parent->fqn) + 1 + 1); + fqn = (char*)ecalloc(strlen(fqnname) + strlen(parent->fqn) + 1 + 1); strcpy(fqn,parent->fqn); strcat(fqn,"."); strcat(fqn,fqnname); @@ -183,7 +183,7 @@ attfqn(Symbol* sym) parentfqn = parent->fqn; fqnname = fqnescape(sym->name); - fqn = (char*)malloc(strlen(fqnname) + strlen(parentfqn) + 1 + 1); + fqn = (char*)ecalloc(strlen(fqnname) + strlen(parentfqn) + 1 + 1); strcpy(fqn,parentfqn); strcat(fqn,"_"); strcat(fqn,fqnname); diff --git a/ncgen/genlib.h b/ncgen/genlib.h index afa5e273cf..cea6c2fba2 100644 --- a/ncgen/genlib.h +++ b/ncgen/genlib.h @@ -194,11 +194,11 @@ extern char *netcdf_name; /* command line -o file name */ extern char *datasetname; /* name from the netcdf {} */ extern char *cdlname; /* name from the command line */ -/* from: util.c */ -extern void* emalloc (size_t); -extern void* ecalloc (size_t); -extern void* erealloc(void*,size_t); - extern const char* specialname(int tag); +extern void init_netcdf(void); +extern void finalize_netcdf(int); +extern void parse_init(void); +extern int ncgparse(void); + #endif /*!NC_GENLIB_H*/ diff --git a/ncgen/jdatajni.c b/ncgen/jdatajni.c index 710a553c3a..c98ef0a2cc 100644 --- a/ncgen/jdatajni.c +++ b/ncgen/jdatajni.c @@ -446,7 +446,7 @@ jopaquestring(Symbol* tsym, Constant* prim, Constant* target) ASSERT((oplen%2) == 0); - opstring = (char*)emalloc(oplen*(2+4)); + opstring = (char*)ecalloc(oplen*(2+4)); opstring[0]='\0'; p=(unsigned char*)op; diff --git a/ncgen/main.c b/ncgen/main.c index 5eb97df512..18ed861632 100644 --- a/ncgen/main.c +++ b/ncgen/main.c @@ -22,13 +22,9 @@ int optind; /* Default is netcdf-3 mode 1 */ #define DFALTCMODE 0 -extern void init_netcdf(void); -extern void parse_init(void); -extern int ncgparse(void); - /* For error messages */ -char* progname; -char* cdlname; +char* progname; /* Global: not reclaimed */ +char* cdlname; /* Global: not reclaimed */ /* option flags */ int nofill_flag; @@ -212,10 +208,10 @@ main( int argc, char *argv[]) { + int code = 0; int c; FILE *fp; struct Languages* langs; - char* lang_name; #ifdef __hpux setlocale(LC_CTYPE,""); #endif @@ -223,8 +219,8 @@ main( init_netcdf(); opterr = 1; /* print error message if bad option */ - progname = ubasename(argv[0]); - cdlname = "-"; + progname = nulldup(ubasename(argv[0])); + cdlname = NULL; netcdf_name = NULL; datasetname = NULL; l_flag = 0; @@ -288,9 +284,10 @@ main( break; case 'H': usage(); - exit(0); + goto done; case 'l': /* specify language, instead of using -c or -f or -b */ { + char* lang_name = NULL; if(l_flag != 0) { fprintf(stderr,"Please specify only one language\n"); return 1; @@ -299,8 +296,7 @@ main( derror("%s: output language is null", progname); return(1); } - lang_name = (char*) emalloc(strlen(optarg)+1); - (void)strcpy(lang_name, optarg); + lang_name = estrdup(optarg); for(langs=legallanguages;langs->name != NULL;langs++) { if(strcmp(lang_name,langs->name)==0) { l_flag = langs->flag; @@ -309,8 +305,10 @@ main( } if(langs->name == NULL) { derror("%s: output language %s not implemented",progname, lang_name); + nullfree(lang_name); return(1); } + nullfree(lang_name); }; break; case 'L': ncloglevel = atoi(optarg); @@ -351,23 +349,18 @@ main( 5 (=> classic 64 bit data aka CDF-5) */ struct Kvalues* kvalue; - char *kind_name = (optarg != NULL - ? (char *) emalloc(strlen(optarg)+1) - : emalloc(1)); - if (! kind_name) { - derror ("%s: out of memory", progname); - return(1); - } - if(optarg != NULL) - (void)strcpy(kind_name, optarg); + if(optarg == NULL) { + derror("-k flag has no value"); + return 2; + } for(kvalue=legalkinds;kvalue->name;kvalue++) { - if(strcmp(kind_name,kvalue->name) == 0) { - k_flag = kvalue->k_flag; - break; - } + if(strcmp(optarg,kvalue->name) == 0) { + k_flag = kvalue->k_flag; + break; + } } if(kvalue->name == NULL) { - derror("Invalid format: %s",kind_name); + derror("Invalid format: %s",optarg); return 2; } } break; @@ -419,19 +412,19 @@ main( #ifndef ENABLE_C if(c_flag) { fprintf(stderr,"C not currently supported\n"); - exit(1); + code=1; goto done; } #endif #ifndef ENABLE_BINARY if(l_flag == L_BINARY) { fprintf(stderr,"Binary netcdf not currently supported\n"); - exit(1); + code=1; goto done; } #endif #ifndef ENABLE_JAVA if(l_flag == L_JAVA) { fprintf(stderr,"Java not currently supported\n"); - exit(1); + code=1; goto done; } #else if(l_flag == L_JAVA && mainname != NULL && strcmp(mainname,"main")==0) @@ -440,7 +433,7 @@ main( #ifndef ENABLE_F77 if(l_flag == L_F77) { fprintf(stderr,"F77 not currently supported\n"); - exit(1); + code=1; goto done; } #endif @@ -486,13 +479,12 @@ main( break; } } + } - cdlname = (char*)emalloc(NC_MAX_NAME); - cdlname = nulldup(argv[0]); - if(cdlname != NULL) { - if(strlen(cdlname) > NC_MAX_NAME) - cdlname[NC_MAX_NAME] = '\0'; - } + cdlname = nulldup(argv[0]); + if(cdlname != NULL) { + if(strlen(cdlname) > NC_MAX_NAME) + cdlname[NC_MAX_NAME] = '\0'; } parse_init(); @@ -586,7 +578,9 @@ main( if(!syntax_only && error_count == 0) define_netcdf(); - return 0; +done: + finalize_netcdf(code); + return code; } void @@ -600,3 +594,10 @@ init_netcdf(void) /* initialize global counts, flags */ stmt = bbNew(); error_count = 0; /* Track # of errors */ } + +void +finalize_netcdf(int retcode) +{ + nc_finalize(); + exit(retcode); +} diff --git a/ncgen/ncgen.l b/ncgen/ncgen.l index 4b854af380..cbe3b21101 100644 --- a/ncgen/ncgen.l +++ b/ncgen/ncgen.l @@ -88,6 +88,8 @@ static unsigned int MAX_UINT = NC_MAX_UINT; no tag was specified */ #define NC_NOTAG (-1) +extern int errno; + char errstr[100]; /* for short error messages */ int lineno; /* line number for error messages */ @@ -385,7 +387,6 @@ NIL|nil|Nil { int slen = strlen(ncgtext); char* stag = NULL; int tag = NC_NAT; - int signchar = 0; int isneg = 0; int c = ncgtext[0]; int fail = 0; @@ -610,7 +611,7 @@ makepath(char* text0) /* split the text into IDENT chunks, convert to symbols */ Symbol* container = rootgroup; char *ident, *p; - char* text = strdup(text0); + char* text = estrdup(text0); int c,lastident; ident=text+1; p=ident; /* skip leading '/' */ do { @@ -659,8 +660,6 @@ Return the value. static unsigned long long parseULL(char* text, int* failp) { - int result = 0; - extern int errno; char* endptr; unsigned long long uint64 = 0; diff --git a/ncgen/ncgen.y b/ncgen/ncgen.y index 5d4fc51c3e..59ef869346 100644 --- a/ncgen/ncgen.y +++ b/ncgen/ncgen.y @@ -957,8 +957,7 @@ Symbol* install(const char *sname) { Symbol* sp; - sp = (Symbol*) emalloc (sizeof (struct Symbol)); - memset((void*)sp,0,sizeof(struct Symbol)); + sp = (Symbol*) ecalloc (sizeof (struct Symbol)); sp->name = nulldup(sname); sp->next = symlist; sp->lineno = lineno; @@ -1046,7 +1045,7 @@ makeconstdata(nc_type nctype) char* s; int len; len = bbLength(lextext); - s = (char*)emalloc(len+1); + s = (char*)ecalloc(len+1); strncpy(s,bbContents(lextext),len); s[len] = '\0'; con.value.opaquev.stringv = s; @@ -1057,7 +1056,7 @@ makeconstdata(nc_type nctype) break; /* no associated value*/ #endif - case NC_FILLVALUE: + case NC_FILLVALUE: break; /* no associated value*/ default: @@ -1160,7 +1159,6 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst) int tf = 0; char* sdata = NULL; int idata = -1; - unsigned int udata = 0; if((GLOBAL_SPECIAL & tag) != 0) { if(vsym != NULL) { @@ -1246,7 +1244,7 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst) else if(tag == _SUPERBLOCK_FLAG) globalspecials._Superblock = idata; else if(tag == _NCPROPS_FLAG) - globalspecials._NCProperties = strdup(sdata); + globalspecials._NCProperties = estrdup(sdata); } else { Specialdata* special; /* Set up special info */ @@ -1313,7 +1311,7 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst) case _CHUNKSIZES_FLAG: { int i; special->nchunks = list->length; - special->_ChunkSizes = (size_t*)emalloc(sizeof(size_t)*special->nchunks); + special->_ChunkSizes = (size_t*)ecalloc(sizeof(size_t)*special->nchunks); for(i=0;inchunks;i++) { iconst.nctype = NC_INT; convert1(&list->data[i],&iconst); @@ -1398,7 +1396,8 @@ containsfills(Datalist* list) for(i=0;ilength;i++,con++) { if(con->nctype == NC_COMPOUND) { if(containsfills(con->value.compoundv)) return 1; - } else if(con->nctype == NC_FILLVALUE) return 1; + } else if(con->nctype == NC_FILLVALUE) + return 1; } } return 0; diff --git a/ncgen/ncgenl.c b/ncgen/ncgenl.c index 6c5da63d13..85c060d766 100644 --- a/ncgen/ncgenl.c +++ b/ncgen/ncgenl.c @@ -1,5 +1,5 @@ -#line 3 "lex.ncg.c" +#line 3 "ncgenl.c" #define YY_INT_ALIGNED short int @@ -65,7 +65,6 @@ typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; -typedef uint64_t flex_uint64_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; @@ -172,12 +171,7 @@ typedef unsigned int flex_uint32_t; typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t ncgleng; +extern int ncgleng; extern FILE *ncgin, *ncgout; @@ -203,6 +197,11 @@ extern FILE *ncgin, *ncgout; #define unput(c) yyunput( c, (yytext_ptr) ) +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state @@ -220,7 +219,7 @@ struct yy_buffer_state /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - yy_size_t yy_n_chars; + int yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -290,8 +289,8 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* yy_hold_char holds the character lost when ncgtext is formed. */ static char yy_hold_char; -static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t ncgleng; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int ncgleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; @@ -319,7 +318,7 @@ static void ncg_init_buffer (YY_BUFFER_STATE b,FILE *file ); YY_BUFFER_STATE ncg_scan_buffer (char *base,yy_size_t size ); YY_BUFFER_STATE ncg_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE ncg_scan_bytes (yyconst char *bytes,yy_size_t len ); +YY_BUFFER_STATE ncg_scan_bytes (yyconst char *bytes,int len ); void *ncgalloc (yy_size_t ); void *ncgrealloc (void *,yy_size_t ); @@ -374,7 +373,7 @@ static void yy_fatal_error (yyconst char msg[] ); */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ - ncgleng = (yy_size_t) (yy_cp - yy_bp); \ + ncgleng = (size_t) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; @@ -1239,6 +1238,8 @@ static unsigned int MAX_UINT = NC_MAX_UINT; no tag was specified */ #define NC_NOTAG (-1) +extern int errno; + char errstr[100]; /* for short error messages */ int lineno; /* line number for error messages */ @@ -1330,7 +1331,7 @@ ID ([A-Za-z_]|{UTF8})([A-Z.@#\[\]a-z_0-9+-]|{UTF8})* /* Note: this definition of string will work for utf8 as well, although it is a very relaxed definition */ -#line 1334 "lex.ncg.c" +#line 1335 "ncgenl.c" #define INITIAL 0 #define ST_C_COMMENT 1 @@ -1371,7 +1372,7 @@ FILE *ncgget_out (void ); void ncgset_out (FILE * out_str ); -yy_size_t ncgget_leng (void ); +int ncgget_leng (void ); char *ncgget_text (void ); @@ -1432,7 +1433,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - yy_size_t n; \ + int n; \ for ( n = 0; n < max_size && \ (c = getc( ncgin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -1514,9 +1515,9 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 218 "ncgen.l" +#line 220 "ncgen.l" -#line 1520 "lex.ncg.c" +#line 1521 "ncgenl.c" if ( !(yy_init) ) { @@ -1601,14 +1602,14 @@ YY_DECL case 1: YY_RULE_SETUP -#line 219 "ncgen.l" +#line 221 "ncgen.l" { /* whitespace */ break; } YY_BREAK case 2: YY_RULE_SETUP -#line 223 "ncgen.l" +#line 225 "ncgen.l" { /* comment */ break; } @@ -1616,7 +1617,7 @@ YY_RULE_SETUP case 3: /* rule 3 can match eol */ YY_RULE_SETUP -#line 227 "ncgen.l" +#line 229 "ncgen.l" {int len; /* In netcdf4, this will be used in a variety of places, so only remove escapes */ @@ -1643,7 +1644,7 @@ ncgtext[MAXTRST-1] = '\0'; YY_BREAK case 4: YY_RULE_SETUP -#line 251 "ncgen.l" +#line 253 "ncgen.l" { /* drop leading 0x; pad to even number of chars */ char* p = ncgtext+2; int len = ncgleng - 2; @@ -1658,118 +1659,118 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 263 "ncgen.l" +#line 265 "ncgen.l" {return lexdebug(COMPOUND);} YY_BREAK case 6: YY_RULE_SETUP -#line 264 "ncgen.l" +#line 266 "ncgen.l" {return lexdebug(ENUM);} YY_BREAK case 7: YY_RULE_SETUP -#line 265 "ncgen.l" +#line 267 "ncgen.l" {return lexdebug(OPAQUE_);} YY_BREAK case 8: YY_RULE_SETUP -#line 267 "ncgen.l" +#line 269 "ncgen.l" {return lexdebug(FLOAT_K);} YY_BREAK case 9: YY_RULE_SETUP -#line 268 "ncgen.l" +#line 270 "ncgen.l" {return lexdebug(CHAR_K);} YY_BREAK case 10: YY_RULE_SETUP -#line 269 "ncgen.l" +#line 271 "ncgen.l" {return lexdebug(BYTE_K);} YY_BREAK case 11: YY_RULE_SETUP -#line 270 "ncgen.l" +#line 272 "ncgen.l" {return lexdebug(UBYTE_K);} YY_BREAK case 12: YY_RULE_SETUP -#line 271 "ncgen.l" +#line 273 "ncgen.l" {return lexdebug(SHORT_K);} YY_BREAK case 13: YY_RULE_SETUP -#line 272 "ncgen.l" +#line 274 "ncgen.l" {return lexdebug(USHORT_K);} YY_BREAK case 14: YY_RULE_SETUP -#line 273 "ncgen.l" +#line 275 "ncgen.l" {return lexdebug(INT_K);} YY_BREAK case 15: YY_RULE_SETUP -#line 274 "ncgen.l" +#line 276 "ncgen.l" {return lexdebug(UINT_K);} YY_BREAK case 16: YY_RULE_SETUP -#line 275 "ncgen.l" +#line 277 "ncgen.l" {return lexdebug(INT64_K);} YY_BREAK case 17: YY_RULE_SETUP -#line 276 "ncgen.l" +#line 278 "ncgen.l" {return lexdebug(UINT64_K);} YY_BREAK case 18: YY_RULE_SETUP -#line 277 "ncgen.l" +#line 279 "ncgen.l" {return lexdebug(DOUBLE_K);} YY_BREAK case 19: YY_RULE_SETUP -#line 278 "ncgen.l" +#line 280 "ncgen.l" {return lexdebug(STRING_K);} YY_BREAK case 20: YY_RULE_SETUP -#line 280 "ncgen.l" +#line 282 "ncgen.l" {int32_val = -1; return lexdebug(NC_UNLIMITED_K);} YY_BREAK case 21: YY_RULE_SETUP -#line 283 "ncgen.l" +#line 285 "ncgen.l" {return lexdebug(TYPES);} YY_BREAK case 22: YY_RULE_SETUP -#line 284 "ncgen.l" +#line 286 "ncgen.l" {return lexdebug(DIMENSIONS);} YY_BREAK case 23: YY_RULE_SETUP -#line 285 "ncgen.l" +#line 287 "ncgen.l" {return lexdebug(VARIABLES);} YY_BREAK case 24: YY_RULE_SETUP -#line 286 "ncgen.l" +#line 288 "ncgen.l" {return lexdebug(DATA);} YY_BREAK case 25: YY_RULE_SETUP -#line 287 "ncgen.l" +#line 289 "ncgen.l" {return lexdebug(GROUP);} YY_BREAK case 26: YY_RULE_SETUP -#line 289 "ncgen.l" +#line 291 "ncgen.l" {BEGIN(TEXT);return lexdebug(NETCDF);} YY_BREAK case 27: YY_RULE_SETUP -#line 291 "ncgen.l" +#line 293 "ncgen.l" { /* missing value (pre-2.4 backward compatibility) */ if (ncgtext[0] == '-') { double_val = NEGNC_INFINITE; @@ -1782,7 +1783,7 @@ YY_RULE_SETUP YY_BREAK case 28: YY_RULE_SETUP -#line 300 "ncgen.l" +#line 302 "ncgen.l" { /* missing value (pre-2.4 backward compatibility) */ double_val = NAN; specialconstants = 1; @@ -1791,7 +1792,7 @@ YY_RULE_SETUP YY_BREAK case 29: YY_RULE_SETUP -#line 306 "ncgen.l" +#line 308 "ncgen.l" {/* missing value (pre-2.4 backward compatibility)*/ if (ncgtext[0] == '-') { float_val = NEGNC_INFINITEF; @@ -1804,7 +1805,7 @@ YY_RULE_SETUP YY_BREAK case 30: YY_RULE_SETUP -#line 315 "ncgen.l" +#line 317 "ncgen.l" { /* missing value (pre-2.4 backward compatibility) */ float_val = NANF; specialconstants = 1; @@ -1813,7 +1814,7 @@ YY_RULE_SETUP YY_BREAK case 31: YY_RULE_SETUP -#line 321 "ncgen.l" +#line 323 "ncgen.l" { #ifdef USE_NETCDF4 if(l_flag == L_C || l_flag == L_BINARY) @@ -1826,7 +1827,7 @@ YY_RULE_SETUP YY_BREAK case 32: YY_RULE_SETUP -#line 331 "ncgen.l" +#line 333 "ncgen.l" { bbClear(lextext); bbAppendn(lextext,(char*)ncgtext,ncgleng+1); /* include null */ @@ -1837,7 +1838,7 @@ YY_RULE_SETUP YY_BREAK case 33: YY_RULE_SETUP -#line 340 "ncgen.l" +#line 342 "ncgen.l" {struct Specialtoken* st; bbClear(lextext); bbAppendn(lextext,(char*)ncgtext,ncgleng+1); /* include null */ @@ -1851,7 +1852,7 @@ YY_RULE_SETUP case 34: /* rule 34 can match eol */ YY_RULE_SETUP -#line 350 "ncgen.l" +#line 352 "ncgen.l" { int c; char* p; char* q; @@ -1871,7 +1872,7 @@ YY_RULE_SETUP YY_BREAK case 35: YY_RULE_SETUP -#line 367 "ncgen.l" +#line 369 "ncgen.l" { char* id; int len; bbClear(lextext); bbAppendn(lextext,(char*)ncgtext,ncgleng+1); /* include null */ @@ -1886,7 +1887,7 @@ YY_RULE_SETUP YY_BREAK case 36: YY_RULE_SETUP -#line 379 "ncgen.l" +#line 381 "ncgen.l" { /* We need to try to see what size of integer ((u)int). @@ -1896,7 +1897,6 @@ YY_RULE_SETUP int slen = strlen(ncgtext); char* stag = NULL; int tag = NC_NAT; - int signchar = 0; int isneg = 0; int c = ncgtext[0]; int fail = 0; @@ -1955,7 +1955,7 @@ done: return 0; YY_BREAK case 37: YY_RULE_SETUP -#line 445 "ncgen.l" +#line 446 "ncgen.l" { int c; int token = 0; @@ -2006,7 +2006,7 @@ YY_RULE_SETUP YY_BREAK case 38: YY_RULE_SETUP -#line 492 "ncgen.l" +#line 493 "ncgen.l" { if (sscanf((char*)ncgtext, "%le", &double_val) != 1) { sprintf(errstr,"bad long or double constant: %s",(char*)ncgtext); @@ -2017,7 +2017,7 @@ YY_RULE_SETUP YY_BREAK case 39: YY_RULE_SETUP -#line 499 "ncgen.l" +#line 500 "ncgen.l" { if (sscanf((char*)ncgtext, "%e", &float_val) != 1) { sprintf(errstr,"bad float constant: %s",(char*)ncgtext); @@ -2029,7 +2029,7 @@ YY_RULE_SETUP case 40: /* rule 40 can match eol */ YY_RULE_SETUP -#line 506 "ncgen.l" +#line 507 "ncgen.l" { (void) sscanf((char*)&ncgtext[1],"%c",&byte_val); return lexdebug(BYTE_CONST); @@ -2037,7 +2037,7 @@ YY_RULE_SETUP YY_BREAK case 41: YY_RULE_SETUP -#line 510 "ncgen.l" +#line 511 "ncgen.l" { int oct = unescapeoct(&ncgtext[2]); if(oct < 0) { @@ -2050,7 +2050,7 @@ YY_RULE_SETUP YY_BREAK case 42: YY_RULE_SETUP -#line 519 "ncgen.l" +#line 520 "ncgen.l" { int hex = unescapehex(&ncgtext[3]); if(byte_val < 0) { @@ -2063,7 +2063,7 @@ YY_RULE_SETUP YY_BREAK case 43: YY_RULE_SETUP -#line 528 "ncgen.l" +#line 529 "ncgen.l" { switch ((char)ncgtext[2]) { case 'a': byte_val = '\007'; break; /* not everyone under- @@ -2085,7 +2085,7 @@ YY_RULE_SETUP case 44: /* rule 44 can match eol */ YY_RULE_SETUP -#line 546 "ncgen.l" +#line 547 "ncgen.l" { lineno++ ; break; @@ -2093,7 +2093,7 @@ YY_RULE_SETUP YY_BREAK case 45: YY_RULE_SETUP -#line 551 "ncgen.l" +#line 552 "ncgen.l" {/*initial*/ BEGIN(ST_C_COMMENT); break; @@ -2102,21 +2102,21 @@ YY_RULE_SETUP case 46: /* rule 46 can match eol */ YY_RULE_SETUP -#line 556 "ncgen.l" +#line 557 "ncgen.l" {/* continuation */ break; } YY_BREAK case 47: YY_RULE_SETUP -#line 560 "ncgen.l" +#line 561 "ncgen.l" {/* final */ BEGIN(INITIAL); break; } YY_BREAK case YY_STATE_EOF(ST_C_COMMENT): -#line 565 "ncgen.l" +#line 566 "ncgen.l" {/* final, error */ fprintf(stderr,"unterminated /**/ comment"); BEGIN(INITIAL); @@ -2125,17 +2125,17 @@ case YY_STATE_EOF(ST_C_COMMENT): YY_BREAK case 48: YY_RULE_SETUP -#line 571 "ncgen.l" +#line 572 "ncgen.l" {/* Note: this next rule will not work for UTF8 characters */ return lexdebug(ncgtext[0]) ; } YY_BREAK case 49: YY_RULE_SETUP -#line 574 "ncgen.l" +#line 575 "ncgen.l" ECHO; YY_BREAK -#line 2139 "lex.ncg.c" +#line 2139 "ncgenl.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(TEXT): yyterminate(); @@ -2322,7 +2322,7 @@ static int yy_get_next_buffer (void) else { - yy_size_t num_to_read = + int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) @@ -2336,7 +2336,7 @@ static int yy_get_next_buffer (void) if ( b->yy_is_our_buffer ) { - yy_size_t new_size = b->yy_buf_size * 2; + int new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -2367,7 +2367,7 @@ static int yy_get_next_buffer (void) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); + (yy_n_chars), (size_t) num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } @@ -2477,7 +2477,7 @@ static int yy_get_next_buffer (void) if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ - register yy_size_t number_to_move = (yy_n_chars) + 2; + register int number_to_move = (yy_n_chars) + 2; register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; register char *source = @@ -2526,7 +2526,7 @@ static int yy_get_next_buffer (void) else { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + int offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) @@ -2550,7 +2550,7 @@ static int yy_get_next_buffer (void) case EOB_ACT_END_OF_FILE: { if ( ncgwrap( ) ) - return 0; + return EOF; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; @@ -2802,7 +2802,7 @@ void ncgpop_buffer_state (void) */ static void ncgensure_buffer_stack (void) { - yy_size_t num_to_alloc; + int num_to_alloc; if (!(yy_buffer_stack)) { @@ -2899,11 +2899,12 @@ YY_BUFFER_STATE ncg_scan_string (yyconst char * yystr ) * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE ncg_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) +YY_BUFFER_STATE ncg_scan_bytes (yyconst char * yybytes, int _yybytes_len ) { YY_BUFFER_STATE b; char *buf; - yy_size_t n, i; + yy_size_t n; + int i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; @@ -2985,7 +2986,7 @@ FILE *ncgget_out (void) /** Get the length of the current token. * */ -yy_size_t ncgget_leng (void) +int ncgget_leng (void) { return ncgleng; } @@ -3133,7 +3134,7 @@ void ncgfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 574 "ncgen.l" +#line 575 "ncgen.l" static int @@ -3174,7 +3175,7 @@ makepath(char* text0) /* split the text into IDENT chunks, convert to symbols */ Symbol* container = rootgroup; char *ident, *p; - char* text = strdup(text0); + char* text = estrdup(text0); int c,lastident; ident=text+1; p=ident; /* skip leading '/' */ do { @@ -3223,8 +3224,6 @@ Return the value. static unsigned long long parseULL(char* text, int* failp) { - int result = 0; - extern int errno; char* endptr; unsigned long long uint64 = 0; diff --git a/ncgen/ncgeny.c b/ncgen/ncgeny.c index bc856f89d3..da6447ddbc 100644 --- a/ncgen/ncgeny.c +++ b/ncgen/ncgeny.c @@ -1,14 +1,13 @@ -/* A Bison parser, made by GNU Bison 2.3. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,9 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -47,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.3" +#define YYBISON_VERSION "3.0.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -55,140 +52,25 @@ /* Pure parsers. */ #define YYPURE 0 -/* Using locations. */ -#define YYLSP_NEEDED 0 +/* Push parsers. */ +#define YYPUSH 0 -/* Substitute the variable and function names. */ -#define yyparse ncgparse -#define yylex ncglex -#define yyerror ncgerror -#define yylval ncglval -#define yychar ncgchar -#define yydebug ncgdebug -#define yynerrs ncgnerrs - - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - NC_UNLIMITED_K = 258, - CHAR_K = 259, - BYTE_K = 260, - SHORT_K = 261, - INT_K = 262, - FLOAT_K = 263, - DOUBLE_K = 264, - UBYTE_K = 265, - USHORT_K = 266, - UINT_K = 267, - INT64_K = 268, - UINT64_K = 269, - STRING_K = 270, - IDENT = 271, - TERMSTRING = 272, - CHAR_CONST = 273, - BYTE_CONST = 274, - SHORT_CONST = 275, - INT_CONST = 276, - INT64_CONST = 277, - UBYTE_CONST = 278, - USHORT_CONST = 279, - UINT_CONST = 280, - UINT64_CONST = 281, - FLOAT_CONST = 282, - DOUBLE_CONST = 283, - DIMENSIONS = 284, - VARIABLES = 285, - NETCDF = 286, - DATA = 287, - TYPES = 288, - COMPOUND = 289, - ENUM = 290, - OPAQUE_ = 291, - OPAQUESTRING = 292, - GROUP = 293, - PATH = 294, - FILLMARKER = 295, - NIL = 296, - _FILLVALUE = 297, - _FORMAT = 298, - _STORAGE = 299, - _CHUNKSIZES = 300, - _DEFLATELEVEL = 301, - _SHUFFLE = 302, - _ENDIANNESS = 303, - _NOFILL = 304, - _FLETCHER32 = 305, - _NCPROPS = 306, - _ISNETCDF4 = 307, - _SUPERBLOCK = 308, - _FILTER = 309, - DATASETID = 310 - }; -#endif -/* Tokens. */ -#define NC_UNLIMITED_K 258 -#define CHAR_K 259 -#define BYTE_K 260 -#define SHORT_K 261 -#define INT_K 262 -#define FLOAT_K 263 -#define DOUBLE_K 264 -#define UBYTE_K 265 -#define USHORT_K 266 -#define UINT_K 267 -#define INT64_K 268 -#define UINT64_K 269 -#define STRING_K 270 -#define IDENT 271 -#define TERMSTRING 272 -#define CHAR_CONST 273 -#define BYTE_CONST 274 -#define SHORT_CONST 275 -#define INT_CONST 276 -#define INT64_CONST 277 -#define UBYTE_CONST 278 -#define USHORT_CONST 279 -#define UINT_CONST 280 -#define UINT64_CONST 281 -#define FLOAT_CONST 282 -#define DOUBLE_CONST 283 -#define DIMENSIONS 284 -#define VARIABLES 285 -#define NETCDF 286 -#define DATA 287 -#define TYPES 288 -#define COMPOUND 289 -#define ENUM 290 -#define OPAQUE_ 291 -#define OPAQUESTRING 292 -#define GROUP 293 -#define PATH 294 -#define FILLMARKER 295 -#define NIL 296 -#define _FILLVALUE 297 -#define _FORMAT 298 -#define _STORAGE 299 -#define _CHUNKSIZES 300 -#define _DEFLATELEVEL 301 -#define _SHUFFLE 302 -#define _ENDIANNESS 303 -#define _NOFILL 304 -#define _FLETCHER32 305 -#define _NCPROPS 306 -#define _ISNETCDF4 307 -#define _SUPERBLOCK 308 -#define _FILTER 309 -#define DATASETID 310 +/* Pull parsers. */ +#define YYPULL 1 +/* Substitute the variable and function names. */ +#define yyparse ncgparse +#define yylex ncglex +#define yyerror ncgerror +#define yydebug ncgdebug +#define yynerrs ncgnerrs +#define yylval ncglval +#define yychar ncgchar /* Copy the first part of user declarations. */ -#line 11 "ncgen.y" +#line 11 "ncgen.y" /* yacc.c:339 */ /* static char SccsId[] = "$Id: ncgen.y,v 1.42 2010/05/18 21:32:46 dmh Exp $"; @@ -317,11 +199,15 @@ static void yyerror(fmt,va_alist) const char* fmt; va_dcl; extern int lex_init(void); +#line 203 "ncgeny.c" /* yacc.c:339 */ -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 1 -#endif +# ifndef YY_NULLPTR +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE @@ -331,37 +217,111 @@ extern int lex_init(void); # define YYERROR_VERBOSE 1 #endif -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 +/* In a future release of Bison, this section will be replaced + by #include "ncgeny.h". */ +#ifndef YY_NCG_NCGEN_TAB_H_INCLUDED +# define YY_NCG_NCGEN_TAB_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int ncgdebug; #endif +/* Token type. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + NC_UNLIMITED_K = 258, + CHAR_K = 259, + BYTE_K = 260, + SHORT_K = 261, + INT_K = 262, + FLOAT_K = 263, + DOUBLE_K = 264, + UBYTE_K = 265, + USHORT_K = 266, + UINT_K = 267, + INT64_K = 268, + UINT64_K = 269, + STRING_K = 270, + IDENT = 271, + TERMSTRING = 272, + CHAR_CONST = 273, + BYTE_CONST = 274, + SHORT_CONST = 275, + INT_CONST = 276, + INT64_CONST = 277, + UBYTE_CONST = 278, + USHORT_CONST = 279, + UINT_CONST = 280, + UINT64_CONST = 281, + FLOAT_CONST = 282, + DOUBLE_CONST = 283, + DIMENSIONS = 284, + VARIABLES = 285, + NETCDF = 286, + DATA = 287, + TYPES = 288, + COMPOUND = 289, + ENUM = 290, + OPAQUE_ = 291, + OPAQUESTRING = 292, + GROUP = 293, + PATH = 294, + FILLMARKER = 295, + NIL = 296, + _FILLVALUE = 297, + _FORMAT = 298, + _STORAGE = 299, + _CHUNKSIZES = 300, + _DEFLATELEVEL = 301, + _SHUFFLE = 302, + _ENDIANNESS = 303, + _NOFILL = 304, + _FLETCHER32 = 305, + _NCPROPS = 306, + _ISNETCDF4 = 307, + _SUPERBLOCK = 308, + _FILTER = 309, + DATASETID = 310 + }; +#endif + +/* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE -#line 142 "ncgen.y" + +union YYSTYPE { +#line 142 "ncgen.y" /* yacc.c:355 */ + Symbol* sym; unsigned long size; /* allow for zero size to indicate e.g. UNLIMITED*/ long mark; /* track indices into the sequence*/ int nctype; /* for tracking attribute list type*/ Datalist* datalist; NCConstant constant; -} -/* Line 193 of yacc.c. */ -#line 352 "ncgen.tab.c" - YYSTYPE; -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 + +#line 308 "ncgeny.c" /* yacc.c:355 */ +}; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 #endif +extern YYSTYPE ncglval; -/* Copy the second part of user declarations. */ +int ncgparse (void); +#endif /* !YY_NCG_NCGEN_TAB_H_INCLUDED */ -/* Line 216 of yacc.c. */ -#line 365 "ncgen.tab.c" +/* Copy the second part of user declarations. */ + +#line 325 "ncgeny.c" /* yacc.c:358 */ #ifdef short # undef short @@ -375,11 +335,8 @@ typedef unsigned char yytype_uint8; #ifdef YYTYPE_INT8 typedef YYTYPE_INT8 yytype_int8; -#elif (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -typedef signed char yytype_int8; #else -typedef short int yytype_int8; +typedef signed char yytype_int8; #endif #ifdef YYTYPE_UINT16 @@ -399,8 +356,7 @@ typedef short int yytype_int16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# elif ! defined YYSIZE_T # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else @@ -414,38 +370,67 @@ typedef short int yytype_int16; # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid +# endif +#endif + +#ifndef YY_ATTRIBUTE +# if (defined __GNUC__ \ + && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ + || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +# else +# define YY_ATTRIBUTE(Spec) /* empty */ +# endif +#endif + +#ifndef YY_ATTRIBUTE_PURE +# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#endif + +#if !defined _Noreturn \ + && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +# if defined _MSC_VER && 1200 <= _MSC_VER +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif -/* Identity function, used to suppress warnings about constant conditions. */ -#ifndef lint -# define YYID(n) (n) +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") #else -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static int -YYID (int i) -#else -static int -YYID (i) - int i; +# define YY_INITIAL_VALUE(Value) Value #endif -{ - return i; -} +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + #if ! defined yyoverflow || YYERROR_VERBOSE @@ -464,11 +449,11 @@ YYID (i) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -476,8 +461,8 @@ YYID (i) # endif # ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) # ifndef YYSTACK_ALLOC_MAXIMUM /* The OS might guarantee only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely @@ -491,25 +476,23 @@ YYID (i) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) + && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined malloc && ! defined EXIT_SUCCESS void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined free && ! defined EXIT_SUCCESS void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif @@ -519,14 +502,14 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss; - YYSTYPE yyvs; - }; + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; +}; /* The size of the maximum gap between one aligned stack and the next. */ # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) @@ -537,42 +520,46 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack, Stack, yysize); \ - Stack = &yyptr->Stack; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (YYID (0)) +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 5 /* YYLAST -- Last index in YYTABLE. */ @@ -584,17 +571,19 @@ union yyalloc #define YYNNTS 67 /* YYNRULES -- Number of rules. */ #define YYNRULES 153 -/* YYNRULES -- Number of states. */ +/* YYNSTATES -- Number of states. */ #define YYNSTATES 262 -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned + by yylex, with out-of-bounds checking. */ #define YYUNDEFTOK 2 #define YYMAXUTOK 310 -#define YYTRANSLATE(YYX) \ +#define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, without out-of-bounds checking. */ static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -632,80 +621,7 @@ static const yytype_uint8 yytranslate[] = }; #if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const yytype_uint16 yyprhs[] = -{ - 0, 0, 3, 7, 9, 14, 20, 21, 24, 25, - 26, 36, 37, 39, 42, 44, 47, 49, 51, 54, - 57, 60, 63, 66, 67, 69, 76, 78, 82, 86, - 92, 98, 104, 107, 111, 114, 116, 118, 120, 122, - 124, 126, 128, 130, 132, 134, 136, 138, 139, 141, - 144, 147, 151, 153, 155, 157, 161, 165, 169, 171, - 172, 174, 177, 180, 184, 186, 188, 191, 193, 197, - 200, 201, 205, 207, 211, 213, 215, 219, 222, 223, - 227, 229, 233, 235, 237, 239, 241, 243, 245, 246, - 250, 255, 260, 265, 270, 277, 283, 289, 296, 302, - 308, 314, 320, 326, 332, 338, 344, 349, 351, 353, - 354, 356, 359, 362, 366, 370, 372, 374, 375, 377, - 381, 383, 387, 389, 391, 393, 395, 397, 399, 401, - 406, 408, 412, 414, 416, 418, 420, 422, 424, 426, - 428, 430, 432, 434, 436, 438, 442, 444, 446, 448, - 450, 452, 454, 456 -}; - -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yytype_int16 yyrhs[] = -{ - 66, 0, -1, 31, 67, 68, -1, 55, -1, 56, - 69, 70, 57, -1, 112, 74, 89, 95, 115, -1, - -1, 70, 71, -1, -1, -1, 38, 131, 56, 72, - 69, 70, 73, 57, 112, -1, -1, 33, -1, 33, - 75, -1, 77, -1, 75, 77, -1, 131, -1, 78, - -1, 113, 58, -1, 80, 79, -1, 85, 79, -1, - 84, 79, -1, 83, 79, -1, -1, 58, -1, 88, - 35, 76, 56, 81, 57, -1, 82, -1, 81, 59, - 82, -1, 131, 60, 128, -1, 36, 61, 21, 62, - 76, -1, 110, 61, 63, 62, 76, -1, 34, 76, - 56, 86, 57, -1, 87, 58, -1, 86, 87, 58, - -1, 110, 104, -1, 4, -1, 5, -1, 6, -1, - 7, -1, 8, -1, 9, -1, 10, -1, 11, -1, - 12, -1, 13, -1, 14, -1, 15, -1, -1, 29, - -1, 29, 90, -1, 91, 58, -1, 90, 91, 58, - -1, 92, -1, 113, -1, 93, -1, 92, 59, 93, - -1, 94, 60, 128, -1, 94, 60, 3, -1, 131, - -1, -1, 30, -1, 30, 96, -1, 97, 58, -1, - 96, 97, 58, -1, 98, -1, 113, -1, 110, 99, - -1, 100, -1, 99, 59, 100, -1, 131, 101, -1, - -1, 61, 102, 62, -1, 103, -1, 102, 59, 103, - -1, 114, -1, 105, -1, 104, 59, 105, -1, 131, - 106, -1, -1, 61, 107, 62, -1, 108, -1, 107, - 59, 108, -1, 25, -1, 21, -1, 111, -1, 111, - -1, 114, -1, 88, -1, -1, 113, 58, 112, -1, - 64, 51, 60, 129, -1, 64, 52, 60, 130, -1, - 64, 53, 60, 128, -1, 64, 131, 60, 118, -1, - 110, 111, 64, 131, 60, 118, -1, 111, 64, 131, - 60, 118, -1, 111, 64, 42, 60, 118, -1, 110, - 111, 64, 42, 60, 118, -1, 111, 64, 44, 60, - 129, -1, 111, 64, 45, 60, 127, -1, 111, 64, - 50, 60, 130, -1, 111, 64, 46, 60, 128, -1, - 111, 64, 47, 60, 130, -1, 111, 64, 48, 60, - 129, -1, 111, 64, 54, 60, 129, -1, 111, 64, - 49, 60, 130, -1, 64, 43, 60, 129, -1, 131, - -1, 39, -1, -1, 32, -1, 32, 116, -1, 117, - 58, -1, 116, 117, 58, -1, 109, 60, 118, -1, - 119, -1, 120, -1, -1, 121, -1, 118, 59, 121, - -1, 122, -1, 56, 118, 57, -1, 126, -1, 37, - -1, 40, -1, 41, -1, 123, -1, 124, -1, 114, - -1, 131, 61, 125, 62, -1, 126, -1, 125, 59, - 126, -1, 18, -1, 19, -1, 20, -1, 21, -1, - 22, -1, 23, -1, 24, -1, 25, -1, 26, -1, - 27, -1, 28, -1, 17, -1, 128, -1, 127, 59, - 128, -1, 21, -1, 25, -1, 22, -1, 26, -1, - 17, -1, 129, -1, 128, -1, 16, -1 -}; - -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { 0, 224, 224, 230, 232, 239, 246, 246, 249, 258, @@ -727,7 +643,7 @@ static const yytype_uint16 yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +#if YYDEBUG || YYERROR_VERBOSE || 1 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -744,7 +660,7 @@ static const char *const yytname[] = "_FLETCHER32", "_NCPROPS", "_ISNETCDF4", "_SUPERBLOCK", "_FILTER", "DATASETID", "'{'", "'}'", "';'", "','", "'='", "'('", "')'", "'*'", "':'", "$accept", "ncdesc", "datasetid", "rootgroup", "groupbody", - "subgrouplist", "namedgroup", "@1", "@2", "typesection", "typedecls", + "subgrouplist", "namedgroup", "$@1", "$@2", "typesection", "typedecls", "typename", "type_or_attr_decl", "typedecl", "optsemicolon", "enumdecl", "enumidlist", "enumid", "opaquedecl", "vlendecl", "compounddecl", "fields", "field", "primtype", "dimsection", "dimdecls", @@ -755,13 +671,13 @@ static const char *const yytname[] = "attrdecllist", "attrdecl", "path", "datasection", "datadecls", "datadecl", "datalist", "datalist0", "datalist1", "dataitem", "constdata", "econstref", "function", "arglist", "simpleconstant", - "intlist", "constint", "conststring", "constbool", "ident", 0 + "intlist", "constint", "conststring", "constbool", "ident", YY_NULLPTR }; #endif # ifdef YYPRINT -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to - token YYLEX-NUM. */ +/* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, @@ -774,97 +690,18 @@ static const yytype_uint16 yytoknum[] = }; # endif -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 65, 66, 67, 68, 69, 70, 70, 72, 73, - 71, 74, 74, 74, 75, 75, 76, 77, 77, 78, - 78, 78, 78, 79, 79, 80, 81, 81, 82, 83, - 84, 85, 86, 86, 87, 88, 88, 88, 88, 88, - 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, - 90, 90, 91, 91, 92, 92, 93, 93, 94, 95, - 95, 95, 96, 96, 97, 97, 98, 99, 99, 100, - 101, 101, 102, 102, 103, 104, 104, 105, 106, 106, - 107, 107, 108, 108, 109, 110, 111, 111, 112, 112, - 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, - 113, 113, 113, 113, 113, 113, 113, 114, 114, 115, - 115, 115, 116, 116, 117, 118, 118, 119, 120, 120, - 121, 121, 122, 122, 122, 122, 122, 122, 123, 124, - 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 127, 127, 128, 128, 128, 128, - 129, 130, 130, 131 -}; +#define YYPACT_NINF -145 -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 3, 1, 4, 5, 0, 2, 0, 0, - 9, 0, 1, 2, 1, 2, 1, 1, 2, 2, - 2, 2, 2, 0, 1, 6, 1, 3, 3, 5, - 5, 5, 2, 3, 2, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 0, 1, 2, - 2, 3, 1, 1, 1, 3, 3, 3, 1, 0, - 1, 2, 2, 3, 1, 1, 2, 1, 3, 2, - 0, 3, 1, 3, 1, 1, 3, 2, 0, 3, - 1, 3, 1, 1, 1, 1, 1, 1, 0, 3, - 4, 4, 4, 4, 6, 5, 5, 6, 5, 5, - 5, 5, 5, 5, 5, 5, 4, 1, 1, 0, - 1, 2, 2, 3, 3, 1, 1, 0, 1, 3, - 1, 3, 1, 1, 1, 1, 1, 1, 1, 4, - 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, - 1, 1, 1, 1 -}; +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-145))) -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 0, 0, 0, 3, 0, 1, 88, 2, 35, 36, - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 153, 108, 0, 6, 87, 0, 85, 11, 0, 86, - 107, 0, 0, 0, 0, 0, 0, 0, 0, 12, - 47, 88, 0, 0, 0, 0, 117, 0, 4, 7, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 13, 14, 17, 23, 23, 23, 23, - 87, 0, 0, 48, 59, 89, 150, 106, 90, 146, - 148, 147, 149, 152, 151, 91, 92, 143, 132, 133, - 134, 135, 136, 137, 138, 139, 140, 141, 142, 123, - 124, 125, 117, 128, 93, 115, 116, 118, 120, 126, - 127, 122, 107, 0, 0, 0, 117, 0, 0, 0, - 0, 0, 0, 0, 0, 117, 0, 16, 0, 15, - 24, 19, 22, 21, 20, 0, 0, 18, 49, 0, - 52, 54, 0, 53, 107, 60, 109, 0, 0, 0, - 8, 117, 117, 96, 98, 99, 144, 101, 102, 103, - 105, 100, 104, 95, 0, 0, 0, 0, 0, 50, - 0, 0, 61, 0, 64, 0, 65, 110, 5, 121, - 119, 0, 130, 88, 97, 94, 0, 0, 0, 0, - 85, 0, 0, 0, 51, 55, 58, 57, 56, 0, - 62, 66, 67, 70, 0, 84, 111, 0, 0, 129, - 6, 145, 31, 0, 32, 34, 75, 78, 29, 0, - 26, 0, 30, 63, 0, 0, 69, 117, 0, 112, - 131, 9, 33, 0, 0, 77, 25, 0, 0, 68, - 70, 0, 72, 74, 114, 113, 0, 76, 83, 82, - 0, 80, 27, 28, 0, 71, 88, 0, 79, 73, - 10, 81 -}; +#define YYTABLE_NINF -108 -/* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = -{ - -1, 2, 4, 7, 23, 36, 49, 183, 246, 40, - 63, 126, 64, 65, 131, 66, 219, 220, 67, 68, - 69, 187, 188, 24, 74, 138, 139, 140, 141, 142, - 146, 172, 173, 174, 201, 202, 226, 241, 242, 215, - 216, 235, 250, 251, 204, 25, 26, 27, 28, 29, - 178, 206, 207, 104, 105, 106, 107, 108, 109, 110, - 181, 111, 155, 83, 84, 85, 30 -}; +#define yytable_value_is_error(Yytable_value) \ + 0 -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -#define YYPACT_NINF -145 + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ static const yytype_int16 yypact[] = { -10, -19, 54, -145, 12, -145, 219, -145, -145, -145, @@ -896,7 +733,41 @@ static const yytype_int16 yypact[] = -145, -145 }; -/* YYPGOTO[NTERM-NUM]. */ + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 0, 0, 0, 3, 0, 1, 88, 2, 35, 36, + 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, + 153, 108, 0, 6, 87, 0, 85, 11, 0, 86, + 107, 0, 0, 0, 0, 0, 0, 0, 0, 12, + 47, 88, 0, 0, 0, 0, 117, 0, 4, 7, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 13, 14, 17, 23, 23, 23, 23, + 87, 0, 0, 48, 59, 89, 150, 106, 90, 146, + 148, 147, 149, 152, 151, 91, 92, 143, 132, 133, + 134, 135, 136, 137, 138, 139, 140, 141, 142, 123, + 124, 125, 117, 128, 93, 115, 116, 118, 120, 126, + 127, 122, 107, 0, 0, 0, 117, 0, 0, 0, + 0, 0, 0, 0, 0, 117, 0, 16, 0, 15, + 24, 19, 22, 21, 20, 0, 0, 18, 49, 0, + 52, 54, 0, 53, 107, 60, 109, 0, 0, 0, + 8, 117, 117, 96, 98, 99, 144, 101, 102, 103, + 105, 100, 104, 95, 0, 0, 0, 0, 0, 50, + 0, 0, 61, 0, 64, 0, 65, 110, 5, 121, + 119, 0, 130, 88, 97, 94, 0, 0, 0, 0, + 85, 0, 0, 0, 51, 55, 58, 57, 56, 0, + 62, 66, 67, 70, 0, 84, 111, 0, 0, 129, + 6, 145, 31, 0, 32, 34, 75, 78, 29, 0, + 26, 0, 30, 63, 0, 0, 69, 117, 0, 112, + 131, 9, 33, 0, 0, 77, 25, 0, 0, 68, + 70, 0, 72, 74, 114, 113, 0, 76, 83, 82, + 0, 80, 27, 28, 0, 71, 88, 0, 79, 73, + 10, 81 +}; + + /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { -145, -145, -145, -145, 24, -2, -145, -145, -145, -145, @@ -908,11 +779,21 @@ static const yytype_int16 yypgoto[] = -145, -144, -145, -35, -31, -100, -22 }; -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -108 + /* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = +{ + -1, 2, 4, 7, 23, 36, 49, 183, 246, 40, + 63, 126, 64, 65, 131, 66, 219, 220, 67, 68, + 69, 187, 188, 24, 74, 138, 139, 140, 141, 142, + 146, 172, 173, 174, 201, 202, 226, 241, 242, 215, + 216, 235, 250, 251, 204, 25, 26, 27, 28, 29, + 178, 206, 207, 104, 105, 106, 107, 108, 109, 110, + 181, 111, 155, 83, 84, 85, 30 +}; + + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int16 yytable[] = { 35, 75, 103, 147, 37, 182, 72, 166, 20, 71, @@ -1001,8 +882,8 @@ static const yytype_int16 yycheck[] = -1, -1, -1, 39 }; -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { 0, 31, 66, 55, 67, 0, 56, 68, 4, 5, @@ -1034,95 +915,83 @@ static const yytype_uint8 yystos[] = 112, 108 }; -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 65, 66, 67, 68, 69, 70, 70, 72, 73, + 71, 74, 74, 74, 75, 75, 76, 77, 77, 78, + 78, 78, 78, 79, 79, 80, 81, 81, 82, 83, + 84, 85, 86, 86, 87, 88, 88, 88, 88, 88, + 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, + 90, 90, 91, 91, 92, 92, 93, 93, 94, 95, + 95, 95, 96, 96, 97, 97, 98, 99, 99, 100, + 101, 101, 102, 102, 103, 104, 104, 105, 106, 106, + 107, 107, 108, 108, 109, 110, 111, 111, 112, 112, + 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, + 113, 113, 113, 113, 113, 113, 113, 114, 114, 115, + 115, 115, 116, 116, 117, 118, 118, 119, 120, 120, + 121, 121, 122, 122, 122, 122, 122, 122, 123, 124, + 125, 125, 126, 126, 126, 126, 126, 126, 126, 126, + 126, 126, 126, 126, 127, 127, 128, 128, 128, 128, + 129, 130, 130, 131 +}; + + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 3, 1, 4, 5, 0, 2, 0, 0, + 9, 0, 1, 2, 1, 2, 1, 1, 2, 2, + 2, 2, 2, 0, 1, 6, 1, 3, 3, 5, + 5, 5, 2, 3, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0, 1, 2, + 2, 3, 1, 1, 1, 3, 3, 3, 1, 0, + 1, 2, 2, 3, 1, 1, 2, 1, 3, 2, + 0, 3, 1, 3, 1, 1, 3, 2, 0, 3, + 1, 3, 1, 1, 1, 1, 1, 1, 0, 3, + 4, 4, 4, 4, 6, 5, 5, 6, 5, 5, + 5, 5, 5, 5, 5, 5, 4, 1, 1, 0, + 1, 2, 2, 3, 3, 1, 1, 0, 1, 3, + 1, 3, 1, 1, 1, 1, 1, 1, 1, 4, + 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, + 1, 1, 1, 1 +}; -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 -/* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab -#define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ - YYPOPSTACK (1); \ - goto yybackup; \ - } \ - else \ - { \ +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (YYID (0)) - - -#define YYTERROR 1 -#define YYERRCODE 256 - - -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ - while (YYID (0)) -#endif + YYERROR; \ + } \ +while (0) +/* Error token number */ +#define YYTERROR 1 +#define YYERRCODE 256 -/* YY_LOCATION_PRINT -- Print the location on the stream. - This macro was not mandated originally: define only if we know - we won't break user code: when these are the locations we know. */ -#ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif -#endif - - -/* YYLEX -- calling `yylex' with the right arguments. */ - -#ifdef YYLEX_PARAM -# define YYLEX yylex (YYLEX_PARAM) -#else -# define YYLEX yylex () -#endif /* Enable debugging if requested. */ #if YYDEBUG @@ -1132,54 +1001,46 @@ while (YYID (0)) # define YYFPRINTF fprintf # endif -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (YYID (0)) +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +/* This macro is provided for backward compatibility. */ +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (YYID (0)) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +/*----------------------------------------. +| Print this symbol's value on YYOUTPUT. | +`----------------------------------------*/ + static void yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif { + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; # ifdef YYPRINT if (yytype < YYNTOKENS) YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# else - YYUSE (yyoutput); # endif - switch (yytype) - { - default: - break; - } + YYUSE (yytype); } @@ -1187,22 +1048,11 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep) | Print this symbol on YYOUTPUT. | `--------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif { - if (yytype < YYNTOKENS) - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); - else - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + YYFPRINTF (yyoutput, "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); yy_symbol_value_print (yyoutput, yytype, yyvaluep); YYFPRINTF (yyoutput, ")"); @@ -1213,66 +1063,54 @@ yy_symbol_print (yyoutput, yytype, yyvaluep) | TOP (included). | `------------------------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) -#else static void -yy_stack_print (bottom, top) - yytype_int16 *bottom; - yytype_int16 *top; -#endif +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) { YYFPRINTF (stderr, "Stack now"); - for (; bottom <= top; ++bottom) - YYFPRINTF (stderr, " %d", *bottom); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } YYFPRINTF (stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (YYID (0)) +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule) -#else -static void -yy_reduce_print (yyvsp, yyrule) - YYSTYPE *yyvsp; - int yyrule; -#endif +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) { + unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - unsigned long int yylno = yyrline[yyrule]; YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); + yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { - fprintf (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); - fprintf (stderr, "\n"); + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); + YYFPRINTF (stderr, "\n"); } } -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyvsp, Rule); \ -} while (YYID (0)) +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ @@ -1286,7 +1124,7 @@ int yydebug; /* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH +#ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif @@ -1301,7 +1139,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -1310,15 +1147,8 @@ int yydebug; # define yystrlen strlen # else /* Return the length of YYSTR. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static YYSIZE_T yystrlen (const char *yystr) -#else -static YYSIZE_T -yystrlen (yystr) - const char *yystr; -#endif { YYSIZE_T yylen; for (yylen = 0; yystr[yylen]; yylen++) @@ -1334,16 +1164,8 @@ yystrlen (yystr) # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static char * yystpcpy (char *yydest, const char *yysrc) -#else -static char * -yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -#endif { char *yyd = yydest; const char *yys = yysrc; @@ -1373,27 +1195,27 @@ yytnamerr (char *yyres, const char *yystr) char const *yyp = yystr; for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } do_not_strip_quotes: ; } @@ -1404,211 +1226,209 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) { - int yyn = yypact[yystate]; + YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } + } - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else + switch (yycount) { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; - -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - - if (yysize_overflow) - return YYSIZE_MAXIMUM; - - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ } + + { + YYSIZE_T yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) -#else -static void -yydestruct (yymsg, yytype, yyvaluep) - const char *yymsg; - int yytype; - YYSTYPE *yyvaluep; -#endif { YYUSE (yyvaluep); - if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - switch (yytype) - { - - default: - break; - } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_END } - -/* Prevent warnings from -Wmissing-prototypes. */ - -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ -/* The look-ahead symbol. */ +/* The lookahead symbol. */ int yychar; -/* The semantic value of the look-ahead symbol. */ +/* The semantic value of the lookahead symbol. */ YYSTYPE yylval; - /* Number of syntax errors so far. */ int yynerrs; - /*----------. | yyparse. | `----------*/ -#ifdef YYPARSE_PARAM -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -int -yyparse (void *YYPARSE_PARAM) -#else -int -yyparse (YYPARSE_PARAM) - void *YYPARSE_PARAM; -#endif -#else /* ! YYPARSE_PARAM */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) int yyparse (void) -#else -int -yyparse () - -#endif -#endif { - - int yystate; + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. + + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYSIZE_T yystacksize; + int yyn; int yyresult; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - /* Look-ahead token as an internal (translated) token number. */ + /* Lookahead token as an internal (translated) token number. */ int yytoken = 0; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; @@ -1616,54 +1436,22 @@ yyparse () YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif - /* Three stacks and their tools: - `yyss': related to states, - `yyvs': related to semantic values, - `yyls': related to locations. - - Refer to the stacks thru separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss = yyssa; - yytype_int16 *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - YYSTYPE *yyvsp; - - - #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - YYSIZE_T yystacksize = YYINITDEPTH; - - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - - /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yystacksize = YYINITDEPTH; + YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - - yyssp = yyss; - yyvsp = yyvs; - + yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; /*------------------------------------------------------------. @@ -1684,25 +1472,23 @@ yyparse () #ifdef yyoverflow { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE @@ -1710,23 +1496,22 @@ yyparse () # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; + goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; + yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss); - YYSTACK_RELOCATE (yyvs); - + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ @@ -1734,16 +1519,18 @@ yyparse () yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) - YYABORT; + YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + if (yystate == YYFINAL) + YYACCEPT; + goto yybackup; /*-----------. @@ -1752,20 +1539,20 @@ yyparse () yybackup: /* Do appropriate processing given the current state. Read a - look-ahead token if we need one and don't already have one. */ + lookahead token if we need one and don't already have one. */ - /* First try to decide what to do without reference to look-ahead token. */ + /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; - /* Not known => get a look-ahead token if don't already have one. */ + /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + yychar = yylex (); } if (yychar <= YYEOF) @@ -1787,29 +1574,27 @@ yyparse () yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } - if (yyn == YYFINAL) - YYACCEPT; - /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; - /* Shift the look-ahead token. */ + /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - /* Discard the shifted token unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; + /* Discard the shifted token. */ + yychar = YYEMPTY; yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END goto yynewstate; @@ -1832,7 +1617,7 @@ yyparse () yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. + '$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison @@ -1846,75 +1631,84 @@ yyparse () switch (yyn) { case 2: -#line 227 "ncgen.y" - {if (error_count > 0) YYABORT;;} +#line 227 "ncgen.y" /* yacc.c:1646 */ + {if (error_count > 0) YYABORT;} +#line 1637 "ncgeny.c" /* yacc.c:1646 */ break; case 3: -#line 230 "ncgen.y" - {createrootgroup(datasetname);;} +#line 230 "ncgen.y" /* yacc.c:1646 */ + {createrootgroup(datasetname);} +#line 1643 "ncgeny.c" /* yacc.c:1646 */ break; case 8: -#line 249 "ncgen.y" +#line 249 "ncgen.y" /* yacc.c:1646 */ { - Symbol* id = (yyvsp[(2) - (3)].sym); + Symbol* id = (yyvsp[-1].sym); markcdf4("Group specification"); if(creategroup(id) == NULL) yyerror("duplicate group declaration within parent group for %s", id->name); - ;} + } +#line 1655 "ncgeny.c" /* yacc.c:1646 */ break; case 9: -#line 258 "ncgen.y" - {listpop(groupstack);;} +#line 258 "ncgen.y" /* yacc.c:1646 */ + {listpop(groupstack);} +#line 1661 "ncgeny.c" /* yacc.c:1646 */ break; case 12: -#line 264 "ncgen.y" - {;} +#line 264 "ncgen.y" /* yacc.c:1646 */ + {} +#line 1667 "ncgeny.c" /* yacc.c:1646 */ break; case 13: -#line 266 "ncgen.y" - {markcdf4("Type specification");;} +#line 266 "ncgen.y" /* yacc.c:1646 */ + {markcdf4("Type specification");} +#line 1673 "ncgeny.c" /* yacc.c:1646 */ break; case 16: -#line 272 "ncgen.y" +#line 272 "ncgen.y" /* yacc.c:1646 */ { /* Use when defining a type */ - (yyvsp[(1) - (1)].sym)->objectclass = NC_TYPE; - if(dupobjectcheck(NC_TYPE,(yyvsp[(1) - (1)].sym))) + (yyvsp[0].sym)->objectclass = NC_TYPE; + if(dupobjectcheck(NC_TYPE,(yyvsp[0].sym))) yyerror("duplicate type declaration for %s", - (yyvsp[(1) - (1)].sym)->name); - listpush(typdefs,(void*)(yyvsp[(1) - (1)].sym)); - ;} + (yyvsp[0].sym)->name); + listpush(typdefs,(void*)(yyvsp[0].sym)); + } +#line 1685 "ncgeny.c" /* yacc.c:1646 */ break; case 17: -#line 281 "ncgen.y" - {;} +#line 281 "ncgen.y" /* yacc.c:1646 */ + {} +#line 1691 "ncgeny.c" /* yacc.c:1646 */ break; case 18: -#line 281 "ncgen.y" - {;} +#line 281 "ncgen.y" /* yacc.c:1646 */ + {} +#line 1697 "ncgeny.c" /* yacc.c:1646 */ break; case 25: -#line 295 "ncgen.y" +#line 295 "ncgen.y" /* yacc.c:1646 */ { int i; - addtogroup((yyvsp[(3) - (6)].sym)); /* sets prefix*/ - (yyvsp[(3) - (6)].sym)->objectclass=NC_TYPE; - (yyvsp[(3) - (6)].sym)->subclass=NC_ENUM; - (yyvsp[(3) - (6)].sym)->typ.basetype=(yyvsp[(1) - (6)].sym); - (yyvsp[(3) - (6)].sym)->typ.size = (yyvsp[(1) - (6)].sym)->typ.size; - (yyvsp[(3) - (6)].sym)->typ.alignment = (yyvsp[(1) - (6)].sym)->typ.alignment; - stackbase=(yyvsp[(5) - (6)].mark); + addtogroup((yyvsp[-3].sym)); /* sets prefix*/ + (yyvsp[-3].sym)->objectclass=NC_TYPE; + (yyvsp[-3].sym)->subclass=NC_ENUM; + (yyvsp[-3].sym)->typ.basetype=(yyvsp[-5].sym); + (yyvsp[-3].sym)->typ.size = (yyvsp[-5].sym)->typ.size; + (yyvsp[-3].sym)->typ.alignment = (yyvsp[-5].sym)->typ.alignment; + stackbase=(yyvsp[-1].mark); stacklen=listlength(stack); - (yyvsp[(3) - (6)].sym)->subnodes = listnew(); + (yyvsp[-3].sym)->subnodes = listnew(); /* Variety of field fixups*/ /* 1. add in the enum values*/ /* 2. make this type be their container*/ @@ -1924,83 +1718,89 @@ yyparse () Symbol* eid = (Symbol*)listget(stack,i); assert(eid->subclass == NC_ECONST); addtogroup(eid); - listpush((yyvsp[(3) - (6)].sym)->subnodes,(void*)eid); - eid->container = (yyvsp[(3) - (6)].sym); - eid->typ.basetype = (yyvsp[(3) - (6)].sym)->typ.basetype; + listpush((yyvsp[-3].sym)->subnodes,(void*)eid); + eid->container = (yyvsp[-3].sym); + eid->typ.basetype = (yyvsp[-3].sym)->typ.basetype; } listsetlength(stack,stackbase);/* remove stack nodes*/ - ;} + } +#line 1728 "ncgeny.c" /* yacc.c:1646 */ break; case 26: -#line 324 "ncgen.y" - {(yyval.mark)=listlength(stack); listpush(stack,(void*)(yyvsp[(1) - (1)].sym));;} +#line 324 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=listlength(stack); listpush(stack,(void*)(yyvsp[0].sym));} +#line 1734 "ncgeny.c" /* yacc.c:1646 */ break; case 27: -#line 326 "ncgen.y" +#line 326 "ncgen.y" /* yacc.c:1646 */ { int i; - (yyval.mark)=(yyvsp[(1) - (3)].mark); + (yyval.mark)=(yyvsp[-2].mark); /* check for duplicates*/ - stackbase=(yyvsp[(1) - (3)].mark); + stackbase=(yyvsp[-2].mark); stacklen=listlength(stack); for(i=stackbase;iname,elem->name)==0) + if(strcmp((yyvsp[0].sym)->name,elem->name)==0) yyerror("duplicate enum declaration for %s", elem->name); } - listpush(stack,(void*)(yyvsp[(3) - (3)].sym)); - ;} + listpush(stack,(void*)(yyvsp[0].sym)); + } +#line 1753 "ncgeny.c" /* yacc.c:1646 */ break; case 28: -#line 343 "ncgen.y" +#line 343 "ncgen.y" /* yacc.c:1646 */ { - (yyvsp[(1) - (3)].sym)->objectclass=NC_TYPE; - (yyvsp[(1) - (3)].sym)->subclass=NC_ECONST; - (yyvsp[(1) - (3)].sym)->typ.econst=(yyvsp[(3) - (3)].constant); - (yyval.sym)=(yyvsp[(1) - (3)].sym); - ;} + (yyvsp[-2].sym)->objectclass=NC_TYPE; + (yyvsp[-2].sym)->subclass=NC_ECONST; + (yyvsp[-2].sym)->typ.econst=(yyvsp[0].constant); + (yyval.sym)=(yyvsp[-2].sym); + } +#line 1764 "ncgeny.c" /* yacc.c:1646 */ break; case 29: -#line 352 "ncgen.y" +#line 352 "ncgen.y" /* yacc.c:1646 */ { vercheck(NC_OPAQUE); - addtogroup((yyvsp[(5) - (5)].sym)); /*sets prefix*/ - (yyvsp[(5) - (5)].sym)->objectclass=NC_TYPE; - (yyvsp[(5) - (5)].sym)->subclass=NC_OPAQUE; - (yyvsp[(5) - (5)].sym)->typ.typecode=NC_OPAQUE; - (yyvsp[(5) - (5)].sym)->typ.size=int32_val; - (yyvsp[(5) - (5)].sym)->typ.alignment=nctypealignment(NC_OPAQUE); - ;} + addtogroup((yyvsp[0].sym)); /*sets prefix*/ + (yyvsp[0].sym)->objectclass=NC_TYPE; + (yyvsp[0].sym)->subclass=NC_OPAQUE; + (yyvsp[0].sym)->typ.typecode=NC_OPAQUE; + (yyvsp[0].sym)->typ.size=int32_val; + (yyvsp[0].sym)->typ.alignment=nctypealignment(NC_OPAQUE); + } +#line 1778 "ncgeny.c" /* yacc.c:1646 */ break; case 30: -#line 364 "ncgen.y" +#line 364 "ncgen.y" /* yacc.c:1646 */ { - Symbol* basetype = (yyvsp[(1) - (5)].sym); + Symbol* basetype = (yyvsp[-4].sym); vercheck(NC_VLEN); - addtogroup((yyvsp[(5) - (5)].sym)); /*sets prefix*/ - (yyvsp[(5) - (5)].sym)->objectclass=NC_TYPE; - (yyvsp[(5) - (5)].sym)->subclass=NC_VLEN; - (yyvsp[(5) - (5)].sym)->typ.basetype=basetype; - (yyvsp[(5) - (5)].sym)->typ.typecode=NC_VLEN; - (yyvsp[(5) - (5)].sym)->typ.size=VLENSIZE; - (yyvsp[(5) - (5)].sym)->typ.alignment=nctypealignment(NC_VLEN); - ;} + addtogroup((yyvsp[0].sym)); /*sets prefix*/ + (yyvsp[0].sym)->objectclass=NC_TYPE; + (yyvsp[0].sym)->subclass=NC_VLEN; + (yyvsp[0].sym)->typ.basetype=basetype; + (yyvsp[0].sym)->typ.typecode=NC_VLEN; + (yyvsp[0].sym)->typ.size=VLENSIZE; + (yyvsp[0].sym)->typ.alignment=nctypealignment(NC_VLEN); + } +#line 1794 "ncgeny.c" /* yacc.c:1646 */ break; case 31: -#line 378 "ncgen.y" +#line 378 "ncgen.y" /* yacc.c:1646 */ { int i,j; vercheck(NC_COMPOUND); - addtogroup((yyvsp[(2) - (5)].sym)); + addtogroup((yyvsp[-3].sym)); /* check for duplicate field names*/ - stackbase=(yyvsp[(4) - (5)].mark); + stackbase=(yyvsp[-1].mark); stacklen=listlength(stack); for(i=stackbase;iobjectclass=NC_TYPE; - (yyvsp[(2) - (5)].sym)->subclass=NC_COMPOUND; - (yyvsp[(2) - (5)].sym)->typ.basetype=NULL; - (yyvsp[(2) - (5)].sym)->typ.typecode=NC_COMPOUND; - (yyvsp[(2) - (5)].sym)->subnodes = listnew(); + (yyvsp[-3].sym)->objectclass=NC_TYPE; + (yyvsp[-3].sym)->subclass=NC_COMPOUND; + (yyvsp[-3].sym)->typ.basetype=NULL; + (yyvsp[-3].sym)->typ.typecode=NC_COMPOUND; + (yyvsp[-3].sym)->subnodes = listnew(); /* Add in the fields*/ for(i=stackbase;icontainer = (yyvsp[(2) - (5)].sym); - listpush((yyvsp[(2) - (5)].sym)->subnodes,(void*)fsym); + fsym->container = (yyvsp[-3].sym); + listpush((yyvsp[-3].sym)->subnodes,(void*)fsym); } listsetlength(stack,stackbase);/* remove stack nodes*/ - ;} + } +#line 1828 "ncgeny.c" /* yacc.c:1646 */ break; case 32: -#line 410 "ncgen.y" - {(yyval.mark)=(yyvsp[(1) - (2)].mark);;} +#line 410 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=(yyvsp[-1].mark);} +#line 1834 "ncgeny.c" /* yacc.c:1646 */ break; case 33: -#line 411 "ncgen.y" - {(yyval.mark)=(yyvsp[(1) - (3)].mark);;} +#line 411 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=(yyvsp[-2].mark);} +#line 1840 "ncgeny.c" /* yacc.c:1646 */ break; case 34: -#line 415 "ncgen.y" +#line 415 "ncgen.y" /* yacc.c:1646 */ { int i; - (yyval.mark)=(yyvsp[(2) - (2)].mark); - stackbase=(yyvsp[(2) - (2)].mark); + (yyval.mark)=(yyvsp[0].mark); + stackbase=(yyvsp[0].mark); stacklen=listlength(stack); /* process each field in the fieldlist*/ for(i=stackbase;ityp.basetype = (yyvsp[(1) - (2)].sym); + f->typ.basetype = (yyvsp[-1].sym); } - ;} + } +#line 1856 "ncgeny.c" /* yacc.c:1646 */ break; case 35: -#line 428 "ncgen.y" - { (yyval.sym) = primsymbols[NC_CHAR]; ;} +#line 428 "ncgen.y" /* yacc.c:1646 */ + { (yyval.sym) = primsymbols[NC_CHAR]; } +#line 1862 "ncgeny.c" /* yacc.c:1646 */ break; case 36: -#line 429 "ncgen.y" - { (yyval.sym) = primsymbols[NC_BYTE]; ;} +#line 429 "ncgen.y" /* yacc.c:1646 */ + { (yyval.sym) = primsymbols[NC_BYTE]; } +#line 1868 "ncgeny.c" /* yacc.c:1646 */ break; case 37: -#line 430 "ncgen.y" - { (yyval.sym) = primsymbols[NC_SHORT]; ;} +#line 430 "ncgen.y" /* yacc.c:1646 */ + { (yyval.sym) = primsymbols[NC_SHORT]; } +#line 1874 "ncgeny.c" /* yacc.c:1646 */ break; case 38: -#line 431 "ncgen.y" - { (yyval.sym) = primsymbols[NC_INT]; ;} +#line 431 "ncgen.y" /* yacc.c:1646 */ + { (yyval.sym) = primsymbols[NC_INT]; } +#line 1880 "ncgeny.c" /* yacc.c:1646 */ break; case 39: -#line 432 "ncgen.y" - { (yyval.sym) = primsymbols[NC_FLOAT]; ;} +#line 432 "ncgen.y" /* yacc.c:1646 */ + { (yyval.sym) = primsymbols[NC_FLOAT]; } +#line 1886 "ncgeny.c" /* yacc.c:1646 */ break; case 40: -#line 433 "ncgen.y" - { (yyval.sym) = primsymbols[NC_DOUBLE]; ;} +#line 433 "ncgen.y" /* yacc.c:1646 */ + { (yyval.sym) = primsymbols[NC_DOUBLE]; } +#line 1892 "ncgeny.c" /* yacc.c:1646 */ break; case 41: -#line 434 "ncgen.y" - { vercheck(NC_UBYTE); (yyval.sym) = primsymbols[NC_UBYTE]; ;} +#line 434 "ncgen.y" /* yacc.c:1646 */ + { vercheck(NC_UBYTE); (yyval.sym) = primsymbols[NC_UBYTE]; } +#line 1898 "ncgeny.c" /* yacc.c:1646 */ break; case 42: -#line 435 "ncgen.y" - { vercheck(NC_USHORT); (yyval.sym) = primsymbols[NC_USHORT]; ;} +#line 435 "ncgen.y" /* yacc.c:1646 */ + { vercheck(NC_USHORT); (yyval.sym) = primsymbols[NC_USHORT]; } +#line 1904 "ncgeny.c" /* yacc.c:1646 */ break; case 43: -#line 436 "ncgen.y" - { vercheck(NC_UINT); (yyval.sym) = primsymbols[NC_UINT]; ;} +#line 436 "ncgen.y" /* yacc.c:1646 */ + { vercheck(NC_UINT); (yyval.sym) = primsymbols[NC_UINT]; } +#line 1910 "ncgeny.c" /* yacc.c:1646 */ break; case 44: -#line 437 "ncgen.y" - { vercheck(NC_INT64); (yyval.sym) = primsymbols[NC_INT64]; ;} +#line 437 "ncgen.y" /* yacc.c:1646 */ + { vercheck(NC_INT64); (yyval.sym) = primsymbols[NC_INT64]; } +#line 1916 "ncgeny.c" /* yacc.c:1646 */ break; case 45: -#line 438 "ncgen.y" - { vercheck(NC_UINT64); (yyval.sym) = primsymbols[NC_UINT64]; ;} +#line 438 "ncgen.y" /* yacc.c:1646 */ + { vercheck(NC_UINT64); (yyval.sym) = primsymbols[NC_UINT64]; } +#line 1922 "ncgeny.c" /* yacc.c:1646 */ break; case 46: -#line 439 "ncgen.y" - { vercheck(NC_STRING); (yyval.sym) = primsymbols[NC_STRING]; ;} +#line 439 "ncgen.y" /* yacc.c:1646 */ + { vercheck(NC_STRING); (yyval.sym) = primsymbols[NC_STRING]; } +#line 1928 "ncgeny.c" /* yacc.c:1646 */ break; case 48: -#line 443 "ncgen.y" - {;} +#line 443 "ncgen.y" /* yacc.c:1646 */ + {} +#line 1934 "ncgeny.c" /* yacc.c:1646 */ break; case 49: -#line 444 "ncgen.y" - {;} +#line 444 "ncgen.y" /* yacc.c:1646 */ + {} +#line 1940 "ncgeny.c" /* yacc.c:1646 */ break; case 52: -#line 451 "ncgen.y" - {;} +#line 451 "ncgen.y" /* yacc.c:1646 */ + {} +#line 1946 "ncgeny.c" /* yacc.c:1646 */ break; case 53: -#line 451 "ncgen.y" - {;} +#line 451 "ncgen.y" /* yacc.c:1646 */ + {} +#line 1952 "ncgeny.c" /* yacc.c:1646 */ break; case 56: -#line 459 "ncgen.y" +#line 459 "ncgen.y" /* yacc.c:1646 */ { - (yyvsp[(1) - (3)].sym)->dim.declsize = (size_t)extractint((yyvsp[(3) - (3)].constant)); + (yyvsp[-2].sym)->dim.declsize = (size_t)extractint((yyvsp[0].constant)); #ifdef GENDEBUG1 -fprintf(stderr,"dimension: %s = %llu\n",(yyvsp[(1) - (3)].sym)->name,(unsigned long long)(yyvsp[(1) - (3)].sym)->dim.declsize); +fprintf(stderr,"dimension: %s = %llu\n",(yyvsp[-2].sym)->name,(unsigned long long)(yyvsp[-2].sym)->dim.declsize); #endif - ;} + } +#line 1963 "ncgeny.c" /* yacc.c:1646 */ break; case 57: -#line 466 "ncgen.y" +#line 466 "ncgen.y" /* yacc.c:1646 */ { - (yyvsp[(1) - (3)].sym)->dim.declsize = NC_UNLIMITED; - (yyvsp[(1) - (3)].sym)->dim.isunlimited = 1; + (yyvsp[-2].sym)->dim.declsize = NC_UNLIMITED; + (yyvsp[-2].sym)->dim.isunlimited = 1; #ifdef GENDEBUG1 -fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); +fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[-2].sym)->name); #endif - ;} + } +#line 1975 "ncgeny.c" /* yacc.c:1646 */ break; case 58: -#line 476 "ncgen.y" +#line 476 "ncgen.y" /* yacc.c:1646 */ { - (yyvsp[(1) - (1)].sym)->objectclass=NC_DIM; - if(dupobjectcheck(NC_DIM,(yyvsp[(1) - (1)].sym))) + (yyvsp[0].sym)->objectclass=NC_DIM; + if(dupobjectcheck(NC_DIM,(yyvsp[0].sym))) yyerror( "Duplicate dimension declaration for %s", - (yyvsp[(1) - (1)].sym)->name); - addtogroup((yyvsp[(1) - (1)].sym)); - (yyval.sym)=(yyvsp[(1) - (1)].sym); - listpush(dimdefs,(void*)(yyvsp[(1) - (1)].sym)); - ;} + (yyvsp[0].sym)->name); + addtogroup((yyvsp[0].sym)); + (yyval.sym)=(yyvsp[0].sym); + listpush(dimdefs,(void*)(yyvsp[0].sym)); + } +#line 1989 "ncgeny.c" /* yacc.c:1646 */ break; case 60: -#line 488 "ncgen.y" - {;} +#line 488 "ncgen.y" /* yacc.c:1646 */ + {} +#line 1995 "ncgeny.c" /* yacc.c:1646 */ break; case 61: -#line 489 "ncgen.y" - {;} +#line 489 "ncgen.y" /* yacc.c:1646 */ + {} +#line 2001 "ncgeny.c" /* yacc.c:1646 */ break; case 64: -#line 496 "ncgen.y" - {;} +#line 496 "ncgen.y" /* yacc.c:1646 */ + {} +#line 2007 "ncgeny.c" /* yacc.c:1646 */ break; case 65: -#line 496 "ncgen.y" - {;} +#line 496 "ncgen.y" /* yacc.c:1646 */ + {} +#line 2013 "ncgeny.c" /* yacc.c:1646 */ break; case 66: -#line 499 "ncgen.y" +#line 499 "ncgen.y" /* yacc.c:1646 */ { int i; - stackbase=(yyvsp[(2) - (2)].mark); + stackbase=(yyvsp[0].mark); stacklen=listlength(stack); /* process each variable in the varlist*/ for(i=stackbase;iname); yyerror("Duplicate variable declaration for %s", sym->name); } else { - sym->typ.basetype = (yyvsp[(1) - (2)].sym); + sym->typ.basetype = (yyvsp[-1].sym); addtogroup(sym); listpush(vardefs,(void*)sym); } } listsetlength(stack,stackbase);/* remove stack nodes*/ - ;} + } +#line 2037 "ncgeny.c" /* yacc.c:1646 */ break; case 67: -#line 521 "ncgen.y" +#line 521 "ncgen.y" /* yacc.c:1646 */ {(yyval.mark)=listlength(stack); - listpush(stack,(void*)(yyvsp[(1) - (1)].sym)); - ;} + listpush(stack,(void*)(yyvsp[0].sym)); + } +#line 2045 "ncgeny.c" /* yacc.c:1646 */ break; case 68: -#line 525 "ncgen.y" - {(yyval.mark)=(yyvsp[(1) - (3)].mark); listpush(stack,(void*)(yyvsp[(3) - (3)].sym));;} +#line 525 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=(yyvsp[-2].mark); listpush(stack,(void*)(yyvsp[0].sym));} +#line 2051 "ncgeny.c" /* yacc.c:1646 */ break; case 69: -#line 529 "ncgen.y" +#line 529 "ncgen.y" /* yacc.c:1646 */ { int i; Dimset dimset; stacklen=listlength(stack); - stackbase=(yyvsp[(2) - (2)].mark); + stackbase=(yyvsp[0].mark); count = stacklen - stackbase; if(count >= NC_MAX_VAR_DIMS) { - yyerror("%s has too many dimensions",(yyvsp[(1) - (2)].sym)->name); + yyerror("%s has too many dimensions",(yyvsp[-1].sym)->name); count = NC_MAX_VAR_DIMS - 1; stacklen = stackbase + count; } @@ -2240,70 +2070,78 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); Symbol* dsym = (Symbol*)listget(stack,stackbase+i); dimset.dimsyms[i] = dsym; } - (yyvsp[(1) - (2)].sym)->typ.dimset = dimset; + (yyvsp[-1].sym)->typ.dimset = dimset; } - (yyvsp[(1) - (2)].sym)->typ.basetype = NULL; /* not yet known*/ - (yyvsp[(1) - (2)].sym)->objectclass=NC_VAR; + (yyvsp[-1].sym)->typ.basetype = NULL; /* not yet known*/ + (yyvsp[-1].sym)->objectclass=NC_VAR; listsetlength(stack,stackbase);/* remove stack nodes*/ - ;} + } +#line 2080 "ncgeny.c" /* yacc.c:1646 */ break; case 70: -#line 555 "ncgen.y" - {(yyval.mark)=listlength(stack);;} +#line 555 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=listlength(stack);} +#line 2086 "ncgeny.c" /* yacc.c:1646 */ break; case 71: -#line 556 "ncgen.y" - {(yyval.mark)=(yyvsp[(2) - (3)].mark);;} +#line 556 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=(yyvsp[-1].mark);} +#line 2092 "ncgeny.c" /* yacc.c:1646 */ break; case 72: -#line 559 "ncgen.y" - {(yyval.mark)=listlength(stack); listpush(stack,(void*)(yyvsp[(1) - (1)].sym));;} +#line 559 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=listlength(stack); listpush(stack,(void*)(yyvsp[0].sym));} +#line 2098 "ncgeny.c" /* yacc.c:1646 */ break; case 73: -#line 561 "ncgen.y" - {(yyval.mark)=(yyvsp[(1) - (3)].mark); listpush(stack,(void*)(yyvsp[(3) - (3)].sym));;} +#line 561 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=(yyvsp[-2].mark); listpush(stack,(void*)(yyvsp[0].sym));} +#line 2104 "ncgeny.c" /* yacc.c:1646 */ break; case 74: -#line 565 "ncgen.y" - {Symbol* dimsym = (yyvsp[(1) - (1)].sym); +#line 565 "ncgen.y" /* yacc.c:1646 */ + {Symbol* dimsym = (yyvsp[0].sym); dimsym->objectclass = NC_DIM; /* Find the actual dimension*/ dimsym = locate(dimsym); if(dimsym == NULL) { - derror("Undefined or forward referenced dimension: %s",(yyvsp[(1) - (1)].sym)->name); + derror("Undefined or forward referenced dimension: %s",(yyvsp[0].sym)->name); YYABORT; } (yyval.sym)=dimsym; - ;} + } +#line 2119 "ncgeny.c" /* yacc.c:1646 */ break; case 75: -#line 579 "ncgen.y" +#line 579 "ncgen.y" /* yacc.c:1646 */ {(yyval.mark)=listlength(stack); - listpush(stack,(void*)(yyvsp[(1) - (1)].sym)); - ;} + listpush(stack,(void*)(yyvsp[0].sym)); + } +#line 2127 "ncgeny.c" /* yacc.c:1646 */ break; case 76: -#line 583 "ncgen.y" - {(yyval.mark)=(yyvsp[(1) - (3)].mark); listpush(stack,(void*)(yyvsp[(3) - (3)].sym));;} +#line 583 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=(yyvsp[-2].mark); listpush(stack,(void*)(yyvsp[0].sym));} +#line 2133 "ncgeny.c" /* yacc.c:1646 */ break; case 77: -#line 588 "ncgen.y" +#line 588 "ncgen.y" /* yacc.c:1646 */ { int i; Dimset dimset; - stackbase=(yyvsp[(2) - (2)].mark); + stackbase=(yyvsp[0].mark); stacklen=listlength(stack); count = stacklen - stackbase; if(count >= NC_MAX_VAR_DIMS) { - yyerror("%s has too many dimensions",(yyvsp[(1) - (2)].sym)->name); + yyerror("%s has too many dimensions",(yyvsp[-1].sym)->name); count = NC_MAX_VAR_DIMS - 1; stacklen = stackbase + count; } @@ -2314,38 +2152,43 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); Symbol* dsym = (Symbol*)listget(stack,stackbase+i); dimset.dimsyms[i] = dsym; } - (yyvsp[(1) - (2)].sym)->typ.dimset = dimset; + (yyvsp[-1].sym)->typ.dimset = dimset; } - (yyvsp[(1) - (2)].sym)->typ.basetype = NULL; /* not yet known*/ - (yyvsp[(1) - (2)].sym)->objectclass=NC_TYPE; - (yyvsp[(1) - (2)].sym)->subclass=NC_FIELD; + (yyvsp[-1].sym)->typ.basetype = NULL; /* not yet known*/ + (yyvsp[-1].sym)->objectclass=NC_TYPE; + (yyvsp[-1].sym)->subclass=NC_FIELD; listsetlength(stack,stackbase);/* remove stack nodes*/ - (yyval.sym) = (yyvsp[(1) - (2)].sym); - ;} + (yyval.sym) = (yyvsp[-1].sym); + } +#line 2164 "ncgeny.c" /* yacc.c:1646 */ break; case 78: -#line 616 "ncgen.y" - {(yyval.mark)=listlength(stack);;} +#line 616 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=listlength(stack);} +#line 2170 "ncgeny.c" /* yacc.c:1646 */ break; case 79: -#line 617 "ncgen.y" - {(yyval.mark)=(yyvsp[(2) - (3)].mark);;} +#line 617 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=(yyvsp[-1].mark);} +#line 2176 "ncgeny.c" /* yacc.c:1646 */ break; case 80: -#line 621 "ncgen.y" - {(yyval.mark)=listlength(stack); listpush(stack,(void*)(yyvsp[(1) - (1)].sym));;} +#line 621 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=listlength(stack); listpush(stack,(void*)(yyvsp[0].sym));} +#line 2182 "ncgeny.c" /* yacc.c:1646 */ break; case 81: -#line 623 "ncgen.y" - {(yyval.mark)=(yyvsp[(1) - (3)].mark); listpush(stack,(void*)(yyvsp[(3) - (3)].sym));;} +#line 623 "ncgen.y" /* yacc.c:1646 */ + {(yyval.mark)=(yyvsp[-2].mark); listpush(stack,(void*)(yyvsp[0].sym));} +#line 2188 "ncgeny.c" /* yacc.c:1646 */ break; case 82: -#line 628 "ncgen.y" +#line 628 "ncgen.y" /* yacc.c:1646 */ { /* Anonymous integer dimension. Can only occur in type definitions*/ char anon[32]; @@ -2354,11 +2197,12 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); (yyval.sym)->objectclass = NC_DIM; (yyval.sym)->dim.isconstant = 1; (yyval.sym)->dim.declsize = uint32_val; - ;} + } +#line 2202 "ncgeny.c" /* yacc.c:1646 */ break; case 83: -#line 638 "ncgen.y" +#line 638 "ncgen.y" /* yacc.c:1646 */ { /* Anonymous integer dimension. Can only occur in type definitions*/ char anon[32]; @@ -2371,34 +2215,37 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); (yyval.sym)->objectclass = NC_DIM; (yyval.sym)->dim.isconstant = 1; (yyval.sym)->dim.declsize = int32_val; - ;} + } +#line 2220 "ncgeny.c" /* yacc.c:1646 */ break; case 84: -#line 658 "ncgen.y" - {Symbol* vsym = (yyvsp[(1) - (1)].sym); +#line 658 "ncgen.y" /* yacc.c:1646 */ + {Symbol* vsym = (yyvsp[0].sym); if(vsym->objectclass != NC_VAR) { derror("Undefined or forward referenced variable: %s",vsym->name); YYABORT; } (yyval.sym)=vsym; - ;} + } +#line 2232 "ncgeny.c" /* yacc.c:1646 */ break; case 85: -#line 669 "ncgen.y" - {Symbol* tsym = (yyvsp[(1) - (1)].sym); +#line 669 "ncgen.y" /* yacc.c:1646 */ + {Symbol* tsym = (yyvsp[0].sym); if(tsym->objectclass != NC_TYPE) { derror("Undefined or forward referenced type: %s",tsym->name); YYABORT; } (yyval.sym)=tsym; - ;} + } +#line 2244 "ncgeny.c" /* yacc.c:1646 */ break; case 86: -#line 680 "ncgen.y" - {Symbol* tvsym = (yyvsp[(1) - (1)].sym); Symbol* sym; +#line 680 "ncgen.y" /* yacc.c:1646 */ + {Symbol* tvsym = (yyvsp[0].sym); Symbol* sym; /* disambiguate*/ tvsym->objectclass = NC_VAR; sym = locate(tvsym); @@ -2406,364 +2253,438 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); tvsym->objectclass = NC_TYPE; sym = locate(tvsym); if(tvsym == NULL) { - derror("Undefined or forward referenced name: %s",(yyvsp[(1) - (1)].sym)->name); + derror("Undefined or forward referenced name: %s",(yyvsp[0].sym)->name); YYABORT; } else tvsym = sym; } else tvsym = sym; if(tvsym == NULL) { - derror("Undefined name (line %d): %s",(yyvsp[(1) - (1)].sym)->lineno,(yyvsp[(1) - (1)].sym)->name); + derror("Undefined name (line %d): %s",(yyvsp[0].sym)->lineno,(yyvsp[0].sym)->name); YYABORT; } (yyval.sym)=tvsym; - ;} + } +#line 2267 "ncgeny.c" /* yacc.c:1646 */ break; case 87: -#line 698 "ncgen.y" - {(yyval.sym)=(yyvsp[(1) - (1)].sym);;} +#line 698 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym)=(yyvsp[0].sym);} +#line 2273 "ncgeny.c" /* yacc.c:1646 */ break; case 88: -#line 705 "ncgen.y" - {;} +#line 705 "ncgen.y" /* yacc.c:1646 */ + {} +#line 2279 "ncgeny.c" /* yacc.c:1646 */ break; case 89: -#line 705 "ncgen.y" - {;} +#line 705 "ncgen.y" /* yacc.c:1646 */ + {} +#line 2285 "ncgeny.c" /* yacc.c:1646 */ break; case 90: -#line 709 "ncgen.y" - {(yyval.sym) = makespecial(_NCPROPS_FLAG,NULL,NULL,(void*)&(yyvsp[(4) - (4)].constant),ATTRGLOBAL);;} +#line 709 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_NCPROPS_FLAG,NULL,NULL,(void*)&(yyvsp[0].constant),ATTRGLOBAL);} +#line 2291 "ncgeny.c" /* yacc.c:1646 */ break; case 91: -#line 711 "ncgen.y" - {(yyval.sym) = makespecial(_ISNETCDF4_FLAG,NULL,NULL,(void*)&(yyvsp[(4) - (4)].constant),ATTRGLOBAL);;} +#line 711 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_ISNETCDF4_FLAG,NULL,NULL,(void*)&(yyvsp[0].constant),ATTRGLOBAL);} +#line 2297 "ncgeny.c" /* yacc.c:1646 */ break; case 92: -#line 713 "ncgen.y" - {(yyval.sym) = makespecial(_SUPERBLOCK_FLAG,NULL,NULL,(void*)&(yyvsp[(4) - (4)].constant),ATTRGLOBAL);;} +#line 713 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_SUPERBLOCK_FLAG,NULL,NULL,(void*)&(yyvsp[0].constant),ATTRGLOBAL);} +#line 2303 "ncgeny.c" /* yacc.c:1646 */ break; case 93: -#line 715 "ncgen.y" - { (yyval.sym)=makeattribute((yyvsp[(2) - (4)].sym),NULL,NULL,(yyvsp[(4) - (4)].datalist),ATTRGLOBAL);;} +#line 715 "ncgen.y" /* yacc.c:1646 */ + { (yyval.sym)=makeattribute((yyvsp[-2].sym),NULL,NULL,(yyvsp[0].datalist),ATTRGLOBAL);} +#line 2309 "ncgeny.c" /* yacc.c:1646 */ break; case 94: -#line 717 "ncgen.y" - {Symbol* tsym = (yyvsp[(1) - (6)].sym); Symbol* vsym = (yyvsp[(2) - (6)].sym); Symbol* asym = (yyvsp[(4) - (6)].sym); +#line 717 "ncgen.y" /* yacc.c:1646 */ + {Symbol* tsym = (yyvsp[-5].sym); Symbol* vsym = (yyvsp[-4].sym); Symbol* asym = (yyvsp[-2].sym); if(vsym->objectclass == NC_VAR) { - (yyval.sym)=makeattribute(asym,vsym,tsym,(yyvsp[(6) - (6)].datalist),ATTRVAR); + (yyval.sym)=makeattribute(asym,vsym,tsym,(yyvsp[0].datalist),ATTRVAR); } else { derror("Doubly typed attribute: %s",asym->name); YYABORT; } - ;} + } +#line 2322 "ncgeny.c" /* yacc.c:1646 */ break; case 95: -#line 726 "ncgen.y" - {Symbol* sym = (yyvsp[(1) - (5)].sym); Symbol* asym = (yyvsp[(3) - (5)].sym); +#line 726 "ncgen.y" /* yacc.c:1646 */ + {Symbol* sym = (yyvsp[-4].sym); Symbol* asym = (yyvsp[-2].sym); if(sym->objectclass == NC_VAR) { - (yyval.sym)=makeattribute(asym,sym,NULL,(yyvsp[(5) - (5)].datalist),ATTRVAR); + (yyval.sym)=makeattribute(asym,sym,NULL,(yyvsp[0].datalist),ATTRVAR); } else if(sym->objectclass == NC_TYPE) { - (yyval.sym)=makeattribute(asym,NULL,sym,(yyvsp[(5) - (5)].datalist),ATTRGLOBAL); + (yyval.sym)=makeattribute(asym,NULL,sym,(yyvsp[0].datalist),ATTRGLOBAL); } else { derror("Attribute prefix not a variable or type: %s",asym->name); YYABORT; } - ;} + } +#line 2337 "ncgeny.c" /* yacc.c:1646 */ break; case 96: -#line 737 "ncgen.y" - {(yyval.sym) = makespecial(_FILLVALUE_FLAG,(yyvsp[(1) - (5)].sym),NULL,(void*)(yyvsp[(5) - (5)].datalist),0);;} +#line 737 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_FILLVALUE_FLAG,(yyvsp[-4].sym),NULL,(void*)(yyvsp[0].datalist),0);} +#line 2343 "ncgeny.c" /* yacc.c:1646 */ break; case 97: -#line 739 "ncgen.y" - {(yyval.sym) = makespecial(_FILLVALUE_FLAG,(yyvsp[(2) - (6)].sym),(yyvsp[(1) - (6)].sym),(void*)(yyvsp[(6) - (6)].datalist),0);;} +#line 739 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_FILLVALUE_FLAG,(yyvsp[-4].sym),(yyvsp[-5].sym),(void*)(yyvsp[0].datalist),0);} +#line 2349 "ncgeny.c" /* yacc.c:1646 */ break; case 98: -#line 741 "ncgen.y" - {(yyval.sym) = makespecial(_STORAGE_FLAG,(yyvsp[(1) - (5)].sym),NULL,(void*)&(yyvsp[(5) - (5)].constant),1);;} +#line 741 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_STORAGE_FLAG,(yyvsp[-4].sym),NULL,(void*)&(yyvsp[0].constant),1);} +#line 2355 "ncgeny.c" /* yacc.c:1646 */ break; case 99: -#line 743 "ncgen.y" - {(yyval.sym) = makespecial(_CHUNKSIZES_FLAG,(yyvsp[(1) - (5)].sym),NULL,(void*)(yyvsp[(5) - (5)].datalist),0);;} +#line 743 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_CHUNKSIZES_FLAG,(yyvsp[-4].sym),NULL,(void*)(yyvsp[0].datalist),0);} +#line 2361 "ncgeny.c" /* yacc.c:1646 */ break; case 100: -#line 745 "ncgen.y" - {(yyval.sym) = makespecial(_FLETCHER32_FLAG,(yyvsp[(1) - (5)].sym),NULL,(void*)&(yyvsp[(5) - (5)].constant),1);;} +#line 745 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_FLETCHER32_FLAG,(yyvsp[-4].sym),NULL,(void*)&(yyvsp[0].constant),1);} +#line 2367 "ncgeny.c" /* yacc.c:1646 */ break; case 101: -#line 747 "ncgen.y" - {(yyval.sym) = makespecial(_DEFLATE_FLAG,(yyvsp[(1) - (5)].sym),NULL,(void*)&(yyvsp[(5) - (5)].constant),1);;} +#line 747 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_DEFLATE_FLAG,(yyvsp[-4].sym),NULL,(void*)&(yyvsp[0].constant),1);} +#line 2373 "ncgeny.c" /* yacc.c:1646 */ break; case 102: -#line 749 "ncgen.y" - {(yyval.sym) = makespecial(_SHUFFLE_FLAG,(yyvsp[(1) - (5)].sym),NULL,(void*)&(yyvsp[(5) - (5)].constant),1);;} +#line 749 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_SHUFFLE_FLAG,(yyvsp[-4].sym),NULL,(void*)&(yyvsp[0].constant),1);} +#line 2379 "ncgeny.c" /* yacc.c:1646 */ break; case 103: -#line 751 "ncgen.y" - {(yyval.sym) = makespecial(_ENDIAN_FLAG,(yyvsp[(1) - (5)].sym),NULL,(void*)&(yyvsp[(5) - (5)].constant),1);;} +#line 751 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_ENDIAN_FLAG,(yyvsp[-4].sym),NULL,(void*)&(yyvsp[0].constant),1);} +#line 2385 "ncgeny.c" /* yacc.c:1646 */ break; case 104: -#line 753 "ncgen.y" - {(yyval.sym) = makespecial(_FILTER_FLAG,(yyvsp[(1) - (5)].sym),NULL,(void*)&(yyvsp[(5) - (5)].constant),1);;} +#line 753 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_FILTER_FLAG,(yyvsp[-4].sym),NULL,(void*)&(yyvsp[0].constant),1);} +#line 2391 "ncgeny.c" /* yacc.c:1646 */ break; case 105: -#line 755 "ncgen.y" - {(yyval.sym) = makespecial(_NOFILL_FLAG,(yyvsp[(1) - (5)].sym),NULL,(void*)&(yyvsp[(5) - (5)].constant),1);;} +#line 755 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_NOFILL_FLAG,(yyvsp[-4].sym),NULL,(void*)&(yyvsp[0].constant),1);} +#line 2397 "ncgeny.c" /* yacc.c:1646 */ break; case 106: -#line 757 "ncgen.y" - {(yyval.sym) = makespecial(_FORMAT_FLAG,NULL,NULL,(void*)&(yyvsp[(4) - (4)].constant),1);;} +#line 757 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym) = makespecial(_FORMAT_FLAG,NULL,NULL,(void*)&(yyvsp[0].constant),1);} +#line 2403 "ncgeny.c" /* yacc.c:1646 */ break; case 107: -#line 762 "ncgen.y" +#line 762 "ncgen.y" /* yacc.c:1646 */ { - (yyval.sym)=(yyvsp[(1) - (1)].sym); - (yyvsp[(1) - (1)].sym)->ref.is_ref=1; - (yyvsp[(1) - (1)].sym)->is_prefixed=0; - setpathcurrent((yyvsp[(1) - (1)].sym)); - ;} + (yyval.sym)=(yyvsp[0].sym); + (yyvsp[0].sym)->ref.is_ref=1; + (yyvsp[0].sym)->is_prefixed=0; + setpathcurrent((yyvsp[0].sym)); + } +#line 2414 "ncgeny.c" /* yacc.c:1646 */ break; case 108: -#line 769 "ncgen.y" +#line 769 "ncgen.y" /* yacc.c:1646 */ { - (yyval.sym)=(yyvsp[(1) - (1)].sym); - (yyvsp[(1) - (1)].sym)->ref.is_ref=1; - (yyvsp[(1) - (1)].sym)->is_prefixed=1; + (yyval.sym)=(yyvsp[0].sym); + (yyvsp[0].sym)->ref.is_ref=1; + (yyvsp[0].sym)->is_prefixed=1; /* path is set in ncgen.l*/ - ;} + } +#line 2425 "ncgeny.c" /* yacc.c:1646 */ break; case 110: -#line 778 "ncgen.y" - {;} +#line 778 "ncgen.y" /* yacc.c:1646 */ + {} +#line 2431 "ncgeny.c" /* yacc.c:1646 */ break; case 111: -#line 779 "ncgen.y" - {;} +#line 779 "ncgen.y" /* yacc.c:1646 */ + {} +#line 2437 "ncgeny.c" /* yacc.c:1646 */ break; case 114: -#line 787 "ncgen.y" - {(yyvsp[(1) - (3)].sym)->data = (yyvsp[(3) - (3)].datalist);;} +#line 787 "ncgen.y" /* yacc.c:1646 */ + {(yyvsp[-2].sym)->data = (yyvsp[0].datalist);} +#line 2443 "ncgeny.c" /* yacc.c:1646 */ break; case 115: -#line 790 "ncgen.y" - {(yyval.datalist) = (yyvsp[(1) - (1)].datalist);;} +#line 790 "ncgen.y" /* yacc.c:1646 */ + {(yyval.datalist) = (yyvsp[0].datalist);} +#line 2449 "ncgeny.c" /* yacc.c:1646 */ break; case 116: -#line 791 "ncgen.y" - {(yyval.datalist) = (yyvsp[(1) - (1)].datalist);;} +#line 791 "ncgen.y" /* yacc.c:1646 */ + {(yyval.datalist) = (yyvsp[0].datalist);} +#line 2455 "ncgeny.c" /* yacc.c:1646 */ break; case 117: -#line 795 "ncgen.y" - {(yyval.datalist) = builddatalist(0);;} +#line 795 "ncgen.y" /* yacc.c:1646 */ + {(yyval.datalist) = builddatalist(0);} +#line 2461 "ncgeny.c" /* yacc.c:1646 */ break; case 118: -#line 799 "ncgen.y" - {(yyval.datalist) = builddatalist(0); datalistextend((yyval.datalist),&((yyvsp[(1) - (1)].constant)));;} +#line 799 "ncgen.y" /* yacc.c:1646 */ + {(yyval.datalist) = builddatalist(0); datalistextend((yyval.datalist),&((yyvsp[0].constant)));} +#line 2467 "ncgeny.c" /* yacc.c:1646 */ break; case 119: -#line 801 "ncgen.y" - {datalistextend((yyvsp[(1) - (3)].datalist),&((yyvsp[(3) - (3)].constant))); (yyval.datalist)=(yyvsp[(1) - (3)].datalist);;} +#line 801 "ncgen.y" /* yacc.c:1646 */ + {datalistextend((yyvsp[-2].datalist),&((yyvsp[0].constant))); (yyval.datalist)=(yyvsp[-2].datalist);} +#line 2473 "ncgeny.c" /* yacc.c:1646 */ break; case 120: -#line 805 "ncgen.y" - {(yyval.constant)=(yyvsp[(1) - (1)].constant);;} +#line 805 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=(yyvsp[0].constant);} +#line 2479 "ncgeny.c" /* yacc.c:1646 */ break; case 121: -#line 806 "ncgen.y" - {(yyval.constant)=builddatasublist((yyvsp[(2) - (3)].datalist));;} +#line 806 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=builddatasublist((yyvsp[-1].datalist));} +#line 2485 "ncgeny.c" /* yacc.c:1646 */ break; case 122: -#line 810 "ncgen.y" - {(yyval.constant)=(yyvsp[(1) - (1)].constant);;} +#line 810 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=(yyvsp[0].constant);} +#line 2491 "ncgeny.c" /* yacc.c:1646 */ break; case 123: -#line 811 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_OPAQUE);;} +#line 811 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_OPAQUE);} +#line 2497 "ncgeny.c" /* yacc.c:1646 */ break; case 124: -#line 812 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_FILLVALUE);;} +#line 812 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_FILLVALUE);} +#line 2503 "ncgeny.c" /* yacc.c:1646 */ break; case 125: -#line 813 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_NIL);;} +#line 813 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_NIL);} +#line 2509 "ncgeny.c" /* yacc.c:1646 */ break; case 126: -#line 814 "ncgen.y" - {(yyval.constant)=(yyvsp[(1) - (1)].constant);;} +#line 814 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=(yyvsp[0].constant);} +#line 2515 "ncgeny.c" /* yacc.c:1646 */ break; case 128: -#line 819 "ncgen.y" - {(yyval.constant) = makeenumconstref((yyvsp[(1) - (1)].sym));;} +#line 819 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant) = makeenumconstref((yyvsp[0].sym));} +#line 2521 "ncgeny.c" /* yacc.c:1646 */ break; case 129: -#line 823 "ncgen.y" - {(yyval.constant)=evaluate((yyvsp[(1) - (4)].sym),(yyvsp[(3) - (4)].datalist));;} +#line 823 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=evaluate((yyvsp[-3].sym),(yyvsp[-1].datalist));} +#line 2527 "ncgeny.c" /* yacc.c:1646 */ break; case 130: -#line 828 "ncgen.y" - {(yyval.datalist) = builddatalist(0); datalistextend((yyval.datalist),&((yyvsp[(1) - (1)].constant)));;} +#line 828 "ncgen.y" /* yacc.c:1646 */ + {(yyval.datalist) = builddatalist(0); datalistextend((yyval.datalist),&((yyvsp[0].constant)));} +#line 2533 "ncgeny.c" /* yacc.c:1646 */ break; case 131: -#line 830 "ncgen.y" - {datalistextend((yyvsp[(1) - (3)].datalist),&((yyvsp[(3) - (3)].constant))); (yyval.datalist)=(yyvsp[(1) - (3)].datalist);;} +#line 830 "ncgen.y" /* yacc.c:1646 */ + {datalistextend((yyvsp[-2].datalist),&((yyvsp[0].constant))); (yyval.datalist)=(yyvsp[-2].datalist);} +#line 2539 "ncgeny.c" /* yacc.c:1646 */ break; case 132: -#line 834 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_CHAR);;} +#line 834 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_CHAR);} +#line 2545 "ncgeny.c" /* yacc.c:1646 */ break; case 133: -#line 835 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_BYTE);;} +#line 835 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_BYTE);} +#line 2551 "ncgeny.c" /* yacc.c:1646 */ break; case 134: -#line 836 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_SHORT);;} +#line 836 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_SHORT);} +#line 2557 "ncgeny.c" /* yacc.c:1646 */ break; case 135: -#line 837 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_INT);;} +#line 837 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_INT);} +#line 2563 "ncgeny.c" /* yacc.c:1646 */ break; case 136: -#line 838 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_INT64);;} +#line 838 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_INT64);} +#line 2569 "ncgeny.c" /* yacc.c:1646 */ break; case 137: -#line 839 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_UBYTE);;} +#line 839 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_UBYTE);} +#line 2575 "ncgeny.c" /* yacc.c:1646 */ break; case 138: -#line 840 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_USHORT);;} +#line 840 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_USHORT);} +#line 2581 "ncgeny.c" /* yacc.c:1646 */ break; case 139: -#line 841 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_UINT);;} +#line 841 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_UINT);} +#line 2587 "ncgeny.c" /* yacc.c:1646 */ break; case 140: -#line 842 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_UINT64);;} +#line 842 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_UINT64);} +#line 2593 "ncgeny.c" /* yacc.c:1646 */ break; case 141: -#line 843 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_FLOAT);;} +#line 843 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_FLOAT);} +#line 2599 "ncgeny.c" /* yacc.c:1646 */ break; case 142: -#line 844 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_DOUBLE);;} +#line 844 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_DOUBLE);} +#line 2605 "ncgeny.c" /* yacc.c:1646 */ break; case 143: -#line 845 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_STRING);;} +#line 845 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_STRING);} +#line 2611 "ncgeny.c" /* yacc.c:1646 */ break; case 144: -#line 849 "ncgen.y" - {(yyval.datalist) = builddatalist(0); datalistextend((yyval.datalist),&((yyvsp[(1) - (1)].constant)));;} +#line 849 "ncgen.y" /* yacc.c:1646 */ + {(yyval.datalist) = builddatalist(0); datalistextend((yyval.datalist),&((yyvsp[0].constant)));} +#line 2617 "ncgeny.c" /* yacc.c:1646 */ break; case 145: -#line 850 "ncgen.y" - {(yyval.datalist)=(yyvsp[(1) - (3)].datalist); datalistextend((yyvsp[(1) - (3)].datalist),&((yyvsp[(3) - (3)].constant)));;} +#line 850 "ncgen.y" /* yacc.c:1646 */ + {(yyval.datalist)=(yyvsp[-2].datalist); datalistextend((yyvsp[-2].datalist),&((yyvsp[0].constant)));} +#line 2623 "ncgeny.c" /* yacc.c:1646 */ break; case 146: -#line 855 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_INT);;} +#line 855 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_INT);} +#line 2629 "ncgeny.c" /* yacc.c:1646 */ break; case 147: -#line 857 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_UINT);;} +#line 857 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_UINT);} +#line 2635 "ncgeny.c" /* yacc.c:1646 */ break; case 148: -#line 859 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_INT64);;} +#line 859 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_INT64);} +#line 2641 "ncgeny.c" /* yacc.c:1646 */ break; case 149: -#line 861 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_UINT64);;} +#line 861 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_UINT64);} +#line 2647 "ncgeny.c" /* yacc.c:1646 */ break; case 150: -#line 865 "ncgen.y" - {(yyval.constant)=makeconstdata(NC_STRING);;} +#line 865 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=makeconstdata(NC_STRING);} +#line 2653 "ncgeny.c" /* yacc.c:1646 */ break; case 151: -#line 869 "ncgen.y" - {(yyval.constant)=(yyvsp[(1) - (1)].constant);;} +#line 869 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=(yyvsp[0].constant);} +#line 2659 "ncgeny.c" /* yacc.c:1646 */ break; case 152: -#line 870 "ncgen.y" - {(yyval.constant)=(yyvsp[(1) - (1)].constant);;} +#line 870 "ncgen.y" /* yacc.c:1646 */ + {(yyval.constant)=(yyvsp[0].constant);} +#line 2665 "ncgeny.c" /* yacc.c:1646 */ break; case 153: -#line 876 "ncgen.y" - {(yyval.sym)=(yyvsp[(1) - (1)].sym);;} +#line 876 "ncgen.y" /* yacc.c:1646 */ + {(yyval.sym)=(yyvsp[0].sym);} +#line 2671 "ncgeny.c" /* yacc.c:1646 */ break; -/* Line 1267 of yacc.c. */ -#line 2765 "ncgen.tab.c" +#line 2675 "ncgeny.c" /* yacc.c:1646 */ default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -2772,8 +2693,7 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); *++yyvsp = yyval; - - /* Now `shift' the result of the reduction. Determine what state + /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ @@ -2788,10 +2708,14 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); goto yynewstate; -/*------------------------------------. -| yyerrlab -- here on detecting error | -`------------------------------------*/ +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -2799,37 +2723,36 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (yymsg); - } - else - { - yyerror (YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } @@ -2837,24 +2760,24 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); if (yyerrstatus == 3) { - /* If just tried and failed to reuse look-ahead token after an - error, discard it. */ + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = YYEMPTY; - } + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } } - /* Else will try to reuse look-ahead token after shifting the error + /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; @@ -2870,7 +2793,7 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); if (/*CONSTCOND*/ 0) goto yyerrorlab; - /* Do not reclaim the symbols of the rule which action triggered + /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; @@ -2883,38 +2806,37 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ + yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) - YYABORT; + YYABORT; yydestruct ("Error: popping", - yystos[yystate], yyvsp); + yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } - if (yyn == YYFINAL) - YYACCEPT; - + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ @@ -2938,7 +2860,7 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); yyresult = 1; goto yyreturn; -#ifndef yyoverflow +#if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -2949,17 +2871,22 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); #endif yyreturn: - if (yychar != YYEOF && yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); - /* Do not reclaim the symbols of the rule which action triggered + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); + yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow @@ -2970,12 +2897,9 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[(1) - (3)].sym)->name); if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); #endif - /* Make sure YYID is used. */ - return YYID (yyresult); + return yyresult; } - - -#line 879 "ncgen.y" +#line 879 "ncgen.y" /* yacc.c:1906 */ #ifndef NO_STDARG @@ -3057,8 +2981,7 @@ Symbol* install(const char *sname) { Symbol* sp; - sp = (Symbol*) emalloc (sizeof (struct Symbol)); - memset((void*)sp,0,sizeof(struct Symbol)); + sp = (Symbol*) ecalloc (sizeof (struct Symbol)); sp->name = nulldup(sname); sp->next = symlist; sp->lineno = lineno; @@ -3146,7 +3069,7 @@ makeconstdata(nc_type nctype) char* s; int len; len = bbLength(lextext); - s = (char*)emalloc(len+1); + s = (char*)ecalloc(len+1); strncpy(s,bbContents(lextext),len); s[len] = '\0'; con.value.opaquev.stringv = s; @@ -3157,7 +3080,7 @@ makeconstdata(nc_type nctype) break; /* no associated value*/ #endif - case NC_FILLVALUE: + case NC_FILLVALUE: break; /* no associated value*/ default: @@ -3260,7 +3183,6 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst) int tf = 0; char* sdata = NULL; int idata = -1; - unsigned int udata = 0; if((GLOBAL_SPECIAL & tag) != 0) { if(vsym != NULL) { @@ -3346,7 +3268,7 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst) else if(tag == _SUPERBLOCK_FLAG) globalspecials._Superblock = idata; else if(tag == _NCPROPS_FLAG) - globalspecials._NCProperties = strdup(sdata); + globalspecials._NCProperties = estrdup(sdata); } else { Specialdata* special; /* Set up special info */ @@ -3413,7 +3335,7 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst) case _CHUNKSIZES_FLAG: { int i; special->nchunks = list->length; - special->_ChunkSizes = (size_t*)emalloc(sizeof(size_t)*special->nchunks); + special->_ChunkSizes = (size_t*)ecalloc(sizeof(size_t)*special->nchunks); for(i=0;inchunks;i++) { iconst.nctype = NC_INT; convert1(&list->data[i],&iconst); @@ -3498,7 +3420,8 @@ containsfills(Datalist* list) for(i=0;ilength;i++,con++) { if(con->nctype == NC_COMPOUND) { if(containsfills(con->value.compoundv)) return 1; - } else if(con->nctype == NC_FILLVALUE) return 1; + } else if(con->nctype == NC_FILLVALUE) + return 1; } } return 0; @@ -3671,4 +3594,3 @@ evaluate(Symbol* fcn, Datalist* arglist) done: return result; } - diff --git a/ncgen/ncgeny.h b/ncgen/ncgeny.h index 46842d41b1..3c59b97951 100644 --- a/ncgen/ncgeny.h +++ b/ncgen/ncgeny.h @@ -1,14 +1,13 @@ -/* A Bison parser, made by GNU Bison 2.3. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ -/* Skeleton interface for Bison's Yacc-like parsers in C +/* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,9 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -33,143 +30,102 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -/* Tokens. */ +#ifndef YY_NCG_NCGEN_TAB_H_INCLUDED +# define YY_NCG_NCGEN_TAB_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif +#if YYDEBUG +extern int ncgdebug; +#endif + +/* Token type. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - NC_UNLIMITED_K = 258, - CHAR_K = 259, - BYTE_K = 260, - SHORT_K = 261, - INT_K = 262, - FLOAT_K = 263, - DOUBLE_K = 264, - UBYTE_K = 265, - USHORT_K = 266, - UINT_K = 267, - INT64_K = 268, - UINT64_K = 269, - STRING_K = 270, - IDENT = 271, - TERMSTRING = 272, - CHAR_CONST = 273, - BYTE_CONST = 274, - SHORT_CONST = 275, - INT_CONST = 276, - INT64_CONST = 277, - UBYTE_CONST = 278, - USHORT_CONST = 279, - UINT_CONST = 280, - UINT64_CONST = 281, - FLOAT_CONST = 282, - DOUBLE_CONST = 283, - DIMENSIONS = 284, - VARIABLES = 285, - NETCDF = 286, - DATA = 287, - TYPES = 288, - COMPOUND = 289, - ENUM = 290, - OPAQUE_ = 291, - OPAQUESTRING = 292, - GROUP = 293, - PATH = 294, - FILLMARKER = 295, - NIL = 296, - _FILLVALUE = 297, - _FORMAT = 298, - _STORAGE = 299, - _CHUNKSIZES = 300, - _DEFLATELEVEL = 301, - _SHUFFLE = 302, - _ENDIANNESS = 303, - _NOFILL = 304, - _FLETCHER32 = 305, - _NCPROPS = 306, - _ISNETCDF4 = 307, - _SUPERBLOCK = 308, - _FILTER = 309, - DATASETID = 310 - }; + enum yytokentype + { + NC_UNLIMITED_K = 258, + CHAR_K = 259, + BYTE_K = 260, + SHORT_K = 261, + INT_K = 262, + FLOAT_K = 263, + DOUBLE_K = 264, + UBYTE_K = 265, + USHORT_K = 266, + UINT_K = 267, + INT64_K = 268, + UINT64_K = 269, + STRING_K = 270, + IDENT = 271, + TERMSTRING = 272, + CHAR_CONST = 273, + BYTE_CONST = 274, + SHORT_CONST = 275, + INT_CONST = 276, + INT64_CONST = 277, + UBYTE_CONST = 278, + USHORT_CONST = 279, + UINT_CONST = 280, + UINT64_CONST = 281, + FLOAT_CONST = 282, + DOUBLE_CONST = 283, + DIMENSIONS = 284, + VARIABLES = 285, + NETCDF = 286, + DATA = 287, + TYPES = 288, + COMPOUND = 289, + ENUM = 290, + OPAQUE_ = 291, + OPAQUESTRING = 292, + GROUP = 293, + PATH = 294, + FILLMARKER = 295, + NIL = 296, + _FILLVALUE = 297, + _FORMAT = 298, + _STORAGE = 299, + _CHUNKSIZES = 300, + _DEFLATELEVEL = 301, + _SHUFFLE = 302, + _ENDIANNESS = 303, + _NOFILL = 304, + _FLETCHER32 = 305, + _NCPROPS = 306, + _ISNETCDF4 = 307, + _SUPERBLOCK = 308, + _FILTER = 309, + DATASETID = 310 + }; #endif -/* Tokens. */ -#define NC_UNLIMITED_K 258 -#define CHAR_K 259 -#define BYTE_K 260 -#define SHORT_K 261 -#define INT_K 262 -#define FLOAT_K 263 -#define DOUBLE_K 264 -#define UBYTE_K 265 -#define USHORT_K 266 -#define UINT_K 267 -#define INT64_K 268 -#define UINT64_K 269 -#define STRING_K 270 -#define IDENT 271 -#define TERMSTRING 272 -#define CHAR_CONST 273 -#define BYTE_CONST 274 -#define SHORT_CONST 275 -#define INT_CONST 276 -#define INT64_CONST 277 -#define UBYTE_CONST 278 -#define USHORT_CONST 279 -#define UINT_CONST 280 -#define UINT64_CONST 281 -#define FLOAT_CONST 282 -#define DOUBLE_CONST 283 -#define DIMENSIONS 284 -#define VARIABLES 285 -#define NETCDF 286 -#define DATA 287 -#define TYPES 288 -#define COMPOUND 289 -#define ENUM 290 -#define OPAQUE_ 291 -#define OPAQUESTRING 292 -#define GROUP 293 -#define PATH 294 -#define FILLMARKER 295 -#define NIL 296 -#define _FILLVALUE 297 -#define _FORMAT 298 -#define _STORAGE 299 -#define _CHUNKSIZES 300 -#define _DEFLATELEVEL 301 -#define _SHUFFLE 302 -#define _ENDIANNESS 303 -#define _NOFILL 304 -#define _FLETCHER32 305 -#define _NCPROPS 306 -#define _ISNETCDF4 307 -#define _SUPERBLOCK 308 -#define _FILTER 309 -#define DATASETID 310 - - - +/* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE -#line 142 "ncgen.y" + +union YYSTYPE { +#line 142 "ncgen.y" /* yacc.c:1909 */ + Symbol* sym; unsigned long size; /* allow for zero size to indicate e.g. UNLIMITED*/ long mark; /* track indices into the sequence*/ int nctype; /* for tracking attribute list type*/ Datalist* datalist; NCConstant constant; -} -/* Line 1529 of yacc.c. */ -#line 168 "ncgen.tab.h" - YYSTYPE; -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 + +#line 119 "ncgeny.h" /* yacc.c:1909 */ +}; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 #endif + extern YYSTYPE ncglval; +int ncgparse (void); + +#endif /* !YY_NCG_NCGEN_TAB_H_INCLUDED */ diff --git a/ncgen/odom.c b/ncgen/odom.c index 2f628fedfc..1e5a95fbe8 100644 --- a/ncgen/odom.c +++ b/ncgen/odom.c @@ -18,7 +18,7 @@ newodometer(Dimset* dimset, size_t* startp, size_t* countp) Odometer* odom; ASSERT(dimset != NULL); ASSERT(dimset->ndims > 0); - odom = (Odometer*)emalloc(sizeof(Odometer)); + odom = (Odometer*)ecalloc(sizeof(Odometer)); if(odom == NULL) return NULL; odom->origin = odom; odom->offset = 0; @@ -44,7 +44,7 @@ newsubodometer(Odometer* origin, Dimset* dimset, int start, int stop) ASSERT(dimset != NULL); ASSERT(dimset->ndims > 0 && dimset->ndims >= stop); ASSERT(stop > start); - odom = (Odometer*)emalloc(sizeof(Odometer)); + odom = (Odometer*)ecalloc(sizeof(Odometer)); if(odom == NULL) return NULL; odom->origin = origin; odom->offset = start; diff --git a/ncgen/semantics.c b/ncgen/semantics.c index 88be73c0c7..fdc5300a24 100644 --- a/ncgen/semantics.c +++ b/ncgen/semantics.c @@ -387,7 +387,9 @@ static void processenums(void) { unsigned long i,j; +#if 0 /* Unused? */ List* enumids = listnew(); +#endif for(i=0;iobjectclass == NC_TYPE); @@ -395,7 +397,9 @@ processenums(void) for(j=0;jsubnodes);j++) { Symbol* esym = (Symbol*)listget(sym->subnodes,j); ASSERT(esym->subclass == NC_ECONST); +#if 0 /* Unused? */ listpush(enumids,(void*)esym); +#endif } } /* Convert enum values to match enum type*/ @@ -443,7 +447,7 @@ processeconstrefs(void) static void processeconstrefsR(Datalist* data) { - NCConstant* con; + NCConstant* con = NULL; int i; for(i=0,con=data->data;ialloc;i++,con++) { if(con->nctype == NC_COMPOUND) { diff --git a/ncgen/util.c b/ncgen/util.c index 9b2dd70235..89571d8bf3 100644 --- a/ncgen/util.c +++ b/ncgen/util.c @@ -13,7 +13,7 @@ char* append(const char* s1, const char* s2) { int len = (s1?strlen(s1):0)+(s2?strlen(s2):0); - char* result = (char*)emalloc(len+1); + char* result = (char*)ecalloc(len+1); result[0] = '\0'; if(s1) strcat(result,s1); if(s2) strcat(result,s2); @@ -461,7 +461,7 @@ poolalloc(size_t length) if(poolindex == POOLMAX) poolindex=0; if(length == 0) length = POOL_DEFAULT; if(pool[poolindex] != NULL) efree(pool[poolindex]); - pool[poolindex] = (char*)emalloc(length); + pool[poolindex] = (char*)ecalloc(length); return pool[poolindex++]; } @@ -500,7 +500,7 @@ makebytestring(char* s, size_t* lenp) ASSERT((slen%2) == 0); ASSERT(blen > 0); - bytes = (unsigned char*)emalloc(blen); + bytes = (unsigned char*)ecalloc(blen); b = bytes; for(i=0;i