annotate 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
rev   line source
tomwalters@0 1 /*
tomwalters@0 2 ftoa.c frames (SAI or NAP) to ASCII
tomwalters@0 3 ------
tomwalters@0 4
tomwalters@0 5 Each data point is output as a triple: (x,y,z)
tomwalters@0 6 where (x,y) specify the coordinate in terms of a pointwise coordinate
tomwalters@0 7 system with the origin (0,0) in the bottom-left of the display.
tomwalters@0 8
tomwalters@0 9 The output is in space-separated ASCII numbers with one triple per line.
tomwalters@0 10 */
tomwalters@0 11
tomwalters@0 12 #include <stdio.h>
tomwalters@0 13 #include <math.h>
tomwalters@0 14 #include "header.h"
tomwalters@0 15 #include "options.h"
tomwalters@0 16 #include "strmatch.h"
tomwalters@0 17
tomwalters@0 18
tomwalters@0 19 char applic[] = "Frames to ASCII triples (x,y,z). " ;
tomwalters@0 20
tomwalters@0 21 static char *helpstr, *debugstr, *formatstr ;
tomwalters@0 22
tomwalters@0 23 static Options option[] = {
tomwalters@0 24 { "help" , "off" , &helpstr , "help" , DEBUG },
tomwalters@0 25 { "debug" , "off" , &debugstr , "debugging switch" , DEBUG },
tomwalters@0 26 { "format" , "nap" , &formatstr , "frame format (nap or sai)" , VAL },
tomwalters@0 27 ( char * ) 0 } ;
tomwalters@0 28
tomwalters@0 29
tomwalters@0 30 int frameheight, framewidth ; /* Parameters read from header */
tomwalters@0 31 int frames, framebytes ;
tomwalters@0 32
tomwalters@0 33 main(argc, argv)
tomwalters@0 34 int argc ;
tomwalters@0 35 char *argv[] ;
tomwalters@0 36 {
tomwalters@0 37 FILE *fp ;
tomwalters@0 38 char *header, *SaiHeader();
tomwalters@0 39 short *frame ;
tomwalters@0 40 int x, y ;
tomwalters@0 41
tomwalters@0 42 fp = openopts( option,argc,argv ) ;
tomwalters@0 43 if ( !isoff( helpstr ) )
tomwalters@0 44 helpopts( helpstr, argv[0], applic, option ) ;
tomwalters@0 45
tomwalters@0 46 if ( (header = ReadHeader(fp)) == (char *) 0 ) {
tomwalters@0 47 fprintf(stderr,"integrate: header not found\n");
tomwalters@0 48 exit(1);
tomwalters@0 49 }
tomwalters@0 50
tomwalters@0 51 frameheight = HeaderInt( header, "frameheight" );
tomwalters@0 52 framewidth = HeaderInt( header, "framewidth" );
tomwalters@0 53 frames = HeaderInt( header, "frames" );
tomwalters@0 54 framebytes = HeaderInt( header, "framebytes" );
tomwalters@0 55
tomwalters@0 56
tomwalters@0 57 if ( isstr( formatstr, "nap" ) ) {
tomwalters@0 58 framebytes = frames*frameheight*sizeof(short) ;
tomwalters@0 59 framewidth = frames ;
tomwalters@0 60 if ( (frame = (short *)malloc( framebytes )) == (short *)0 ) {
tomwalters@0 61 fprintf(stderr,"ftoa: malloc out of space\n");
tomwalters@0 62 exit(1);
tomwalters@0 63 }
tomwalters@0 64 while ( fread( frame,framebytes,1,fp ) ) {
tomwalters@0 65 for ( x=0 ; x<framewidth ; x++ )
tomwalters@0 66 for ( y=0 ; y<frameheight ; y++ )
tomwalters@0 67 printf("%-5d %-5d %-5d\n", x, y, *frame++ ) ;
tomwalters@0 68 }
tomwalters@0 69 }
tomwalters@0 70
tomwalters@0 71 else if ( isstr( formatstr, "sai" ) ) {
tomwalters@0 72 if ( (frame = (short *)malloc( framebytes )) == (short *)0 ) {
tomwalters@0 73 fprintf(stderr,"ftoa: malloc out of space\n");
tomwalters@0 74 exit(1);
tomwalters@0 75 }
tomwalters@0 76 while ( fread( frame,framebytes,1,fp ) ) {
tomwalters@0 77 for ( y=0 ; y<frameheight ; y++ )
tomwalters@0 78 for ( x=0 ; x<framewidth ; x++ )
tomwalters@0 79 printf("%-5d %-5d %-5d\n", x, y, *frame++ ) ;
tomwalters@0 80 }
tomwalters@0 81 }
tomwalters@0 82
tomwalters@0 83 else {
tomwalters@0 84 fprintf( stderr,"ftoa: unknown format [%s]\n", formatstr ) ;
tomwalters@0 85 exit( 1 ) ;
tomwalters@0 86 }
tomwalters@0 87
tomwalters@0 88 fclose( fp ) ;
tomwalters@0 89 }
tomwalters@0 90
tomwalters@0 91