view tools/ftoa.c @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
line wrap: on
line source
/*
    ftoa.c      frames (SAI or NAP) to ASCII
    ------

    Each data point is output as a triple: (x,y,z)
    where (x,y) specify the coordinate in terms of a pointwise coordinate
    system with the origin (0,0) in the bottom-left of the display.

    The output is in space-separated ASCII numbers with one triple per line.
*/

#include <stdio.h>
#include <math.h>
#include "header.h"
#include "options.h"
#include "strmatch.h"


char applic[]     = "Frames to ASCII triples (x,y,z). " ;

static char *helpstr, *debugstr, *formatstr ;

static Options option[] = {
    {   "help"      ,   "off"       ,  &helpstr     ,   "help"                          , DEBUG },
    {   "debug"     ,   "off"       ,  &debugstr    ,   "debugging switch"              , DEBUG },
    {   "format"    ,   "nap"       ,  &formatstr   ,   "frame format (nap or sai)"     , VAL   },
   ( char * ) 0 } ;


int     frameheight, framewidth ;       /* Parameters read from header */
int     frames, framebytes ;

main(argc, argv)
int   argc ;
char *argv[] ;
{
    FILE   *fp ;
    char   *header, *SaiHeader();
    short  *frame ;
    int     x, y  ;

    fp = openopts( option,argc,argv ) ;
    if ( !isoff( helpstr ) )
	helpopts( helpstr, argv[0], applic, option ) ;

    if ( (header = ReadHeader(fp)) == (char *) 0 ) {
	fprintf(stderr,"integrate: header not found\n");
	exit(1);
    }

    frameheight = HeaderInt( header, "frameheight" );
    framewidth =  HeaderInt( header, "framewidth"  );
    frames =      HeaderInt( header, "frames"      );
    framebytes =  HeaderInt( header, "framebytes"  );


    if ( isstr( formatstr, "nap" ) ) {
	framebytes =  frames*frameheight*sizeof(short) ;
	framewidth =  frames ;
	if ( (frame = (short *)malloc( framebytes )) == (short *)0 ) {
	    fprintf(stderr,"ftoa: malloc out of space\n");
	    exit(1);
	}
	while ( fread( frame,framebytes,1,fp ) ) {
	    for ( x=0 ; x<framewidth ; x++ )
		for ( y=0 ; y<frameheight ; y++ )
		    printf("%-5d %-5d %-5d\n", x, y, *frame++ ) ;
	}
    }

    else if ( isstr( formatstr, "sai" ) ) {
	if ( (frame = (short *)malloc( framebytes )) == (short *)0 ) {
	    fprintf(stderr,"ftoa: malloc out of space\n");
	    exit(1);
	}
	while ( fread( frame,framebytes,1,fp ) ) {
	    for ( y=0 ; y<frameheight ; y++ )
		for ( x=0 ; x<framewidth ; x++ )
		    printf("%-5d %-5d %-5d\n", x, y, *frame++ ) ;
	}
    }

    else {
	fprintf( stderr,"ftoa: unknown format [%s]\n", formatstr ) ;
	exit( 1 ) ;
    }

    fclose( fp ) ;
}