c  1992,9,2 add all BD_star at 1993,12,20
	parameter (nsao=260000)
	character*12 ac,dc
	integer*2 j2,jj
	byte b(3)
	
	open(1,file='/EOD/CROSS/hd_sao.dat',
     *     status='old',access='direct',recl=3)
	open(2,file='/EOD/CROSS/sao_al.dat',
     *     status='old',access='direct',recl=4)
	open(3,file='/EOD/CROSS/sao_de.dat',
     *     status='old',access='direct',recl=4)
	open(4,file='/EOD/CROSS/dm_sao.dat',
     *     status='old',access='direct',recl=4)
        open(11,file='/EOD/CROSS/hd.dat',
     *     status='old',access='direct',recl=3)
        open(12,file='/EOD/CROSS/dm.dat',
     *     status='old',access='direct',recl=4)
        open(13,file='/EOD/CROSS/bd.bin',
     *     status='old',access='direct',recl=10)
	write(*,1)
1	format(//
     *19x,'******* SAO_HD_BD star cross identification *******'//
     *  20x,'notice: not count star annual proper motion'/
     *  20x,'        CD & CP number for display only'/
     *  20x,'        include all BD_star, given roughly position'// 
     *  39x,'Jiang zhaoji 2000.7'//
     *  3x,'EXAMPLE: You can input one of following star:'/
     *  9x,'HD 123'/
     *  9x,'SAO 21085'/

     *  9x,'BD+57 2865'//)
8	write(*,'(a,$)')'output star epoch: (ex. 2000.7) '
	read(*,*,err=8)epoch
	if(epoch.lt.1900.or.epoch.gt.2100)goto 8
	write(*,*)
	goto 10
9	write(*,'(1x,a1)')char(7)
10	write(*,'(a,$)')' star number:  '
	read(*,'(a)')ac
	if(ac(1:3).eq.'SAO'.or.ac(1:3).eq.'sao')goto 100
	if(ac(1:2).eq.'HD'.or.ac(1:2).eq.'hd')goto 110
	if(ac(1:2).eq.'BD'.or.ac(1:2).eq.'bd')goto 120
	if(ac(1:1).eq.'q'.or.ac(1:1).eq.'Q')stop
	goto 9
c for SAO
100	read(ac(4:),*,err=9)k
	if(k.lt.1.or.k.gt.258997)then
	 write(*,*)' SAO star number is 1~~258997 !'
	 goto 9
	endif
 	call hd(k)
	call bd(k)
	goto 200
c for HD
110	read(ac(3:),*,err=9)k
	if(k.gt.358906)then
	  write(*,*)' the largest number here is 358906 !'
          goto 9	! all hd is 358906
	endif
	read(1,rec=k)b
	k=10000*b(1)+100*b(2)+b(3)
	if(k.eq.0)then
	 write(*,*)'                   Sorry, no SAO star'
	 write(*,*)
	 goto 9
	endif
	write(*,"(9x,'SAO',i7)")k
	call bd(k)
	goto 200
c for BD
120	read(ac(4:),*,err=9)i,j
        ib=90-i
	i=i+1
	if(ac(3:3).eq.'-')then
          i=i+90
	  ib=i
	endif
	if(i.gt.113.or.ib.lt.1)then
	  write(*,*)' BD star range is +89 -- -22 degree'
          goto 9	
	endif
	read(4,rec=i)i1
	call swap4(i1,4)
	read(4,rec=i+1)i2
	call swap4(i2,4)
	i2=i2-1
	read(4,rec=i2)k2
	call swap4(k2,4)
	k2=k2/nsao
	if(j.gt.k2.or.j.lt.0)goto 21
	i0=(i2-i1)*j/k2+i1
	read(4,rec=i0)m
	call swap4(m,4)
	mm=m/nsao
	if(mm.eq.j)goto 30
	if(mm.lt.j)then
	 do 20 i=i0+1,i2
	 read(4,rec=i)m
	 call swap4(m,4)
	 mm=m/nsao
	 if(mm.eq.j)goto 30
	 if(mm.gt.j)goto 21
20	 continue
	else
	 do 22 i=i0-1,i1,-1
	 read(4,rec=i)m
	 call swap4(m,4)
	 mm=m/nsao
	 if(mm.eq.j)goto 30
	 if(mm.lt.j)goto 21
22	 continue
	endif
21	write(*,*)'                   Sorry, no SAO star'
        read(13,rec=ib)m,j2,k
	if(j.gt.j2)then
	write(*,"(20x,'BD',a4,' rang is 1 --',i5)")m,j2
	goto 9
	endif
	do 23 i=0,j
	read(13,rec=k)jj,al,de
	if(jj.eq.j)goto 201
23	k=k+1
	goto 9
30	k=mod(m,nsao)
	write(*,"(9x,'SAO',i7)")k
	call hd(k)

200	read(2,rec=k)al
	read(3,rec=k)de
	call swap4(al,4)
	call swap4(de,4)
201     call astprs(al,de,2000.,xa,xd,epoch)
        xa=amod(xa+24.,24.)
	call toms(xa,ac,1)
	call toms(xd,dc,0)
	write(*,"(8x,a,1x,a,'(',f6.1,')')")ac,dc,epoch
	write(*,*)
	goto 10
	end

	subroutine hd(k)
	byte b(3)
	read(11,rec=k)b
        j=10000*b(1)+100*b(2)+b(3)
	if(j.ne.0) write(*,"(9x,'HD',i8)")j
	if(j.eq.0) write(*,"(9x,'no HD')")
	end

        subroutine bd(k)
	byte b(4)
	character*10 dis
        read(12,rec=k)b
	j=b(1)
	if(j.ne.0)then
         dis(3:3)='+'
	 if(j.lt.0)dis(3:3)='-'
         if(j.lt.0)j=-j
         if(j.eq.1)dis(1:2)='BD'
         if(j.eq.2)dis(1:2)='CD'
         if(j.eq.3)dis(1:2)='CP'
	 j=b(3)
	 if(j.lt.0)j=256+j
         j=100*j+b(4)
         write(dis(4:10),'(i2,i5)')b(2),j
         if(dis(4:4).eq.' ')dis(4:4)='0'
         if(j.lt.1000)dis(7:7)='0'
         if(j.lt.100)dis(7:8)='00'
         if(j.lt.10)dis(7:9)='000'
	write(*,'(9x,a)')dis
	else
	write(*,"(9x,'no BD')")
	endif
	end	
