Working on some debugging code and thinking about how to do timers and things like that. Also want to be able to detect local sunrise and sunset. Just because.
void solar_elements::debug_test ()
{
ASSERT (julian_day (1,1,2000)==2451545);
ASSERT (julian_day (6,19,1987)==2446966);
ASSERT (julian_day (12,8,2009)==2455174);
char test_str [256];
int H,M,M1,S;
int start_hour = 4;
int start_minute = 34;
int end_hour = 4;
int end_minute = 38;
for (H=start_hour,M=start_minute;H<=end_hour;H++,M=0)
{
M1 = (H==end_hour?end_minute:60);
for (;M<M1;M++)
for (S=0;S<60;S++)
{
m_hour = H;
m_minute = M;
m_second = S;
compute_local_aspect();
sprintf_s (test_str,256,"LOCAL time = %02d:%02d:%02d AZIMUTH = %f, EL = %f",H,M,S,m_az,m_el);
writeln (output,test_str);
}
}
}
On the other hand, there are a lot of other really fun things that could be done with this code, besides making better abuse of the ternary operator, such as by folding it into the minutes for loop initializer. Maybe. Or even pack the variables H, M, and S into a union just to see if the compiler can chow down on that, and to check out the disassembly on different platforms. Maybe. More important right now is simple testing.

At least for now, it appears to work to a reasonable approximation. I asked OK Google what time is sunrise today, in Reno, NV, and it claims that the sun will rise at 5:38 AM, which would be 4:38 if we were on standard time. So, this looks like it is pretty close. Maybe? At least for the elevation. Otherwise, the basic setting of start time and time for a task seems to be working. Yet what if I decide to try this on a Propeller or an Arduino? And what if I want multiple tasks? Like if I wanted to aim some steerable solar panels, control an irrigation system, dispense cat food, and so on? All according to some predefined schedule.
Open the pod bay doors, please?
P.S. Based on the latitude, this is also quite possibly a pretty good estimate for the azimuth and elevation for local sunrise, in Philadelphia, PA, sometime on or around July 4, 1776. Or perhaps July 5th. Local Time. Not daylight savings, since Ben Franklin hadn't invented that quite yet. Noting, of course, that the Longitude and latitude for Philadelphia are 39.95N, and -75.17W Whereas Reno, NV is 39.53N and -116.42W. Obviously, the elevation of theoretical sunrise will always be zero degrees of elevation, plus or minus, however, you take into account the diameter of the sun and atmospheric effects. Whereas, the azimuth of sunrise and sunset might actually turn out to be really important to know, especially in historic times, when an accurate compass might not have always been available, and where reliable means of celestial navigation were therefore needed, in addition to sighting the north star, when available, or guessing approximate south based on the so called "shadowless shadow stick" method, as it is most likely still taught to the Boy Scouts.
I will need to do more testing on this.
glgorman
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.