function prr = readprr(filename) % Brian Schlining % 24 Jan 2000 %=========== % Open File %=========== if ~nargin [infile inpath] = uigetfile('*.bin','Select binary prr data file',0,0); if infile == 0 return % Return if CANCEL is selected end filename = [inpath infile]; end fid = fopen(filename,'r','b'); % Read a binary file as big-endian if fid <= 0 warning(['Unable to open ' filename]) out = []; return end %====================== % Read the binary data %====================== fseek(fid,0,1); % Move pointer to the end of the file stop = ftell(fid); % Get the length of the file in bytes frewind(fid); % Rewind back to the beginning of the file n = 0; OK = 1; SRE = 9.54*10^-6; % Smallest resolvabel element (for 10 v scale) in volts while OK n = n + 1; address(n,1) = fread(fid, 1, 'int8'); numChannel(n,1) = fread(fid, 1, 'int8'); staleFlag = ones(1,numChannel(n)) * NaN; % Initialize memory gain = staleFlag; count = staleFlag; for i = 1:numChannel(n,1) % Loop through each channel in a data block staleFlag(i) = fread(fid, 1, 'ubit1'); gain(i) = 4^(fread(fid, 1, 'ubit2')*2); count(i) = fread(fid, 1, 'bit13'); end data{n} = count.*SRE.*256./gain; % Convert counts to volts checkSum(n) = fread(fid, 1, 'int8'); pos = ftell(fid); if pos >= stop - 5 OK = 0; end end fclose(fid); % Close the file u = unique(address); % Find the different cpus numCpu = length(u); % Count the number of cpus numRecord = length(data)/numCpu; % Count the number of data records for i = 1:numCpu prr(i).src = filename; good = find(address == u(i)); % Find the data for each cpu prr(i).address = u(i); prr(i).volts = reshape([data{good}]',numChannel(good(1)), numRecord)'; end