[boinc-app-seti] 01/03: Imported Upstream version 7.28~svn3106

Gianfranco Costamagna locutusofborg-guest at moszumanska.debian.org
Wed Oct 28 11:37:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

locutusofborg-guest pushed a commit to annotated tag debian/7.28_svn3106-1
in repository boinc-app-seti.

commit dcd38f1a24f95325249bb2de3ee2c95b12970ad4
Author: Gianfranco Costamagna <costamagnagianfranco at yahoo.it>
Date:   Wed Oct 28 12:21:19 2015 +0100

    Imported Upstream version 7.28~svn3106
---
 db/schema_master.cpp                  |  10 +-
 db/schema_master.h                    |  37 +-
 splitter_pfb/Makefile.am              |   1 +
 splitter_pfb/mb_coords.cpp            |  15 +
 splitter_pfb/mb_coords.h              |   1 +
 splitter_pfb/mb_read_blocks_dr2.cpp   |   4 +
 splitter_pfb/mb_read_blocks_guppi.cpp | 678 +++++++++++++++++++++-------------
 splitter_pfb/mb_read_blocks_guppi.h   |   4 +-
 splitter_pfb/mb_splitter.cpp          |  11 +-
 splitter_pfb/mb_wufiles.cpp           |   4 +-
 splitter_pfb/splitparms.h             |  17 -
 11 files changed, 498 insertions(+), 284 deletions(-)

diff --git a/db/schema_master.cpp b/db/schema_master.cpp
index 47516e4..2c97895 100644
--- a/db/schema_master.cpp
+++ b/db/schema_master.cpp
@@ -4181,8 +4181,12 @@ multiplet::multiplet() :
     mean_threshold(0),
     threshold_stddev(0),
     score(0),
