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

Gianfranco Costamagna locutusofborg-guest at moszumanska.debian.org
Fri Sep 11 07:56:11 UTC 2015


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

locutusofborg-guest pushed a commit to branch master
in repository boinc-app-seti.

commit 56d766684e154adbecb4a3be6d56589eaf231b48
Author: Gianfranco Costamagna <costamagnagianfranco at yahoo.it>
Date:   Fri Sep 11 09:40:39 2015 +0200

    Imported Upstream version 7.28~svn3047
---
 splitter_pfb/Makefile.am              |  16 +-
 splitter_pfb/mb_read_blocks_guppi.cpp | 504 ++++++++++++++++++++++++++++++++++
 splitter_pfb/mb_read_blocks_guppi.h   |   7 +
 splitter_pfb/mb_splitter.cpp          |  94 ++++---
 4 files changed, 576 insertions(+), 45 deletions(-)

diff --git a/splitter_pfb/Makefile.am b/splitter_pfb/Makefile.am
index eb5fd96..cb8f39e 100644
--- a/splitter_pfb/Makefile.am
+++ b/splitter_pfb/Makefile.am
@@ -36,6 +36,7 @@ mb_splitter_SOURCES=mb_angdist.cpp \
 		    mb_message.cpp \
 		    mb_splitter.cpp \
 		    mb_read_blocks_dr2.cpp \
+		    mb_read_blocks_guppi.cpp \
 		    mb_wufiles.cpp \
 		    mb_dotransform.cpp \
 		    mb_validrun.cpp \
@@ -52,13 +53,16 @@ mb_splitter_SOURCES=mb_angdist.cpp \
 		     ../client/hr_min_sec.o
 
 mb_splitter_CXXFLAGS= \
-	   -O3 \
-       -I$(SETIHOME) -I$(SETIHOME)/client -I$(SETIHOME)/db \
-       @MYSQL_CFLAGS@ -I$(HEALPIX)/include \
-       @INFORMIX_CFLAGS@ @SETILIB_CFLAGS@ \
-       @BOINC_CFLAGS@ -I$(BOINCDIR)/tools -I$(BOINCDIR)/sched -I$(BOINCDIR)/db
+	   	-O3 \
+       	-I$(SETIHOME) -I$(SETIHOME)/client \
+		-I$(SETIHOME)/db @MYSQL_CFLAGS@ \
+		-I$(HEALPIX)/include @INFORMIX_CFLAGS@ \
+		@SETILIB_CFLAGS@ @BOINC_CFLAGS@ \
+		-I$(BOINCDIR)/tools -I$(BOINCDIR)/sched \
+		-I$(BOINCDIR)/db -I$(CFITSIO) \
+		-I$(SETI_GBT)/src
 mb_splitter_CFLAGS=$(mb_splitter_CXXFLAGS)
-mb_splitter_LDFLAGS=-static $(AM_LDFLAGS) -L$(HEALPIX)/lib $(LINKOPTIONS)
+mb_splitter_LDFLAGS=-static $(AM_LDFLAGS) -L$(HEALPIX)/lib -L$(SETI_GBT)/lib -lsetigbt -lsla -L$(CFITSIO) -lcfitsio $(LINKOPTIONS)
 mb_splitter_LDADD=$(SPLITLIBS) $(GSL_LIBS)
 
 ../db/sqlifx.cpp: ../db/sqlifx.ec
