function data=allread2(pathstr,prefix,suffix1,suffix2,cfg)
%function data=allread(pathstr,prefeix,suffix1,suffix2,cfg) read
% in all data from  files defined by
%directory path pathstr, prefix prefix, between hex suffix1 and suffix2.
%Requires calibration structure cfg. 24Hz resolution kept when available.

%D. Rudnick 03/23/05
%added oxygen 07/30/06
%adapted from avgall.m to not average by R. Todd 2006-11-6

data.files=fullfile(pathstr,[prefix '.' suffix1 '-' suffix2]);
data.lat=[];
data.lon=[];
data.bottomdepth=[];
data.time=[];
data.t1=[];
data.t2=[];
data.p=[];
data.c1=[];
data.c2=[];
data.trans=[];
data.fl=[];
data.s1=[];
data.s2=[];
data.theta1=[];
data.theta2=[];
data.sigma1=[];
data.sigma2=[];
data.oxygen=[];
data.moog=[];
data.tension=[];
data.wingpitch=[];
data.roll=[];
data.fishpitch=[];
data.proprpm=[];
mcold=[];
for n=hex2dec(suffix1):hex2dec(suffix2)
   d=allread(pathstr,prefix,dec2hex(n,3),cfg);
   if ~isstruct(d)
      data.files=fullfile(pathstr,[prefix '.' suffix1 '-' dec2hex(n-1,3)]);
      return
   elseif ~isempty(d.lat)
      data.lat=[data.lat; d.lat];
      data.lon=[data.lon; d.lon];
      data.bottomdepth=[data.bottomdepth; d.bottomdepth];
      data.time=[data.time; d.time];
      data.moog=[data.moog; d.moog];
      data.tension=[data.tension; d.tension];
      data.t1=[data.t1; d.t1];
      data.t2=[data.t2; d.t2];
      data.p=[data.p; d.p];
      data.c1=[data.c1; d.c1];
      data.c2=[data.c2; d.c2];
      data.trans=[data.trans; d.trans];
      data.fl=[data.fl; d.fl];
      data.s1=[data.s1; d.s1];
      data.s2=[data.s2; d.s2];
      data.theta1=[data.theta1; d.theta1];
      data.theta2=[data.theta2; d.theta2];
      data.sigma1=[data.sigma1; d.sigma1];
      data.sigma2=[data.sigma2; d.sigma2];
      data.oxygen=[data.oxygen; d.oxygen];
      data.wingpitch=[data.wingpitch; d.wingpitch];
      data.roll=[data.roll; d.roll];
      data.fishpitch=[data.fishpitch; d.fishpitch];
      data.proprpm=[data.proprpm; d.proprpm];
      mc=[mcold; d.modcount];
      ii=find(~(diff(mc) == 1 | (mc(1:end-1) == 255 & mc(2:end) == 0)));
      if ~isempty(ii)
         disp('Skipped modulo counts')
      end
      mcold=d.modcount(end);
   end
end
