tomwalters@0: /* tomwalters@0: integrate.c Integrate (ie average) SAI frames over time or frequency. tomwalters@0: ----------- tomwalters@0: tomwalters@0: Sequence of frames must have an SAI header. tomwalters@0: The whole of every frame read in is integrated (in either time or freq). tomwalters@0: Use edframe to set integration limits and select frames. tomwalters@0: The output is a sequence of arrays without a header, one per input frame, tomwalters@0: each of length `framewidth'. tomwalters@0: If `average=on' the output is one array of length `framewidth' which is tomwalters@0: the average of the sequence of arrays. tomwalters@0: tomwalters@0: Example: tomwalters@0: tomwalters@0: 1. Integrate the 2nd SAI frame over time from 10ms to 20ms. tomwalters@0: gensai output=stdout ... | select frame=2 time=10ms-20ms | integrate var=time > ... tomwalters@0: tomwalters@0: 2. Integrate the 2nd SAI frame over frequency from channels 5 to 8 inclusive. tomwalters@0: gensai output=stdout ... | select frame=2 freq=5-8 | integrate var=time > ... tomwalters@0: tomwalters@0: */ tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "header.h" tomwalters@0: #include "options.h" tomwalters@0: #include "strmatch.h" tomwalters@0: tomwalters@0: tomwalters@0: char applic[] = "Integrate SAI frames over time or frequency. " ; tomwalters@0: tomwalters@0: static char *helpstr, *debugstr, *varstr, *avstr, *typestr, *infostr ; tomwalters@0: tomwalters@0: static Options option[] = { tomwalters@0: { "help" , "off" , &helpstr , "help" , DEBUG }, tomwalters@0: { "debug" , "off" , &debugstr , "debugging switch" , DEBUG }, tomwalters@0: { "variable" , "time" , &varstr , "variable of integration (time or frequency)" , VAL }, tomwalters@0: { "average" , "off" , &avstr , "average all integrated frames" , VAL }, tomwalters@0: { "type" , "short" , &typestr , "output data type" , VAL }, tomwalters@0: { "info" , "off" , &infostr , "print frame size info" , VAL }, tomwalters@0: ( char * ) 0 } ; tomwalters@0: tomwalters@0: tomwalters@0: int frameheight, framewidth ; /* Parameters read from header */ tomwalters@0: int framebytes ; tomwalters@0: int average ; tomwalters@0: int type ; tomwalters@0: tomwalters@0: tomwalters@0: main(argc, argv) tomwalters@0: int argc ; tomwalters@0: char *argv[] ; tomwalters@0: { tomwalters@0: FILE *fp ; tomwalters@0: char *header, *SaiHeader(); tomwalters@0: short *frame ; tomwalters@0: float *buf, *avbuf ; tomwalters@0: int i, j, k, n ; tomwalters@0: tomwalters@0: fp = openopts( option,argc,argv ) ; tomwalters@0: if ( !isoff( helpstr ) ) tomwalters@0: helpopts( helpstr, argv[0], applic, option ) ; tomwalters@0: tomwalters@0: average = ison( avstr ) ; tomwalters@0: if ( ( type = typeindex( typestr ) ) < 0 ) { tomwalters@0: fprintf( stderr, "integframe: bad type [%s]\n", typestr ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: tomwalters@0: if ( (header = ReadHeader(fp)) == (char *) 0 ) { tomwalters@0: fprintf(stderr,"integrate: header not found\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: frameheight = HeaderInt( header, "frameheight" ); tomwalters@0: framewidth = HeaderInt( header, "framewidth" ); tomwalters@0: framebytes = HeaderInt( header, "framebytes" ); tomwalters@0: tomwalters@0: if ( ison( infostr ) ) tomwalters@0: fprintf( stderr,"frameheight=%d framewidth=%d\n", frameheight, framewidth ) ; tomwalters@0: tomwalters@0: /* Allocate space for framebytes of data */ tomwalters@0: tomwalters@0: if ( (frame = (short *)malloc( framebytes )) == (short *)0 ) { tomwalters@0: fprintf(stderr,"integrate: malloc out of space\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: if ( iststr( varstr, "time" ) ) { tomwalters@0: if ( (buf = (float *)malloc( frameheight * sizeof( float ) )) == (float *)0 ) { tomwalters@0: fprintf(stderr,"integrate: malloc out of space\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: if ( average ) { tomwalters@0: if ( (avbuf = (float *)malloc( frameheight * sizeof( float ) )) == (float *)0 ) { tomwalters@0: fprintf(stderr,"integrate: malloc out of space\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: for ( i=0 ; i 0 ) { tomwalters@0: for ( i=0 ; i 0 ) { tomwalters@0: for ( i=0 ; i