I've checked and double checked the maths but Excel and the Arduino don't quite come out with the same answer.
This is the current sketch.....
// Variables for return by function "siderealcalculations"
float sr_whole;
float sr_frac;
float sr_days;
float gmst;
float gmst360;
float gmstHrs;
int gmst_H;
int gmst_M;
int gmst_S;
// Variables for return by function "polestarlocate"
float polaris_posH;
float polaris_posDeg;
void siderealcalculations(int y,int m,int d,int h,int mn,int s){
sr_whole=367.0*(float)y - 7.0*((float)y+int(((float)m+9.0)/12.0))/4.0 +int(275.0*(float)m/9.0)+(float)d-730531.5;
sr_frac = ((float)h + (float)mn/60.0 + (float)s/3600.0)/24.0;
sr_days = sr_whole + sr_frac;
gmst = 280.46061837 + (360.98564736629 * sr_days);
gmst360 = fmod(gmst,360.0);
gmstHrs = gmst360/360.024.0;
gmst_H = int(gmstHrs);
gmst_M = int(gmst3601.0/360.024.060.0)-gmst_H60;
gmst_S = int(gmst3601.0/360.024.03600.0)-(gmst_H3600)-(gmst_M60);
}
// Note polestarlocate() relies on the function siderealcalculations having been called first
void polestarlocate(){
polaris_posH = fmod(((24.0-gmstHrs)/2.0)+1.25,12);
polaris_posDeg = 30.0*polaris_posH;
}
void setup()
{
Serial.begin(19200);
siderealcalculations(2012,2,13,14,27,5);
polestarlocate();
Serial.println(sr_whole);
Serial.println(sr_frac);
Serial.println(sr_days);
Serial.println(gmst);
Serial.println(gmst360);
Serial.println(gmstHrs);
Serial.println(polaris_posH);
Serial.println(polaris_posDeg);
Serial.println(gmst_H);
Serial.println(gmst_M);
Serial.println(gmst_S);
}
void loop()
{
}
and I posted the Excel test spreadsheet earlier.
Everything works until the SECONDS part of the calculation
Excel gets 13 seconds
Arduino gets 30 seconds
I PRESUME this may well be down to precision but looking at it I wouldn't have thought that it would be that far out, unless I have messed something up and couldn't see it.
Being out by 17 seconds wouldn't be the end of the world for it's current application but I could do with it accurate if I can get it so as I will then add it to my library and can forget about it....
I really do appreciate the help. I normally program in Pascal (delphi) and assembly but have had to venture into C and JAVA recently. I am getting on with it but some syntax etc has confused me.
Thanks