function ac = cutadcp(instclass, a, ii)
% function ac = cutadcp(instclass, 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, 'heading')
   ac.heading = a.heading(ii);
   ac.pitch = a.pitch(ii);
   ac.roll = a.roll(ii);
   ac.soundspeed = a.soundspeed(ii);
   ac.temperature = a.temperature(ii);
end

if isfield(a, 'bt'),
   ac.bt.vel = a.bt.vel(:,ii);
   ac.bt.range = a.bt.range(:,ii);
   ac.bt.cor = a.bt.cor(:,ii);
   ac.bt.amp = a.bt.amp(:,ii);
   ac.bt.rssi = a.bt.rssi(:,ii);
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

ac.dday = a.dday(ii);
ac.ens_num = a.ens_num(ii);
ac.num_pings = a.num_pings(ii);
ac.config = a.config;
ac.depth = a.depth;

