function a2 = mk_ancil2(instclass, a, avg_flag)

%% a2 is a shipboard ADCP ancil_2 structure represented
%% as a double array.
%% a is a structure from read_os.

if nargin == 2, avg_flag = 0; end

NP = length(a.heading);

aa2 = NaN * ones(23, NP);
ii = ancil2_ind;

aa2(ii.mn_pitch,:) = a.pitch.';
aa2(ii.mn_roll,:) = a.roll.';
aa2(ii.last_good_bin,:) = a.config.ncells;

if avg_flag,
   a2 = NaN * zeros(23, 1);
   iii = [ii.mn_pitch, ii.mn_roll];
   a2(iii) = mean(aa2(iii, :), 2);
   a2(ii.last_good_bin) = a.config.ncells;
else
   a2 = aa2;
end

a2(isnan(a2)) = 1e38;


