	PRO GetNarOrb, fileNa, userTim, NewOrb_p, iNewOrb_p, len
;	----------------------------------------------------------------
;+							9-Apr-91
;	NAME:
;		GetNarOrb (get nearest orbit)
;	PURPOSE:
;		Get the NewOrb_p information and the NewOrb_p-indics 
;		which is nearest in time to the user input times.
;	CALLING SEQUENCE:
;		GetNarOrb, fileNa, userTim, NewOrb_p, iNewOrb_p, len
;	INPUT:
;		fileNa		Observing log file name.
;		userTim		list of user input times.  For example,  
;				start and end times (in order). Structure:
;				userTim = {name, time:long, day:fix}
;	Output:	
;		NewOrb_p	list of NewOrbit times and pointers.
;		iNewOrb_p	list of NewOrb_p-indices corresponding
;				to input times.
;		len		number of 32-byte logical records 
;				following the last requested neworb_p.	
;	History:
;		written 1-Apr-91 by GAL
;		3-Apr-91 added len parameter.
;		9-Apr-91 len parameter correction after improvements were
;			made to observing.log access rountines.  
;-
;	---------------------------------------------------------------
;	ON_ERROR, 2	;force a return to caller if error occurs

;	count and order input times:
	ntimes = SIZE(userTim) 
	ntimes = ntimes(ntimes(0))	;n elements

	ineworb_p = INDGEN(ntimes)	;create output list for indices

;	Get header and New Orbit information:
	Rd_fheader, fileNa, fheader, ndset
	Rd_NewOrb_p, fileNa, neworb_p, newOrb_Hd

	FOR i=0, ntimes-1 DO BEGIN
	  ineworb_p(i) = BinarySea(errStat, userTim(i), neworb_p.day, $
			neworb_p.time)
	ENDFOR

;	print, '*** GetNarOrb-- ***'
;	print, 'neworb_p and found index list: ', neworb_p, ineworb_p

;	check for single neworb_p selection:
	IF (ineworb_p(0) eq ineworb_p(1)) THEN BEGIN
	  ineworb_p = [ineworb_p(0)]	;force it to be an array of 1
	ENDIF 

	norbs = N_ELEMENTS(ineworb_p)	;number of neworb pointers

;	Patch for missing information inside {obs_newOrbit_rec}-- 
;	Added number of 32-byte logical records within an orbit of
;	information: 
	IF (ineworb_p(norbs-1) eq newOrb_Hd.nOrbitRec-1) THEN BEGIN
	  len = ndset - neworb_p(ineworb_p(norbs-1)).StEntry 
	ENDIF ELSE BEGIN
	  len = (neworb_p(ineworb_p(norbs-1)+1).StEntry -1) - $
		neworb_p(ineworb_p(norbs-1)).StEntry
	ENDELSE

	RETURN
	END
