pro rd_hip,ra,dec,hip,vmag,bmv,plax,eplax,pmra,pmdec
; This routine reads the file /local/d/timbrown/stardat/hipparcos.txt and
; returns arrays containing the indicated information for all stars.
;  ra, dec = J2000.0
;  hip = hipparcos ID number
;  vmag, bmv = V, B-V (Johnson magnitudes)
;  plax, eplax = parallax, error in mas
;  pmra,pmdec = proper motion in RA, Eec in mas/yr

; open file, count the lines
filin='/home/tbrown/d/stardat/hipparcos.txt'
openr,iun,filin,/get_lun
ss=''
nn=0
while(not eof(iun)) do begin
  readf,iun,ss
  nn=nn+1
endwhile
point_lun,iun,0

; make the output arrays
ra=dblarr(nn)
dec=dblarr(nn)
hip=lonarr(nn)
vmag=fltarr(nn)
bmv=fltarr(nn)
plax=fltarr(nn)
eplax=fltarr(nn)
pmra=fltarr(nn)
pmdec=fltarr(nn)

; read the data
jj=0
for i=0,nn-1 do begin
  readf,iun,ss
  words=get_words(ss,nw)
  if(nw ge 20) then begin
    hip(jj)=long(words(5))
    vmag(jj)=float(words(12))
    bmv(jj)=float(words(19))
    plax(jj)=float(words(15))
    eplax(jj)=float(words(18))
    pmra(jj)=float(words(16))
    pmdec(jj)=float(words(17))
    hh=fix(words(6))
    mm=fix(words(7))
    sc=float(words(8))
    ra(jj)=15.*(hh+60.*mm+3600.*sc)
    d9=words(9)
    sgn=strmid(d9,0,1)
    ds=strmid(d9,1,2)
    dd=fix(ds)
    mm=fix(words(10))
    sc=float(words(11))
    dec(jj)=float(dd)+60.*mm+3600.*sc
    if(sgn eq '-') then dec(jj)=-dec(jj)
    jj=jj+1
  endif
endfor

; truncate arrays for incomplete lines if necessary
ra=ra(0:jj-1)
dec=dec(0:jj-1)
hip=hip(0:jj-1)
vmag=vmag(0:jj-1)
bmv=bmv(0:jj-1)
plax=plax(0:jj-1)
eplax=eplax(0:jj-1)
pmra=pmra(0:jj-1)
pmdec=pmdec(0:jj-1)

close,iun
free_lun,iun

end