Changeset: 20706c77efbe for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=20706c77efbe
Modified Files:
        sql/backends/monet5/miniseed/miniseed.c
        sql/backends/monet5/miniseed/miniseed.mal
Branch: DVframework
Log Message:

Extended miniseed.mount to return a table


diffs (114 lines):

diff --git a/sql/backends/monet5/miniseed/miniseed.c 
b/sql/backends/monet5/miniseed/miniseed.c
--- a/sql/backends/monet5/miniseed/miniseed.c
+++ b/sql/backends/monet5/miniseed/miniseed.c
@@ -6,10 +6,12 @@
 
 str MiniseedMount(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       int *ret0 = (int*) getArgReference(stk,pci,0);  //return value 1: BAT 
containing timestamps.
-       int *ret1 = (int*) getArgReference(stk,pci,1);  //return value 2: BAT 
containing integer data.
-       str *targetfile = (str*) getArgReference(stk,pci,2); //arg1: string 
containing the input file path.
-       BAT *btime, *bdata; // BATs to return.
+       int *ret0 = (int*) getArgReference(stk,pci,0);  //return value 1: BAT 
containing file_locations.
+       int *ret1 = (int*) getArgReference(stk,pci,1);  //return value 2: BAT 
containing seq_nos.
+       int *ret2 = (int*) getArgReference(stk,pci,2);  //return value 3: BAT 
containing timestamps.
+       int *ret3 = (int*) getArgReference(stk,pci,3);  //return value 4: BAT 
containing integer data.
+       str *targetfile = (str*) getArgReference(stk,pci,4); //arg 1: string 
containing the input file path.
+       BAT *btime, *bdata, *bfile, *bseqno; // BATs to return, representing 
columns of a table.
        
        MSRecord *msr = NULL;
        int retcode;
@@ -18,26 +20,44 @@ str MiniseedMount(Client cntxt, MalBlkPt
        cntxt = cntxt; //to escape 'unused' parameter error.
        mb = mb; //to escape 'unused' parameter error.
        
-       btime = BATnew(TYPE_void, TYPE_timestamp, 0); //create empty BAT for 
ret0.
+       
+       bfile = BATnew(TYPE_void, TYPE_str, 0); //create empty BAT for ret0.
+       if ( bfile == NULL)
+               throw(MAL,"miniseed.mount",MAL_MALLOC_FAIL);
+       BATseqbase(bfile, 0);
+       bseqno = BATnew(TYPE_void, TYPE_int, 0); //create empty BAT for ret1.
+       if ( bseqno == NULL)
+               throw(MAL,"miniseed.mount",MAL_MALLOC_FAIL);
+       BATseqbase(bseqno, 0);  
+       
+       btime = BATnew(TYPE_void, TYPE_timestamp, 0); //create empty BAT for 
ret2.
+       if ( btime == NULL)
+               throw(MAL,"miniseed.mount",MAL_MALLOC_FAIL);
        BATseqbase(btime, 0);
-       bdata = BATnew(TYPE_void, TYPE_int, 0); //create empty BAT for ret1.
+       bdata = BATnew(TYPE_void, TYPE_int, 0); //create empty BAT for ret3.
+       if ( bdata == NULL)
+               throw(MAL,"miniseed.mount",MAL_MALLOC_FAIL);
        BATseqbase(bdata, 0);
        
-       if(btime == NULL || bdata == NULL) //exception handling.
+       if(bfile == NULL || bseqno == NULL || btime == NULL || bdata == NULL) 
//exception handling.
        {
+               if(bfile)
+                       BBPreleaseref(bfile->batCacheid);
+               if(bseqno)
+                       BBPreleaseref(bseqno->batCacheid);
                if(btime)
                        BBPreleaseref(btime->batCacheid);
                if(bdata)
                        BBPreleaseref(bdata->batCacheid);
-               throw(MAL,"mseed.mount", MAL_MALLOC_FAIL);
+               throw(MAL,"miniseed.mount", MAL_MALLOC_FAIL);
        }
        
-       
-       
+       //loop through all records in the target mseed file.
        while ((retcode = ms_readmsr (&msr, *targetfile, 0, NULL, NULL, 1, 1, 
verbose)) == MS_NOERROR)
        {
-               
-               double sample_interval = HPTMODULUS / msr->samprate;
+       
+               int32_t seq_no = msr->sequence_number;
+               double sample_interval = HPTMODULUS / msr->samprate; 
//calculate sampling interval from frequency
                long sampling_time = msr->starttime;
                
                long num_samples = msr->numsamples;
@@ -57,6 +77,9 @@ str MiniseedMount(Client cntxt, MalBlkPt
                        lng st = (lng) sampling_time / 1000;
                        MTIMEtimestamp_lng(&sampling_timestamp, &st);
                        
+                       // For each sample add one row to the table
+                       BUNappend(bfile, (ptr) *targetfile, FALSE);
+                       BUNappend(bseqno, (ptr) &seq_no, FALSE);
                        BUNappend(btime, (ptr) &sampling_timestamp, FALSE);
                        BUNappend(bdata, (ptr) (data_samples+i), FALSE);
                        sampling_time += sample_interval;
@@ -67,11 +90,13 @@ str MiniseedMount(Client cntxt, MalBlkPt
        if ( retcode != MS_ENDOFFILE )
                ms_log (2, "Cannot read %s: %s\n", *targetfile, 
ms_errorstr(retcode));
        
-       /* Cleanup memory and close file */
+       //cleanup memory and close file
        ms_readmsr (&msr, NULL, 0, NULL, NULL, 0, 0, 0);
        
-       BBPkeepref(*ret0 = btime->batCacheid); //return BAT.
-       BBPkeepref(*ret1 = bdata->batCacheid); //return BAT.
+       BBPkeepref(*ret0 = bfile->batCacheid); //return BAT.
+       BBPkeepref(*ret1 = bseqno->batCacheid); //return BAT.
+       BBPkeepref(*ret2 = btime->batCacheid); //return BAT.
+       BBPkeepref(*ret3 = bdata->batCacheid); //return BAT.
        
        return MAL_SUCCEED;
 }
\ No newline at end of file
diff --git a/sql/backends/monet5/miniseed/miniseed.mal 
b/sql/backends/monet5/miniseed/miniseed.mal
--- a/sql/backends/monet5/miniseed/miniseed.mal
+++ b/sql/backends/monet5/miniseed/miniseed.mal
@@ -1,5 +1,5 @@
 module miniseed;
 
-pattern mount{unsafe}(entry:str)(:bat[:oid,:timestamp],:bat[:oid,:int])
+pattern 
mount{unsafe}(entry:str)(:bat[:oid,:str],:bat[:oid,:int],:bat[:oid,:timestamp],:bat[:oid,:int])
 address MiniseedMount
-comment "Mount the content of a mseed file into BATs";
\ No newline at end of file
+comment "Mount the content of a mseed file into BATs in table form";
\ No newline at end of file
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to