#include "../elastro.h" char il_tmptext[256]; /* the following variables will be set by calling cCurrentStarTime*/ /*//the time in seconds when function is called and the adjusted time*/ time_t cCSTcurseconds; long cCSTmillisecs; time_t cCSTadjcurseconds; /*//Julian Date at 0 H UT*/ double JULD; /*//middle Greewich-startime at 0 H UT*/ double GMST0; /*//current middle greenwich startime*/ double GMST; /*//local middle startime for current time*/ double LMST; /*//real greenwich startime //( Greenwich Apparent Sideral Time )*/ double GAST; /*//real local Startime for current time //( Local Apparent Sideral Time )*/ double LAST; double makeAbsoluteDouble( double val ) { double d; char *p; sprintf(&il_tmptext[0],"%f",val); p = strchr(il_tmptext,'.'); if(p != NULL){ p[0] = 0; } p = strchr(il_tmptext,','); if(p != NULL){ p[0] = 0; } d = strtod((const char *)&il_tmptext[0],NULL); return(d); } double makeAbsoluteModf( double val ) { double d; modf(val, &d); return(d); } double makeRestModf( double val ) { double d; return( modf(val, &d) ); } double REST( double val, double t ) { double v; v = val / t; v = makeAbsoluteDouble(v) * t; v = val - v; return( v ); } /* //this calculates and sets utcdatetime, utcseconds, GMST0,GMST,LMST,GAST,and at least LAST. //utcadjust must be the Difference between LocalTime and GMT in seconds //for summertime at Stuttgart this is f.Expl. -7200, -3600 for wintertime //longitude, the longitude in degrees ( 48.xxx ) for the local place. //also the latitude. //seconds must be the number seconds for the current local time. //if seconds <= 0 current time will be calculated automatically, ( to a precession of //milliseconds ) otherwise this value ( additionalyy hsecs ) is used. //if hsecs not 0 ( normally ) the time will be set for precession of seconds, //otherwise for secods + ( hsecs * 1/1000) of seconds, so if not 0 it should //be a number of 0 to 999, indicating milliseconds. //( for unix you can use ftime for getting seconds, and milliseconds of current time ) //function will be set the timevariables above, and the LAST value will be addionally //returned. */ double cCurrentStarTime( double longitude , double latitude, long seconds, long hsecs, long utcadjust ) { double T,M,J,tmpa,tmpb,tmpc,tmpd,tmpe; double p,j,m,jd,b,JD,d; int CAL; double TN,HOUR,MIN,SEC,TE,Omega,L; double Lst,Depsi,Deps,eps0,eps,Depsicoseps; long utcseconds; time_t sec; struct tm *t; long ilhsecs; struct timeb tpa; if( seconds <= 0) { ftime(&tpa); cCSTcurseconds = tpa.time; utcseconds = tpa.time + utcadjust; } else { utcseconds = seconds + utcadjust; cCSTcurseconds = seconds; } cCSTadjcurseconds = utcseconds; sec = (time_t)utcseconds; t = localtime(&sec); SEC = t->tm_sec; MIN = t->tm_min; HOUR = t->tm_hour; T = t->tm_mday; M = t->tm_mon + 1; J = t->tm_year + 1900; tmpa = J; tmpb = M / 100; tmpc = T / 10000; p = tmpa + tmpb + tmpc; /*now we have the format JJJ.MMTT*/ CAL = 2; if( p < 1582.1015 ){ CAL = 1; } if( M > 2 ){ j = J; m = M; } else { j = J - 1; m = M + 12; } jd = floor( 365.25 * j ) + floor( 30.6001 * ( m + 1)) + T + 1720994.5; b = 2 - floor( j / 100 ) + floor( floor( j / 100 ) / 4 ); if( CAL < 2 ){ JD = jd; } else { JD = jd + b; } JULD = JD; /* ///////////////////////////////////////////// // 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; } /* ///////////////////////////////////////////////////// // Now we have the middle Greewich-startime at 0 H UT ///////////////////////////////////////////////////// */ tmpa = HOUR; tmpb = MIN / 60; tmpc = SEC / 3600; /*milliseconds*/ if(seconds <= 0 ){ cCSTmillisecs = tpa.millitm; if( tpa.millitm > 0 ){ tmpe = ( 1.0 / 3600000.0) * (double)tpa.millitm; d = tmpa + tmpb + tmpc + tmpe; } else { d = tmpa + tmpb + tmpc; } } else { if( hsecs > 0 ){ cCSTmillisecs = hsecs; tmpe = ( 1.0 / 3600000.0) * (double)hsecs; d = tmpa + tmpb + tmpc + tmpe; } else { cCSTmillisecs = 0; d = tmpa + tmpb + tmpc; } } tmpd = 1.00273790935 * d; GMST = REST( GMST0 + tmpd, 24.0); /* ///////////////////////////////////////////////////// // Now we have the current middle greenwich startime. ///////////////////////////////////////////////////// */ tmpa = longitude; tmpa = tmpa / 15; LMST = REST(GMST + tmpa + 24, 24.0); /* ////////////////////////////////////////////////////////// // Now, we have the local middle startime for current time ////////////////////////////////////////////////////////// */ tmpb = d / 24; tmpa = JD + tmpb - 2451545.0; TE = tmpa / 36525; Omega = 125.04452 - 1934.136261 * TE + 0.0020708 * TE * TE + TE * TE * TE * 1 / 450000; L = 280.4665 + 36000.7698 * TE; Lst = 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 = eps0 + Deps / 3600; eps = rad( eps ); Depsicoseps = Depsi * cos(eps); tmpc = 15.0 * 3600; GAST = GMST + Depsicoseps / tmpc; /* //////////////////////////////////////////////// //Now, we have the real greenwich startime GAST //( Greenwich Apparent Sideral Time ) //////////////////////////////////////////////// */ tmpc = 15.0 * 3600; LAST = LMST + Depsicoseps / tmpc; if( LAST < 0 ) { LAST = LAST + 24; } /* //////////////////////////////////////////////////////// // Now, we have the real local Startime for current time //////////////////////////////////////////////////////// */ return( LAST ); } void main( int arc, char *argv[] ) { double oldlast,diff; int ct; cCurrentStarTime( 8.7 , 48.1667, 0, 0, 0 ); oldlast = LAST; ct = 0; while( ct < 10 ){ cCurrentStarTime( 8.7 , 48.1667, 0, 0, 0 ); if( cCSTmillisecs != 0 ){ continue; } diff = LAST - oldlast; oldlast = LAST; fprintf(stdout,"\n LAST: %1.26f DIFF: %1.26f",LAST,diff); fprintf(stdout,"\nSECS: %ld + MSECS: %ld",cCSTcurseconds,cCSTmillisecs); fprintf(stdout,"\n"); ct++; } }