#include <stdio.h>
#define FLOAT 4

main()
{
        int pchfd, newpchfd,pval,j;
	int firstframe,lastframe,nbframe;
	long skipbytes;
#define ARRSIZ 200
	float vals[ARRSIZ]; /* enough for 46 poles + 4 data values */
	char  input[32]; /* orig file containing pitches & amps */
	char  output[32]; /* new file containing pitches & amps */
	char	answer[10];

	fprintf(stderr," Enter name of pitch data input file\t");
	scanf("%s",input);
	if((pchfd = open(input,0)) < 0) {
		fprintf(stderr," Can't open pitch analysis file\n");
		exit(1);
		}
	nbframe = 2*FLOAT; 
	printf("counting starts at 1\n");
	fprintf(stderr," Enter frame to start at\t");
	scanf("%d",&firstframe);
	fprintf(stderr," Enter frame to end at\t");
	scanf("%d",&lastframe);
	if(lastframe < firstframe) {
		printf("pedit: error: last frame less than first.\n");
		exit(1);
		}

	printf("first frame is %d, last is %d\n", firstframe, lastframe);
	skipbytes = (firstframe - 1) * nbframe; /* why do I have to do 
							this? */
	if(lseek(pchfd, skipbytes, 0) < 0) {
		printf("error on lseek\n");
		exit(1);
		}
	for(j = firstframe; j <= lastframe; j++) {
		if(read(pchfd, (char *)vals, nbframe) != nbframe) {
			printf(" bad read\n");
			exit(1);
			}	
		fprintf(stderr,
		"  frame %d:\tptch = %f, \trmsamp = %f\n", 
		j,vals[0],vals[1]);

		}
}

