function [encoder]=read_encoder(filename, number_of_packets, start_position)

fid=fopen(['C:\Documents and Settings\lorsolette\My Documents\research\rita\data\',filename(1).name],'r','l');
eofstat=feof(fid);
fseek(fid, 0, 'eof');
length_of_packets = 4268;
length_of_file=ftell(fid)
check=strcmp('KU',filename(1).name(1:2));
encoder=zeros(number_of_packets,1);
fseek(fid, start_position, 'bof');
%---------------------------------------Number of headers------------------------%



    fseek(fid,4130,'cof')
    encoder=fread(fid,number_of_packets,'uint16',4266);
% for iter=1:number_of_packets
%     header=fread(fid,8,'char');
%     Header=char(header');
%     disp(Header);
%     header_counter=fread(fid,1,'int32');
%     status=fread(fid,1,'int32');
%     timehi=fread(fid,1,'uint32');
%     timelo=fread(fid,1,'uint32');
%     
%     fseek(fid,4104,'cof');
%    
% 
%     encoderC=fread(fid,1,'uint16');
%     encoderKU=fread(fid,1,'uint16');
%     if check==1
%         encoder(iter)=encoderKU;
%     else
%         encoder(iter)=[encoder;encoderC];
%     end
%      fseek(fid,136,'cof');
%    
% end


end_position=ftell(fid)
eofstat=feof(fid)
if eofstat==1
    fclose(fid);
end