diff --git a/splitter_pfb/mb_read_blocks_guppi.cpp b/splitter_pfb/mb_read_blocks_guppi.cpp
new file mode 100644
index 0000000..99afe34
--- /dev/null
+++ b/splitter_pfb/mb_read_blocks_guppi.cpp
@@ -0,0 +1,504 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+#include "fitsio.h"
+#include "psrfits.h"
+#include "guppi_params.h"
+#include "fitshead.h"
+#include "median.h"
+#include "setimysql.h"
+#include <fftw3.h>
+#include <sys/stat.h>
+#include "barycenter.h"
+#include "rawdopplersearch.h"
+#include "mb_read_blocks_guppi.h"
+
+/* Guppi channel-frequency mapping */
+/* sample at 1600 MSamp for an 800 MHz BW */
+/* N = 256 channels with frequency centers at m * fs/N */
+/* m = 0,1,2,3,... 255 */
+
+// guppi raw data layout (data portion of a ~psrfits HDU (subintegration)):
+//
+// First of 32 frequency channels / subintegration:
+// Pol0Samp0    Pol0Samp0   Pol1Samp0   Pol1Samp0   ... Pol1Samp255 Pol1Samp255
+// real         imag        real        imag            real        imag
+// |--------------------------------------------|       ----------------------|
+//   byte 0 (2 bit data, quantized from 8 bit)              ... byte 255
+//   time 0                                                 ... time 255
+//
+// The next subintegration will be the same 32 channels, starting with time 256.
+// Thus, each subintegration is 32*256 = 8192 bytes of data.
+
+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
+};
+
+/* Parse info from buffer into param struct */
+extern void guppi_read_obs_params(char *buf, 
+                                     struct guppi_params *g,
+                                     struct psrfits *p);
+
+/* prototypes */
+
+int exists(const char *fname);
+
+int unpack_samples(unsigned char * raw, unsigned char *dest, long int count, int pol);
+
+//-------------------------------------------------------
+int print_header(seti_data & setiheader) {
+//-------------------------------------------------------
+	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);
+}
+
+
+//-------------------------------------------------------
+long int read_blocks_guppi(char * file_prefix,
+                           long int startblock, 
+                           long int numblocks, 
+                           int channel, 
+                           int polarization, 
+                           int vflag, 
+                           unsigned char **setibuffer) {
+//-------------------------------------------------------
+
+	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;
+
+	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 we managed to open a file */
+    if(rawinput.fil){
+	    if(fread(buf, sizeof(char), 32768, rawinput.fil) == 32768){
+		   
+		    guppi_read_obs_params(buf, &rawinput.gf, &rawinput.pf);
+		   
+		    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);
+				
+			    /* rewind to the beginning */	
+		   	    fseek(rawinput.fil, -32768, 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);
+			    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 */
+		   
+		    rawinput.fil = NULL;
+
+		    hgeti4(buf, "OVERLAP", &rawinput.overlap);
+
+			
+		    fprintf(stderr, "   packetindex       : %lld\n", rawinput.gf.packetindex);
+		    fprintf(stderr, "   packetsize        : %d\n", rawinput.gf.packetsize);
+		    fprintf(stderr, "   n_packets         : %d\n", rawinput.gf.n_packets);
+		    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");
+
+    /* number of packets that we *should* increment by */
+    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 = ((rawinput.pf.sub.bytes_per_subint / rawinput.pf.hdr.nchan) - rawinput.overlap) / ftacc;	
+
+    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);
+	    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 */
+    /* 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);
+
+    channelbuffer  = (unsigned char *) calloc( 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 );	
+
+    //	tstart=band[first_good_band].pf.hdr.MJD_epoch;
+    //	tsamp = band[first_good_band].pf.hdr.dt * ftacc;
+
+    //	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))));
+    */
+
+    *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 );
+
+    fflush(stdout);
+
+    startindx = rawinput.gf.packetindex;
+    curindx = startindx;
+
+    filecnt = rawinput.filecnt;
+
+    rawinput.curfile = 0;			
+
+    do{     // start while(!(rawinput.invalid))
+										
+	    if(!rawinput.invalid){						  
+		    if(rawinput.fil == NULL) {
+			    /* no file is open for this band, try to open one */
+			    sprintf(filname, "%s.%04d.raw",rawinput.file_prefix,rawinput.curfile);
+			    if(exists(filname)){
+                    fprintf(stderr, "Opening %s\n", filname);
+				    rawinput.fil = fopen(filname, "rb");			 
+				    if(rawinput.curfile == 0 && rawinput.first_file_skip != 0) fseek(rawinput.fil, rawinput.first_file_skip, SEEK_CUR);  
+			    }	else {
+			  	    rawinput.invalid = 1;
+		  	  	    fprintf(stderr, "couldn't open any more files!\n");
+		  	    }
+		    }
+
+		    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) {
+		            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);
+
+					currentblock = (long int) ((double) rawinput.gf.packetindex/ (double) indxstep);
+
+					if(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,
+						            rawinput.pf.sub.ra,
+						            rawinput.pf.sub.dec,
+						            rawinput.pf.sub.offs,
+						            rawinput.pf.sub.tsubint,
+						            rawinput.pf.hdr.MJD_epoch);
+					}
+					
+					/* 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;           
+					/* 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);    
+
+                    if(currentblock == 1) {
+                        start_data_time = setiheader.data_time;     // assigned once                  
+                    } else {
+                        end_data_time   = setiheader.data_time;     // assigned many times, will end up with the final block's time
+                    }
+					
+			   		if(rawinput.gf.packetindex == curindx) {
+						 /* read a subint with correct index */
+
+						 fseek(rawinput.fil, gethlength(buf), SEEK_CUR);
+						 rv=0;
+						 
+						 if (currentblock > (startblock-1)){
+						 
+						 	rv=fread(rawinput.pf.sub.data, sizeof(char), rawinput.pf.sub.bytes_per_subint, rawinput.fil);		 
+						 	
+							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);						   
+
+                               // 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;
+
+							} else {
+								rawinput.fil = NULL;
+								rawinput.invalid = 1;
+								fprintf(stderr,"ERR: couldn't read as much as the header said we could... assuming corruption and exiting...\n");
+								return 0;
+							}
+
+						 } else (rv = fseek(rawinput.fil, rawinput.pf.sub.bytes_per_subint, SEEK_CUR)); 
+						 
+					} else if( (rawinput.gf.packetindex > curindx) && (currentblock > (startblock-1)) ) {
+
+						 fprintf(stderr,"ERR: curindx: %Ld, pktindx: %Ld Did we drop a whole subintegration? Reusing last subint...\n", 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));
+
+						/* 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 );
+						 /* 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);
+				} else {
+				   fprintf(stderr, "Could not read first/next 32KB\n"); 
+				   fclose(rawinput.fil);
+				   rawinput.fil = NULL;
+				   rawinput.curfile++;						
+				}   // end if((fread(buf...)
+		    }   // end if(rawinput.fil)			 	 	 
+	    }   // end if(!rawinput.invalid)
+										
+	    if(rawinput.fil != NULL) curindx = curindx + indxstep;
+
+    // Keep going until we run out of data or the numblocks request is met
+    } while((!(rawinput.invalid)) && (currentblock <= (numblocks + startblock - 1)));
+	
+    fprintf(stderr, "finishing up...\n");
+
+    if(vflag>=1) fprintf(stderr, "bytes: %ld\n",by);
+	
+    if (rawinput.pf.sub.data) {
+	    free(rawinput.pf.sub.data);
+	    fprintf(stderr, "freed subint data buffer\n");
+    }
+
+    fprintf(stderr, "done\n");
+
+    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);
+    return blocks_read;
+
+}   // end read_blocks_guppi()
+
+//-------------------------------------------------------
+int unpack_samples(unsigned char * raw, unsigned char * dest, long int count, int pol) {
+//-------------------------------------------------------
+/* 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) */
+
+	 int i;
+
+	 float * samples;
+	 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
+
+	 }
+	 memcpy(dest, samples, sizeof(float) * count * 2);
+
+     free(samples);
+	 return 0;
+}
+
+//-------------------------------------------------------
+int exists(const char *fname) {
+//-------------------------------------------------------
+    FILE *file;
+    if ((file = fopen(fname, "r"))) {
+        fclose(file);
+        return 1;
+    }
+    return 0;
+}
diff --git a/splitter_pfb/mb_read_blocks_guppi.h b/splitter_pfb/mb_read_blocks_guppi.h
new file mode 100644
index 0000000..7e8f5c7
--- /dev/null
+++ b/splitter_pfb/mb_read_blocks_guppi.h
@@ -0,0 +1,7 @@
+long int read_blocks_guppi(char * file_prefix,
+                           long int startblock, 
+                           long int numblocks, 
+                           int channel, 
+                           int polarization, 
+                           int vflag, 
+                           unsigned char **setibuffer);
diff --git a/splitter_pfb/mb_splitter.cpp b/splitter_pfb/mb_splitter.cpp
index 0b9714d..9368151 100644
--- a/splitter_pfb/mb_splitter.cpp
+++ b/splitter_pfb/mb_splitter.cpp
@@ -28,6 +28,7 @@
 #include "splittypes.h"
 #include "mb_splitter.h"
 #include "mb_read_blocks_dr2.h"
