C
C________________________________________________________________
C
C     SUBROUTINE  V E C T O R
C________________________________________________________________
C
        subroutine vector(xx,yy,sizel,ista,ier)
c
c       plots random data values and positions
c       in either vector or scalar form
c
        common /vect/ ispost,lowhi,nid,ncharv,szpost,vmin,vmax,
     1    lifmtv(10),lfmtv(4),ich(20),lchid(20),DGRAD,vdum1(2)
        dimension xx(2),yy(2),bz(6),x(200),y(200),vi(200),
     1            vd(200),vm(200)
        character*4 chid(20)
        character*40 ifmtv,blank
        character ivl*3,sta*24,fmtv*16,bid*8
        character*1 ctype
        common/captur/icapt,iwhite,ctype
        logical free
        integer arrow,jsta(6)
        equivalence(ivl,jvl),(sta,jsta(1))
        equivalence (lifmtv,ifmtv),(lfmtv,fmtv),(lchid,chid)
        data arrow/#31/,con/.017453292/,pi/3.14159265/,a/.9423/,
     1    blank/' '/
        ier=0
        free=.false.
        if(ifmtv(1:1).eq.'*') free=.true.

        if(ctype.eq.'l') then
        icol=1
        else
        icol=-1
        endif
c
        if(nid.gt.19) nid=19
        if(ncharv.gt.24) ncharv=24
        jch=ich(1)
        jcol=1*icol
        if(ich(1).gt.99) then
        jcol=(ich(1)/100)*100
        jch=ich(1)-jcol
        jcol=jcol+1
        endif
        if(ispost.gt.1 .or. ispost.lt.0) go to 100
        n=1
1       if(ifmtv.ne.blank) then
          if(free) then
            read(ista,*,end=3,err=90,iostat=icheck)
     1      x(n),y(n),vm(n),vi(n),vd(n)
          else
            read(ista,ifmtv,end=3,err=90,iostat=icheck)
     1      x(n),y(n),vm(n),vi(n),vd(n)
          endif
        else 
          read(ista,end=3,err=90,iostat=icheck)
     1    x(n),y(n),vm(n),vi(n),vd(n)
        endif
        n=n+1
        go to 1
3       n=n-1
        dmax=1.e-10
        do 4 i=1,n
        if(vm(i).gt.dmax) dmax=vm(i)
4       continue
        sca=(vmax-vmin)/alog(dmax)
        pima=pi-a
        pia=pi+a
        pima2=2.*pi-a
        do 10 i=1,n
        incl=int(vi(i))
        if(vm(i).le.0.) then
          print *,'magnetic values must be positive'
          ier = 1
          return
        endif
        v=alog(vm(i))
        if(v.lt.0.) v=0.
        vlen=sca*v+vmin
        th=-vd(i)*con
        if((th.gt.a .and. th.lt.pima)  .OR.
     1    (th.gt.pia .and. th.lt.pima2)) THEN
         XL = SIZEL
         YL = 0.0
        ELSE IF((TH.le.a)  .OR.
     1    (th.ge.pi .and. th.le.PIA)) THEN
         XL = 0.0
         YL = -SIZEL
         ELSE
         XL = 0.0
         YL = SIZEL
        ENDIF
        WRITE (IVL,'(i3)') INCL
        CALL VCHAR(x(i),y(i),3,1,1*icol,.05,0.,0.,0.)
        CALL VCHAR(x(i),y(i),arrow,1,1*icol,vlen,th,0.,0.)
        CALL VCHAR(x(i),y(i),jvl,3,2*icol,sizel,0.,xl,yl)
10      continue
        go to 99
c
100     m1=1
        m2=2
        if(xx(1).lt.xx(2)) go to 140
        m1=2
        m2=1
140     m3=1
        m4=2
        if(yy(1).lt.yy(2)) go to 141
        m3=2
        m4=1
141     yoff=-sizel*.5
        xoff=2.*sizel
c
c     put in by r.godson to plot different intervals
c     of number of input points
c
      ic=0
      if(ispost.gt.-31.and.ispost.lt.3) then
      icnt=1
      else if(ispost.gt.2) then
      icnt=ispost/2
      else
      icnt=iabs(ispost)/31
      ispost=ispost-(-31*icnt)
      endif
        iz=mod(iabs(ispost),10)
        idbr=iabs(ispost)/10 - 1
         ibr=-1
         if(ifmtv.eq.blank) ibr=0
         if(ispost.lt.0) ibr=1
        if(ibr) 101,102,103
101     if(free) then
        read(ista,*,end=99,err=90,iostat=icheck) sx,sy,sz
        else
        read(ista,ifmtv,end=99,err=90,iostat=icheck) sx,sy,sz
        endif
        go to 104
102     read(ista,end=99,err=90,iostat=icheck) sx,sy,sz
        go to 104
103     read(ista,end=99,err=90,iostat=icheck) bid,sx,sy,bz
        sz=bz(iz)
104     if(sx.lt.xx(m1) .or. sx.gt.xx(m2)) go to 122
        if(sy.lt.yy(m3) .or. sy.gt.yy(m4)) go to 122
        if(nid.ne.0) then
         call match(nid,chid,bid,isym)
         if(ich(isym).gt.99) then
           jcol=(ich(isym)/100)*100
           jch=ich(isym)-jcol
           jcol=jcol+1
         else
           jcol=1*icol
           jch=ich(isym)
         endif
        endif
      if(mod(ic,icnt).eq.0) then
      call vchar(sx,sy,jch,1,jcol,szpost,0.,0.,0.)
      endif
      ic=ic+1
        if(idbr.ne.0 .and. ncharv.gt.0) then
         write(sta,fmtv)sz
         n=leftj(sta)
         call vchar(sx,sy,jsta,n,2*icol,sizel,.3,xoff,yoff)
        endif
        if(idbr.ge.0) then
      if(bid.ne.'       ') then
         sta=bid
         n=leftj(sta)
         call vchar(sx,sy,jsta,n,2*icol,sizel,.785,xoff,0.)
      endif
        endif
122     if(ibr) 101,102,103
90      print *,'error no. ',icheck,' reading random data file'
        ier=1
99      return
        end
C
C________________________________________________________________
C
C     SUBROUTINE  M A T C H
C________________________________________________________________
C
        subroutine match(n,chk,test,isym)
c       compares two character strings and returns
c       a symbol index number
        character*8 test
        character*4 chk(20)
        do 10 isym = 1,n
        if(chk(isym).eq.' ') go to 10
        length = index(chk(isym)//' ', ' ')-1
        if (index(test,chk(isym)(1:length)) .gt. 0) return
10      continue
        isym=n+1
        return
        end
