function a1 = mk_ancil1(instclass, a, avg_flag)
% function a1 = mk_ancil1(instclass, a, avg_flag)
%% c1 is a shipboard ADCP ancil_1 structure represented
%% as a double array.
%% a is a structure from read_os.
%% avg_flag is an optional argument; if true, a single
%% time-averaged structure will be returned.

if nargin == 2, avg_flag = 0;   end

NP = length(a.dday);
ii = ancil1_ind;

c1 = NaN * ones(10, NP);

c1(ii.tr_temp, :) = a.temperature.';
c1(ii.snd_spd_used, :) = a.soundspeed.';
c1(ii.mn_heading, :) = a.heading.';
c1(ii.pgs_sample, :) = a.num_pings.';

if avg_flag,
   a1 = NaN * ones(10, 1);
   iii = [ii.tr_temp, ii.snd_spd_used, ii.mn_heading];
   a1(iii) = mean(c1(iii, :), 2);
   hc = exp(i * a.heading * pi/180);
   a1(ii.mn_heading) = (180/pi) * angle(mean(hc));
   a1(ii.pgs_sample) = sum(c1(ii.pgs_sample, :));
else
   a1 = c1;
end

a1(isnan(a1)) = 1e38;



