	program Sidereal_Time
	implicit none
	real*8 theta,L,L1,L2,L3,Pi,JD2000,M0,M1,M2,t,tz,lw,h,s,thetay
	real*8 J0,J1,J2,Jd,J,c0,theta1,thetap,theta0,thetax,t0,mm
	integer*4 i,m,d,x,icnt
	character*1 ANS

	Pi = 4*Atan(1.0_8)
	L = 99.967794687
	L1 = 360.98564736628603
	L2 = 2.907879*(10**(-13))
	L3 = -5.302*(10**(-22))
	M0 = 15.04106864026192
	M1 = 2.423233*(10**(-14))
	M2 = -6.628*(10**(-23))

	write(*,*)'Enter Year:'
	read(*,*) i
	write(*,*)'Month:'
	read(*,*) m
	write(*,*)'Day:'
	read(*,*) d
	write(*,*)'Time in Hours (0-24):'
	read(*,*) t
	write(*,*)'Daylight Savings Time? (Y/N):'
	read(*,*) ANS
	if (ANS.eq.'Y') then
		tz = 7		!UTC minus clock time !DAYLIGHT SAVINGS then 7, if not 8 for PT.
	else
		tz = 8
	endif

	lw = 116.759361	!West longitude in degrees lw = -le

	J0 = 1721117
	JD2000 = 2451545		!Jan 1.5, 2000 (noon)
	if(m.lt.3) c0 = -1
	if(m.ge.3) c0 = 0
	J1 = Int((1461*(i+c0))/4)
	J2 = Int((153*m-1836*c0-457)/5)
	Jd = Int(J1+J2+d+J0-JD2000-13)
	J = Jd + ((t+tz)/24)
	print*,Jd,J

	theta1 = M0+(M1*Jd)+(M2*(Jd**2))
	thetap = (L2*(Jd**2))+(L3*(Jd**3))-lw+(theta1*tz)
	theta0 = L+L1*Jd+thetap

	if(theta0.gt.360)then
		do x = 0,10000000
			thetay = theta0 - (360*x)
			if(thetay.ge.0.and.thetay.le.360) EXIT
		enddo
	endif
	if(theta0.lt.0)then
		do x = 0,1000000
			thetay = theta0 + (360*x)
			if(thetay.ge.0.and.thetay.le.360) EXIT
		enddo
	endif
c	print*,thetay,icnt,theta1,thetap

	theta = theta0+(theta1*t)

	if(theta.ge.0.and.theta.le.360)thetax=theta
	if(theta.gt.360)then
		do x = 0,10000000
			thetax = theta - (360*x)
			if(thetax.ge.0.and.thetax.le.360) EXIT
		enddo
	endif
	if(theta.lt.0)then
		do x = 0,10000000
			thetax = theta + (360*x)
			if(thetax.ge.0.and.thetax.le.360) EXIT
		enddo
	endif

	print*,thetax
	h = thetax/15
	mm =(h-Int(h))*60
	s = (mm-Int(mm))*60
	print*,Int(h),'h',Int(mm),'m',Int(s),'s'
 99	stop
	end	
