function [data,chans,sampling,sens,chann,id,pr,jm,date,time]=read_alien(file);
%function [data,chans,sampling,sens,chann,id,pr,jm,date,time]=read_alien(file);
%reads data from EEG datafile created by Alien SW
% file-string of file name   
%23-11-2005 Jan Kremlacek jan.kremlacek@lfhk.cuni.cz

% open file

fid = fopen(file, 'r');

% read head
id=sprintf('%c',fread(fid,10,'*char'))
 fseek(fid, 12, 'bof');
pr=sprintf('%c',fread(fid,15,'*char'))
 fseek(fid, 28, 'bof');
jm=sprintf('%c',fread(fid,10,'*char'))
 fseek(fid, 40, 'bof');
date=sprintf('%c',fread(fid,10,'*char'))
 fseek(fid, 52, 'bof');
time=sprintf('%c',fread(fid,8,'*char'))
 fseek(fid, 60, 'bof');
sampling=fread(fid,1,'uint16');
 fseek(fid, 62, 'bof');
chans=fread(fid,1,'uint8');
 fseek(fid, 63, 'bof');
sens=fread(fid,1,'uint8'); % uV/bit

if (sens > 128)  
    head=1024;
    sens=sens-128; 
else
    head=512;  end;
%
fseek(fid, 64, 'bof'); 
for i=1:chans c(i,:)=fread(fid,6,'*char'); end;
chann=cellstr(c);

% read data
fseek(fid, head, 'bof');
x=fread(fid,inf,'*int16');

%
data=reshape(x,chans,size(x,1)/chans);
for i=1:chans data(i,:)=data(i,:)-int16(mean(data(i,:))); end;

%
fclose(fid);