/**************************************************************************
 *                                                                        *
 * Copyright (c) 1996 Michael Richmond and Richard Treffers               *
 *                                                                        *
 *                    This software may be copied and distributed for     *
 *                    educational, research and not for profit services   *
 *                    provided that this copyright and statement are      *
 *                    included in all such copies.                        *
 *                                                                        *
 **************************************************************************/


/*	
	Shows circles and computes the  integrated sum inside

	aperint  [rad=]  [sky=] [del]
	
*/

#include <stdio.h>
#include <unistd.h>
#include "pcvista.h"
#include "pcvimage.h"


void main(int, char **);

char *progname = "aperint";

#define DEFAULT_RAD	5


#define USAGE "usage: aperint [rad=] [sky=] "
void 
main(argc, argv)
int argc;
char *argv[];
{
	char *gotit, buf[BIG_BUF];
	int rad=DEFAULT_RAD;
	int sky=0;

	for(i = 1; i < argc; i++) {		/* extract new values from command line */
		if (gotit = find("rad", argv[i])) {
			rad = (int)(evaluate(gotit) + .5);
			continue;
		}
		if (gotit = find("sky", argv[i])) {
			sky = (int)(evaluate(gotit) + .5);
			continue;
		}
		fprintf(stderr,"aperint: unknown option '%s'\n",argv[i]);
		exit(1);
	}

	image_init(TV_GREYSCALE);
		
	int_circle(&cr, &cc, &rad);

	exit(0);
}

	sum = 0.;
	pix = 0.;
	for (x = -radius; x <= radius; x++) {
		chord = (int)(sqrt(radius*radius + SMALL - ((double) x)*x) + 0.5);
		fits_get_data(fh,
			curses_row + x,
			curses_col - chord,
			data,
			2*chord+1);
			for (y = 0; y <= 2*chord; y++) {
			sum += ((double)data[y] - sky);
			pix += 1.0;
			}
	}
}																																												  