+#include "mb_read_blocks_guppi.h"
 #include "mb_validrun.h"
 #include "mb_wufiles.h"
 #include "mb_dotransform.h"
@@ -105,6 +106,7 @@ int iters=-1;
 int beam;
 int pol;
 int alfa;
+int gbt;
 int useanalysiscfgid = 0;
 int usereceivercfgid = 0;
 int userecordercfgid = 0;
@@ -134,6 +136,8 @@ buffer_pos_t start_of_wu,end_of_wu;  /* position of start and end of wu in
                                       tape buffer */
 int seqno;
 
+
+
 //-------------------------------------------------------------------------
 void cleanup(void) {
 //-------------------------------------------------------------------------
@@ -152,7 +156,7 @@ int process_command_line(int argc, char *argv[],char **tape_device,
                          int *norewind, int *startblock, int *resumetape,
                          int *nodb, int *dataclass, int *atnight,
                          int *max_wus_ondisk, char **projectdir,
-			 int *iters, int *beam, int *pol, int *alfa,
+			 int *iters, int *beam, int *pol, int *alfa, int *gbt,
                          int *useanalysiscfgid, int *usereceivercfgid,
                          int *userecordercfgid, int *usesplittercfgid) {
 //-------------------------------------------------------------------------
@@ -204,18 +208,25 @@ int process_command_line(int argc, char *argv[],char **tape_device,
                           if (!strncmp(argv[i],"-appname",MAX(ep-argv[i],3))) { 
  		                    strlcpy(appname,ep+1,sizeof(appname)); 
  		                   } else if (!strncmp(argv[i],"-trigger_file_path",MAX(ep-argv[i],2))) {
-			    char *fe=ep+1;
-			    memset(trigger_file_path,0,sizeof(trigger_file_path));
-			    while (isgraph(*(fe++))) trigger_file_path[fe-ep-2]=*fe ;
+			                    char *fe=ep+1;
+			                    memset(trigger_file_path,0,sizeof(trigger_file_path));
+			                    while (isgraph(*(fe++))) trigger_file_path[fe-ep-2]=*fe ;
                           } else if (!strncmp(argv[i],"-alfa",MAX(ep-argv[i],3))) {
-			    sscanf(ep+1,"%d,%d",beam,pol);
-			    if (((*beam<0) || (*beam>6)) ||
-			        ((*pol<0) || (*pol>1))) {
-                                 log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"ALFA receivers must be specified with beam (0-6) and polarization (0-1), i.e. -alfa=4,0\n");
-				 exit(EXIT_FAILURE);
-		            }
-
-			    *alfa=1;
+			                    sscanf(ep+1,"%d,%d",beam,pol);
+			                    if (((*beam<0) || (*beam>6)) ||
+			                        ((*pol<0) || (*pol>1))) {
+                                    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"ALFA receivers must be specified with beam (0-6) and polarization (0-1), i.e. -alfa=4,0\n");
+				                    exit(EXIT_FAILURE);
+		                        }
+			                    *alfa=1;
+                          } else if (!strncmp(argv[i],"-gbt",MAX(ep-argv[i],3))) {
+			                    sscanf(ep+1,"%d,%d",beam,pol);
+			                    if ((*beam != 0)  ||
+			                        ((*pol<0) || (*pol>1))) {
+                                    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"GBT receivers must be specified with beam 0 and polarization (0-1), i.e. -gbt=0,1\n");
+				                    exit(EXIT_FAILURE);
+		                        }
+			                    *gbt=1;
                           } else if (!strncmp(argv[i],"-iterations",MAX(ep-argv[i],2))) {
 			    sscanf(ep+1,"%d",iters);
 			  } else if (!strncmp(argv[i],"-startblock",MAX(ep-argv[i],2))) {
@@ -513,7 +524,7 @@ int main(int argc, char *argv[]) {
   /* Process command line arguments */
   if (process_command_line(argc,argv,&tape_device,&norewind,&startblock,&resumetape,
                            &nodb,&dataclass,&atnight,&max_wus_ondisk,&projectdir,&iters,
-			   &beam,&pol,&alfa,&useanalysiscfgid,&usereceivercfgid,
+			   &beam,&pol,&alfa,&gbt,&useanalysiscfgid,&usereceivercfgid,
                            &userecordercfgid,&usesplittercfgid))  {
     fprintf(stderr,"Usage: splitter tape_device -projectdir=s [-atnight] [-nodb]\n"
     "[-xml] [-gregorian] [-resumetape | -norewind | -startblock=n] [-dataclass=n]\n"
@@ -523,6 +534,9 @@ int main(int argc, char *argv[]) {
     exit(EXIT_FAILURE);
   }
 
+  if(alfa) file_type = dr2;
+  if(gbt)  file_type = guppi;
+
   // MATTL
   if (blanking_bit == SOFTWARE_BLANKING_BIT) log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,"blanking bit: %d (SOFTWARE)\n",blanking_bit);
   else log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,"blanking bit: %d (HARDWARE)\n",blanking_bit);
@@ -549,15 +563,14 @@ int main(int argc, char *argv[]) {
 
   check_for_halt();
 
-  if ((tape_fd=open(tape_device,O_RDONLY|0x2000, 0777))<0) {
-    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Unable to open tape device\n");
-    exit(EXIT_FAILURE);
-  }
-
   if(file_type == dr2) {
+    if ((tape_fd=open(tape_device,O_RDONLY|0x2000, 0777))<0) {
+        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Unable to open tape device\n");
+        exit(EXIT_FAILURE);
+    }
     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");
+    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");
@@ -594,15 +607,32 @@ int main(int argc, char *argv[]) {
     // End check, and maybe wait on, various run conditions
 
     if(file_type == dr2) {
-        good_read = read_blocks_dr2(tape_fd,
-                                    startblock,               // long int
-                                    512-tapebuffer.size(),    // the 512 allows for WU time overlap
-                                    beam,
+        good_read = read_blocks_dr2(tape_fd,                    // raw dr2 input
+                                    startblock,                 // long int
+                                    512-tapebuffer.size(),      // the 512 allows for WU time overlap
+                                    beam,                       // data selection for dr2 is beam wise
                                     pol,
                                     vflag);
     } else if(file_type == guppi) {
-        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"guppi file type not implemented");
+        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;
+	    long int numblocks          = 325;  // gives ~107s of data for guppi kepler, TODO - needs overlap, specify in secs, not blocks? 
+	    int channel                 = 1;
+
+        vflag=1;
+	    good_read = read_blocks_guppi(tape_device,             // file_prefix, raw guppi input         
+                                      startblock,  
+                                      numblocks,               // what about WU time overlap? 
+                                      channel,                 // data selection for guppi is channel wise
+                                      pol, 
+                                      vflag,
+                                      &setibuffer);
+        fprintf(stderr, "goodread = %ld\n", good_read);
     } else {
         log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"invalid file type");
         exit(1);
@@ -611,6 +641,7 @@ int main(int argc, char *argv[]) {
     if(!good_read) {
       break;        // drop out of main loop on first bad read
     } else {
+      //continue;   // short circuit for guppi/gbt testing
       if (make_wu_headers(tapebuffer,tel,wuheaders)) {
         int child_pid=-1;
         log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,"doing transform..." );
@@ -757,21 +788,6 @@ int main(int argc, char *argv[]) {
  * *** empty log message ***
  *
  * Revision 1.6  2003/09/22 17:05:38  korpela
- * *** empty log message ***
- *
- * Revision 1.5  2003/09/13 20:48:38  korpela
- * directory reorg.  Moved client files to ./client
- *
- * Revision 1.4  2003/09/11 18:53:38  korpela
- * *** empty log message ***
- *
- * Revision 1.3  2003/08/13 23:18:47  korpela
- * *** empty log message ***
- *
- * Revision 1.2  2003/08/05 17:23:42  korpela
- * More work on database stuff.
- * Further tweaks.
- *
  * Revision 1.1  2003/07/29 20:35:50  korpela
  *
  * renames .C files to .cpp

-- 
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