0001 function [B, channel, npts, dt] = getbtiraw(topdir,datfile,hdrfile)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if ~exist('hdrfile') hdrfile = []; end
0013 [channel bfactors npts dt] = parseheader(topdir, hdrfile);
0014
0015 fid = fopen(fullfile(topdir,datfile), 'r', 'ieee-be');
0016
0017 if ~exist('rformat'), rformat = 'integer*2'; end
0018
0019
0020
0021 nchans = size(channel,1);
0022 [B num] = fread(fid,[nchans npts],rformat);
0023 if num ~= (npts*nchans)
0024 error('Number of data points read doesnt match number requested')
0025 end
0026
0027 fclose(fid);
0028
0029 sortarray = [];
0030 for i=1:nchans
0031 if channel(i,1) == 'A'
0032 sortarray(i) = str2num(channel(i,2:end));
0033 elseif channel(i,1:3) == 'TRI'
0034 sortarray(i) = 500;
0035 elseif channel(i,1:3) == 'RES'
0036 sortarray(i) = 501;
0037 elseif channel(i,1) == 'X'
0038 sortarray(i) = 1000 + str2num(channel(i,2:end));
0039 else
0040 sortarray(i) = 2000 + i;
0041 end
0042 end
0043
0044 [channum sortindex] = sort(sortarray);
0045 sortindex = sortindex(channum<2000);
0046 B = B(sortindex,:)';
0047 channel = channel(sortindex,:);
0048 bfactors = bfactors(sortindex);
0049 bmeans = mean(B);
0050 nbchans = find(strcmp(cellstr(channel),'TRIGGER')) - 1;
0051 bmeans(nbchans+1:end) = 0*bmeans(nbchans+1:end);
0052
0053 if rformat == 'integer*2'
0054 for i=1:size(B,2)
0055 B(:,i) = bfactors(i)*(B(:,i)-bmeans(i));
0056 end
0057 end
0058