Example #1
0
File: guide.c Project: cmatei/GCX
/* Search the frame for suitable guide star
 * Return 0 if found, -1 for an error. update x & y
 * with the star's coordinates if found.
 */
struct gui_star *detect_guide_star(struct ccd_frame *fr, struct region *reg)
{
	struct gui_star *gs;
	struct sources *src;
 	double score, max_score = 0;
	int gsi = 0, i = 0;
	double xc, yc, ds; //rf
//	double ref_flux = 0.0, ref_fwhm = 0.0;

	src = new_sources(P_INT(SD_MAX_STARS));
	if (src == NULL) {
		err_printf("detect_guide_star: cannot create sources\n");
		return NULL;
	}
//	rf = (fr->w * fr->w + fr->h * fr->h) / PI / 2;
	xc = fr->w / 2;
	yc = fr->h / 2;
	extract_stars(fr, reg, 0, P_DBL(SD_SNR), src);
	if (src->ns <= 0)
		return NULL;
	for (i = 0; i < src->ns; i++) {
		if (src->s[i].peak > P_DBL(AP_SATURATION))
			continue;
//		ref_flux = src->s[i].flux;
//		ref_fwhm = src->s[i].fwhm;
		break;
	}
	for (i = 0; i < src->ns; i++) {
		if (src->s[i].peak > P_DBL(AP_SATURATION))
			continue;
		xc = cos((src->s[i].x - fr->w / 2) / fr->w * PI);
		yc = cos((src->s[i].y - fr->h / 2) / fr->h * PI);
		ds = sqr(xc * yc);
		score = src->s[i].flux * ds;
		d3_printf("%5.1f %5.1f ds: %.3f score: %.1f\n",
			  src->s[i].x, src->s[i].y, ds, score);
		if (score > max_score) {
			max_score = score;
			gsi = i;
		}
	}
	gs = gui_star_new();
	gs->x = src->s[gsi].x;
	gs->y = src->s[gsi].y;
	gs->size = 1.0 * P_INT(DO_DEFAULT_STAR_SZ);
	gs->flags = STAR_TYPE_ALIGN;
	gs->s = (struct star *)g_malloc(sizeof(struct star));
	*STAR(gs->s) = src->s[gsi];
	STAR(gs->s)->ref_count = 1;
	release_sources(src);

	return gs;
}
Example #2
0
void GEMENI_charsent() {
	unsigned long r = s->log[s->lc];
	if (UCA0IFG & UCTXIFG) {
		s->nch++;
		switch (s->nch) {
			case 1:
				UCA0TXBUF = SL(r) << 5 |TL(r)<<4|KL(r)<<3|PL(r)<<2|WL(r)<<1|HL(r);
			break;
			case 2:
				UCA0TXBUF = RL(r)<<6 | AL(r)<<5 | OL(r)<<4 | STAR(r)<<3;
			break;
			case 3:
				UCA0TXBUF = ER(r)<<3 | UR(r)<<2 | FR(r)<<1 | RR(r);
			break;
			case 4:
				UCA0TXBUF = PR(r)<<6 | BR(r)<<5 | LR(r)<<4 | GR(r)<<3 | TR(r)<<2 | SR(r)<<1 | DRS(r);
			break;
			case 5:
				UCA0TXBUF = POUND(r)<<1 | ZRS(r);
			break;
			default:
				s->lc++;
				if (s->lc != s->nc-1) {

  					s->nch = 0;
  					UCA0TXBUF = 1 << 7; // first packet, no fn or '#'
				} else {
					s->flags &= ~CSEND;
				}

		}
	}
}
Example #3
0
//static int getBlockMasks ( PUZZLE *puzzle, int row, int column, int *masks )
static int getBlockMasks ( PUZZLE *puzzle, int row, int column, short **pmasks )