-    num_detections(0),
-    signal_ids((sqlint8_t *)0,0,_x_csv) {
+    num_detections(0)
+#ifndef NEBULA
+    ,
+    signal_ids((sqlint8_t *)0,0,_x_csv)
+#endif
+{
     db_open();
 }
 
@@ -4392,6 +4396,7 @@ std::string multiplet::print_xml(int full_subtables, int show_ids, int no_refs,c
     rv << xml_indent() << "<threshold_stddev>" << threshold_stddev << "</threshold_stddev>\n";
     rv << xml_indent() << "<score>" << score << "</score>\n";
     rv << xml_indent() << "<num_detections>" << num_detections << "</num_detections>\n";
+#ifndef NEBULA
     if (signal_ids.size()) {
         rv << xml_indent() << "<signal_ids";
         {
@@ -4400,6 +4405,7 @@ std::string multiplet::print_xml(int full_subtables, int show_ids, int no_refs,c
             rv << enc_string;
         }
     }
+#endif
     rv << "</signal_ids>\n";
     xml_indent(-2);
     rv << xml_indent() << "</" << tag << ">\n";
diff --git a/db/schema_master.h b/db/schema_master.h
index f3e50b4..98806fb 100644
--- a/db/schema_master.h
+++ b/db/schema_master.h
@@ -431,7 +431,6 @@ class  meta_candidate  : public db_table<meta_candidate> {
     private:
 };
 
-
 class  multiplet  : public db_table<multiplet> {
     public:
         long  id;
@@ -458,7 +457,11 @@ class  multiplet  : public db_table<multiplet> {
         double  threshold_stddev;
         double  score;
         long  num_detections;
+#ifdef NEBULA
+        std::vector<long> signal_ids;
+#else
         sqlblob<sqlint8_t>  signal_ids ;
+#endif
         multiplet();
         multiplet(const multiplet &a);
         multiplet(const SQL_ROW &a);
@@ -702,11 +705,23 @@ class  result  : public db_table<result> {
     private:
 };
 
+struct DB_REF {
+    long id;
+    void parse_xml(std::string &buf, const char *tag){}
+    void parse(const std::string &buf){}
+    void parse(const SQL_ROW &buf){}
+    std::string print(int full_subtables=0, int show_ids=1, int no_refs=0) const{}
+    std::string print_xml(int full_subtables=1, int show_ids=0, int no_refs=1, const char *tag=0) const{}
+};
 
 class  triplet  : public db_table<triplet> {
     public:
         sqlint8_t  id;
+#ifdef NEBULA
+        DB_REF result_id;
+#else
         db_reference<result,sqlint8_t> result_id;
+#endif
         double  peak_power;
         double  mean_power;
         double  time;
@@ -745,7 +760,11 @@ class  triplet  : public db_table<triplet> {
 class  triplet_small  : public db_table<triplet_small> {
     public:
         sqlint8_t  id;
+#ifdef NEBULA
+        DB_REF result_id;
+#else
         db_reference<result,sqlint8_t> result_id;
+#endif
         double  peak_power;
         double  mean_power;
         double  time;
@@ -784,7 +803,11 @@ class  triplet_small  : public db_table<triplet_small> {
 class  gaussian  : public db_table<gaussian> {
     public:
         sqlint8_t  id;
+#ifdef NEBULA
+        DB_REF result_id;
+#else
         db_reference<result,sqlint8_t> result_id;
+#endif
         double  peak_power;
         double  mean_power;
         double  time;
@@ -871,7 +894,11 @@ class  gaussian_small  : public db_table<gaussian_small> {
 class  pulse  : public db_table<pulse> {
     public:
         sqlint8_t  id;
+#ifdef NEBULA
+        DB_REF result_id;
+#else
         db_reference<result,sqlint8_t> result_id;
+#endif
         double  peak_power;
         double  mean_power;
         double  time;
@@ -1045,7 +1072,11 @@ class  hotpix  : public db_table<hotpix> {
 class  spike  : public db_table<spike> {
     public:
         sqlint8_t  id;
+#ifdef NEBULA
+        DB_REF result_id;
+#else
         db_reference<result,sqlint8_t> result_id;
+#endif
         double  peak_power;
         double  mean_power;
         double  time;
@@ -1121,7 +1152,11 @@ class  spike_small  : public db_table<spike_small> {
 class  autocorr  : public db_table<autocorr> {
     public:
         sqlint8_t  id;
+#ifdef NEBULA
+        DB_REF result_id;
+#else
         db_reference<result,sqlint8_t> result_id;
+#endif
         double  peak_power;
         double  mean_power;
         double  time;
diff --git a/splitter_pfb/Makefile.am b/splitter_pfb/Makefile.am
index cb8f39e..ad175e2 100644
--- a/splitter_pfb/Makefile.am
+++ b/splitter_pfb/Makefile.am
@@ -40,6 +40,7 @@ mb_splitter_SOURCES=mb_angdist.cpp \
 		    mb_wufiles.cpp \
 		    mb_dotransform.cpp \
 		    mb_validrun.cpp \
+		    mb_coords.cpp \
 		    cmap_interp.cpp \
 		    ../db/schema_master.cpp \
 	            ../db/sqlifx.cpp \
diff --git a/splitter_pfb/mb_coords.cpp b/splitter_pfb/mb_coords.cpp
new file mode 100644
index 0000000..2db10af
--- /dev/null
+++ b/splitter_pfb/mb_coords.cpp
@@ -0,0 +1,15 @@
+#include "setilib.h"
+#include "mb_splitter.h"
+
+void get_coord_history() {
+// insert telescope coordinates into the coordinate history.
+// this should be converted to a more accurate routine.
+
+    std::vector<dr2_compact_block_t>::iterator i=tapebuffer.begin();
+
+    for (;i!=tapebuffer.end();i++) {
+        coord_history[i->header.coord_time].ra   = i->header.ra;
+        coord_history[i->header.coord_time].dec  = i->header.dec;
+        coord_history[i->header.coord_time].time = i->header.coord_time.jd().uval();
+    }
+}
diff --git a/splitter_pfb/mb_coords.h b/splitter_pfb/mb_coords.h
new file mode 100644
index 0000000..c983259
--- /dev/null
+++ b/splitter_pfb/mb_coords.h
@@ -0,0 +1 @@
+void get_coord_history();
diff --git a/splitter_pfb/mb_read_blocks_dr2.cpp b/splitter_pfb/mb_read_blocks_dr2.cpp
index f5a4c6f..ba75d75 100644
--- a/splitter_pfb/mb_read_blocks_dr2.cpp
+++ b/splitter_pfb/mb_read_blocks_dr2.cpp
@@ -3,6 +3,7 @@
 #include "setilib.h"
 #include "mb_splitter.h"
 #include "mb_validrun.h"
+#include "mb_coords.h"
 
 //-------------------------------------------------------------------------
 int read_blocks_dr2(int   tape_fd,
@@ -36,6 +37,8 @@ int read_blocks_dr2(int   tape_fd,
     while (num_blocks_read == num_blocks_to_read) {
         //check for an uninterrupted run
         if (valid_run(tapebuffer,splitter_settings.receiver_cfg->min_vgc)) {
+            get_coord_history();
+#if 0
             std::vector<dr2_compact_block_t>::iterator i=tapebuffer.begin();
             // insert telescope coordinates into the coordinate history.
             // this should be converted to a more accurate routine.
@@ -44,6 +47,7 @@ int read_blocks_dr2(int   tape_fd,
                 coord_history[i->header.coord_time].dec  = i->header.dec;
                 coord_history[i->header.coord_time].time = i->header.coord_time.jd().uval();
             }
+#endif
             good_read = 1;
             break;
         } else {
diff --git a/splitter_pfb/mb_read_blocks_guppi.cpp b/splitter_pfb/mb_read_blocks_guppi.cpp
index 99afe34..1dbf8ab 100644
--- a/splitter_pfb/mb_read_blocks_guppi.cpp
+++ b/splitter_pfb/mb_read_blocks_guppi.cpp
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
+#include <vector>
 #include "fitsio.h"
 #include "psrfits.h"
 #include "guppi_params.h"
@@ -14,7 +15,12 @@
 #include <sys/stat.h>
 #include "barycenter.h"
 #include "rawdopplersearch.h"
+#include "setilib.h"
 #include "mb_read_blocks_guppi.h"
+#include "mb_splitter.h"
+#include "mb_coords.h"
+
+//#include "seti_dr2utils.h"
 
 /* Guppi channel-frequency mapping */
 /* sample at 1600 MSamp for an 800 MHz BW */
@@ -32,21 +38,76 @@
 //
 // The next subintegration will be the same 32 channels, starting with time 256.
 // Thus, each subintegration is 32*256 = 8192 bytes of data.
+//
+#if 0
+
+struct gpu_input {
+    char *file_prefix;
+    struct                  guppi_params gf;
+    struct                  psrfits pf;
+    unsigned int filecnt;
+    FILE *fil;
+    int invalid;
+    int curfile;
+    int overlap;   /* add this keyword here since it doesn't seem to appear in guppi_params.c */
+    long int first_file_skip; /* in case there's 8bit data in the header of file 0 */
+};
+
+struct guppi_params {
+    /* Packet information for the current block */
+    long long packetindex;      // Index of first packet in raw data block
+    int packetsize;             // Size in bytes of data portion of each packet
+    int n_packets;              // Total number of packets in current block
+    int n_dropped;              // Number of packets dropped in current block
+};
+
+struct psrfits {
+    char mode;              // Read (r) or write (w).
+    struct                  hdrinfo hdr;
+    struct                  subint sub;
+};
 
-struct seti_data {
-    int               header_size;    //                                                            need for gbt data
-    int               data_size;      //                                                            need for gbt data
-    char              name[36];       //                                                            need for gbt data
-    int               channel;        //                                                            need for gbt data
-    int 			  polarization;    // which pol?  0 or 1
-    double            data_time;      // time stamp : the final data sample in this block           need for gbt data
-    double            coord_time;     // time stamp : ra/dec (ie, the time of Az/Za acquisition)    need for gbt data - 
-    double            ra;             // ra for the beam from which the data in this block came     need for gbt data
-    double            dec;            // dec for the beam from which the data in this block came    need for gbt data
-    long              sky_freq;       // aka center frequency, Hz                                   need for gbt data
-    double            samplerate;     //                                                            need for gbt data
+struct hdrinfo {
+    char source[24];        // Source name
+    char frontend[24];      // Frontend used
+    long double MJD_epoch;  // Starting epoch in MJD
+    double fctr;            // Center frequency of the observing band (MHz)
+    double df;              // Frequency spacing between the channels (MHz)
+    double BW;              // Bandwidth of the observing band (MHz)
+    int nbits;              // Number of bits per data sample
+    int nchan;              // Number of channels
+    int rcvr_polns;         // Number of polns provided by the receiver
 };
 
+struct subint {
+    double tsubint;         // Length of subintegration (sec)
+    double offs;            // Offset from Start of subint centre (sec)
+    double ra;              // RA (J2000) at subint centre (deg)
+    double dec;             // Dec (J2000) at subint centre (deg)
+    int bytes_per_subint;   // Number of bytes for one row of raw data
+    unsigned char *data;    // Ptr to the raw data itself
+};
+
+#endif
+
+#define RAW_DATA_HEADER_BUF_SIZE 32768
+
+typedef struct {
+    // file control...
+    long long int   startindx;
+    long long int   curindx;
+	long long int   chanbytes;
+	long long int   subint_offset;
+	long int        currentblock;
+	int             indxstep;
+    // user prefs...
+    int             channel;
+    int             polarization;
+    long int        startblock; 
+    long int        numblocks; 
+    int             vflag; 
+} control_block_t;
+
 /* Parse info from buffer into param struct */
 extern void guppi_read_obs_params(char *buf, 
                                      struct guppi_params *g,
@@ -56,145 +117,103 @@ extern void guppi_read_obs_params(char *buf,
 
 int exists(const char *fname);
 
-int unpack_samples(unsigned char * raw, unsigned char *dest, long int count, int pol);
+int unpack_samples(unsigned char * raw, long int count, int pol, dr2_compact_block_t &this_tapebuffer);
 
 //-------------------------------------------------------
-int print_header(seti_data & setiheader) {
+int print_header(dr2_compact_block_t &this_tapebuffer) {
 //-------------------------------------------------------
-	fprintf(stderr, "setiheader :  Header Size: %d Data Size: %d Data Time: %f Coordinate Time: %f RA: %f Dec: %f\n", 
-            setiheader.header_size,
-	        setiheader.data_size,		
-	        setiheader.data_time,
-	        setiheader.coord_time,
-	        setiheader.ra,
-	        setiheader.dec);
-}
 
+	fprintf(stderr, "setiheader : Name: %s Header Size: %d Data Size: %d Channel: %d Polarization: N samplerate %lf sky_freq %ld Data Time: %lf Coordinate Time: %lf RA: %f Dec: %f\n", 
+            this_tapebuffer.header.name,
+            this_tapebuffer.header.header_size,
+	        this_tapebuffer.header.data_size,		
+	        this_tapebuffer.header.channel,		
+	        this_tapebuffer.header.samplerate,		
+	        this_tapebuffer.header.sky_freq,		
+            this_tapebuffer.header.data_time.mjd().uval(),
+            this_tapebuffer.header.coord_time.mjd().uval(),
+	        this_tapebuffer.header.ra,
+	        this_tapebuffer.header.dec);
+}
 
 //-------------------------------------------------------
-long int read_blocks_guppi(char * file_prefix,
-                           long int startblock, 
-                           long int numblocks, 
-                           int channel, 
-                           int polarization, 
-                           int vflag, 
-                           unsigned char **setibuffer) {
+int populate_header(
+	            control_block_t     &control_block,
+                struct gpu_input    &rawinput,
+                dr2_compact_block_t &this_tapebuffer
+) {
 //-------------------------------------------------------
 
-	int overlap; // amount of overlap between sub integrations in samples
-
-	int filecnt=0;
-    char buf[32768];
-
-	unsigned char *channelbuffer;	
-
-	char filname[250];
-
-	struct gpu_input rawinput;	
-
-	struct seti_data setiheader;
-	
-	long long int startindx;
-	long long int curindx;
-	long long int chanbytes=0;
-	long long int chanbytes_overlap = 0;
-	long long int subint_offset = 0;
-	long long int setibuffer_pos = 0;
-	long int currentblock=0;
-	int indxstep = 0;
-	size_t rv=0;
-	long unsigned int by=0;
-	long int i=0,j=0;
-
-    double start_data_time;
-    double end_data_time;
+    /* size of this header */
+    this_tapebuffer.header.header_size = sizeof(this_tapebuffer.header);
 
-	rawinput.file_prefix = NULL;
-	rawinput.fil = NULL;
-	rawinput.invalid = 0;
-	rawinput.first_file_skip = 0;  
+    /* number of samples * size of a signed char * 2 for real/imag */
+    this_tapebuffer.header.data_size = (control_block.chanbytes * sizeof(signed char) * 2);
 
-    opterr = 0;
-    rawinput.file_prefix=file_prefix;
-     
-    /* no input specified */
-    if(rawinput.file_prefix == NULL) {
-	    printf("WARNING no input stem specified%ld\n", (i+1));
-	    return 0;
-    }
-
-    if(strstr(rawinput.file_prefix, ".0000.raw") != NULL) memset(rawinput.file_prefix + strlen(rawinput.file_prefix) - 9, 0x0, 9);
+    /* populate with source name from psrfits header */
+    sprintf(this_tapebuffer.header.name, "%s", rawinput.pf.hdr.source);
 
-    // get size of data set, in terms of file count and byte count
-    fprintf(stderr, "Finding size of data set...\n");
-    j = 0;
-    struct stat st;
-    long int size=0;
-    do {
-	    sprintf(filname, "%s.%04ld.raw",rawinput.file_prefix,j);
-	    fprintf(stderr, "  trying %s ...",filname);		
-	    j++;
-	    if(exists(filname)) { 
-            fprintf(stderr, " found\n");
-		    stat(filname, &st);
-		    size = size + st.st_size;
-	    } else {
-            fprintf(stderr, " not found\n");
-        }
-    } while (exists(filname));
-    rawinput.filecnt = j-1;
-    fprintf(stderr, "  File count is %i  Total size is %ld bytes\n",rawinput.filecnt, size);
+    /* populate channel and polarization */
+    this_tapebuffer.header.channel      = control_block.channel;
+    //this_tapebuffer.header.polarization = control_block.polarization;   // TODO add polarization
 
-    /* didn't find any files */
-    if(rawinput.filecnt < 1) {
-	    fprintf(stderr, "no files for stem %s found\n",rawinput.file_prefix);
-	    exit(1);		
-    }
+    /* (complex) sample rate in Hz */
+    this_tapebuffer.header.samplerate = rawinput.pf.hdr.df * 1000000;
+
+    this_tapebuffer.header.sky_freq =   (long int) (
+                              (double) 1000000 * 
+                              ( 
+                                (rawinput.pf.hdr.fctr   - 
+                                (rawinput.pf.hdr.BW/2)) + 
+                                ((control_block.channel+0.5) * rawinput.pf.hdr.df)
+                              )
+                            );
+
+    print_header(this_tapebuffer);
+}
 
-    /* open the first file for input */
-    sprintf(filname, "%s.0000.raw", rawinput.file_prefix);
-    fprintf(stderr, "Opening %s\n", filname);
-    rawinput.fil = fopen(filname, "rb");
 
-    /* if we managed to open a file */
-    if(rawinput.fil){
-	    if(fread(buf, sizeof(char), 32768, rawinput.fil) == 32768){
+//-------------------------------------------------------
+int get_params(
+	            control_block_t     &control_block,
+                struct gpu_input    &rawinput,
+                char                header_buf[],
+                char                filname[],
+	            unsigned char *     &channelbuffer	
+) {
+//-------------------------------------------------------
+	long long int chanbytes_overlap = 0;
+        // Read first raw data header
+	    if(fread(header_buf, sizeof(char), RAW_DATA_HEADER_BUF_SIZE, rawinput.fil) == RAW_DATA_HEADER_BUF_SIZE){
 		   
-		    guppi_read_obs_params(buf, &rawinput.gf, &rawinput.pf);
+		    guppi_read_obs_params(header_buf, &rawinput.gf, &rawinput.pf);
 		   
+            // Get to first 2 bit data header...
+            // At regular intervals, as a sanity check, the 2 bit
+            // data are preceeded by the full 8 bit version of
+            // the same data.  We ignore the 8 bit data here.
 		    if(rawinput.pf.hdr.nbits == 8) {
-
-                // At regular intervals, as a sanity check, the 2 bit
-                // data are preceeded by the full 8 bit version of
-                // the same data.  We ignore the 8 bit data here.
-			  
 			    fprintf(stderr, "caught an 8 bit header... moving on to first/next 2 bit header\n");
-			  
 			    /* figure out the size of the first subint + header */
-		        rawinput.first_file_skip = rawinput.pf.sub.bytes_per_subint + gethlength(buf);
-				
+		        rawinput.first_file_skip = rawinput.pf.sub.bytes_per_subint + gethlength(header_buf);
 			    /* rewind to the beginning */	
-		   	    fseek(rawinput.fil, -32768, SEEK_CUR);
-		   	  
+		   	    fseek(rawinput.fil, -RAW_DATA_HEADER_BUF_SIZE, SEEK_CUR);
 		   	    /* seek past the first subint + header */
 		   	    fseek(rawinput.fil, rawinput.first_file_skip, SEEK_CUR);
-
 			    /* read the next header */
-		   	    fread(buf, sizeof(char), 32768, rawinput.fil);
-			    guppi_read_obs_params(buf, &rawinput.gf, &rawinput.pf);
+		   	    fread(header_buf, sizeof(char), RAW_DATA_HEADER_BUF_SIZE, rawinput.fil);
+			    guppi_read_obs_params(header_buf, &rawinput.gf, &rawinput.pf);
 			    fclose(rawinput.fil);
-
 		    } else {
                 // not 8 bit data 
 			    fclose(rawinput.fil);
 		    }   // end if(rawinput.pf.hdr.nbits == 8)
 
-		    /* we'll use this file to set the params for the whole observation */
+		    /* we'll use this header to set the params for the whole observation */
 		   
 		    rawinput.fil = NULL;
 
-		    hgeti4(buf, "OVERLAP", &rawinput.overlap);
-
+		    hgeti4(header_buf, "OVERLAP", &rawinput.overlap);
 			
 		    fprintf(stderr, "   packetindex       : %lld\n", rawinput.gf.packetindex);
 		    fprintf(stderr, "   packetsize        : %d\n", rawinput.gf.packetsize);
@@ -202,55 +221,47 @@ long int read_blocks_guppi(char * file_prefix,
 		    fprintf(stderr, "   n_dropped         : %d\n",rawinput.gf.n_dropped);
 		    fprintf(stderr, "   bytes_per_subint  : %d\n",rawinput.pf.sub.bytes_per_subint);
 		    fprintf(stderr, "   overlap           : %d\n",rawinput.overlap);
-
-		    if (rawinput.pf.sub.data) free(rawinput.pf.sub.data);
-		   
-		    rawinput.pf.sub.data  = (unsigned char *) malloc(rawinput.pf.sub.bytes_per_subint);
-			
 	        } else {    
 	  		    fprintf(stderr, "couldn't read a header\n");
 			    return 0;
 	        }   // end fread(buf...
-        } else {
-	        fprintf(stderr, "couldn't open first file\n");
-	        return 0;
-        }   // end, if we managed to open a file
 
 
-    if(vflag>=1) fprintf(stderr, "calculating index step\n");
+    if(control_block.vflag>=1) fprintf(stderr, "calculating index step\n");
 
     /* number of packets that we *should* increment by */
-    indxstep = (int) ((rawinput.pf.sub.bytes_per_subint * 4) / rawinput.gf.packetsize)              - 
+    control_block.indxstep = (int) ((rawinput.pf.sub.bytes_per_subint * 4) / rawinput.gf.packetsize)              - 
                       (int) (rawinput.overlap * rawinput.pf.hdr.nchan * rawinput.pf.hdr.rcvr_polns  * 
                       2 / rawinput.gf.packetsize);
 
-    //spectraperint = indxstep * band[first_good_band].gf.packetsize / (band[first_good_band].pf.hdr.nchan * band[first_good_band].pf.hdr.rcvr_polns * 2 * ftacc);
+    //spectraperint = control_block.indxstep * band[first_good_band].gf.packetsize / (band[first_good_band].pf.hdr.nchan * band[first_good_band].pf.hdr.rcvr_polns * 2 * ftacc);
     //spectraperint = ((rawinput.pf.sub.bytes_per_subint / rawinput.pf.hdr.nchan) - rawinput.overlap) / ftacc;	
 
-    overlap = rawinput.overlap;
+    //overlap = rawinput.overlap;
 
-    if (channel >= rawinput.pf.hdr.nchan) {
-	    fprintf(stderr, "channel %d more than channels in data %d\n", channel, rawinput.pf.hdr.nchan);
+    if (control_block.channel >= rawinput.pf.hdr.nchan) {
+	    fprintf(stderr, "control_block.channel %d more than channels in data %d\n", control_block.channel, rawinput.pf.hdr.nchan);
 	    return 0;
     } else {
 	    fprintf(stderr, "Numer of channels in file %d\n", rawinput.pf.hdr.nchan);
     }
 
     /* number of non-overlapping bytes in each channel */
-    /* indxstep increments by the number of unique packets in each sub-integration */
+    /* control_block.indxstep increments by the number of unique packets in each sub-integration */
     /* packetsize is computed based on the original 8 bit resolution */
     /* divide by 4 to get to 2 bits, nchan to get to number of channels */
 
-    chanbytes = indxstep * rawinput.gf.packetsize / (4 * rawinput.pf.hdr.nchan); 
-    fprintf(stderr, "chan bytes %lld\n", chanbytes);
+    control_block.chanbytes = control_block.indxstep * rawinput.gf.packetsize / (4 * rawinput.pf.hdr.nchan); 
+    fprintf(stderr, "chan bytes %lld\n", control_block.chanbytes);
 
-    channelbuffer  = (unsigned char *) calloc( chanbytes , sizeof(char) );
-    if (!channelbuffer) {
-	    fprintf(stderr, "error: couldn't allocate memory for buffer\n");
-	    return 0;
-    }
+    // commented out by jeffc - channelbuffer is unused 
+    //channelbuffer  = (unsigned char *) calloc( control_block.chanbytes , sizeof(char) );
+    //if (!channelbuffer) {
+	//    fprintf(stderr, "error: couldn't allocate memory for buffer\n");
+	//    return 0;
+    //}
 
-    fprintf(stderr, "malloc'ed %Ld bytes for channel %d\n",  chanbytes, channel );	
+    //fprintf(stderr, "malloc'ed %Ld bytes for channel %d\n",  control_block.chanbytes, control_block.channel );	
 
     //	tstart=band[first_good_band].pf.hdr.MJD_epoch;
     //	tsamp = band[first_good_band].pf.hdr.dt * ftacc;
@@ -258,61 +269,41 @@ long int read_blocks_guppi(char * file_prefix,
     //	strcat(buf, strtok(band[first_good_band].pf.hdr.ra_str, ":"));
     //	strcat(buf, strtok(band[first_good_band].pf.hdr.dec_str, ":"));
 
-    /* size of this header */
-    setiheader.header_size = sizeof(setiheader);
-
-    /* number of samples * size of a float * 2 for real/imag */
-    setiheader.data_size = (chanbytes * sizeof(float) * 2);
-
-    /* populate with source name from psrfits header */
-    sprintf(setiheader.name, "%s", rawinput.pf.hdr.source);
-
-    /* populate channel and polarization */
-    setiheader.channel = channel;
-    setiheader.polarization = polarization;
-
-    /* (complex) sample rate in Hz */
-    setiheader.samplerate = rawinput.pf.hdr.df * 1000000;
-
-    /* sky frequency in Hz */
-    setiheader.sky_freq = (long int) ((double) 1000000 * ((rawinput.pf.hdr.fctr - (rawinput.pf.hdr.BW/2)) + ((channel+0.5) * rawinput.pf.hdr.df)));
-
     /*
     fprintf(stderr, "freq %ld\n", setiheader.sky_freq);
     fprintf(stderr, "fctr %lf\n", rawinput.pf.hdr.fctr);
     fprintf(stderr, "bandwidth %lf\n", rawinput.pf.hdr.BW);
-    fprintf(stderr, "freqdouble %lf\n", ((double) 1000000 * ((rawinput.pf.hdr.fctr - (rawinput.pf.hdr.BW/2)) + ((channel+0.5) * rawinput.pf.hdr.df))));
+    fprintf(stderr, "freqdouble %lf\n", ((double) 1000000 * ((rawinput.pf.hdr.fctr - (rawinput.pf.hdr.BW/2)) + ((control_block.channel+0.5) * rawinput.pf.hdr.df))));
     */
 
-    *setibuffer = (unsigned char *) calloc( ((chanbytes * sizeof(float) * 2) + setiheader.header_size) * numblocks, sizeof(char) ); 
-
-    if (!*setibuffer) {
-	    fprintf(stderr, "error: couldn't allocate memory for buffer\n");
-	    return 0;
-    }
-
-    if(vflag>=1) fprintf(stderr, "malloced %Ld bytes for storing channel %d\n", ((chanbytes * sizeof(float) * 2) + setiheader.header_size) * numblocks, channel );	
-
     /* total number of bytes per channel, including overlap */
     chanbytes_overlap = rawinput.pf.sub.bytes_per_subint / rawinput.pf.hdr.nchan;
 
     /* memory offset for our chosen channel within a subint */
-    subint_offset = channel * chanbytes_overlap;
-
-    if(vflag>=1) fprintf(stderr, "Index step: %d\n", indxstep);
-    if(vflag>=1) fprintf(stderr, "bytes per subint %d\n",rawinput.pf.sub.bytes_per_subint );
+    control_block.subint_offset = control_block.channel * chanbytes_overlap;
 
-    fflush(stdout);
+    if(control_block.vflag>=1) fprintf(stderr, "Index step: %d\n", control_block.indxstep);
+    if(control_block.vflag>=1) fprintf(stderr, "bytes per subint %d\n",rawinput.pf.sub.bytes_per_subint );
+}
 
-    startindx = rawinput.gf.packetindex;
-    curindx = startindx;
 
-    filecnt = rawinput.filecnt;
+//-------------------------------------------------------
+int read_block(
+	            control_block_t     &control_block,
+                struct gpu_input    &rawinput,
+                char                header_buf[],
+                char                filname[],
+                double              &start_data_time,
+                double              &end_data_time,
+                long int            file_cnt,
+                dr2_compact_block_t &this_tapebuffer
+) {
+//-------------------------------------------------------
 
-    rawinput.curfile = 0;			
+	size_t rv=0;
+    int retval=0;
+	//long int j=0;
 
-    do{     // start while(!(rawinput.invalid))
-										
 	    if(!rawinput.invalid){						  
 		    if(rawinput.fil == NULL) {
 			    /* no file is open for this band, try to open one */
@@ -329,23 +320,22 @@ long int read_blocks_guppi(char * file_prefix,
 
 		    if(rawinput.fil){		  
 		        fprintf(stderr, "Reading first/next 32KB\n"); 
-	            //if((fread(buf, sizeof(char), 32768, rawinput.fil) == 32768) && (currentblock < (numblocks + startblock - 1)) ) {				
-	            if(fread(buf, sizeof(char), 32768, rawinput.fil) == 32768) {
+	            //if((fread(buf, sizeof(char), RAW_DATA_HEADER_BUF_SIZE, rawinput.fil) == RAW_DATA_HEADER_BUF_SIZE) && (control_block.currentblock < (control_block.numblocks + control_block.startblock - 1)) ) {				
+	            if(fread(header_buf, sizeof(char), RAW_DATA_HEADER_BUF_SIZE, rawinput.fil) == RAW_DATA_HEADER_BUF_SIZE) {
 		            fprintf(stderr, "...success!\n"); 
-					fseek(rawinput.fil, -32768, SEEK_CUR);                                  // reposition to the start of this 32KB
-					if(vflag>=1) fprintf(stderr, "read 32KB\n", gethlength(buf));
-					if(vflag>=1) fprintf(stderr, "header length: %d\n", gethlength(buf));
-					guppi_read_obs_params(buf, &rawinput.gf, &rawinput.pf);
+					fseek(rawinput.fil, -RAW_DATA_HEADER_BUF_SIZE, SEEK_CUR);                                  // reposition to the start of this 32KB
+					if(control_block.vflag>=1) fprintf(stderr, "header length: %d\n", gethlength(header_buf));
+					guppi_read_obs_params(header_buf, &rawinput.gf, &rawinput.pf);
 
-					currentblock = (long int) ((double) rawinput.gf.packetindex/ (double) indxstep);
+					control_block.currentblock = (long int) ((double) rawinput.gf.packetindex/ (double) control_block.indxstep);
 
-					if(vflag>=1) {
+					if(control_block.vflag>=1) {
 						 fprintf(stderr, "packetindex %Ld packetsize: %d n_packets %d n_dropped: %d blocks: %ld RA: %f DEC: %f subintoffset %f tsubint %f MJD %Lf\n", 
                                     rawinput.gf.packetindex,
 						            rawinput.gf.packetsize,
 						            rawinput.gf.n_packets,
 						            rawinput.gf.n_dropped,
-						            currentblock,
+						            control_block.currentblock,
 						            rawinput.pf.sub.ra,
 						            rawinput.pf.sub.dec,
 						            rawinput.pf.sub.offs,
@@ -355,40 +345,41 @@ long int read_blocks_guppi(char * file_prefix,
 					
 					/* populate the variables that change with each block */
 				    /* RA (J2000) at subint centre (deg), Dec (J2000) at subint centre (deg), time in MJD */
-					setiheader.ra           = rawinput.pf.sub.ra;            
-					setiheader.dec          = rawinput.pf.sub.dec;           
+					this_tapebuffer.header.ra           = rawinput.pf.sub.ra/15.0;      // splitter expects RA in decimal hours            
+					this_tapebuffer.header.dec          = rawinput.pf.sub.dec;           
 					/* increment time for data by 0.5 x length of block to push quoted time to the _last_ sample in the block */					
-					setiheader.data_time    = rawinput.pf.hdr.MJD_epoch + ((rawinput.pf.sub.offs + rawinput.pf.sub.tsubint/2)/86400.0) ;     
-					setiheader.coord_time   = rawinput.pf.hdr.MJD_epoch + (rawinput.pf.sub.offs/86400.0);    
+					double data_mjd                           = rawinput.pf.hdr.MJD_epoch + ((rawinput.pf.sub.offs + rawinput.pf.sub.tsubint/2)/86400.0);     
+					double coord_mjd                          = rawinput.pf.hdr.MJD_epoch + (rawinput.pf.sub.offs/86400.0);    
+                    this_tapebuffer.header.data_time    = seti_time(days(data_mjd),MJD0);
+                    this_tapebuffer.header.coord_time   = seti_time(days(coord_mjd),MJD0);
 
-                    if(currentblock == 1) {
-                        start_data_time = setiheader.data_time;     // assigned once                  
+                    if(control_block.currentblock == 1) {
+                        start_data_time = this_tapebuffer.header.data_time.mjd().uval();
                     } else {
-                        end_data_time   = setiheader.data_time;     // assigned many times, will end up with the final block's time
+                        end_data_time = this_tapebuffer.header.data_time.mjd().uval();     // assigned many times, will end up with the final block's time
                     }
 					
-			   		if(rawinput.gf.packetindex == curindx) {
+			   		if(rawinput.gf.packetindex == control_block.curindx) {
 						 /* read a subint with correct index */
 
-						 fseek(rawinput.fil, gethlength(buf), SEEK_CUR);
+						 fseek(rawinput.fil, gethlength(header_buf), SEEK_CUR);
 						 rv=0;
 						 
-						 if (currentblock > (startblock-1)){
+						 if (control_block.currentblock > (control_block.startblock-1)){
 						 
-						 	rv=fread(rawinput.pf.sub.data, sizeof(char), rawinput.pf.sub.bytes_per_subint, rawinput.fil);		 
+						 	rv=fread(rawinput.pf.sub.data, sizeof(char), rawinput.pf.sub.bytes_per_subint, rawinput.fil);  // read raw samples		 
 						 	
 							if( ((long int)rv == rawinput.pf.sub.bytes_per_subint) ){
-							   if(vflag>=1) fprintf(stderr,"read %d bytes from %ld in curfile %d\n", rawinput.pf.sub.bytes_per_subint, j, rawinput.curfile);						   
-							   memcpy((*setibuffer)+setibuffer_pos, &setiheader, sizeof(setiheader));
-							   setibuffer_pos = setibuffer_pos + sizeof(setiheader);
-							   unpack_samples(rawinput.pf.sub.data + subint_offset, (*setibuffer) + setibuffer_pos, chanbytes, polarization);					   
-							   setibuffer_pos = setibuffer_pos + (chanbytes * 2 * sizeof(float));
-							   
-							   	if(vflag>=1) fprintf(stderr,"buffer position: %Ld\n", setibuffer_pos);						   
+							   if(control_block.vflag>=1) fprintf(stderr,"read %d bytes from %ld in curfile %d\n", 
+                                                                  rawinput.pf.sub.bytes_per_subint, file_cnt, rawinput.curfile);						
+							   unpack_samples(rawinput.pf.sub.data + control_block.subint_offset, 
+                                              control_block.chanbytes, 
+                                              control_block.polarization,
+                                              this_tapebuffer);   					               // unpack samples to the return vector   
 
                                // The following two lines were commented out in Andrews code.
-							   //memcpy(channelbuffer + channelbuffer_pos, rawinput.pf.sub.data + subint_offset, chanbytes);										   
-							   //channelbuffer_pos = channelbuffer_pos + chanbytes;
+							   //memcpy(channelbuffer + channelbuffer_pos, rawinput.pf.sub.data + control_block.subint_offset, control_block.chanbytes);										   
+							   //channelbuffer_pos = channelbuffer_pos + control_block.chanbytes;
 
 							} else {
 								rawinput.fil = NULL;
@@ -399,96 +390,275 @@ long int read_blocks_guppi(char * file_prefix,
 
 						 } else (rv = fseek(rawinput.fil, rawinput.pf.sub.bytes_per_subint, SEEK_CUR)); 
 						 
-					} else if( (rawinput.gf.packetindex > curindx) && (currentblock > (startblock-1)) ) {
+					} else if( (rawinput.gf.packetindex > control_block.curindx) && (control_block.currentblock > (control_block.startblock-1)) ) {
 
-						 fprintf(stderr,"ERR: curindx: %Ld, pktindx: %Ld Did we drop a whole subintegration? Reusing last subint...\n", curindx, rawinput.gf.packetindex );
+						 fprintf(stderr,"ERR: control_block.curindx: %Ld, pktindx: %Ld Did we drop a whole subintegration? Reusing last subint...\n", 
+                                 control_block.curindx, rawinput.gf.packetindex );
 						 /* read a subint with too high an indx, must have dropped a whole subintegration*/
 
 						/* pf.sub.data *should* still contain the last valid subint */
 						/* grab a copy of the last subint  - probably should add gaussian noise here, but this is better than nothing! */
 
 						/* we'll keep the ra/dec values from this subint, but push back the time to keep everything sensible */
-					    setiheader.data_time = rawinput.pf.hdr.MJD_epoch + ((rawinput.pf.sub.offs - rawinput.pf.sub.tsubint/2)/86400.0) ;     
-
-						memcpy((*setibuffer) + setibuffer_pos, &setiheader, sizeof(setiheader));
-						setibuffer_pos = setibuffer_pos + sizeof(setiheader);
-						memmove((*setibuffer) + setibuffer_pos, (*setibuffer) + setibuffer_pos - sizeof(setiheader) - chanbytes, (chanbytes * 2 * sizeof(float)));
-						setibuffer_pos = setibuffer_pos + (chanbytes * 2 * sizeof(float));
+					    data_mjd = rawinput.pf.hdr.MJD_epoch + ((rawinput.pf.sub.offs - rawinput.pf.sub.tsubint/2)/86400.0) ;     
+                        this_tapebuffer.header.data_time = seti_time(days(data_mjd),MJD0);
+
+                        // TODO keep the following demo buffer code to remind me what to do here
+                        // header to return buffer
+						//memcpy((*setibuffer) + control_block.setibuffer_pos, 
+                        //       &setiheader, 
+                        //       sizeof(setiheader));
+						//control_block.setibuffer_pos += sizeof(setiheader);
+
+                        // data to return buffer
+						//memmove((*setibuffer) + control_block.setibuffer_pos, 
+                        //        (*setibuffer) + control_block.setibuffer_pos - sizeof(setiheader) - control_block.chanbytes, 
+                        //        (control_block.chanbytes * 2 * sizeof(unsigned char)));
+						//control_block.setibuffer_pos += (control_block.chanbytes * 2 * sizeof(unsigned char));
 
 						/* We'll get the current valid subintegration again on the next time through this loop */
 
-					} else if(rawinput.gf.packetindex < curindx) {
-						 fprintf(stderr,"Error expecting a higher packet index than we got curindx: %Ld, pktindx: %Ld\n", curindx, rawinput.gf.packetindex );
+					} else if(rawinput.gf.packetindex < control_block.curindx) {
+						 fprintf(stderr,"Error expecting a higher packet index than we got control_block.curindx: %Ld, pktindx: %Ld\n", 
+                                 control_block.curindx, rawinput.gf.packetindex );
 						 /* somehow we were expecting a higher packet index than we got !?!? */	
 						 fprintf(stderr, "assuming corruption and exiting...\n");
 						 return(0);
 					}
     
-                if(vflag>=1) fprintf(stderr, "Read block %ld\n", currentblock);
-                if(vflag>=1) print_header(setiheader);
+                if(control_block.vflag>=1) fprintf(stderr, "Read block %ld\n", control_block.currentblock);
+                //if(control_block.vflag>=1) {print_header_old(setiheader); print_header(this_tapebuffer);}
+                if(control_block.vflag>=1) print_header(this_tapebuffer);
+                retval = true;
 				} else {
 				   fprintf(stderr, "Could not read first/next 32KB\n"); 
 				   fclose(rawinput.fil);
 				   rawinput.fil = NULL;
 				   rawinput.curfile++;						
+                   retval = false;
 				}   // end if((fread(buf...)
 		    }   // end if(rawinput.fil)			 	 	 
 	    }   // end if(!rawinput.invalid)
 										
-	    if(rawinput.fil != NULL) curindx = curindx + indxstep;
+	    if(rawinput.fil != NULL) {
+            control_block.curindx = control_block.curindx + control_block.indxstep;
+            retval = 1;     // we have a new block
+        } else {
+            retval = 0;     // we do not have a new block
+        }
+
+    return(retval);
+}
+
+//-------------------------------------------------------
+long int read_blocks_guppi(char *           file_prefix,
+                           long int         startblock, 
+                           long int         numblocks, 
+                           int              channel, 
+                           int              polarization, 
+                           int              vflag 
+) {
+//-------------------------------------------------------
+
+	int overlap; // amount of overlap between sub integrations in samples
+
+    int retval=0;
+
+	int filecnt=0;
+    char header_buf[RAW_DATA_HEADER_BUF_SIZE];   // we read the raw data headers into this buffer
 
-    // Keep going until we run out of data or the numblocks request is met
-    } while((!(rawinput.invalid)) && (currentblock <= (numblocks + startblock - 1)));
+	unsigned char *channelbuffer;	
+
+	char filname[250];
+
+    dr2_compact_block_t this_tapebuffer;
+
+	struct gpu_input rawinput;	
+
+    control_block_t control_block;
+    control_block.chanbytes     = 0;
+    control_block.subint_offset = 0;
+    control_block.currentblock  = 0;
+    control_block.indxstep      = 0;
+    control_block.channel       = channel;
+    control_block.polarization  = polarization;
+    control_block.numblocks     = numblocks;
+    control_block.startblock    = startblock;
+    control_block.vflag         = vflag;
+
+    size_t rv=0;
+	long unsigned int by=0;
+	long int i=0,j=0;
+
+    double start_data_time;
+    double end_data_time;
+
+	rawinput.file_prefix = NULL;
+	rawinput.fil = NULL;
+	rawinput.invalid = 0;
+	rawinput.first_file_skip = 0;  
+
+    opterr = 0;
+    rawinput.file_prefix=file_prefix;
+     
+    /* no input specified */
+    if(rawinput.file_prefix == NULL) {
+	    printf("WARNING no input stem specified%ld\n", (i+1));
+	    return 0;
+    }
+
+    if(strstr(rawinput.file_prefix, ".0000.raw") != NULL) memset(rawinput.file_prefix + strlen(rawinput.file_prefix) - 9, 0x0, 9);
+
+    // get size of data set, in terms of file count and byte count
+    fprintf(stderr, "Finding size of data set...\n");
+    j = 0;
+    struct stat st;
+    long int size=0;
+    do {
+	    sprintf(filname, "%s.%04ld.raw",rawinput.file_prefix,j);
+	    fprintf(stderr, "  trying %s ...",filname);		
+	    j++;
+	    if(exists(filname)) { 
+            fprintf(stderr, " found\n");
+		    stat(filname, &st);
+		    size = size + st.st_size;
+	    } else {
+            fprintf(stderr, " not found\n");
+        }
+    } while (exists(filname));
+    rawinput.filecnt = j-1;
+    fprintf(stderr, "  File count is %i  Total size is %ld bytes\n",rawinput.filecnt, size);
+
+    /* didn't find any files */
+    if(rawinput.filecnt < 1) {
+	    fprintf(stderr, "no files for stem %s found\n",rawinput.file_prefix);
+	    exit(1);		
+    }
+
+    /* open the first file for input */
+    sprintf(filname, "%s.0000.raw", rawinput.file_prefix);
+    fprintf(stderr, "Opening %s\n", filname);
+    rawinput.fil = fopen(filname, "rb");
+    if(!rawinput.fil){
+        fprintf(stderr, "couldn't open first file\n");
+	    return 0;
+    }  
+
+    get_params(
+                control_block,
+                rawinput,
+                header_buf,
+                filname,
+                channelbuffer
+    );
+
+    // Now that we know our sizing requirements, allocate the buffers...
+    // ...raw data read buffer (allocate and free each time because we don 't know 
+    // how many times we'll be here)
+    rawinput.pf.sub.data  = (unsigned char *) malloc(rawinput.pf.sub.bytes_per_subint);
+    if(!rawinput.pf.sub.data) {
+	    fprintf(stderr, "error: couldn't allocate memory for the raw data read buffer\n");
+	    return 0;
+    } else {
+        fprintf(stderr, "malloc'ed %ld bytes at %p for the raw data read buffer!\n", rawinput.pf.sub.bytes_per_subint, rawinput.pf.sub.data);
+    }
+
+    // populate the header with static items
+    populate_header(
+	            control_block,
+                rawinput,
+                this_tapebuffer
+    );
+
+    //fflush(stdout);
+
+    control_block.startindx        = rawinput.gf.packetindex;
+    control_block.curindx          = control_block.startindx;
+    filecnt                        = rawinput.filecnt;
+    rawinput.curfile               = 0;			
+
+    // Read blocks until we run out of data or the numblocks request is met
+    do{    
+        retval = read_block(
+	                control_block,
+                    rawinput,
+                    header_buf,
+                    filname,
+                    start_data_time,
+                    end_data_time,
+                    j,
+                    this_tapebuffer
+                 );
+        if(retval) {
+            //tapebuffer.push_back(this_tapebuffer);
+            tapebuffer.push_back(this_tapebuffer);
+            this_tapebuffer.data.clear();
+        }
+    } while((!(rawinput.invalid)) && (control_block.currentblock <= (numblocks + control_block.startblock - 1)));
+
+    fprintf(stderr, "getting coordinate history...\n");
+    get_coord_history();
 	
     fprintf(stderr, "finishing up...\n");
 
-    if(vflag>=1) fprintf(stderr, "bytes: %ld\n",by);
+    if(control_block.vflag>=1) fprintf(stderr, "bytes: %ld\n",by);
 	
+    // free the raw data read buffer
     if (rawinput.pf.sub.data) {
+        fprintf(stderr, "freeing rawinput.pf.sub.data at %p\n", rawinput.pf.sub.data);
 	    free(rawinput.pf.sub.data);
+        rawinput.pf.sub.data = NULL;
 	    fprintf(stderr, "freed subint data buffer\n");
     }
 
     fprintf(stderr, "done\n");
 
-    free(channelbuffer);
+    // commented out by jeffc
+    //free(channelbuffer);
 
-    int blocks_read = setibuffer_pos / ((chanbytes * 2 * sizeof(float)) + sizeof(setiheader));
-    if(vflag>=1) fprintf(stderr, "grabbed %Ld blocks covering %lf seconds of time\n", blocks_read, (end_data_time-start_data_time)*86400);
+    int blocks_read = tapebuffer.size();
+    if(control_block.vflag>=1) fprintf(stderr, "grabbed %Ld blocks covering %lf seconds of time\n", 
+                                       blocks_read, (end_data_time-start_data_time)*86400);
     return blocks_read;
 
 }   // end read_blocks_guppi()
 
 //-------------------------------------------------------
-int unpack_samples(unsigned char * raw, unsigned char * dest, long int count, int pol) {
+int unpack_samples(unsigned char * raw, long int count, int pol, dr2_compact_block_t &this_tapebuffer) {
 //-------------------------------------------------------
-/* unpack guppi samples stored in raw into dest as 32 bit floats real/imag */
-/* count is number of samples, offset is a memory offset within dest (bytes), pol is polarization (0 for X, 1 for Y) */
+// unpack guppi 2 bit complex samples into a vector of complex signed chars
+// pol is polarization (0 for X, 1 for Y) 
 
 	 int i;
-
-	 float * samples;
+     int shift_factor = pol * 2;    // shift_factor will be 0 or 2
 	 float quantlookup[4];
-
-	 samples = (float *)malloc(sizeof(float) * count * 2);
-
-	 quantlookup[0] = 3.3358750;
-	 quantlookup[1] = 1.0;
-	 quantlookup[2] = -1.0;
-	 quantlookup[3] = -3.3358750;
-
-	 for(i=0;i<count;i=i+2) {
-
-		  /* real */
-		  samples[i] = quantlookup[( raw[i] >> (0 * 2) & 1) +  (2 * (raw[i] >> (0 * 2 + 1) & 1))]   ; //real pol 0
-
-		  /* imag */
-		  samples[i+1] = quantlookup[(raw[i] >> (1 * 2) & 1) +  (2 * (raw[i] >> (1 * 2 + 1) & 1))]   ; //imag pol 0
-
+     std::complex<signed char> sample;
+
+     // the * 10 is to keep some of the precision intact as we
+     // go to signed char  
+	 quantlookup[0] = 3.3358750     * 10;
+	 quantlookup[1] = 1.0           * 10;      
+	 quantlookup[2] = -1.0          * 10;
+	 quantlookup[3] = -3.3358750    * 10;
+
+	 for(i=0; i < count; i++) {
+          // real (2 bits of raw data)
+		  sample.real( (signed char)quantlookup[( raw[i] >> (shift_factor * 2)      & 1)        +   // bit 0 or 4  
+                                                ((raw[i] >> (shift_factor * 2 + 1)  & 1) * 2)]      // bit 1 or 5
+                     ); 
+		  // imag (2 bits of raw data)
+		  sample.imag( (signed char)quantlookup[( raw[i] >> (shift_factor+1 * 2)      & 1)      +   // bit 2 or 6 
+                                                ((raw[i] >> (shift_factor+1 * 2 + 1)  & 1) * 2)]    // bit 3 or 7
+                     ); 
+          // add this sample to our vector
+          this_tapebuffer.data.push_back(sample);
 	 }
-	 memcpy(dest, samples, sizeof(float) * count * 2);
 
-     free(samples);
+//fprintf(stderr, "old count : %ld    new count : %ld\n", count,  this_tapebuffer.data.size());
+//fprintf(stderr, "old data  : %d %d  new data  :  %d %d\n", samples[0], samples[1], this_tapebuffer.data[0].real(), this_tapebuffer.data[0].imag());
+//fprintf(stderr, "old data  : %d %d  new data  :  %d %d\n", samples[2], samples[3], this_tapebuffer.data[1].real(), this_tapebuffer.data[1].imag());
+//fprintf(stderr, "old data  : %d %d  new data  :  %d %d\n", samples[count*2-2], samples[count*2-1], this_tapebuffer.data[count-1].real(), this_tapebuffer.data[count-1].imag());
+
 	 return 0;
 }
 
diff --git a/splitter_pfb/mb_read_blocks_guppi.h b/splitter_pfb/mb_read_blocks_guppi.h
index 7e8f5c7..a70f08c 100644
--- a/splitter_pfb/mb_read_blocks_guppi.h
+++ b/splitter_pfb/mb_read_blocks_guppi.h
@@ -3,5 +3,5 @@ long int read_blocks_guppi(char * file_prefix,
                            long int numblocks, 
                            int channel, 
                            int polarization, 
-                           int vflag, 
-                           unsigned char **setibuffer);
+                           int vflag 
+);
diff --git a/splitter_pfb/mb_splitter.cpp b/splitter_pfb/mb_splitter.cpp
index 9368151..b130f68 100644
--- a/splitter_pfb/mb_splitter.cpp
+++ b/splitter_pfb/mb_splitter.cpp
@@ -570,8 +570,8 @@ int main(int argc, char *argv[]) {
     }
     find_start_point_dr2(tape_fd, beam, pol);
   } else if(file_type == guppi) {
-    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"guppi file type not implemented\n");
-    exit(1);
+    //log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"guppi file type not implemented\n");
+    //exit(1);
   } else {
     log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"invalid file type");
     exit(1);
@@ -614,13 +614,14 @@ int main(int argc, char *argv[]) {
                                     pol,
                                     vflag);
     } else if(file_type == guppi) {
+        // UNcomment the following two lines for a production build
         log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"guppi file type not implemented\n");
         exit(1);
 
         // guppi data for a WUG may be spread out over more than one file.  File naming
         // determines the order of files.  Thus, we pass a partial file name instead of
         // an open descriptor.
-	    unsigned char *setibuffer   = NULL;
+        std::vector<dr2_compact_block_t> tapebuffer_guppi;
 	    long int numblocks          = 325;  // gives ~107s of data for guppi kepler, TODO - needs overlap, specify in secs, not blocks? 
 	    int channel                 = 1;
 
@@ -630,8 +631,7 @@ int main(int argc, char *argv[]) {
                                       numblocks,               // what about WU time overlap? 
                                       channel,                 // data selection for guppi is channel wise
                                       pol, 
-                                      vflag,
-                                      &setibuffer);
+                                      vflag);
         fprintf(stderr, "goodread = %ld\n", good_read);
     } else {
         log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"invalid file type");
@@ -641,6 +641,7 @@ int main(int argc, char *argv[]) {
     if(!good_read) {
       break;        // drop out of main loop on first bad read
     } else {
+      // COMMENT the following line for a production build
       //continue;   // short circuit for guppi/gbt testing
       if (make_wu_headers(tapebuffer,tel,wuheaders)) {
         int child_pid=-1;
diff --git a/splitter_pfb/mb_wufiles.cpp b/splitter_pfb/mb_wufiles.cpp
index 2ef609a..005d469 100644
--- a/splitter_pfb/mb_wufiles.cpp
+++ b/splitter_pfb/mb_wufiles.cpp
@@ -248,9 +248,7 @@ tel, std::vector<workunit> &wuheader) {
     bin_data[i].clear();
     wuheader[i].group_info=wugrp;
     wuheader[i].group_info.id=wugrp.id;
-    sprintf(wuheader[i].name,"%s.%ld.%d.%ld.%d.%d",tapebuffer[0].header.name,
-       procid, tapebuffer[0].header.dataseq,
-       tel-AO_430,s.id,i);
+    sprintf(wuheader[i].name,"%s.%d", wugrp.name, i);
     if (group_is_vlar) {
       strlcat(wuheader[i].name,".vlar",sizeof(wuheader[i].name));
     }
diff --git a/splitter_pfb/splitparms.h b/splitter_pfb/splitparms.h
index 64337a4..bc0c4a5 100644
--- a/splitter_pfb/splitparms.h
+++ b/splitter_pfb/splitparms.h
@@ -28,23 +28,6 @@
 #define IFFT_LEN 1
 #define NSTRIPS (FFT_LEN/IFFT_LEN)
 
-/* Tape format parameters */
-#define TAPE_HEADER_SIZE 1024L
-#define TAPE_DATA_SIZE 1048576L
-#define TAPE_FRAMES_PER_RECORD 8L
-#define TAPE_FRAME_SIZE (TAPE_HEADER_SIZE+TAPE_DATA_SIZE)
-#define TAPE_RECORD_SIZE (TAPE_FRAMES_PER_RECORD*TAPE_FRAME_SIZE)
-#define TAPE_BUFFER_SIZE (((NSTRIPS*NBYTES*7/4)/TAPE_RECORD_SIZE+1)*TAPE_RECORD_SIZE)
-#define TAPE_RECORDS_IN_BUFFER (TAPE_BUFFER_SIZE/TAPE_RECORD_SIZE)
-#define TAPE_FRAMES_IN_BUFFER (TAPE_RECORDS_IN_BUFFER*8)
-#define TAPE_FRAMES_PER_WU (NBYTES*NSTRIPS/TAPE_DATA_SIZE)
-#define WU_OVERLAP_RECORDS 2
-#define WU_OVERLAP_FRAMES (TAPE_FRAMES_PER_RECORD*WU_OVERLAP_RECORDS)
-#define WU_OVERLAP_BYTES (WU_OVERLAP_FRAMES*TAPE_DATA_SIZE)
-#define RECORDER_BUFFER_BYTES (1024L*1024L)
-#define RECORDER_BUFFER_SAMPLES (RECORDER_BUFFER_BYTES*4)
-
-
 /* Time Zone Parameters */
 #define UTC  0.0
 #define AST  (UTC-4.0)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-boinc/boinc-app-seti.git



More information about the pkg-boinc-commits mailing list