binfiles = dirs('binfiles/*adu.bin');

i_dday = 2;
i_head = 3;
i_pitch = 4;
i_roll = 5;
i_reacq = 8;

allbin = NaN*ones(8, 6600*length(binfiles));
starti = 1;
for filei = 1:length(binfiles)
   binfile = binfiles(filei).name;
   bindata = read_bin(['binfiles/',binfile]);
   N = length(bindata(1,:));
   allbin(:,[starti : starti + N - 1])  = bindata;
   starti = starti + N;
end
badi = find(allbin(8,:)==1); %reaquire
fprintf('percent of ashtech reaquisitions: %f\n',...
        100*length(badi)/length(allbin(1,:)))
allbin(:,badi)=[];


gbinfiles = dirs('gbinfiles/*adu.gbin');

g_dday = 1;
g_head = 2;
g_pitch = 3;
g_roll = 4;

starti = 1;
allgbin = NaN*ones(6, 6600*length(binfiles));
for filei = 1:length(gbinfiles)
   gbinfile = gbinfiles(filei).name;
   gbindata = read_bin(['gbinfiles/',gbinfile]);
   N = length(gbindata(1,:));
   allgbin(:,[starti : starti + N - 1])  = gbindata;
   starti = starti + N;
end

badi = find(isnan(allgbin(1,:)));
allgbin(:,badi) = [];


fprintf('getting a running stddev of pitch')
%get a 5 minute running std dev of pitch
dt = 5*60/86400;
gbin_t = [allgbin(g_dday,1) : dt : max(allgbin(g_dday,:)) + dt];
gbin_std = NaN*gbin_t(1:end-1);
for starti = 1:length(gbin_std)-1
   ii = find( (allgbin(g_dday,:) >= gbin_t(starti)) & ...
              (allgbin(g_dday,:) <= gbin_t(starti+1)));
   [mm ss] = mstdgap(allgbin(g_pitch, ii));
   if (~isempty(ss))
      gbin_std(starti) = ss;
   end
end

   
