Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias stringlength url parameter and maxstrlen #619

Merged
merged 9 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions docs/OPeNDAP.dox
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*! \page dap2 DAP2 Support
/*!
\page dap2 DAP2 Support

\tableofcontents

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:

Expand Down Expand Up @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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=<file>" - Turn on logging and send the log output to
Expand All @@ -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_<var>=NN" - Specify the default string length to use
for a string dimension for the specified variable. The default is
64.
64. The name "maxstrlen_<var>" is an alias for "stringlength_<var>".
- "cache" - This enables caching.
- "cachelimit=NN" - Specify the maximum amount of space allowed for
the cache.
Expand Down
9 changes: 6 additions & 3 deletions libdap2/cdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,13 +810,15 @@ fprintf(stderr,"dimsettrans3: node=%s/%d\n",node->ocname,nclistlength(node->arra
dimsettrans = clonedimset(nccomm,node->container->array.dimsettrans,node);
}
/* concat parent dimset0 and dimset;*/
if(dimsettrans == NULL)
dimsettrans = nclistnew();
for(i=0;i<nclistlength(node->array.dimset0);i++) {
CDFnode* clone = NULL;
if(dimsettrans == NULL) dimsettrans = nclistnew();
clone = (CDFnode*)nclistget(node->array.dimset0,i);
CDFnode* clone = NULL;
clone = (CDFnode*)nclistget(node->array.dimset0,i);
nclistpush(dimsettrans,(void*)clone);
}
node->array.dimsettrans = dimsettrans;
dimsettrans = NULL;
#ifdef DEBUG1
fprintf(stderr,"dimsettrans: |%s|=%d\n",node->ocname,(int)nclistlength(dimsettrans));
#endif
Expand Down Expand Up @@ -1105,6 +1107,7 @@ free1cdfnode(CDFnode* node)
nclistfree(node->array.dimsetplus);
nclistfree(node->array.dimsetall);
nclistfree(node->array.dimset0);
nclistfree(node->array.dimsettrans);

/* Clean up the ncdap4 fields also */
nullfree(node->typename);
Expand Down
17 changes: 13 additions & 4 deletions libdap2/ncd2dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ constrainable(NCURI* durl)
return 0;
}

/* Lookup a parameter key; case insensitive */
static const char*
paramlookup(NCDAPCOMMON* state, const char* key)
{
Expand All @@ -1213,7 +1214,7 @@ applyclientparams(NCDAPCOMMON* nccomm)
int dfaltseqlim = DEFAULTSEQLIMIT;
const char* value;
char tmpname[NC_MAX_NAME+32];
char* pathstr;
char* pathstr = NULL;
OClink conn = nccomm->oc.conn;
unsigned long limit;

Expand Down Expand Up @@ -1259,21 +1260,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;i<nclistlength(nccomm->cdf.ddsroot->tree->varnodes);i++) {
CDFnode* var = (CDFnode*)nclistget(nccomm->cdf.ddsroot->tree->varnodes,i);
/* Define the client param stringlength for this variable*/
/* Define the client param stringlength/maxstrlen for this variable*/
/* create the variable path name */
var->maxstringlength = 0; /* => use global dfalt */
strncpy(tmpname,"stringlength_",sizeof(tmpname));
pathstr = makeocpathstring(conn,var->ocnode,".");
strlcat(tmpname,pathstr,sizeof(tmpname));
nullfree(pathstr);
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;
}
Expand Down
1 change: 1 addition & 0 deletions libdispatch/ddispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ NC_urlmodel(const char* path, int mode, char** newurl)
}
if(newurl)
*newurl = ncuribuild(url,NULL,NULL,NCURIALL);
if(url) ncurifree(url);
return model;
fail:
if(url) ncurifree(url);
Expand Down
4 changes: 2 additions & 2 deletions libdispatch/drc.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ rcorder(NClist* rc)
{
int i;
int len = nclistlength(rc);
NClist* tmprc = nclistnew();
NClist* tmprc = NULL;
if(rc == NULL || len == 0) return;
tmprc = nclistnew();
/* Copy rc into tmprc and clear rc */
for(i=0;i<len;i++) {
NCTriple* ti = nclistget(rc,i);
Expand All @@ -249,7 +250,6 @@ rcorder(NClist* rc)
storedump("reorder:",rc);
#endif
nclistfree(tmprc);

}

/* Create a triple store from a file */
Expand Down
6 changes: 4 additions & 2 deletions libdispatch/ncuri.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion nc_test4/Make0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Test c output
T=tst_dims
T=t_dap3a

#SRC=hdf5plugins/H5Zmisc.c

Expand Down
3 changes: 2 additions & 1 deletion ncdap_test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ clean-local-check:
-rm -rf results
-rm -f .dodsrc


# If valgrind is present, add valgrind targets.
@VALGRIND_CHECK_RULES@
13 changes: 12 additions & 1 deletion ncdap_test/t_srcdir.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
static const char*
gettopsrcdir(void)
{
const char* topsrcdir;
const char* topsrcdir = NULL;
#ifdef TOPSRCDIR
topsrcdir = STRINGIFY(TOPSRCDIR);
#else
static char tsd[4096];
extern char *getcwd(char *buf, size_t size);
tsd[0] = '\0';
getcwd(tsd,sizeof(tsd));
if(strlen(tsd) > 0) {
strcat(tsd,"/..");
topsrcdir = tsd;
}
#endif
if(topsrcdir == NULL) {
fprintf(stderr,"*** FAIL: $abs_top_srcdir not defined\n");
exit(1);
Expand Down
23 changes: 20 additions & 3 deletions ncdap_test/testurl.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

#NOP=1
#NOP=1
#NOS=1
#NOB=1

Expand Down Expand Up @@ -30,6 +30,7 @@ PREFIX="[log][show=fetch]"
SUFFIX="log&show=fetch"
BOTHP="[log][show=fetch]"
BOTHS="noprefetch&fetch=disk"
STRLEN="[maxstrlen=16]"

locreset () {
rm -f ./tmp_testurl ./errtmp_testurl
Expand Down Expand Up @@ -57,8 +58,25 @@ if test "x$NOP" != x1 ; then
echo "***Testing url prefix parameters"
buildurl $PREFIX ""
# Invoke ncdump to extract the URL

echo "command: ${NCDUMP} -h $url"

${NCDUMP} -h "$url" >./tmp_testurl 2> ./errtmp_testurl
if test "x${SHOW}" = x1 ; then cat ./tmp ; 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
Expand All @@ -71,6 +89,7 @@ if test "x${SHOW}" = x1 ; then cat ./tmp_testurl ; fi
fi

locreset

if test "x$NOB" != x1 ; then
echo "***Testing url prefix+suffix parameters"
buildurl $BOTHP $BOTHS
Expand All @@ -87,5 +106,3 @@ if test "x$pass" = x0 ; then
fi
echo "***PASS"
exit 0