function [I, times] = convints(c,t,preCode) % function [i, times] = convints(c, t, preCode) % % c The encodes in the cortex data file you would like to extract % floating point information from % t The times that the corresponding encodes were output % preCode Optional argument that causes the program to extract only the % integers which follow this encoded value. This allows you to % "mark" different integers as having different meanings in the % data file. % % Given a set of Matlab encode values and their times, % read out the integer numbers and store them in the array i, % along with their time of occurrence. This code is used to extract % information embedded in the data file with the routines in "extenc.h" % and "extenc.c" % % If preCode is given, then only get integers which follow % preCode in the data. Effectively, this replaces INT_MARKER % with preCode. % % Because of the way Cortex encodes things, intervening codes can be % mixed with integer data. You must be careful to never have % two threads running which both try to encode integer values, % as the resulting data file can intermingle the bytes of two separate % ints, making it impossible to later decode. % % This code needs access to either a global structure Encodes, or % an m-file called 'encodes.m' that creates the structure. % % Version 1.0 % For additional code, updated versions, questions or comments, please refer % to the Active Perception Lab home page % http://www.cnbc.cmu.edu/~tai/lab.html % Copyright 1998-1999 % Rick Romero % rickr+@cmu.edu % Permission to use and modify is granted, % but not to redistribute original or modified code. % Assumes that ints are coded as follows: % All floats are marked by a INT_MARKER (127) before the float data % The float data is encoded using four encodes, ENCODE_INT[1-4] in % increasing order of byte number. % Some encode values, just so we have them if (exist('Encodes') == 0) global Encodes evalin('caller','global Encodes;encodes'); end if (nargin < 3) preCode = Encodes.INT_MARKER; end which = find(c == preCode); times = t(which); numints = prod(size(which)); I = zeros(numints, 1); for i=1:numints if (i == numints) cndx = which(i):prod(size(c)); else cndx = which(i):(which(i+1)-1); end cc = c(cndx); cencodes = find((cc >= Encodes.ENCODE_INT1) & ... (cc < Encodes.ENCODE_INT4 + 256)); if (prod(size(cencodes)) < 4) error('Problem reading in float data--wrong number of markers'); end if ((cc(cencodes(1)) >= Encodes.ENCODE_INT2) | ... (cc(cencodes(2)) >= Encodes.ENCODE_INT3) | ... (cc(cencodes(3)) >= Encodes.ENCODE_INT4) | ... (cc(cencodes(4)) < Encodes.ENCODE_INT4) | ... (cc(cencodes(3)) < Encodes.ENCODE_INT3) | ... (cc(cencodes(2)) < Encodes.ENCODE_INT2)) errmsg = sprintf('Out of order float data: received following encodes (0x%X 0x%X 0x%X 0x%X)', cc(cencodes(1)), cc(cencodes(2)), cc(cencodes(3)), cc(cencodes(4))); error(errmsg); end cencodes = cc(cencodes(1:4)); cencodes = fliplr(bitand(cencodes, 255)); if (cencodes(1) > 127) fsign = -1; else fsign = 1; end I(i) = sum(([256 256 256 256] .^ [3 2 1 0]) .* cencodes); if (I(i) >= (128 * (256 ^ 3))) I(i) = I(i) - 256 * (256 ^ 3); end end