Changeset: 7ecca33bae95 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7ecca33bae95
Added Files:
sql/backends/monet5/vaults/netcdf/74_netcdf.mal
sql/backends/monet5/vaults/netcdf/Makefile.ag
sql/backends/monet5/vaults/netcdf/netcdf.c
sql/backends/monet5/vaults/netcdf/netcdf.mal
sql/backends/monet5/vaults/netcdf/netcdf_vault.h
sql/scripts/74_netcdf.sql
Modified Files:
configure.ag
sql/backends/monet5/vaults/Makefile.ag
Branch: SciQL-2-NetCDF
Log Message:
NetCDF data vault
diffs (truncated from 655 to 300 lines):
diff --git a/configure.ag b/configure.ag
--- a/configure.ag
+++ b/configure.ag
@@ -165,6 +165,13 @@ AC_ARG_ENABLE(rdf,
enable_rdf=$enableval,
enable_rdf=$dft_rdf)
+dft_netcdf=no
+AC_ARG_ENABLE(netcdf,
+ AS_HELP_STRING([--enable-netcdf],
+ [enable support for netcdf (default=no)]),
+ enable_netcdf=$enableval,
+ enable_netcdf=$dft_netcdf)
+
dft_datacell=no
AC_ARG_ENABLE(datacell,
AS_HELP_STRING([--enable-datacell],
@@ -2430,6 +2437,20 @@ AC_SUBST(gdal_LIBS, $GDAL_LIBS)
AM_CONDITIONAL(HAVE_GDAL, test x"$have_gdal" != xno)
+# netcdf
+org_have_netcdf=no
+have_netcdf=$org_have_netcdf
+if test "x$enable_netcdf" != xno; then
+ req_netcdf='4.2'
+ PKG_CHECK_MODULES([netcdf], [netcdf],
+ [AC_DEFINE(HAVE_NETCDF, 1, [Define if you have netcdf
installed])
+ have_netcdf="yes"],
+ [if test "x$enable_netcdf" = xyes; then AC_MSG_ERROR([netcdf
library required for RDF support]); fi
+ have_netcdf="no"; why_have_netcdf="(netcdf library not found)"
+ enable_netcdf=no; disable_netcdf="(netcdf library not found)"])
+fi
+AM_CONDITIONAL(HAVE_NETCDF, test x"$have_netcdf" != xno)
+
# geos, only used in geom module
org_have_geos=auto
have_geos=$org_have_geos
@@ -3325,6 +3346,7 @@ for comp in \
'geom ' \
'fits ' \
'rdf ' \
+ 'netcdf ' \
'datacell' \
'odbc ' \
'jdbc ' \
@@ -3357,6 +3379,7 @@ for comp in \
'java_jdbc ' \
'libxml2 ' \
'mseed ' \
+ 'netcdf ' \
'openssl ' \
'pcre ' \
'perl ' \
diff --git a/sql/backends/monet5/vaults/Makefile.ag
b/sql/backends/monet5/vaults/Makefile.ag
--- a/sql/backends/monet5/vaults/Makefile.ag
+++ b/sql/backends/monet5/vaults/Makefile.ag
@@ -15,7 +15,7 @@
# Copyright August 2008-2013 MonetDB B.V.
# All Rights Reserved.
-SUBDIRS = HAVE_GEOTIFF?geotiff HAVE_GDAL?gdal
+SUBDIRS = HAVE_GEOTIFF?geotiff HAVE_GDAL?gdal HAVE_NETCDF?netcdf
INCLUDES = ../../../include \
../../../common \
diff --git a/sql/backends/monet5/vaults/netcdf/74_netcdf.mal
b/sql/backends/monet5/vaults/netcdf/74_netcdf.mal
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/vaults/netcdf/74_netcdf.mal
@@ -0,0 +1,20 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.monetdb.org/Legal/MonetDBLicense
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2013 MonetDB B.V.
+# All Rights Reserved.
+
+# This loads the MonetDB/SQL module
+library netcdf;
+include netcdf;
diff --git a/sql/backends/monet5/vaults/netcdf/Makefile.ag
b/sql/backends/monet5/vaults/netcdf/Makefile.ag
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/vaults/netcdf/Makefile.ag
@@ -0,0 +1,55 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.monetdb.org/Legal/MonetDBLicense
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2013 MonetDB B.V.
+# All Rights Reserved.
+
+INCLUDES = ../.. \
+ ../../../../server \
+ ../../../../include \
+ ../../../../common \
+ ../../../../storage \
+ ../../../../../monetdb5/mal \
+ ../../../../../monetdb5/modules/atoms \
+ ../../../../../monetdb5/modules/kernel \
+ ../../../../../monetdb5/modules/mal \
+ ../../../../../monetdb5/optimizer \
+ ../../../../../clients/mapilib \
+ ../../../../../gdk \
+ ../../../../../ \
+ ../../../../../common/stream \
+ ../../../../../common/options \
+ $(netcdf_CFLAGS)
+
+lib__netcdf = {
+ MODULE
+ DIR = libdir/monetdb5
+ SOURCES = netcdf.c netcdf_vault.h
+
+ LIBS = ../../../../../monetdb5/tools/libmonetdb5 $(netcdf_LIBS)
+}
+
+headers_netcdf_mal = {
+ HEADERS = mal
+ DIR = libdir/monetdb5
+ SOURCES = netcdf.mal
+}
+
+headers_autoload = {
+ HEADERS = mal
+ DIR = libdir/monetdb5/autoload
+ SOURCES = 74_netcdf.mal
+}
+
+EXTRA_DIST = netcdf_vault.h netcdf.mal 74_netcdf.mal
diff --git a/sql/backends/monet5/vaults/netcdf/netcdf.c
b/sql/backends/monet5/vaults/netcdf/netcdf.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/vaults/netcdf/netcdf.c
@@ -0,0 +1,361 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+*/
+
+#include <monetdb_config.h>
+#include "netcdf.h"
+#include "sql_mvc.h"
+#include "sql.h"
+#include "sql_scenario.h"
+#include "mal_exception.h"
+#include "array.h"
+#include "netcdf_vault.h"
+
+#define INSFILE \
+ "INSERT INTO netcdf_files(file_id,location) \
+ VALUES(%d, '%s');"
+
+#define INSDIM \
+ "INSERT INTO netcdf_dims(dim_id,file_id,name,length) \
+VALUES(%d, %d, '%s', %d);"
+
+#define INSVAR \
+ "INSERT INTO netcdf_vars(var_id,file_id,name,vartype,ndim,coord_dim_id)
\
+VALUES(%d, %d, '%s', '%s', %d, %d);"
+
+#define INSVARDIM \
+ "INSERT INTO netcdf_vardim(var_id,dim_id,file_id,dimpos) \
+VALUES(%d, %d, %d, %d);"
+
+#define INSATTR \
+ "INSERT INTO
netcdf_attrs(obj_name,att_name,att_type,value,file_id,gr_name) \
+VALUES('%s', '%s', '%s', '%s', %d, '%s');"
+
+str
+NCDFtest(int *vars, str *fname)
+{
+ int ncid; /* dataset id */
+ int dims, ngatts, unlimdim;
+ int retval;
+
+ str msg = MAL_SUCCEED;
+
+ /* Open NetCDF file */
+ if ((retval = nc_open(*fname, NC_NOWRITE, &ncid)))
+ return createException(MAL, "netcdf.test", "Cannot open NetCDF file %s:
%s", *fname, nc_strerror(retval));
+
+ if ((retval = nc_inq(ncid, &dims, vars, &ngatts, &unlimdim)))
+ return createException(MAL, "netcdf.test", "Cannot read NetCDF header:
%s", nc_strerror(retval));
+
+ if ((retval = nc_close(ncid)))
+ return createException(MAL, "netcdf.test", "Cannot close file %s: \
+%s", *fname, nc_strerror(retval));
+
+ return msg;
+}
+
+/* use function from ncdump utility: NetCDF type number to name */
+static const char *
+prim_type_name(nc_type type)
+{
+ switch (type) {
+ case NC_BYTE:
+ return "byte";
+ case NC_CHAR:
+ return "char";
+ case NC_SHORT:
+ return "short";
+ case NC_INT:
+ return "int";
+ case NC_FLOAT:
+ return "float";
+ case NC_DOUBLE:
+ return "double";
+#ifdef USE_NETCDF4
+ case NC_UBYTE:
+ return "ubyte";
+ case NC_USHORT:
+ return "ushort";
+ case NC_UINT:
+ return "uint";
+ case NC_INT64:
+ return "int64";
+ case NC_UINT64:
+ return "uint64";
+ case NC_STRING:
+ return "string";
+#endif /* USE_NETCDF4 */
+ default:
+ return "bad type";
+ }
+}
+
+
+str
+NCDFattach(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ mvc *m = NULL;
+ sql_schema *sch = NULL;
+ sql_table *tfiles = NULL, *tdims = NULL, *tvars = NULL, *tvardim = NULL,
*tattrs = NULL;
+ sql_column *col;
+ str msg = MAL_SUCCEED;
+ str fname = *(str*)getArgReference(stk, pci, 1);
+ char buf[BUFSIZ], *s= buf;
+ oid fid, rid = oid_nil;
+
+ int ncid; /* dataset id */
+ int ndims, nvars, ngatts, unlimdim;
+ int didx, vidx, vndims, vnatts, i, aidx, coord_dim_id = -1;
+ int vdims[NC_MAX_VAR_DIMS];
+
+ size_t dlen, alen;
+ char dname[NC_MAX_NAME+1], vname[NC_MAX_NAME+1], aname[NC_MAX_NAME +1],
+ abuf[80], *aval;
+ char **dims = NULL;
+ nc_type vtype, atype; /* == int */
+
+ int retval, avalint;
+ float avalfl;
+ double avaldbl;
+
+ msg = getSQLContext(cntxt, mb, &m, NULL);
+ if (msg)
+ return msg;
+
+ sch = mvc_bind_schema(m, "sys");
+ if ( !sch )
+ return createException(MAL, "netcdf.attach", "Cannot get schema sys\n");
+
+ tfiles = mvc_bind_table(m, sch, "netcdf_files");
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list