Changeset: 18ccf0f79b19 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=18ccf0f79b19
Modified Files:
sql/backends/monet5/vaults/netcdf/netcdf.c
sql/backends/monet5/vaults/netcdf/netcdf.mal
sql/backends/monet5/vaults/netcdf/netcdf_vault.h
Branch: SciQL-2-NetCDF
Log Message:
Import NetCDF variables
diffs (truncated from 886 to 300 lines):
diff --git a/sql/backends/monet5/vaults/netcdf/netcdf.c
b/sql/backends/monet5/vaults/netcdf/netcdf.c
--- a/sql/backends/monet5/vaults/netcdf/netcdf.c
+++ b/sql/backends/monet5/vaults/netcdf/netcdf.c
@@ -31,246 +31,280 @@
VALUES(%d, '%s');"
#define INSDIM \
- "INSERT INTO netcdf_dims(dim_id,file_id,name,length) \
+ "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)
\
+ "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) \
+ "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) \
+ "INSERT INTO
netcdf_attrs(obj_name,att_name,att_type,value,file_id,gr_name) \
VALUES('%s', '%s', '%s', '%s', %d, '%s');"
+#define LOAD_NCDF_VAR(tpe,ncdftpe) \
+ { \
+ tpe *databuf; \
+ res = BATnew(TYPE_void, TYPE_##tpe, sz); \
+ if ( res == NULL ) \
+ return createException(MAL, "netcdf.importvar",
MAL_MALLOC_FAIL); \
+ BATseqbase(res, 0); \
+ databuf = (tpe *)Tloc(res, BUNfirst(res)); \
+ if ( (retval = nc_get_var_##ncdftpe(ncid, varid, databuf)) ) \
+ return createException(MAL, "netcdf.importvar", \
+ "Cannot read variable %d
values: %s", \
+ varid, nc_strerror(retval));
\
+ }
+
str
NCDFtest(int *vars, str *fname)
{
- int ncid; /* dataset id */
- int dims, ngatts, unlimdim;
- int retval;
+ int ncid; /* dataset id */
+ int dims, ngatts, unlimdim;
+ int retval;
- str msg = MAL_SUCCEED;
+ str msg = MAL_SUCCEED;
/* Open NetCDF file */
- if ((retval = nc_open(*fname, NC_NOWRITE, &ncid)))
+ 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)))
+ 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: \
+ if ((retval = nc_close(ncid)))
+ return createException(MAL, "netcdf.test", "Cannot close file %s: \
%s", *fname, nc_strerror(retval));
- return msg;
+ 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";
+ 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";
+ 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";
- }
+ default:
+ return "bad type";
+ }
}
+/* To Do: check SQL/SciQL type correspondence */
+
+static str
+NCDFARRAYseries(bat *bid, bte start, bte step, int stop, int group, int series)
+{
+ if (stop <= (int) GDK_bte_max && group <= (int) GDK_bte_max &&
+ series <= (int) GDK_bte_max) {
+ bte sta = (bte) start, ste = (bte) step, sto = (bte) stop;
+ return ARRAYseries_bte(bid, &sta, &ste, &sto, &group, &series);
+ }
+ else if (stop <= (int) GDK_sht_max && group <= (int) GDK_sht_max &&
+ series <= (int) GDK_sht_max) {
+ sht sta = (sht) start, ste = (sht) step, sto = (sht) stop;
+ return ARRAYseries_sht(bid, &sta, &ste, &sto, &group, &series);
+ }
+ else {
+ int sta = (int) start, ste = (int) step, sto = (int) stop;
+ return ARRAYseries_int(bid, &sta, &ste, &sto, &group, &series);
+ }
+}
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;
+ 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];
+ 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 */
+ 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;
+ int retval, avalint;
+ float avalfl;
+ double avaldbl;
- msg = getSQLContext(cntxt, mb, &m, NULL);
- if (msg)
- return msg;
+ 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");
+ 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");
- tdims = mvc_bind_table(m, sch, "netcdf_dims");
- tvars = mvc_bind_table(m, sch, "netcdf_vars");
- tvardim = mvc_bind_table(m, sch, "netcdf_vardim");
- tattrs = mvc_bind_table(m, sch, "netcdf_attrs");
+ tfiles = mvc_bind_table(m, sch, "netcdf_files");
+ tdims = mvc_bind_table(m, sch, "netcdf_dims");
+ tvars = mvc_bind_table(m, sch, "netcdf_vars");
+ tvardim = mvc_bind_table(m, sch, "netcdf_vardim");
+ tattrs = mvc_bind_table(m, sch, "netcdf_attrs");
- if (tfiles == NULL || tdims == NULL || tvars == NULL ||
- tvardim == NULL || tattrs == NULL)
- return createException(MAL, "netcdf.attach", "Catalog table mi\
+ if (tfiles == NULL || tdims == NULL || tvars == NULL ||
+ tvardim == NULL || tattrs == NULL)
+ return createException(MAL, "netcdf.attach", "Catalog table mi\
ssing\n");
- /* check if the file is already attached */
- col = mvc_bind_column(m, tfiles, "location");
- rid = table_funcs.column_find_row(m->session->tr, col, fname, NULL);
- if (rid != oid_nil)
- return createException(SQL, "netcdf.attach", "File %s is already a\
+ /* check if the file is already attached */
+ col = mvc_bind_column(m, tfiles, "location");
+ rid = table_funcs.column_find_row(m->session->tr, col, fname, NULL);
+ if (rid != oid_nil)
+ return createException(SQL, "netcdf.attach", "File %s is already a\
ttached\n", fname);
- /* Open NetCDF file */
- if ((retval = nc_open(fname, NC_NOWRITE, &ncid)))
- return createException(MAL, "netcdf.test", "Cannot open NetCDF \
+ /* 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, &ndims, &nvars, &ngatts, &unlimdim)))
- return createException(MAL, "netcdf.test", "Cannot read NetCDF \
+ if ((retval = nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdim)))
+ return createException(MAL, "netcdf.test", "Cannot read NetCDF \
header: %s", nc_strerror(retval));
- /* Insert row into netcdf_files table */
- col = mvc_bind_column(m, tfiles, "file_id");
- fid = store_funcs.count_col(col, 1) + 1;
+ /* Insert row into netcdf_files table */
+ col = mvc_bind_column(m, tfiles, "file_id");
+ fid = store_funcs.count_col(col, 1) + 1;
- snprintf(buf, BUFSIZ, INSFILE, (int)fid, fname);
- if ( ( msg = SQLstatementIntern(cntxt,&s,"netcdf.attach",TRUE,FALSE))
- != MAL_SUCCEED )
- goto finish;
+ snprintf(buf, BUFSIZ, INSFILE, (int)fid, fname);
+ if ( ( msg = SQLstatementIntern(cntxt,&s,"netcdf.attach",TRUE,FALSE))
+ != MAL_SUCCEED )
+ goto finish;
- /* Read dimensions from NetCDF header and insert a row for each one into
netcdf_dims table */
+ /* Read dimensions from NetCDF header and insert a row for each one
into netcdf_dims table */
- dims = (char **)GDKzalloc(sizeof(char *) * ndims);
- for (didx = 0; didx < ndims; didx++){
- if ((retval = nc_inq_dim(ncid, didx, dname, &dlen)))
- return createException(MAL, "netcdf.attach", "Cannot read dimension %d :
%s", didx, nc_strerror(retval));
+ dims = (char **)GDKzalloc(sizeof(char *) * ndims);
+ for (didx = 0; didx < ndims; didx++){
+ if ((retval = nc_inq_dim(ncid, didx, dname, &dlen)))
+ return createException(MAL, "netcdf.attach", "Cannot read dimension
%d : %s", didx, nc_strerror(retval));
- snprintf(buf, BUFSIZ, INSDIM, didx, (int)fid, dname, (int)dlen);
- if ( ( msg = SQLstatementIntern(cntxt,&s,"netcdf.attach",TRUE,FALSE))
+ snprintf(buf, BUFSIZ, INSDIM, didx, (int)fid, dname, (int)dlen);
+ if ( ( msg = SQLstatementIntern(cntxt,&s,"netcdf.attach",TRUE,FALSE))
!= MAL_SUCCEED )
- goto finish;
+ goto finish;
- dims[didx] = GDKstrdup(dname);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list