%N basants %F $MIR/src/subs/basant.for
%D Determine antennas from baseline number
%P pjt
%: calibration, uv-i/o, uv-data, utilities
%B
      subroutine basants(baseline, ant1, ant2, check)
      implicit none
      integer ant1, ant2
      double precision baseline
      logical check

  BasAnt is a Miriad routine that returns the antenna numbers that are
  required to produce the input baseline number.  According to the
  Miriad programming manual, the relationship between the baseline
  and the antenna numbers is defined as
    baseline = (Ant1 * 256) + Ant2.
  if Ant2 < 256 or
    baseline = (Ant1 * 2048) + Ant2 + 65536.
  otherwise. As should be clear, at most 2047 antennas are
  supported, regardless of the value of the MAXANT configuration
  parameter, because of the data storage format (see below).

  The output values are not clipped to MAXANT.

  Note:  Because Ant1 is ALWAYS supposed to be less than Ant2,
         it is considered a fatal error if Ant2 is larger than
         Ant1.  (No restriction is placed on the condition Ant1
         equal to Ant2 to allow for autocorrelation data.) This
         is true even if check is .FALSE.

  Older versions of MIRIAD only support 255 antennas and use only the
  first part of the encoding scheme shown above. The modified scheme
  maintains compatibility with these datasets but also allows eight
  times as many antennas.

  The factor of 2048 in the encoding scheme is referred to as MAXIANT
  in the implementation of BASANT. The value of MAXIANT is limited by
  the MIRIAD visibility data format. The 'baseline' UV variable is
  stored as a 32-bit floating point number, which means it has about 24
  bits of available precision. MAXIANT = 2048 consumes approximately 22
  of those bits, while MAXIANT = 4096 would push the limit. An
  easy-to-write test program confirms that 4096 in fact fails for large
  values of Ant1 and Ant2.

  There is hypothetical room for increasing the number of representable
  antennas because (1) MAXIANT need not be a power of 2 and (2) one
  could offset the antenna numbers by 256 in the high-antenna-number
  case. Note also that if the 32-bit baseline value was treated as an
  unsigned integer and antenna numbers started at zero, one could
  handle 65536 distinct antennas. This encoding would not, however, be
  compatible with any existing MIRIAD datasets and would probably lead
  to problems elsewhere within MIRIAD.

  Input:
    baseline The baseline number.  This value is usually obtained
             as the fourth or fifth element in the double precision array
             PREAMBLE (for example, see UVREAD).
             It is the fifth element if 
               call uvset(tvis,'preamble','uvw/time/baseline',0,0.,0.,0.)
             was used.

  Output:
    ant1     The first antenna number. Numbered 1...MAXIANT
    ant2     The second antenna number. Numbered 1...MAXIANT
