function ac = cutadcp(a, ii)
% function ac = cutadcp(a, ii)
% Returns subset of "a" with time indices ii.
% It would be nice to have a more automated way of doing this.

% This initialization is not necessary, but it ensures that
% the order of the fields remains the same, even if they are
% changed in read_os.


ac = a;


if isfield(a, 'vel'), ac.vel = a.vel(:, :, ii); end
if isfield(a, 'amp'), ac.amp = a.amp(:, :, ii); end
if isfield(a, 'pg'), ac.pg = a.pg(:, :, ii); end
if isfield(a, 'cor'), ac.cor = a.cor(:, :, ii); end
if isfield(a, 'sw'), ac.sw = a.sw(:, :, ii); end
if isfield(a, 'rssi'), ac.rssi = a.rssi(:, :, ii); end
if isfield(a, 'status'), ac.sw =      a.sw(:, :, ii); end
if isfield(a, 'HiV'),    ac.HiV =     a.HiV(:, :, ii); end
if isfield(a, 'XmtAmps'),ac.XmtAmps = a.XmtAmps(:, :, ii); end

if isfield(a, 'heading'),         ac.heading     = a.heading(ii);     end
if isfield(a, 'pitch'),           ac.pitch       = a.pitch(ii);       end
if isfield(a, 'roll'),            ac.roll        = a.roll(ii);        end
if isfield(a, 'soundspeed'),      ac.soundspeed  = a.soundspeed(ii);  end
if isfield(a, 'meas_soundspeed'),
      ac.meas_soundspeed  = a.meas_soundspeed(ii);  end
if isfield(a, 'temperature'),     ac.temperature = a.temperature(ii); end
if isfield(a, 'aduheading'),      ac.aduheading  = a.aduheading(ii);  end
if isfield(a, 'attdday'),         ac.attdday     = a.attdday(ii);     end
if isfield(a, 'mrms'),            ac.mrms        = a.mrms(ii);        end
if isfield(a, 'brms'),            ac.brms        = a.brms(ii);        end
if isfield(a, 'dday'),          ac.dday      = a.dday(ii);            end
if isfield(a, 'ens_num'),       ac.ens_num   = a.ens_num(ii);         end
if isfield(a, 'num_pings'),     ac.num_pings = a.num_pings(ii);       end
if isfield(a, 'RDIens_num'),    ac.RDIens_num    = a.RDIens_num(ii);  end
if isfield(a, 'RDIymdhms'),     ac.RDIymdhms    = a.RDIymdhms(ii);    end
if isfield(a, 'config_nbytes'), ac.config_nbytes= a.config_nbytes(ii);end
if isfield(a, 'config_nleader'),ac.config_nleader= a.config_nleader(ii); end


if isfield(a, 'bt'),
   ac.bt.vel = a.bt.vel(:,ii);
   ac.bt.range = a.bt.range(:,ii);
   if isfield(ac.bt, 'cor'),    ac.bt.cor    = a.bt.cor(:,ii);     end
   if isfield(ac.bt, 'amp'),    ac.bt.amp    = a.bt.amp(:,ii);     end
   if isfield(ac.bt, 'rssi'),   ac.bt.rssi   = a.bt.rssi(:,ii);    end
   if isfield(ac.bt, 'pg'),     ac.bt.pg     = a.bt.pg(:,ii);      end   
end

if isfield(a, 'nav'),
   ac.nav.sec_pc_minus_utc = a.nav.sec_pc_minus_utc(ii);
   ac.nav.txy1 = a.nav.txy1(:,ii);
   ac.nav.txy2 = a.nav.txy2(:,ii);
end

if isfield(a, 'config'),        ac.config    = a.config;       end
if isfield(a, 'info'),          ac.info      = a.info;       end
if isfield(a, 'depth'),         ac.depth     = a.depth;        end
if isfield(a, 'add_to_ens'),    ac.add_to_ens= a.add_to_ens;   end



if isfield(a, 'vel1'), ac.vel1 = a.vel1(:,ii); end
if isfield(a, 'vel2'), ac.vel2 = a.vel2(:,ii); end
if isfield(a, 'vel3'), ac.vel3 = a.vel3(:,ii); end
if isfield(a, 'vel4'), ac.vel4 = a.vel4(:,ii); end
if isfield(a, 'amp1'), ac.amp1 = a.amp1(:,ii); end
if isfield(a, 'amp2'), ac.amp2 = a.amp2(:,ii); end
if isfield(a, 'amp3'), ac.amp3 = a.amp3(:,ii); end
if isfield(a, 'amp4'), ac.amp4 = a.amp4(:,ii); end
if isfield(a, 'cor1'), ac.cor1 = a.cor1(:,ii); end
if isfield(a, 'cor2'), ac.cor2 = a.cor2(:,ii); end
if isfield(a, 'cor3'), ac.cor3 = a.cor3(:,ii); end
if isfield(a, 'cor4'), ac.cor4 = a.cor4(:,ii); end
if isfield(a, 'pg1'), ac.pg1 = a.pg1(:,ii); end
if isfield(a, 'pg2'), ac.pg2 = a.pg2(:,ii); end
if isfield(a, 'pg3'), ac.pg3 = a.pg3(:,ii); end
if isfield(a, 'pg4'), ac.pg4 = a.pg4(:,ii); end
if isfield(a,  'umeas'),ac.umeas = a.umeas(:,ii); end
if isfield(a,  'vmeas'),ac.vmeas = a.vmeas(:,ii); end
if isfield(a, 'fmeas'), ac.fmeas = a.fmeas(:,ii); end
if isfield(a, 'pmeas'), ac.pmeas = a.pmeas(:,ii); end
if isfield(a, 'wmeas'), ac.wmeas = a.wmeas(:,ii); end
if isfield(a, 'emeas'), ac.emeas = a.emeas(:,ii); end
if isfield(a,   'sw1'), ac.sw1 = a.sw1(:,ii); end
if isfield(a,   'sw2'), ac.sw2 = a.sw2(:,ii); end
if isfield(a,   'sw3'), ac.sw3 = a.sw3(:,ii); end
if isfield(a,   'sw4'), ac.sw4 = a.sw4(:,ii); end
