%N vectav %F $MIR/src/subs/calphase.for
%D Vector averaging with lookup index table
%: calibration, vector-average
%P pjt
%B
      SUBROUTINE vectav (b,p,count,avidx,clump,nclump,x,y,dtaver,tmax)

      INTEGER avidx(*), clump(*), b, p, count, nclump
      REAL    x(*), y(*), dtaver,tmax

  Vector average the wide band calibration data in rdata(). For a
  given set (baseline,slot)=(b,p) a vector average with time
  resolution 'dtaver' is done. Data are assumed to be timesorted
  through the avidx() index array.
  Note that the data in /CALDATA/ must be in unscaled K, after the
  vector averaging is done, rescaling is done to get requested
  K/Jy (see AMPSCAL how this can be done)

  Input:
     b        --  baseline index (1..nbl)
     p        --  slot for phase/amplitude (1..4)
     count    --  length of index array (lookup table in Rtime())
     avidx    --  index array: Rtime(avidx(i)) are used
     dtaver   --  max timestep in clump formation
     tmax     --  max time to integrate for in clump formation
  Output:
     nclump   --  length of filled in data in array (x,y)
     x        --  array of averaged times (x(j), j=1..nclump)
     y        --  array of vector averaged phase or amplitude (see p)
     clump    --  lookup table of original data into clumps:
                   Data-element avidx(i) was used in clump(j)
                   (i=1..count)  (j=1..nclump)
