17 int jday(
int month,
int day)
21 int jday[] = {0,0,31,59,90,120,151,180,211,242,272,303,333 };
24 return(jday[month]+day);
32 dummy = modf(x, &tmp);
40 y = (
TWO_PI/365.0) * (
jday(month,day)-1.0 +((hour-12.0)/24));
45 double n(
int month,
int day,
int hour,
int min,
int sec)
47 return(364.5 +
jday(month,day) + (hour + min/60.0 + sec/3600.0)/24.0);
50 double JD(
int year,
int month,
int day)
65 if ((year > 1582) || ((year == 1582) && ((month > 10)
66 || ((month == 10) && (day > 4)))))
70 return ip (365.25 * (y + 4716)) +
ip (30.6001 * (m + 1)) + day + B - 1524.5 ;
92 newtime = gmtime( <ime );
100 double y,eqtime,decl,time_offset, tst,ha,theta,phi,sdecl;
112 eqtime = 229.18 * (0.000075 +
115 (0.014615 * cos(2.0 * y)) -
116 (0.040849 * sin(2.0 * y)) );
122 (0.006758* cos(2.0 * y)) +
123 (0.000907* sin(2.0 * y)) -
124 (0.002697* cos(3.0 * y)) +
125 (0.00148 * sin(3.0 * y));
130 time_offset = eqtime - (4.0 * loc->
lon) + (60.0 * loc->
timezone);
134 tst = (newtime->tm_hour * 60.0) + newtime->tm_min + (newtime->tm_sec / 60.0) + time_offset;
138 ha = (tst / 4.0) - 180.0;
145 theta = acos(((loc->
slat * cos(phi)) - sdecl) / (loc->
clat * sin(phi)));
150 printf(
"\nY=%f Eqtime=%f decl=%f\n tOff=%f tst=%f ha=%f tz=%f \n",y,eqtime,decl,time_offset,tst,ha,loc->
timezone );
151 printf(
"Phi=%f, theta=%f\n", phi, theta);
273 double AZ, EL, AZr, ELr, HOUR, SOLDIA, SOLDST;
278 double DEC, DEN, ECLONG, GMST, HA,
JD, LMST,
279 MNANOM, MNLONG, NUM, OBLQEC, RA,
302 YEAR = newtime->tm_year+1900;
303 DAY =
jday(newtime->tm_mon, newtime->tm_mday);
304 HOUR = newtime->tm_hour + (newtime->tm_min/60.0) + (newtime->tm_sec/3600.0) + loc->
timezone - loc->
dst;
306 printf(
"Hour=%f\n",HOUR);
313 JD = 32916.5 + ((DELTA * 365.0) + LEAP + DAY) + HOUR / 24.0 +1;
320 if( ( ( YEAR % 100 ) == 0) && (( YEAR % 400 ) != 0) ) JD = JD - 1.0;
326 printf(
"JD=%f TIME=%f\n",JD,TIME);
329 MNLONG = 280.460 + 0.9856474 * TIME;
330 MNLONG = fmod( MNLONG, 360.0 );
331 if( MNLONG < 0.0 ) MNLONG = MNLONG + 360.0;
334 MNANOM = 357.528 + 0.9856003 * TIME;
335 MNANOM = fmod( MNANOM, 360.0 );
336 if( MNANOM < 0.0) MNANOM = MNANOM + 360.0;
337 printf(
"Mean Long=%f Mean Anom=%f\n",MNLONG,MNANOM);
343 ECLONG = MNLONG + 1.915 * sin( MNANOM ) + 0.020 * sin( 2.0 * MNANOM );
344 ECLONG = fmod( ECLONG, 360.0 );
345 if( ECLONG < 0.0 ) ECLONG = ECLONG + 360.0;
347 OBLQEC = 23.439 - 0.0000004 * TIME;
350 printf(
"Ecc Long=%f Obliq=%f\n",ECLONG*
RAD_TO_DEG,OBLQEC*RAD_TO_DEG);
353 NUM = cos( OBLQEC )* sin( ECLONG );
355 RA = atan2( NUM , DEN );
356 printf(
"RA-raw = %f num=%f, den=%f\n",RA*RAD_TO_DEG,NUM,DEN);
360 if( DEN < 0.0 ) RA = RA +
M_PI;
361 else if( NUM < 0.0 ) RA = RA +
TWO_PI;
363 printf(
"RA = %f ",RA*RAD_TO_DEG);
366 DEC = asin( sin(OBLQEC) * sin(ECLONG) );
368 printf(
"DEC = %f \n",DEC*RAD_TO_DEG);
371 GMST = 6.697375 + 0.0657098242*TIME + HOUR;
375 GMST = fmod( GMST, 24.0 );
376 if( GMST < 0.0 ) GMST = GMST + 24.0;
379 LMST = GMST + loc->
lon / 15.0;
380 LMST = fmod( LMST, 24.0 );
381 if( LMST < 0.0 ) LMST = LMST + 24.0;
388 if( HA < -M_PI ) HA = HA +
TWO_PI;
389 if( HA > M_PI ) HA = HA -
TWO_PI;
391 printf(
"HA=%f deg\n",HA*RAD_TO_DEG);
396 ELr = asin( sin( DEC )* loc->
slat +
397 cos( DEC )* loc->
clat * cos( HA ) );
400 AZr = atan( sin( HA ) / ((cos( HA ) * loc->
slat) - (tan(DEC) * loc->
clat)) );
401 printf(
"raw az=%f DECL = %f\n",AZr*RAD_TO_DEG, DEC*RAD_TO_DEG);
404 if( sin( DEC ) - sin( ELr ) * loc->
slat >= 0.0 )
407 if( sin(AZr) < 0.0) AZr = AZr +
TWO_PI;
408 else AZr = M_PI - AZr;
418 if( EL >= 19.225 ) REFRAC = 0.00452 * 3.51823 / tan( ELr );
421 if( (EL > -0.766) && (EL < 19.225) )
422 REFRAC = 3.51823 * ( 0.1594 + EL*(0.0196 + 0.00002*EL) ) /
423 ( 1.0 + EL * (0.505 + 0.0845 * EL) );
424 else if( EL <= -0.766 ) REFRAC = 0.0;
426 printf(
"Refrac = %f deg\n",REFRAC);
432 SOLDST = 1.00014 - 0.01671 * cos(MNANOM) - 0.00014 * cos( 2.0 *MNANOM );
433 SOLDIA = 0.5332 / SOLDST;
435 if( EL < -90.0 || EL > 90.0 ) printf(
"SUNAE--output argument EL out of range(%f)\n",EL);
436 if( AZ < 0.0 || AZ > 360.0 ) printf(
"SUNAE--output argument AZ out of range(%f)\n",AZ);
444 #define oe_base (23.0+(26.0/60.0)+(21.448/3600.0))
449 double u,u2,u3,u4,u5,u6,u7,u8,u9,u10;
463 - (4680.93/3600.0 * u)
464 - (1.55 /3600.0 * u2)
465 + (1999.25/3600.0 * u3)
466 - (51.38 /3600.0 * u4)
467 - (249.67 /3600.0 * u5)
468 - (39.05 /3600.0 * u6)
469 + (7.12 /3600.0 * u7)
470 + (27.87 /3600.0 * u8)
471 + (5.79 /3600.0 * u9)
472 + (2.45 /3600.0 * u10)
484 double jd,l0, t,t2,t3,m,m_r, e,
c,r,
485 trueLon,trueLon_r,trueLon2k,trueAnom,trueAnom_r,
486 partDay,appLon,appLon_r,oe,oec,oe_r,oec_r,om,om_r,ra,dec;
489 year = newtime->tm_year+1900;
490 partDay = (newtime->tm_hour + (newtime->tm_min/60.0) + (newtime->tm_sec / 3600.0) - loc->
timezone)/24.0;
493 jd =
JD(year,newtime->tm_mon,newtime->tm_mday);
494 printf(
"\nJD=%10.5f ",jd+partDay);
497 t=(jd+partDay- 2451545.0)/36525.0;
500 printf(
"T=%2.10f\n",t);
503 l0 = 280.46645 + (36000.76983 * t) + (0.0003032 * t2);
504 if(l0 < 0.0) l0 = fmod(l0,360.0) + 360.0;
507 m = 357.52910 + (35999.05030 * t) - (0.0001559 * t2) - (0.00000048 * t3);
512 e = 0.016708617 - (0.000042037 * t) - (0.0000001236 * t2);
515 c = (1.914600 - (0.004817 * t) - (0.000014 * t2)) * sin(m_r) +
516 (0.019993 - (0.000101 * t)) * sin(m_r+m_r) +
517 (0.000290 * sin(m_r+m_r+m_r));
524 trueLon2k = trueLon - (0.01397 * (year - 2000));
525 printf(
"\nl0= %f m=%f e=%f c=%f trueLon=%f trueAnom=%f\n",l0,m,e,c,trueLon,trueAnom);
528 r = (1.000001018 * (1.0-(e*e)))/(1.0 + e *cos(trueAnom_r));
531 om = 125.04 - 1934.136 * t;
533 appLon = trueLon - 0.00569 - (0.00478 * sin(om_r));
539 oec = oe + 0.00256 * cos(DEG_TO_RAD*(125.04-1934.1136*t));
542 printf(
"\nom=%f appLon=%f oe=%f oec=%f r=%f\n",om,appLon,oe,oec,r);
544 ra = atan2(cos(oec_r)*sin(appLon_r), cos(appLon_r))*
RAD_TO_DEG;
547 dec = asin(sin(oec_r)*sin(appLon_r))*
RAD_TO_DEG;
548 printf(
"\nra=%f, dec=%f\n",ra, dec);