;+
;  Name:
;       ORBIT
;  Calling sequence:
;	 orbit, ut, x_pos,y_pos,z_pos, period=period, 
; 	next_night=night,next_day=day,bad_data=bad_data
;  Purpose and Procedure:
;	given a small number of samples (~100) of the time and position vectors from
;	the spacecraft ephemeris, determine the orbital period, and the times of the
;	next passage into night and the next passage into day after night.  
;	While this routine will find the period and day/night transitions from
;	a small data set, it works best with sufficient data to actually cover the
;	day/night transitions.
; Category:
;	BATSE
; Inputs:
;	ut
;	x(yz)_pos
;	
; Calls: 
;	DN_TRANS
; Outputs:
;	period- orbital period in seconds
;	next_night
;	next_day
;	bad_data- set to 1 if there is insufficient valid orbital data
; History:
;	Version 1, RAS 1991
;	AKT, 1992
;	Version 3, RAS 9 June 1996, added documentation
;-
pro orbit, ut, x_pos,y_pos,z_pos, period=period,$
	 next_night=night,next_day=day,bad_data=bad_data

nsamp=n_elements(ut)	
dn_trans,ut,x_pos,y_pos,z_pos, bad_data=bad_data, $
                 d_period=period, days=days, nights=nights

if bad_data then goto,getout  ; added by akt ++++++++++++++++++++++

night = nights((where (nights gt ut(0)))(0))
day   = days((where( days gt night))(0))     

getout:

end

