%this is the part of attplot that gets the data.  gattplot plots it

FID_LOG = fopen('attplot.log', 'a');
fprintf(FID_LOG, '\n\nattplot,  %s\n', pctime);


att_ = [];
att  = []; % Initialization needed for Matlab 5.2 parser.

[nfiles nn] = size(attfile);
for ii = 1:nfiles
   eval(['load ' attfile(ii,:) '.mat'])
   att_ = [att_ att];
   fprintf(FID_LOG, ['  ' attfile(ii,:) '.mat\n']);
end
att = att_;
clear att_;

igood = find(~isnan(att(i_r_mean,:)));
if (isempty(igood))
     fprintf(FID_LOG, 'no good data');
     error('no good data')
end

dhm = mean(att(i_dh_mean, igood));
rm = mean(att(i_r_mean, igood));
pm = mean(att(i_p_mean, igood));

good_mask = (att(i_n_used,:) > 20) ...
           & att(i_dh_max,:)-att(i_dh_min,:) < 5 ...
           & abs(att(i_dh_mean,:) - dhm) <  10 ...
           & abs(att(i_r_mean,:)  - rm ) < 7    ...
           & abs(att(i_p_mean,:)  - pm ) < 5;

[ni, nj] = size(att);

fprintf(FID_LOG, '  All files: %d points, %d accepted; %5.2f percent rejected\n', ...
                            nj, sum(good_mask), 100 * sum(~good_mask)/nj);

% Rows to plot, from the bottom up:
%irows = [ i_n_used i_r_std i_r_mean i_p_std i_p_mean i_dh_std i_dh_mean];
irows_1 = [ i_n_used i_r_std  i_p_std i_dh_std i_dh_mean];
irows_2 = [ i_r_min i_r_max i_r_mean i_p_min i_p_max i_p_mean ];
irows_3 = [i_mrms_mean i_brms_mean i_n_mrms i_n_brms i_n_outlier i_n_reacq i_n_att  ];

labels = zeros(ni,7);
labels(i_dh_mean,:)        = 'dh mean'; % Ashtech minus gyro
labels(i_dh_std,:)         = 'dh std ';
labels(i_p_mean,:)         = 'p mean ';
labels(i_p_std, :)         = 'p std  ';
labels(i_r_mean, :)        = 'r mean ';
labels(i_r_std, :)         = 'r std  ';
labels(i_n_used, :)        = 'n used ';
labels(i_p_max, :)         = 'p max  ';
labels(i_p_min, :)         = 'p min  ';
labels(i_r_max, :)         = 'r max  ';
labels(i_r_min, :)         = 'r min  ';
labels(i_n_att, :)         = 'n att  ';
labels(i_n_reacq, :)       = 'reacq  ';
labels(i_n_outlier,:)      = 'outlier';
labels(i_n_brms,:)         = 'n brms ';
labels(i_n_mrms,:)         = 'n mrms ';
labels(i_brms_mean,:)      = 'brms mn';
labels(i_mrms_mean,:)      = 'mrms mn';
if (~v4), labels = char(labels); end

ym = 0.1;                                % top and bottom margin
ysep = 0.01;                              % separation between panels

% match refplot:
px0 = 0.2;
xp = 0.65;

