;+
; NAME:
;     CLOSE_ANT
; PURPOSE:
;     Close the phases of a single antenna (actually returns closed
;     phases for a single triad of antennas, e.g. 1-2-4 or 1-2-5).
; CATEGORY:
;     OVRO APC DATA CALIBRATION
; CALLING SEQUENCE:
;     amfout = close_ant(amfdat)
; INPUTS:
;     amfdat    The array of data obtained from reading an AMF file
;                 for a single antenna (array of size [6,NF,3], where
;                 first index is AMF file column number, NF is number
;                 of frequencies, and 3 is the number of baselines for
;                 a single triad of antennas).
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
; ROUTINES CALLED:
;     pclose
; OUTPUTS:
;     amfout    The same as the input data, except the phases are forced
;                 to close to 135 degrees.
; COMMENTS:
; SIDE EFFECTS:
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     Written 25-Mar-2002 by Dale E. Gary
;     03-Jan-2003  DG
;       Changed due to correction of backend phases, which
;       now cause all phases to close to zero.
;-

function close_ant,amfdat

   ; Loop over frequency
   nf = n_elements(amfdat[0,*,0])
   amfout = amfdat
   for i = 0, nf-1 do begin
      ; Input phases for this frequency, one for each baseline
      pin = reform(amfdat[3,i,*])

      ; Weights (3-element array)
      w = reform(amfdat[2,i,*]/amfdat[1,i,*])

      ; Close to 0 degrees.
      amfout[3,i,*] = pclose(pin,w,0.)
   endfor

return,amfout
end