function [raw,header,tailer]=readraw(filename,size,precision,head,tail,skip,mach,bskip)
% readraw Read chunk of data from a file. 
% usage:: [raw,header,tailer]=readraw(filename,size,[precision,head,tail,skip,mach,bskip])
% 
% raw is the data from file filename, which is filled with size element of type 
% precision (default: 'unsigned char').  
% 
% head is the length of file header in bytes and is returned as header.
%   (default: 0)
% skip is a number of bytes to be skiped before the header and is *not* 
%   returned as header. (default: 0)
% tail is the length of file tailer in bytes and is returned as tailer.
% mach determines the byte ordering.  (default: 'ieee-le') See fread for
%   more info.
% bskip is a number of bits to skip after skip, but before head. 
%  (default: 0)

% revision history:
% 08/11/96 Mark D. Shattuck <mds> readraw.m 
% 10/19/99 mds added bskip

if nargin<=2 
  precision=['unsigned char'];
  head=0;
  tail=0;
  skip=0;
  mach='ieee-le';
  bskip=0;
elseif nargin<=3 
  head=0;
  tail=0;
  skip=0;
  mach='ieee-le';
  bskip=0;
elseif nargin<=4
  tail=0;
  skip=0;
  mach='ieee-le';
  bskip=0;
elseif nargin<=5
  skip=0;
  mach='ieee-le';
  bskip=0;
elseif nargin<=6
  mach='ieee-le';
  bskip=0;
elseif nargin<=7
  bskip=0;
end

fid=fopen(filename,'r',mach);
%disp(['skiping ' num2str(skip) ' bytes']);  
fseek(fid,skip,0);
fread(fid,bskip,'ubit1');
header=fread(fid,head,'char');
raw=fread(fid,size,precision);
tailer=fread(fid,tail,'char');
fclose(fid);