{
   int	status = 0;

#if	defined(DEBUG)
   //fprintf ( logFile, "getBlockMasks ( %p, %d, %d, %p ) {\n", puzzle, row,
								//column, masks );
   fprintf ( logFile, "getBlockMasks ( %p, %d, %d, %p ) {\n", puzzle, row,
								column, pmasks );
   fflush ( logFile );
#endif

   /* Make sure the 3x3 block is not already full. */
   if ( puzzle->blockMasks [row][column] ) {

	int	rowMax = ( row + 1 ) * 3;
	int	columnMax = ( column + 1 ) * 3;
	int	k = 0;
	//int	mask = 0;
	short	mask = 0;
	int	i;

	status = 1;

	/* Make masks for the 3x3 block. */
	for ( i = rowMax - 3; i < rowMax; ++i ) {

		int	j;

		for ( j = columnMax - 3; j < columnMax; ++j ) {

			//masks [k] = puzzle->masks [i][j];
			STAR(pmasks [k]) = puzzle->masks [i][j];
			IFT(pmasks [k], puzzle->pmasks [i][j]);
			//mask |= masks [k];
			mask |= star(pmasks [k]);

			++k;
		}
	}

	if ( mask != puzzle->blockMasks [row][column] ) status = -1;
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} = %d /* getBlockMasks () */\n", status );
   fflush ( logFile );
#endif

   return ( status );
}
Example #4
0
//static int crossHatch ( int *masks )
static int crossHatch ( short **pmasks )

{
   int	progress = 0;
   //int	solutions [9];
   short	solutions [9];
   short	*psolutions [9];
   int	k;
   for ( k = 0; k < 9; k++ ) {
   	psolutions [k] = &solutions[k];
   }
   int	i;

#if	defined(DEBUG)
   //fprintf ( logFile, "crossHatch ( %04X ) {\n", (unsigned int)masks );
   fprintf ( logFile, "crossHatch ( %p ) {\n", pmasks );
   fflush ( logFile );
#endif

   for ( i = 0; i < 9; ++i ) {

	int	j;

	//solutions [i] = masks [i];
	solutions [i] = star(pmasks [i]);
	IFT(psolutions [i], pmasks [i]);

	//for ( j = 0; j < 9; ++j ) if ( j != i ) solutions [i] &= ~masks [j];
	for ( j = 0; j < 9; ++j ) {
		if ( j != i ) {
			solutions [i] &= ~(star(pmasks [j]));
			IFT(psolutions [i], pmasks [j]);
		}
	}
		
   }

   for ( i = 0; i < 9; ++i ) {

	//if ( masks [i] = bit2digit ( solutions [i] ) ) ++progress;
	if ( STAR(pmasks [i]) = bit2digit ( solutions [i] ) ) ++progress;
	IFT(pmasks [i], psolutions [i]);
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} = %d /* crossHatch () */\n", progress );
   fflush ( logFile );
#endif

   return ( progress );
}
Example #5
0
//static int getColumnMasks ( PUZZLE *puzzle, int column, int *masks )
static int getColumnMasks ( PUZZLE *puzzle, int column, short **pmasks )

{
   int	status = 0;

#if	defined(DEBUG)
   //fprintf ( logFile, "getColumnMasks ( %p, %d, %p ) {\n", puzzle, column,
									//masks );
   fprintf ( logFile, "getColumnMasks ( %p, %d, %p ) {\n", puzzle, column,
									pmasks );
   fflush ( logFile );
#endif

   /* Make sure the column is not already filled. */
   if ( puzzle->columnMasks [column] ) {

	//int	mask = 0;
	short	mask = 0;
	int	row;

	status = 1;

	/* Make masks for the column. */
	for ( row = 0; row < 9; ++row ) {

		//masks [row] = puzzle->masks [row][column];
		STAR(pmasks [row]) = puzzle->masks [row][column];
		IFT(pmasks [row], puzzle->pmasks [row][column]);
		//mask |= masks [row];
		mask |= star(pmasks [row]);
	}

	if ( mask != puzzle->columnMasks [column] ) status = -1;
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} = %d /* getColumnMasks () */\n", status );
   fflush ( logFile );
#endif

   return ( status );
}
Example #6
0
//static int getRowMasks ( PUZZLE *puzzle, int row, int *masks )
static int getRowMasks ( PUZZLE *puzzle, int row, short **pmasks )

