Changeset: 6c50cfe36233 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6c50cfe36233
Modified Files:
Branch: sciql
Log Message:
merged with default
diffs (truncated from 401 to 300 lines):
diff --git a/sql/backends/monet5/vaults/fits.c
b/sql/backends/monet5/vaults/fits.c
--- a/sql/backends/monet5/vaults/fits.c
+++ b/sql/backends/monet5/vaults/fits.c
@@ -196,6 +196,374 @@
return 1;
}
+str FITSexportTable(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ str msg = MAL_SUCCEED;
+ str tname = *(str*) getArgReference(stk, pci, 1);
+ mvc *m = NULL;
+ sql_schema *sch;
+ sql_table *tbl, *column, *tables = NULL;
+ sql_column *col;
+ oid rid = oid_nil;
+ str type, name, *colname, *tform;
+ fitsfile *fptr;
+ char filename[BUFSIZ];
+ long nrows = 0, optimal;
+ rids * rs;
+
+ int tm0, texportboolean=0, texportchar=0, texportstring=0,
texportshort=0, texportint=0, texportlong=0, texportfloat=0, texportdouble=0;
+ int numberrow = 0, cc = 0, status = 0, j = 0, columns, fid, dimension =
0, block = 0;
+ int boolcols = 0, charcols = 0, strcols = 0, shortcols = 0, intcols =
0, longcols = 0, floatcols = 0, doublecols = 0;
+ int hdutype;
+
+ char charvalue, *readcharrows;
+ str strvalue; char **readstrrows;
+ short shortvalue, *readshortrows;
+ int intvalue, *readintrows;
+ long longvalue, *readlongrows;
+ float realvalue, *readfloatrows;
+ double doublevalue, *readdoublerows;
+ _Bool boolvalue, *readboolrows;
+ struct list * set;
+
+ msg = getContext(cntxt, mb, &m, NULL);
+ if (msg)
+ return msg;
+
+ sch = mvc_bind_schema(m, "sys");
+
+ /* First step: look if the table exists in the database. If the table
is not in the database, the export function cannot continue */
+
+ tbl = mvc_bind_table(m, sch, tname);
+ if (tbl == NULL) {
+ msg = createException (MAL, "fits.exporttable", "Table %s is
missing.\n", tname);
+ return msg;
+ }
+
+ set = (*tbl).columns.set;
+
+ columns = list_length(set);
+ colname = (str *) GDKmalloc(columns * sizeof(str));
+ tform = (str *) GDKmalloc(columns * sizeof(str));
+
+ /* mnstr_printf(GDKout,"Number of columns: %d\n", columns);*/
+
+ tables = mvc_bind_table(m, sch, "_tables");
+ col = mvc_bind_column(m, tables, "name");
+ rid = table_funcs.column_find_row(m->session->tr, col, tname, NULL);
+
+ col = mvc_bind_column(m, tables, "id");
+ fid = *(int*) table_funcs.column_find_value(m->session->tr, col, rid);
+
+ column = mvc_bind_table(m, sch, "_columns");
+ col = mvc_bind_column(m, column, "table_id");
+
+ rs = table_funcs.rids_select(m->session->tr, col, (void *) &fid, (void
*) &fid, NULL);
+
+ while ((rid = table_funcs.rids_next(rs)) != oid_nil)
+ {
+ col = mvc_bind_column(m, column, "name");
+ name = (char *) table_funcs.column_find_value(m->session->tr,
col, rid);
+ colname[j] = toLower(name);
+
+ col = mvc_bind_column(m, column, "type");
+ type = (char *) table_funcs.column_find_value(m->session->tr,
col, rid);
+
+ if (strcmp(type,"boolean")==0) tform[j] = "1L";
+
+ if (strcmp(type,"char")==0) tform[j] = "1S";
+
+ if (strcmp(type,"varchar")==0) tform[j] = "8A";
+
+ if (strcmp(type,"smallint")==0) tform[j] = "1I";
+
+ if (strcmp(type,"int")==0) tform[j] = "1J";
+
+ if (strcmp(type,"bigint")==0) tform[j] = "1K";
+
+ if (strcmp(type,"real")==0) tform[j] = "1E";
+
+ if (strcmp(type,"double")==0) tform[j] = "1D";
+
+ j++;
+ }
+
+ col = mvc_bind_column(m, tbl, colname[0]);
+
+ nrows = store_funcs.count_col(col);
+
+ snprintf(filename,BUFSIZ,"\n%s.fit",tname);
+ mnstr_printf(GDKout, "Filename: %s\n", filename);
+
+ remove(filename);
+
+ status=0;
+
+ fits_create_file(&fptr, filename, &status);
+ fits_create_img(fptr, USHORT_IMG, 0, NULL, &status);
+ fits_close_file(fptr, &status);
+ fits_open_file(&fptr, filename, READWRITE, &status);
+
+ fits_movabs_hdu(fptr, 1, &hdutype, &status);
+ fits_create_tbl( fptr, BINARY_TBL, 0, columns, colname, tform, NULL,
tname, &status);
+
+ for (cc = 0; cc < columns; cc++)
+ {
+ char * columntype;
+ col = mvc_bind_column(m, tbl, colname[cc]);
+ columntype = col -> type.type->sqlname;
+
+ if (strcmp(columntype,"boolean")==0)
+ {
+ boolcols++; dimension = 0; block = 0;
+ fits_get_rowsize(fptr,&optimal,&status);
+ readboolrows = (_Bool *) GDKmalloc (sizeof(_Bool) *
optimal);
+
+ for (numberrow = 0; numberrow < nrows ; numberrow++)
+ {
+ boolvalue = *(_Bool*)
table_funcs.column_find_value(m->session->tr, col, numberrow);
+ readboolrows[dimension] = boolvalue;
+ dimension++;
+
+ if (dimension == optimal)
+ {
+ dimension = 0;
+ tm0 = GDKms();
+ fits_write_col(fptr, TLOGICAL, cc+1,
(optimal*block)+1, 1, optimal, readboolrows, &status);
+ texportboolean += GDKms() - tm0;
+ GDKfree(readboolrows);
+ readboolrows = (_Bool *) GDKmalloc
(sizeof(_Bool) * optimal);
+ block++;
+ }
+ }
+ tm0 = GDKms();
+ fits_write_col(fptr, TLOGICAL, cc+1, (optimal*block)+1,
1, dimension, readboolrows, &status);
+ texportboolean += GDKms() - tm0;
+ GDKfree(readboolrows);
+ }
+
+ if (strcmp(columntype,"char")==0)
+ {
+ charcols++; dimension = 0; block = 0;
+ fits_get_rowsize(fptr,&optimal,&status);
+ readcharrows = (char *) GDKmalloc (sizeof(char) *
optimal);
+
+ for (numberrow = 0; numberrow < nrows ; numberrow++)
+ {
+ charvalue = *(char*)
table_funcs.column_find_value(m->session->tr, col, numberrow);
+ readcharrows[dimension] = charvalue;
+ dimension++;
+
+ if (dimension == optimal)
+ {
+ dimension = 0;
+ tm0 = GDKms();
+ fits_write_col(fptr, TBYTE, cc+1,
(optimal*block)+1, 1, optimal, readcharrows, &status);
+ texportchar += GDKms() - tm0;
+ GDKfree(readcharrows);
+ readcharrows = (char *) GDKmalloc
(sizeof(char) * optimal);
+ block++;
+ }
+ }
+ tm0 = GDKms();
+ fits_write_col(fptr, TBYTE, cc+1, (optimal*block)+1, 1,
dimension, readcharrows, &status);
+ texportchar += GDKms() - tm0;
+ GDKfree(readcharrows);
+ }
+
+ if (strcmp(columntype,"varchar")==0)
+ {
+ strcols++; dimension=0; block=0;
+ fits_get_rowsize(fptr,&optimal,&status);
+ readstrrows = (char **) GDKmalloc (sizeof(char *) *
optimal);
+
+ for (numberrow = 0; numberrow < nrows ; numberrow++)
+ {
+ strvalue = (char *)
table_funcs.column_find_value(m->session->tr, col, numberrow);
+ readstrrows[dimension] = strvalue;
+ dimension++;
+
+ if (dimension == optimal)
+ {
+ dimension = 0;
+ tm0 = GDKms();
+ fits_write_col_str(fptr, cc+1,
(optimal*block)+1, 1, optimal, readstrrows, &status);
+ texportstring += GDKms() - tm0;
+ GDKfree(readstrrows);
+ readstrrows = (char **)
GDKmalloc(sizeof(char *) * optimal);
+ block++;
+ }
+ }
+ tm0 = GDKms();
+ fits_write_col_str(fptr, cc+1, (optimal*block)+1, 1,
dimension, readstrrows, &status);
+ texportstring += GDKms() - tm0;
+ GDKfree(readstrrows);
+ }
+
+ if (strcmp(columntype,"smallint")==0)
+ {
+ shortcols++; dimension = 0; block = 0;
+ fits_get_rowsize(fptr,&optimal,&status);
+ readshortrows = (short *) GDKmalloc (sizeof(short) *
optimal);
+
+ for (numberrow = 0; numberrow < nrows ; numberrow++)
+ {
+ shortvalue = *(short*)
table_funcs.column_find_value(m->session->tr, col, numberrow);
+ readshortrows[dimension] = shortvalue;
+ dimension++;
+
+ if (dimension == optimal)
+ {
+ dimension = 0;
+ tm0 = GDKms();
+ fits_write_col(fptr, TSHORT, cc+1,
(optimal*block)+1, 1, optimal, readshortrows, &status);
+ texportshort += GDKms() - tm0;
+ GDKfree(readshortrows);
+ readshortrows = (short *) GDKmalloc
(sizeof(short) * optimal);
+ block++;
+ }
+ }
+ tm0 = GDKms();
+ fits_write_col(fptr, TSHORT, cc+1, (optimal*block)+1,
1, dimension, readshortrows, &status);
+ texportshort += GDKms() - tm0;
+ GDKfree(readshortrows);
+ }
+
+ if (strcmp(columntype,"int")==0)
+ {
+ intcols++; dimension = 0; block = 0;
+ fits_get_rowsize(fptr,&optimal,&status);
+ readintrows = (int *) GDKmalloc (sizeof(int) * optimal);
+
+ for (numberrow = 0; numberrow < nrows ; numberrow++)
+ {
+ intvalue = *(int*)
table_funcs.column_find_value(m->session->tr, col, numberrow);
+ readintrows[dimension] = intvalue;
+ dimension++;
+
+ if (dimension == optimal)
+ {
+ dimension = 0;
+ tm0 = GDKms();
+ fits_write_col(fptr, TINT, cc+1,
(optimal*block)+1, 1, optimal, readintrows, &status);
+ texportint += GDKms() - tm0;
+ GDKfree(readintrows);
+ readintrows = (int *) GDKmalloc
(sizeof(int) * optimal);
+ block++;
+ }
+ }
+ tm0 = GDKms();
+ fits_write_col(fptr, TINT, cc+1, (optimal*block)+1, 1,
dimension, readintrows, &status);
+ texportint += GDKms() - tm0;
+ GDKfree(readintrows);
+ }
+
+ if (strcmp(columntype,"bigint")==0)
+ {
+ longcols++; dimension = 0; block = 0;
+ fits_get_rowsize(fptr,&optimal,&status);
+ readlongrows = (long *) GDKmalloc (sizeof(long) *
optimal);
+
+ for (numberrow = 0; numberrow < nrows ; numberrow++)
+ {
+ longvalue = *(long*)
table_funcs.column_find_value(m->session->tr, col, numberrow);
+ readlongrows[dimension] = longvalue;
+ dimension++;
+
+ if (dimension == optimal)
+ {
+ dimension = 0;
+ tm0 = GDKms();
+ fits_write_col(fptr, TLONG, cc+1,
(optimal*block)+1, 1, optimal, readlongrows, &status);
+ texportlong += GDKms() - tm0;
+ GDKfree(readlongrows);
+ readlongrows = (long *) GDKmalloc
(sizeof(long) * optimal);
+ block++;
+ }
+ }
+ tm0 = GDKms();
+ fits_write_col(fptr, TLONG, cc+1, (optimal*block)+1, 1,
dimension, readlongrows, &status);
+ texportlong += GDKms() - tm0;
+ GDKfree(readlongrows);
+ }
+
+ if (strcmp(columntype,"real")==0)
+ {
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list