;	(11-jun-92)
function get_orb_epoch,tim_in,orb_files=orb_files
;+
;  Name:
;    get_orb_epoch
;  Purpose:
;    Return the orbital epoch of the on-line /ydb/orb_ files containing
;    the Yohkoh orbital elements.
;  Calling Sequence:
;    Result = get_orb_epoch()		; Returns the most recent version
;    Result= get_orb_epoch('11-jun-92')	; Returns the value closest to 11-jun-92
;    Result= get_orb_epoch(tim_in,orb_files=orb_files)
;    Result= get_orb_epoch('*')		; Returns all available cases.
;
;    The result is given in dd-mmm-yy hh:mm:ss format.
;
;  Inputs:
;    tim_in	= time and date in any format.  Vectors O.K.
;		  If tim_in = "*", then all cases will be returned.
;
;  Outputs:
;    Result is the time/date of the orbital element solution.
;  Optional Output Keywords:
;    orb_files	= Contains the full path of the orbital element solution.
;  Modification History:
;    11-jun-92, Written, J. R. Lemen
;-

orbit_sol = '$DIR_GEN_ORBIT_SOL/orbit_*'		; Search Path
files = findfile(orbit_sol,count=nfiles)	; Get the file names
if nfiles eq 0 then begin
   print,'** Error in get_orb_epoch:  No files round **'
   print,'**        Used search path = ',orbit_sol
   return,''
end

if n_elements(tim_in) eq 0 then tim_in = !stime	; Default to current time
if strpos(tim_in(0),'*') ne -1 then all=1 else all=0

nfiles = n_elements(files)
orbit_times = lonarr(7,nfiles)                         ; External format
for i=0,nfiles-1 do begin
    openr,lun,files(i),/get_lun
    buf = '' & readf,lun,buf & buf = strmid(buf,0,12)
    orbit_times(6,i) = long(strmid(buf,0,2))            ; year
    orbit_times(5,i) = long(strmid(buf,2,2))            ; month
    orbit_times(4,i) = long(strmid(buf,4,2))            ; day
    orbit_times(0,i) = long(strmid(buf,6,2))            ; Hours
    orbit_times(1,i) = long(strmid(buf,8,2))            ; Minutes
    orbit_times(2,i) = long(strmid(buf,10,2))           ; Seconds
    free_lun,lun
endfor
o_tim_ints = anytim2ints( orbit_times )
o_tim_rel  = int2secarr( o_tim_ints, o_tim_ints(0))

if all then ss = indgen(nfiles) else begin
  
  r_tim_rel = int2secarr(anytim2ints(tim_in),o_tim_ints(0))
  ss = intarr(n_elements(r_tim_rel))
  for i=0,n_elements(r_tim_rel)-1 do begin
    xx = min(abs(r_tim_rel(i)-o_tim_rel),ij) & ss(i) = ij
  endfor
endelse

orb_files = files(ss)
return,fmt_tim(o_tim_ints(ss))
end