{
   int	status = 0;

#if	defined(DEBUG)
   //fprintf ( logFile, "getRowMasks ( %p, %d, %p ) {\n", puzzle, row, masks );
   fprintf ( logFile, "getRowMasks ( %p, %d, %p ) {\n", puzzle, row, pmasks );
   fflush ( logFile );
#endif

   if ( puzzle->rowMasks [row] ) {

	//int	mask = 0;
	short	mask = 0;
	int	column;

	status = 1;

	/* Make masks for the row. */
	for ( column = 0; column < 9; ++column ) {

		//masks [column] = puzzle->masks [row][column];
		STAR(pmasks [column]) = puzzle->masks [row][column];
		IFT(pmasks [column], puzzle->pmasks [row][column]);
		//mask |= masks [column];
		mask |= star(pmasks [column]);
	}

	if ( mask != puzzle->rowMasks [row] ) status = -1;
   }

#if	defined(DEBUG)
   fprintf ( logFile, "} = %d /* getRowMasks () */\n", status );
   fflush ( logFile );
#endif

   return ( status );
}
Example #7
0
PEG_FUNC(parse_peg_hide);

/*************************************************/

/* grammar */

PEG_PARSE(parse_peg_grammar,        PEG_GRAMMAR_NODE,               L"PEG grammar",             SEQ(T(parse_peg_spacing),
                                                                                                    SEQ(PLUS(T(parse_peg_rule)),
                                                                                                        T(parse_peg_eof))));

PEG_PARSE(parse_peg_rule,           PEG_RULE_NODE,                  L"PEG rule",                SEQ(T(parse_peg_identifier),
                                                                                                    SEQ(QUES(T(parse_peg_literal)),
                                                                                                        SEQ(T(parse_peg_left_arrow),
                                                                                                            T(parse_peg_disjunction)))));

PEG_PARSE(parse_peg_disjunction,    PEG_DISJ_NODE,                  L"expression",              SEQ(T(parse_peg_conjunction), STAR(SEQ(T(parse_peg_slash), T(parse_peg_conjunction)))));

PEG_PARSE(parse_peg_conjunction,    PEG_CONJ_NODE,                  L"term",                    PLUS(T(parse_peg_prefix_exp)));

PEG_PARSE(parse_peg_prefix_exp,     PEG_PREFIX_EXP_NODE,            L"term",                    SEQ(QUES(DISJ(T(parse_peg_and), DISJ(T(parse_peg_not), T(parse_peg_hide)))), T(parse_peg_suffix_exp)));

PEG_PARSE(parse_peg_suffix_exp,     PEG_SUFFIX_EXP_NODE,            L"term",                    SEQ(T(parse_peg_term),
                                                                                                    QUES(DISJ(DISJ(T(parse_peg_question), 
                                                                                                                   T(parse_peg_star)),
                                                                                                                   T(parse_peg_plus)))));

PEG_PARSE(parse_peg_term, PEG_TERM_NODE, L"term", DISJ(SEQ(T(parse_peg_identifier), 
                                                           BANG(SEQ(QUES(T(parse_peg_literal)), 
                                                                    T(parse_peg_left_arrow)))),
                                                       DISJ(SEQ(T(parse_peg_open), 
                                                                SEQ(T(parse_peg_disjunction), 
Example #8
0
PLUS()PLUS()                  //R + + 
STRINGIZE( PLUS()PLUS() )     //R "++" 
//R 
MINUS()MINUS()                //R - - 
STRINGIZE( MINUS()MINUS() )   //R "--" 
//R 
DOT()DOT()DOT()               //R .. . 
STRINGIZE( DOT()DOT()DOT() )  //R "..." 

// the following are regressions reported by Stefan Seefeld
//R #line 43 "t_9_003.cpp"
GREATER()GREATER()            //R > > 
STRINGIZE( GREATER()GREATER() ) //R ">>" 
//R
LESS()LESS()                  //R < < 
STRINGIZE( LESS()LESS() )     //R "<<" 

#define COMMA() ,
#define AND() &
#define CHAR() char
#define STAR() *

// Make sure no whitespace gets inserted in between the operator symbols
//R #line 56 "t_9_003.cpp"
void foo(char&, char)               //R void foo(char&, char) 
void foo(char *)                    //R void foo(char *) 
void foo(char *&)                   //R void foo(char *&) 
void foo(CHAR()AND()COMMA() CHAR()) //R void foo(char&, char) 
void foo(CHAR() STAR())             //R void foo(char *) 
void foo(CHAR() STAR()AND())        //R void foo(char *&)