;+
; NAME:
;     GPARM_ACTIVE
; PURPOSE:
;     Selects gain parameter information for the active antennas from the
;     complete set of gain parameters for all antennas, as measured during
;     a GCAL.
; CATEGORY:
;     OVRO APC DATA ANALYSIS
; CALLING SEQUENCE:
;     gparm = gparm_active(gainparm,aa)
; INPUTS:
;     gainparm  The full set of gain parameters as a GPARM structure, containing
;                 nonlinearity, attenuation factors, and offsets from a GCAL
;     aa        A simple list of active antennas, e.g. active antennas 4, 5,
;                 and 6 would be represented by an array [4,5,6].
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
; ROUTINES CALLED:
; OUTPUTS:
;     gparm    A new GPARM structure, but restricted to only the active antennas.
; COMMENTS:
; SIDE EFFECTS:
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     Written 14-Nov-1999 by Dale E. Gary
;     18-Jul-2004  DG
;       Add dimension to GCAL so that both R and L are returned.
;-

function gparm_active,gainparm,aa

   nant = n_elements(aa)
   antlist = [1,2,4,5,6,7,8,9]

   ; Generate translation from antenna number to index in "finder" array
   iants = intarr(nant)
   ibls = intarr(nant,nant)
   k = -1
   for i = 0, nant-1 do begin
      iants[i] = where(antlist eq aa[i])
   endfor

   ; Get corresponding offsets (converts square 8 x 8 array
   ; into a square array of size nant x nant)
   offsets = (*gainparm.poffsets)
   offs = (offsets(iants,*))(*,iants)

   gnp = (*gainparm.pgnp)[iants]

   ; Get GCAL array for active antennas only
   gcal = (*gainparm.pgcal)[iants,*,*]

   ; Form new GPARM structure containing info only for active antennas
   gparm = {epoch:gainparm.epoch, poffsets:ptr_new(offs), pgnp:ptr_new(gnp), dlcal:gainparm.dlcal, pgcal:ptr_new(gcal)}

return,gparm
end
