/* now problem is that for >1 chan scan, hist will show || of all channels */ /* ok-->that's not a bug, it's a feature! */ #include "../H/sfheader.h" #include #include #include #include #include #include #define BUFSIZE 131072 #define ABS(x) ((x < 0) ? (-x) : (x)) SFHEADER sfh; int loopsize,bytestoread; main(argc,argv) int argc; char *argv[]; { SFMAXAMP sfm; struct stat sfst; char *cp,*sfname,*getsfcode(); int is_fft,i,j,bytes,sf,result; int bytenumber,next,total,segments,loopbytes; int shutup(); double atof(); char buffer[BUFSIZE]; /* hard wire to keep sloppy users from bad uses*/ float maxamps[4]; float incr,start,end; float jpeak,opeak; float scanshort(),scanfloat(),sample; int nskips,nprints,nstars,sampleflag; int chfirst,chlast,noplot=0; if(argc == 1) { printf("usage: hist [-p] filename\n"); printf("run-time args: increments [-nsamples], start [-sampletime], dur [-nsamples], [ch_first, ch_last], [overall_peak]\n"); printf("run-time defaults: scan all channels (scan ch 0 for sampl scan), overall_peak read from header\n"); exit(0); } while((*++argv)[0] == '-') { argc -= 2; /* Take away two args */ for(cp = argv[0]+1; *cp; cp++) { switch(*cp) { /* Grap options */ case 'p': noplot = 1; break; } } } sfname = argv[0]; readopensf(sfname,sf,sfh,sfst,"hist",result); if(result < 0) { close(sf); exit(1); } cp = getsfcode(&sfh,SF_MAXAMP); bcopy(cp + sizeof(SFCODE), (char *) &sfm, sizeof(SFMAXAMP)); opeak = 0; nstars = 40; printsf(&sfh); fflush(stdout); while(1) { is_fft=0; fprintf(stderr, "Enter increments, starting time, ending time:\t"); gets(buffer); i = sscanf(buffer, "%f %f %f %d %d %f", &incr,&start,&end,&chfirst,&chlast,&opeak); if(i == 3) { chfirst = 0; chlast = sfchans(&sfh) - 1; } if(i == 4) chlast = chfirst; if(i < 6) { for(i=chfirst; i<=chlast; i++) if(sfmaxamp(&sfm,i) > opeak) opeak = sfmaxamp(&sfm,i); } if(!opeak) opeak = 32678; /* default for files with no amp */ /* if increments is < 0 it means specify incr in samplesize if starting time is < 0 it means sample number if duration < 0 it indicates number of samples to look at */ sampleflag = (incr < 0) ? 1 : 0; if(incr < 0.) incr = -incr/sfsrate(&sfh); if(start < 0.) start = -start/sfsrate(&sfh); if(end < 0.) end = start - end/sfsrate(&sfh); bytes = start * sfclass(&sfh) * sfchans(&sfh) * sfsrate(&sfh); bytes -= bytes % (sfclass(&sfh) * sfchans(&sfh)); signal(SIGINT, shutup); /* roundout to multiple of sampleblocksize */ loopsize = incr * sfsrate(&sfh) + .5; loopbytes = loopsize * sfclass(&sfh) * sfchans(&sfh); if((bytenumber = sflseek(sf,bytes,0)) < 0) { printf("bad lseek on file %s\n",sfname); exit(-1); } bytenumber -= SIZEOF_HEADER; bytestoread = sfsrate(&sfh) * sfclass(&sfh) * sfchans(&sfh) * (end-start); while(bytestoread > 0) { total = next = (bytestoread > loopbytes) ? loopbytes : bytestoread; for(i=0; i 0) { segments = (next > BUFSIZE) ? BUFSIZE : next; if((read(sf,buffer,segments)) != segments) { fprintf(stderr,"Reached eof!\n"); goto nextstep; } bytenumber += segments; if(sfclass(&sfh) == SF_SHORT) sample = scanshort(buffer,segments,maxamps, chfirst,chlast); else sample = scanfloat(buffer,segments,maxamps, chfirst,chlast); next -= segments; } bytestoread -= total; if(sampleflag) { /* print with + & - along central axis */ printf("%d %e ",(bytenumber-segments)/ sfclass(&sfh)/sfchans(&sfh),sample); if(!noplot) { nprints = (float)nstars/2 * ABS(sample)/opeak; nskips = (sample < 0.) ? nstars/2 - nprints : nstars/2; printf("\t"); for(j=0;j jpeak) ? maxamps[i] : jpeak; } if(!noplot) { nprints = (float)nstars * jpeak/opeak; for(j=0;j maxamps[j]) maxamps[j] = ABS(buffer[sampleno+j]); sampleno += sfchans(&sfh); } return((float)buffer[chfirst]); /* return first value for sample scan*/ } float scanfloat(buffer,segments,maxamps,chfirst,chlast) float *maxamps; float *buffer; { int i,j,sampleno,samplesize; samplesize = segments / (SF_FLOAT * sfchans(&sfh)); for(i=0,sampleno=0; i maxamps[j]) maxamps[j] = ABS(buffer[sampleno+j]); sampleno += sfchans(&sfh); } return(buffer[chfirst]); } shutup() { bytestoread = 0; }