#include "astro.h" #include "koor.h" //instead KOOR_RA, KOOR_DEC volatile struct RADECKOOR KOOR; volatile double KOOR_AZ; volatile double KOOR_ALT; volatile double LAST; double REST( double val, double t ); void cCurrentStarTime( void ); /* This calculates and sets GAST,and LAST. YEAR,MONTH,DAY,MINUTE,SECOND,MSECOND must contain correct time before. Also LONGITUTE must contain correct value. */ void cCurrentStarTime( void ) { double TN,TE,Omega,L,GAST; double Lst,Depsi,Deps,eps0,eps,Depsicoseps; double GMST0,GMST,LMST; int CAL; double tmpa,tmpb,tmpc,tmpe;//tmpd double p,j,m,jd,b,JD,d; tmpa = (double)YEAR; tmpb = (double)MONTH / 100; tmpc = (double)DAY / 10000; p = tmpa + tmpb + tmpc; /*now we have the format JJJ.MMTT*/ CAL = 2; if( p < 1582.1015 ){ CAL = 1; } if( MONTH > 2 ){ j = (double)YEAR; m = (double)MONTH; } else { j = (double)YEAR - 1; m = (double)MONTH + 12; } jd = floor( 365.25 * j ) + floor( 30.6001 * ( m + 1)) + (double)DAY + 1720994.5; b = 2 - floor( j / 100 ) + floor( floor( j / 100 ) / 4 ); if( CAL < 2 ){ JD = jd; } else { JD = jd + b; } /* ///////////////////////////////////////////// // Now we have the julian date for time 0h UT ///////////////////////////////////////////// */ TN = ( JD - 2451545 ) / 36525; GMST0 = 24110.54841 + 8640184.812866 * TN + 0.093104 * TN * TN - 0.0000062 * TN * TN * TN; GMST0 = REST( GMST0 / 3600.0, 24.0 ); if( GMST0 < 0 ){ GMST0 = GMST0 + 24; } /* JULD = JD ///////////////////////////////////////////////////// // Now we have the middle Greewich-startime at 0 H UT ///////////////////////////////////////////////////// */ tmpa = (double)HOUR; tmpb = (double)MINUTE / 60; tmpc = (double)SECOND / 3600; /*milliseconds*/ if( MSECOND > 0 ){ tmpe = ( 1.0 / 3600000.0) * (double)MSECOND; d = tmpa + tmpb + tmpc + tmpe; } else { d = tmpa + tmpb + tmpc; } // tmpd = 1.00273790935 * d; // GMST = REST( GMST0 + tmpd, 24.0); GMST = REST( GMST0 + ( 1.00273790935 * d ), 24.0); /* ///////////////////////////////////////////////////// // Now we have the current middle greenwich startime. ///////////////////////////////////////////////////// */ // tmpa = cfg.LONGITUDE; // tmpa = tmpa / 15; // LMST = REST(GMST + tmpa + 24, 24.0); LMST = REST(GMST + ( cfg.LONGITUDE / 15 ) + 24, 24.0); /* ////////////////////////////////////////////////////////// // Now, we have the local middle startime for current time ////////////////////////////////////////////////////////// */ // tmpb = d / 24; // tmpa = JD + tmpb - 2451545.0; // TE = tmpa / 36525; TE = ( JD + ( d / 24 ) - 2451545.0 ) / 36525; Omega = rad( 125.04452 - 1934.136261 * TE + 0.0020708 * TE * TE + TE * TE * TE * 1 / 450000 ); L = rad( 280.4665 + 36000.7698 * TE ); Lst = rad( 218.3165 + 481267.8813 * TE ); // Omega = rad( Omega ); // L = rad( L ); // Lst = rad( Lst ); Depsi = -17.20 * sin( Omega ) - 1.32 * sin( 2 * L ) - 0.23 * sin( 2 * Lst ) + 0.21 * sin( 2 * Omega ); Deps = 9.20 * cos( Omega ) + 0.57 * cos( 2 * L ) + 0.10 * cos( 2 * Lst ) - 0.09 * cos( 2 * Omega ); eps0 = 23.43929111 + ( -46.815 * TE - 0.00059 * TE * TE + 0.001813 * TE * TE * TE ) / 3600; eps = rad( eps0 + Deps / 3600 ); // eps = rad( eps ); Depsicoseps = Depsi * cos(eps); // tmpc = 15.0 * 3600; // GAST = GMST + Depsicoseps / tmpc; GAST = GMST + Depsicoseps / 54000; /* //////////////////////////////////////////////// //Now, we have the real greenwich startime GAST //( Greenwich Apparent Sideral Time ) //////////////////////////////////////////////// */ // tmpc = 15.0 * 3600; // LAST = LMST + Depsicoseps / tmpc; LAST = LMST + Depsicoseps / 54000; if( LAST < 0 ) { LAST = LAST + 24; } /* //////////////////////////////////////////////////////// // Now, we have the real local Startime for current time //////////////////////////////////////////////////////// */ } double REST( double val, double t ) { double x; modf( val / t ,&x); return( val - ( x * t )); } /* Calculates Rektazension/Declination-kooordinates to azimuth/altitude-koordinates for the local time, and place. This sets KOOR_AZ, KOOR_ALT ( as floatnumbers of degrees ) KOOR.ra must be set as hours KOOR.dec dec as degrees. the current local startime ( LAST ), must be set before by calling cCurrentStartTime Also cfg.LATITUDE must contain correct value. */ void cAzAlt( void ) { double d,Q,f,Zlr,Nnr,tmpa,tmpb,tmpc; /*Stundenwinkel*/ tmpa = LAST - KOOR.ra + 24.0; tmpb = tmpa / 24.0; modf(tmpb,&tmpc); tmpb = tmpc * 24.0; f = rad ( cfg.LATITUDE ); d = rad ( KOOR.dec ); Q = rad ( (tmpa - tmpb ) * 15.0 ); KOOR_ALT = deg( asin( sin(f) * sin(d) + cos(f) * cos(d) * cos(Q))); Zlr = sin(Q); Nnr = (cos(Q) * sin(f) - tan(d) * cos(f)); KOOR_AZ = 0.0; /*q3*/ if( ( Nnr < 0.0 ) && ( Zlr < 0.0 )){ KOOR_AZ = deg( atan( Zlr / Nnr ) ); return; } /*q4*/ if( ( Nnr < 0.0 ) && ( Zlr > 0.0 )){ KOOR_AZ = ( 360.0 + deg( atan( Zlr / Nnr ) ) ); return; } /*q1 oder q2*/ if( ( Nnr > 0.0 ) && ( Zlr != 0.0 )){ KOOR_AZ = ( 180.0 + deg( atan( Zlr / Nnr ) ) ); return; } } /* Calculates Azimut/Altitude-kooordinates to Rectaszension/Declination-koordinates for the local time, and place. This KOOR.ra, KOOR.dec ( as floatnumbers of Hours/degrees ) KOOR_AZ, and KOOR_ALT must be set as floatnumber of degrees. The current startime LAST must be set before by calling cCurrentStarTime, also the cfg.LATITUDE. */ void cRaDec( void ) { double _lat,_az,_alt,_last,_z,_dec,_ra,_stw,_stw1,_stw2; _lat = rad( cfg.LATITUDE ); _az = rad( KOOR_AZ ); _alt = rad( KOOR_ALT ); _last = rad( LAST * 15 ); _z = rad( 90.0 - KOOR_ALT ); _dec = asin( sin( _alt ) * sin( _lat ) + cos( _alt ) * cos( _lat ) * cos( _az ) ); _stw1 = asin( -sin( _az ) * cos( _alt ) / cos( _dec ) ); _stw2 = cos( _z ) * cos( _lat ) - sin( _z ) * sin( _lat ) * cos( _az ); if( _stw1 >= 0.0 ){ _stw = acos( _stw2 / cos( _dec ) ); } else { _stw = -acos( _stw2 / cos( _dec ) ); } _ra = _last - _stw; KOOR.ra = deg( _ra ) / 15; if( KOOR.ra < 0.0 ){ KOOR.ra = 24.0 + KOOR.ra; } if( KOOR.ra >= 23.999999 ){ KOOR.ra = KOOR.ra - 24.0; } KOOR.dec = deg( _dec ); }