function ac = catadcp(instclass, a, c, ii)
% function ac = catadcp(instclass, a, c, ii)
% Returns concatenation of a and c.
% 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.


if (isempty(a) & isempty(c))
   ac = [];
elseif (isempty(a))
   ac = c;
elseif (isempty(c))
   ac = a;
else
   

   ac = a;
   if nargin == 3, ii = 1:length(a.dday); end


   if isfield(a, 'vel'), ac.vel = cat(3, a.vel(:, :, ii), c.vel); end
   if isfield(a, 'enu'), ac.enu = cat(3, a.enu(:, :, ii), c.enu); end
   if isfield(a, 'xyze'), ac.xyze = cat(3, a.xyze(:, :, ii), c.xyze); end
   if isfield(a, 'amp'), ac.amp = cat(3, a.amp(:, :, ii), c.amp); end
   if isfield(a, 'pg'), ac.pg = cat(3, a.pg(:, :, ii), c.pg); end
   if isfield(a, 'cor'), ac.cor = cat(3, a.cor(:, :, ii), c.cor); end
   if isfield(a, 'heading')
      ac.heading = cat(1, a.heading(ii), c.heading);
      ac.pitch = cat(1, a.pitch(ii), c.pitch);
      ac.roll = cat(1, a.roll(ii), c.roll);
      ac.soundspeed = cat(1, a.soundspeed(ii), c.soundspeed);
      ac.temperature = cat(1, a.temperature(ii), c.temperature);
   end

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

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

   ac.dday = cat(1, a.dday(ii), c.dday);
   ac.ens_num = cat(1, a.ens_num(ii), c.ens_num);
   ac.num_pings = cat(1, a.num_pings(ii), c.num_pings);
   ac.config = a.config;
   ac.depth = a.depth;

end
