c     programme bda/progf/multiref.f
c
c     Search and display references for a sample
c
c     Unit 10:  reference file
c     Unit 11:  data type
c     Unit 12:  list of reference numbers
c
      character inf*70,nfich*5,fil*45,path*45,user*45,stat*4
      logical lx
c
      call getenv('BDA',path)
      call getenv('BTP',user)
c
      fil=user(1:index(user,' ')-1)//'/type.out'
      inquire(file=fil,exist=lx)
      if(.not.lx) then
        stat='new'
      else
        stat='old'
      endif
      open(11,file=fil,status=stat)
c
      read(11,90) nfich
   90 format(a5)
      do 50 j=1,5
      ll=6-j
      if(nfich(ll:ll).ne.' ') goto 51
   50 continue
   51 fil=path(1:index(path,' ')-1)//'/references/'//nfich(1:ll)//'.ref'
      open(10,file=fil,status='old')
c
      fil=user(1:index(user,' ')-1)//'/ref.out'
      inquire(file=fil,exist=lx) 
      if(.not.lx) then 
        stat='new' 
      else 
        stat='old' 
      endif 
      open(12,file=fil,status=stat)
c
    1 read(12,500,err=8,end=10) noref
  500 format(6x,i4)
      if(noref.eq.0) goto 1
    2 read(10,100,err=9,end=10) no,inf
  100 format(1x,i4,3x,a70)
      if(no.eq.0) goto 2
      if(no.ne.noref) goto 2
      write(6,190)
  190 format(1x)
      n=lnblnk(inf)
      write(6,200) no,inf(1:n)
      nopr=noref
  200 format(1x,i4,3x,a)
    3 read(10,100,end=10) no,inf
      if(inf(1:5).eq.'     ') goto 1
      n=lnblnk(inf)
      write(6,201) inf(1:n)
  201 format(8x,a)
      goto 3
c
    8 write(6,300)
  300 format(' Read error on reference number list')
      goto 1
    9 write(6,310)
  310 format(' Read error on reference file')
c
   10 stop
      end
