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