Moving provenance info out so that it doesn't depend on netCDF4 support to display.

This commit is contained in:
Ward Fisher 2018-11-27 16:09:17 -07:00
parent 231e1a28af
commit a8673c3dfe
5 changed files with 77 additions and 57 deletions

View File

@ -19,7 +19,8 @@ ncuri.h ncutf8.h ncdispatch.h ncdimscale.h netcdf_f.h err_macros.h \
ncbytes.h nchashmap.h ceconstraints.h rnd.h nclog.h ncconfigure.h \
nc4internal.h nctime.h nc3internal.h onstack.h ncrc.h ncauth.h \
ncoffsets.h nctestserver.h nc4dispatch.h nc3dispatch.h ncexternl.h \
ncwinpath.h ncfilter.h ncindex.h hdf4dispatch.h hdf5internal.h
ncwinpath.h ncfilter.h ncindex.h hdf4dispatch.h hdf5internal.h \
nc_provenance.h
if USE_DAP
noinst_HEADERS += ncdap.h

View File

@ -21,6 +21,7 @@
#include "ncdimscale.h"
#include "nc_logging.h"
#include "ncindex.h"
#include "nc_provenance.h"
#ifdef USE_PARALLEL
#include "netcdf_par.h"
@ -451,34 +452,6 @@ extern const NC_reservedatt* NC_findreserved(const char* name);
#define NC_ATT_COORDINATES COORDINATES /*defined above*/
#define NC_ATT_FORMAT "_Format"
/**************************************************/
/**
For netcdf4 files, capture state information about the following:
1. Global: netcdf library version
2. Global: hdf5 library version
3. Per file: superblock version
4. Per File: was it created by netcdf-4?
5. Per file: _NCProperties attribute
*/
/* Most of this needs to be moved to hdf5internal.h */
#define NCPROPS "_NCProperties"
#define NCPVERSION "version" /* Of the properties format */
#define NCPHDF5LIB1 "hdf5libversion"
#define NCPNCLIB1 "netcdflibversion"
#define NCPHDF5LIB2 "hdf5"
#define NCPNCLIB2 "netcdf"
#define NCPROPS_VERSION (2)
/* Version 2 changes this because '|' was causing bash problems */
#define NCPROPSSEP1 '|'
#define NCPROPSSEP2 ','
/* Other hidden attributes */
#define ISNETCDF4ATT "_IsNetcdf4"
#define SUPERBLOCKATT "_SuperblockVersion"
struct NCPROVENANCE {
int superblockversion;
struct NCPROPINFO {
@ -488,7 +461,7 @@ struct NCPROVENANCE {
"netcdflibversion=<version|hdf5libversion=<version>"
Version 2 format is:
"<mainbuildlib>=<version|<supportlib1>=<version>...|<other>=..."
*/
*/
/* The _NCProperties values are stored as an arbitrary
set of (key,value) pairs */
/* It is assumed that the first entry is the primary library

47
include/nc_provenance.h Normal file
View File

@ -0,0 +1,47 @@
/* Copyright 2005-2018 University Corporation for Atmospheric
Research/Unidata. */
/**
/**
* @file
* @internal Contains information for creating provenance
* info and/or displaying provenance info.
*
* @author Dennis Heimbigner, Ward Fisher
/**************************************************/
/**
It has come to pass that we can't guarantee that this information is
contained only within netcdf4 files. As a result, we need
to make printing these hidden attributes available to
netcdf3 as well.
For netcdf4 files, capture state information about the following:
1. Global: netcdf library version
2. Global: hdf5 library version
3. Per file: superblock version
4. Per File: was it created by netcdf-4?
5. Per file: _NCProperties attribute
*/
#ifndef _NCPROVENANCE_
#define _NCPROVENANCE_
#define NCPROPS "_NCProperties"
#define NCPVERSION "version" /* Of the properties format */
#define NCPHDF5LIB1 "hdf5libversion"
#define NCPNCLIB1 "netcdflibversion"
#define NCPHDF5LIB2 "hdf5"
#define NCPNCLIB2 "netcdf"
#define NCPROPS_VERSION (2)
/* Version 2 changes this because '|' was causing bash problems */
#define NCPROPSSEP1 '|'
#define NCPROPSSEP2 ','
/* Other hidden attributes */
#define ISNETCDF4ATT "_IsNetcdf4"
#define SUPERBLOCKATT "_SuperblockVersion"
#endif /* _NCPROVENANCE_ */

View File

@ -696,29 +696,29 @@ copy_var_filter(int igrp, int varid, int ogrp, int o_varid, int inkind, int outk
outputdefined = 0; /* default is no filter defined */
/* Only bother to look if output is netcdf-4 variant */
if(outnc4) {
/* See if any output filter spec is defined for this output variable */
for(i=0;i<nfilterspecs;i++) {
/* See if any output filter spec is defined for this output variable */
for(i=0;i<nfilterspecs;i++) {
if(strcmp(filterspecs[i].fqn,ofqn)==0) {
ospec = filterspecs[i];
outputdefined = 1;
break;
ospec = filterspecs[i];
outputdefined = 1;
break;
}
}
}
}
/* Is there a filter on the input variable */
inputdefined = 0; /* default is no filter defined */
/* Only bother to look if input is netcdf-4 variant */
if(innc4) {
stat=nc_inq_var_filter(vid.grpid,vid.varid,&inspec.filterid,&inspec.nparams,NULL);
if(stat && stat != NC_EFILTER)
stat=nc_inq_var_filter(vid.grpid,vid.varid,&inspec.filterid,&inspec.nparams,NULL);
if(stat && stat != NC_EFILTER)
goto done; /* true error */
if(stat == NC_NOERR) {/* input has a filter */
if(stat == NC_NOERR) {/* input has a filter */
inspec.params = (unsigned int*)malloc(sizeof(unsigned int)*inspec.nparams);
if((stat=nc_inq_var_filter(vid.grpid,vid.varid,&inspec.filterid,&inspec.nparams,inspec.params)))
goto done;
goto done;
inputdefined = 1;
}
}
}
/* Rules for choosing output filter are as follows:
@ -737,17 +737,17 @@ copy_var_filter(int igrp, int varid, int ogrp, int o_varid, int inkind, int outk
unfiltered = 0;
if(suppressfilters && !outputdefined) /* row 1 */
unfiltered = 1;
unfiltered = 1;
else if(suppressfilters && outputdefined && ospec.nofilter) /* row 2 */
unfiltered = 1;
unfiltered = 1;
else if(suppressfilters && outputdefined) /* row 3 */
actualspec = ospec;
actualspec = ospec;
else if(!suppressfilters && !outputdefined && inputdefined) /* row 4 */
actualspec = inspec;
actualspec = inspec;
else if(!suppressfilters && outputdefined && ospec.nofilter) /* row 5 */
unfiltered = 1;
unfiltered = 1;
else if(!suppressfilters && outputdefined) /* row 6 */
actualspec = ospec;
actualspec = ospec;
/* Apply actual filter spec if any */
if(!unfiltered) {
@ -836,7 +836,7 @@ copy_chunking(int igrp, int i_varid, int ogrp, int o_varid, int ndims, int inkin
int odimid = dimmap_odimid(idimid);
size_t chunksize;
size_t dimlen;
/* Get input dimension length */
NC_CHECK(nc_inq_dimlen(igrp, idimid, &dimlen));
@ -853,7 +853,7 @@ copy_chunking(int igrp, int i_varid, int ogrp, int o_varid, int ndims, int inkin
ocontig = 0; /* cannot use contiguous */
goto next;
}
/* Not specified in -c; Apply defaulting rules as defined in nccopy.1 */
/* If input is chunked, then use that chunk size */

View File

@ -49,6 +49,7 @@ int optind;
#include "nclog.h"
#include "ncwinpath.h"
#include "netcdf_aux.h"
#include "nc_provenance.h"
#ifdef USE_NETCDF4
#include "nc4internal.h" /* to get name of the special properties file */
@ -1067,7 +1068,7 @@ pr_att_specials(
printf(" = \"%u",id);
if(nparams > 0) {
int i;
for(i=0;i<nparams;i++)
for(i=0;i<nparams;i++)
printf(",%u",params[i]);
}
printf("\" ;\n");
@ -1095,7 +1096,7 @@ pr_att_specials(
}
#endif /* USE_NETCDF4 */
#ifdef USE_NETCDF4
static void
pr_att_hidden(
int ncid,
@ -1145,7 +1146,6 @@ pr_att_hidden(
}
}
}
#endif /* USE_NETCDF4 */
/*
* Print a variable attribute for NcML
@ -1798,9 +1798,8 @@ do_ncdump_rec(int ncid, const char *path)
}
if (is_root && formatting_specs.special_atts) { /* output special attribute
* for format variant */
#ifdef USE_NETCDF4
pr_att_hidden(ncid, kind);
#endif
pr_att_hidden(ncid, kind);
pr_att_global_format(ncid, kind);
}
@ -2155,7 +2154,7 @@ main(int argc, char *argv[])
int Xp_flag = 0; /* indicate that -Xp flag was set */
char* path = NULL;
char errmsg[4096];
errmsg[0] = '\0';
#if defined(WIN32) || defined(msdos) || defined(WIN64)
@ -2353,7 +2352,7 @@ main(int argc, char *argv[])
} else /* just a file */
ncstat = nc_open(path, NC_NOWRITE, &ncid);
if (ncstat != NC_NOERR) goto fail;
NC_CHECK( nc_inq_format(ncid, &formatting_specs.nc_kind) );
NC_CHECK( nc_inq_format_extended(ncid,
&formatting_specs.nc_extended,