;+
; NAME:
;     BASLIN_PCLOSE
; PURPOSE:
;     Force phase closure in baseline calibration data.
; CATEGORY:
;     OVRO APC CALIBRATION
; CALLING SEQUENCE:
;     blout = baslin_pclose(blin)
; INPUTS:
;     blin    A float array of size (nb*2,nmeas) where NB=7 is the number of
;                baselines for which the baseline calibration data were taken,
;                and NMEAS is the number of measurements.  The first dimension
;                is 2*NB because it consists of 7 phases and 7 chi-square
;                values, alternating.
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
; ROUTINES CALLED:
;     pclose
; OUTPUTS:
;     blout  An exactly parallel array to BLIN, but with phases corrected
;                for phase closure.
; COMMENTS:
; SIDE EFFECTS:
; RESTRICTIONS:
;     This routine will have to be fixed to work with more than 5
;     antennas (7 baselines)
; MODIFICATION HISTORY:
;     Written 01-Jul-1999 by Dale E. Gary
;-

function baslin_pclose,blin

   blout = blin
   nmeas = n_elements(blin[0,*])
   nb = n_elements(blin[*,0])/2
   iphz = indgen(nb)*2
   iwts = indgen(nb)*2+1
   for i = 0, nmeas-1 do begin

      ; Input phases for this measurement, one for each baseline
      pin = reform(blin[iphz,i])
      wts = reform(blin[iwts,i])

      ; Correct the phases for all of the baselines
      blout[iphz,i] = pclose(pin,wts,0,cor=Cor)
   endfor

return,blout
end