С удовольствием. Может, немного неряшливо состряпяно. Но работает.
package test;
import java.util.GregorianCalendar;
/**
*
* @author kostya
*/
class time_t{
public int tm_year;
public int tm_mon;
public int tm_day;
public int tm_hour;
public int tm_min;
public int tm_sec;
};
public class SiderealTime {
/*
Function: julian_date
Inputs: a time_t type value
Returns: the Julian date corresponding to the input time, as
a double type value
*/
double julian_date(time_t time_now){
GregorianCalendar GC=new GregorianCalendar(time_now.tm_year+1900, time_now.tm_mon, time_now.tm_day, time_now.tm_hour, time_now.tm_min, time_now.tm_sec);
double JD;
int year,month,day;
double UT;
/* julian date formula from
http://scienceworld.wolfram.com/astronomy/JulianDate.html */
time_t now_time=new time_t();
now_time.tm_day = time_now.tm_day;
now_time.tm_hour = time_now.tm_hour;
now_time.tm_min = time_now.tm_min;
now_time.tm_mon = time_now.tm_mon;
now_time.tm_sec = time_now.tm_sec;
now_time.tm_year = time_now.tm_year;
year=now_time.tm_year+1900;
month=now_time.tm_mon+1;
day=now_time.tm_day;
UT=now_time.tm_hour+now_time.tm_min/60.0+now_time.tm_sec/3600.0;
JD=367*year-
(int)(7.0*((float)year+(int)(((float)month+9.0)/12.0))/4.0)-
(int)(3.0*((int)(((float)year+((float)month-9.0)/7.0)/100.0)
+1.0)/4.0)+
(int)(275.0*(float)month/9.0)+
day+1721028.5+UT/24.0;
return(JD);
}
/*
Function: sidereal_time
Inputs:
- a time_t type value, the time
- an integer type flag specifying which sidereal time
you want returned, one of:
SIDEREAL_GMST = the Greenwich Mean Sidereal Time
SIDEREAL_GAST = the Greenwich Apparent Sidereal Time
SIDEREAL_LMST = the Local Mean Sidereal Time
SIDEREAL_LAST = the Local Apparent Sidereal Time
- a double type value, the local longitude in degrees,
only needs to be filled if you want a Local Sidereal
Time, and east longitudes are positive
Returns:
- the requested Sidereal Time type for the specified
time
*/
public static final int SIDEREAL_GMST = -100; /* get Greenwich Mean Sidereal Time */
public static final int SIDEREAL_GAST = -200; /* get Greenwich Apparent Sidereal Time */
public static final int SIDEREAL_LMST = -300; /* get Local Mean Sidereal Time */
public static final int SIDEREAL_LAST = -400; /* get Local Apparent Sidereal Time */
double sidereal_time(time_t time_now,int type,double longitude){
GregorianCalendar GC=new GregorianCalendar(time_now.tm_year+1900, time_now.tm_mon, time_now.tm_day, time_now.tm_hour, time_now.tm_min, time_now.tm_sec);
double JD_J2000,JD_now,JD_diff;
double gmst,gast,JC,eqtime,last,lmst;
time_t time_ref=new time_t();
time_t ref_time=new time_t();
time_t now_time=new time_t();
/* set reference time to be 12:00:00 01/01/2000 (J2000.0) */
ref_time.tm_sec=0;
ref_time.tm_min=0;
ref_time.tm_hour=12;
ref_time.tm_day=1;
ref_time.tm_mon=0;
ref_time.tm_year=100;
time_ref.tm_sec=0;
time_ref.tm_min=0;
time_ref.tm_hour=12;
time_ref.tm_day=1;
time_ref.tm_mon=0;
time_ref.tm_year=100;
JD_J2000=julian_date(time_ref); /* should be 2451543.5 */
/* the difference between now and reference */
JD_now=julian_date(time_now);
JD_diff=JD_now-JD_J2000;
JC=JD_diff/36525.0; /* in Julian centuries */
/* calculate Greenwich mean sidereal time, from
http://www.pietro.org/Astro_Util_StaticDemo/FDetailSiderealConv.htm */
gmst=280.46061837+360.98564736629*JD_diff+
0.0003887933*Math.pow(JC,2)-
Math.pow(JC,3)/38710000.0;
while(gmst>=360.0)
gmst-=360.0;
gmst=gmst/15.0; /* into hours */
if (type==SIDEREAL_GMST)
return(gmst);
/* equinox correction for Greenwich apparent sidereal time */
now_time.tm_day = time_now.tm_day;
now_time.tm_hour = time_now.tm_hour;
now_time.tm_min = time_now.tm_min;
now_time.tm_mon = time_now.tm_mon;
now_time.tm_sec = time_now.tm_sec;
now_time.tm_year = time_now.tm_year;
//eqtime=(-0.49+0.3*now_time.tm_yday/365.0+
// 0.07*cos(2.0*6.2831853*(now_time.tm_yday-35.0)/365.0))/3600.0;
eqtime=(-0.49+0.3*GC.DAY_OF_YEAR/365.0+
0.07*Math.cos(2.0*6.2831853*(GC.DAY_OF_YEAR-35.0)/365.0))/3600.0;
gast=gmst+eqtime;
while(gast>24.0)
gast-=24.0;
if (type==SIDEREAL_GAST)
return(gast);
/* local apparent sidereal time */
last=gast+24.0+longitude/15.0;
while(last>24.0)
last-=24.0;
if (type==SIDEREAL_LAST)
return(last);
/* local mean sidereal time */
lmst=gmst+24.0+longitude/15.0;
while(lmst>24.0)
lmst-=24.0;
if (type==SIDEREAL_LMST)
return(lmst);
/* default is to return LMST */
return(lmst);
}
/** Creates a new instance of SiderealTime */
public SiderealTime() {
}
public static void main(String[] strs){
SiderealTime ST=new SiderealTime();
time_t time=new time_t();
time.tm_year=106;
time.tm_mon=11;
time.tm_day=19;
time.tm_hour=20;
time.tm_min=48;
time.tm_sec=10;
// west - negative, east - positive
double srt=ST.sidereal_time(time,SIDEREAL_LAST,-79.35);
System.out.println("SRT="+srt);
}
}