
#include <stdio.h>
#include <math.h>
#include "bait.h"
#include "pf.h"
#include "solvepht.h"

#define PAGE_LEN  20	/* # lines to print between page prompts */
#define STOP      1		/* don't print any more */
#define CONTINUE  2		/* keep printing */


static int print_one_star( /* FILE *fp; struct s_allstar *p, int len */ );
static int print_one_image( /* FILE *fp; struct s_image *im */ );
static int page_scroll( /* */ );

static int line_num = 0;


	/* print information on each star: they should be in order 
	   by master list x-coordinate */

print_stars(fp, len)
FILE *fp;
int len;
{
	int i;

	for (i = 0; i < num_ids; i++) {
		if (print_one_star(fp, &(star_arr[i]), len) == STOP)
			break;
	}	
}

	/* print the pertinent information from a single star entry
	   (which records all instances of the same star) from the given 
	   FILE pointer.  Each 'master star' gets N+1 lines of output,
	   where N is the number of actual instances of the star.  The first
	   line includes the number N at its end.  return the result
	   of page_scroll(). */

static int
print_one_star(fp, allstar, len)
FILE *fp;
struct s_allstar *allstar;
int len;
{
	int i;
	struct s_star *star;

	fprintf(fp, "%6d   %6.2lf %6.2lf %6d %d %d\n", allstar->id, allstar->xc, 
						allstar->yc, allstar->num, allstar->include,
						allstar->variable);

	if (len == SHORT)
		return(page_scroll());
	else 
		if (page_scroll() == STOP)
			return(STOP);
	
	for (star = allstar->stars, i = 0; i < allstar->num; i++) {
		if (star == NULL) 
			break;
		fprintf(fp, 
			"    %6d %10s %1d %6.0lf %5.2lf %4.2lf %5.2lf %6.3lf %8.0lf %d\n",
						star->id, star->image->name, star->saturated,
						star->peak, star->fwhm, star->sharp,
						star->round, star->mag, star->weight, star->include);
		star = star->next;
		if (page_scroll() == STOP)
			return(STOP);
	}
	return(CONTINUE);
}


	/* print information on each image, which should be in order 
	   by date and time of observation */

print_images(fp)
FILE *fp;
{
	int i;

	for (i = 0; i < num_images; i++) {
		if (print_one_image(fp, &(image_arr[i])) == STOP)
			break;
	}	
}

	/* print the pertinent information in a single image structure to
	   the given FILE pointer. return the result of page_scroll() */

static int
print_one_image(fp, im)
FILE *fp;
struct s_image *im;
{

	fprintf(fp, "%4d %10s %30s %10s %6.1lf %5.2lf %8.5lf %11.5lf %6d %6d %d\n",
			im->index, im->name, im->object, im->filter, im->exptime, 
			im->airmass, im->ut,
			im->mjd, im->num_star, im->num_match, im->include);
	return(page_scroll());

}

	/* print a message on the screen and wait for the user to type 
	   'return'; depending on the user's input, return STOP or
	   CONTINUE */

static int
page_scroll()
{
	static int num = 0;
	int c;

	if (++num >= PAGE_LEN) {
		num = 0;
		printf("             --  Type ENTER for more, or 'q' to quit --\n");
		if (((c = getchar()) == 'q') || (c == 'Q'))
			return(STOP);
		else
			return(CONTINUE);
	}
	else
		return(CONTINUE);
}
