c     programme bda/progf/sref.f
c
c     Search and display the references according to the
c     data type given
c
      character inf*70,nfich*6,fil*60,path*35,lang*3
      logical l
c
      call getenv("LNG",lang)
c
      narg=iargc()
      if(narg.eq.0) then
      if(lang(1:2).eq.'fr') then
        write(6,485)
  485   format(/,' Pour quel type de donnees?  ',$)
      else
        write(6,490)
  490   format(/,' For which kind of data?   ',$)
      endif
      read *,nfich
      else
      call getarg(1,nfich)
      endif
   21 if(nfich(1:1).eq.'?'.or.nfich(1:4).eq.'help') goto 20
      do 50 j=1,6
      ll=7-j
      if(nfich(ll:ll).ne.' ') goto 51
   50 continue
   51 call getenv('BDA',path)
      fil=path(1:index(path,' ')-1)//'/references/'//nfich(1:ll)//'.ref'
      inquire(file=fil,exist=l)
      if(.not.l) goto 20
      open(10,file=fil,status='old')
c
      nopr=1
    1 if(lang(1:2).eq.'fr') then
        write(6,498)
  498   format(/,' Donnez le numero de la reference :  ',$)
      else
        print 500
  500   format(/,' Give the reference number :   ',$)
      endif
      read(5,*) noref
      if(noref.eq.0) goto 10
      if(noref.lt.0) goto 20
   11 if(noref.lt.nopr) rewind 10
    2 read(10,100,end=9) no,inf
  100 format(1x,i4,2x,a70)
      if(no.ne.noref) goto 2
      print *
      n=lnblnk(inf)
      write(6,200) no,inf(1:n)
      nopr=noref
  200 format(1x,i4,2x,a)
    3 read(10,100,end=9) no,inf
      if(inf(1:5).eq.'     ') goto 4
      n=lnblnk(inf)
      write(6,201) inf(1:n)
  201 format(7x,a)
      goto 3
    4 if(lang(1:2).eq.'fr') then
        write(6,602)
  602   format(/,' Une autre reference?  ',$)
      else
        write(6,601)
  601   format(/,' Another reference?   ',$)
      endif
      read *,noref
      if(noref.gt.0) goto 11
      if(noref.eq.0) goto 10
c
c     A negative choice allows one to change the reference file
c
   20 if(lang(1:2).eq.'fr') then
        write(6,660)
  660   format(/,' Le choix peut etre fait dans la liste suivante: ')
      else
        write(6,650)
  650   format(/,' Choice can be made in the following list: ')
      endif
      write(6,651)
  651 format(//,
     &' - ubv - pgh - ccd - sit - cam - rgu - hrd - cmd -',//, 
     &' - uvby - beta - wal - vil - ddo - cmt - egg - ccdy -',//,
     &' - smi - ric - rij - rie - rik - jhk - vic - ',//,
     &' - mk - spt - vsn - irv - mrv - gpo - rfs - orb - prd -',//,
     &' - coo - pos - prob - apm - rpm - prob - lyn -',//)
      if(lang(1:2).eq.'fr') then
        write(6,492)
  492   format(' Precisez votre choix:  ',$)
      else
        write(6,495)
  495   format(' Precise your choice:   ',$)
      endif
      read *,nfich
      goto 21
c
    9 write(6,300) noref
  300 format(/,' La reference ',i3,' n''existe pas',/)
      rewind 10
      goto 4
c
   10 print *
      stop
      end
