	FUNCTION ACTAN(SINX,COSX)
	COMMON/C2/DE2RA,PI,PIO2,TWOPI,X3PIO2
	ACTAN=0.
	IF (COSX.EQ.0. ) GO TO 5
	IF (COSX.GT.0. ) GO TO 1
	ACTAN=PI
	GO TO 7
   1	IF (SINX.EQ.0. ) GO TO 8
	IF (SINX.GT.0. ) GO TO 7
	ACTAN=TWOPI
	GO TO 7
   5	IF (SINX.EQ.0. ) GO TO 8
	IF (SINX.GT.0. ) GO TO 6
	ACTAN=X3PIO2
	GO TO 8
   6	ACTAN=PIO2 GO TO 8
   7	TEMP=SINX/COSX
   	ACTAN=ACTAN+ATAN(TEMP)
   8	RETURN
	END

	FUNCTION FMOD2P(X)
	COMMON/C2/DE2RA,PI,PIO2,TWOPI,X3PIO2
	FMOD2P=X
	I=FMOD2P/TWOPI
	FMOD2P=FMOD2P-I*TWOPI
	IF(FMOD2P.LT.0) FMOD2P=FMOD2P+TWOPI
	RETURN
	END

	FUNCTION THETAG(EP)
	COMMON /E1/XMO,XNODEO,OMEGAO,EO,XINCL,XNO,XNDT2O,XNDD6O,BSTAR,X,Y,Z,XDOT,YDOT,ZDOT,EPOCH,DS50
	DOUBLE PRECISION EPOCH,D,THETA,TWOPI,YR,TEMP,EP,DS50
	TWOPI=6.28318530717959D0
	YR=(EP+2.D-7)*1.D-3
	JY=YR
	YR=JY
	D=EP-YR*1.D3
	IF(JY.LT.10) JY=JY+80
	N=(JY-69)/4
	IF(JY.LT.70) N=(JY-72)/4
	DS50=7305.D0 + 365.D0*(JY-70) +N + D
	THETA=1.72944494D0 + 6.3003880987D0*DS50
	TEMP=THETA/TWOPI
	I=TEMP
	TEMP=I
	THETAG=THETA-TEMP*TWOPI
	IF(THETAG.LT.0.D0) THETAG=THETAG+TWOPI
	RETURN
	END
