{ RCSid $Id: reinhart.cal,v 1.4 2009/12/09 21:34:23 greg Exp $ }
{
	Compute Reinhart high-density sky patches
	Actual density controlled by MF constant

	Modified from Tregenza.cal

	Need to specify MF constant before loading (usu. power of two)

	June 2009	G. Ward
}
DEGREE : PI/180;
Asin(x) : if(x-1, PI/2, if(-1-x, -PI/2, asin(x)));
posangle(a) : if(-a, a + 2*PI, a);
Atan2(y,x) : posangle(atan2(y,x));

alt = Asin(Dz)/DEGREE;
azi = Atan2(Dx,Dy)/DEGREE;

alpha : 90/(MF*7 + .5);		{ Separation between rows in degrees }
				{ Number of patches per row }
tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6);
rnaz(r) : if(r-(7*MF-.5), 1, MF*tnaz(floor((r+.5)/MF) + 1));

raccum(r) : if(r-.5, rnaz(r-1) + raccum(r-1), 0);

r_row = floor(alt/alpha);

r_inc = 360/rnaz(r_row);

r_azn = if(359.9999-.5*r_inc - azi, floor((azi+.5*r_inc)/r_inc), 0);

rbin = if (-alt, 0, raccum(r_row) + r_azn + 1);

Nrbins : raccum(7*MF+1) + 1;	{ total number of bins }
