-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSTAddrLogicalExtract.m
96 lines (73 loc) · 2.98 KB
/
STAddrLogicalExtract.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function [varargout] = STAddrLogicalExtract(addrLog, stasSpecification)
% STAddrLogicalExtract - FUNCTION Extract the neuron and synapse IDs from a logical address
% $Id: STAddrLogicalExtract.m 2411 2005-11-07 16:48:24Z dylan $
%
% Usage: [nAddr1, nAddr2, ...] = STAddrLogicalExtract(addrLog)
% [nAddr1, nAddr2, ...] = STAddrLogicalExtract(addrLog, stasSpecification)
%
% 'addrLog' should be a logical address as constructed by
% STAddrLogicalConstruct. STAddrLogicalExtract will extract the
% indices for each addressing field, as defined by the addressing
% specification. If this specification is not supplied in the argument
% list, the default output addressing specification will be taken from
% the toolbox options. The field indices will be returned in the variable
% length argument list. STAddrLogicalExtract is vectorised.
% Author: Dylan Muir <dylan@ini.phys.ethz.ch>
% Created: 9th May, 2004
% Copyright (c) 2004, 2005 Dylan Richard Muir
% -- Get options
stOptions = STOptions;
% -- Check arguments
if (nargin > 2)
disp('--- STAddrLogicalExtract: Extra arguments ignored');
end
if (nargin < 2)
stasSpecification = stOptions.stasDefaultOutputSpecification;
end
if (nargin < 1)
disp('*** STAddrLogicalExtract: Incorrect usage');
help STAddrLogicalExtract;
return;
end
% - Check for a valid address specification
if (~STIsValidAddrSpec(stasSpecification))
disp('*** STAddrLogicalExtract: Invalid addressing specification supplied');
return;
end
% - Check for the correct number of output arguments
nRequiredFields = sum(~[stasSpecification.bIgnore]);
if (nargout ~= nRequiredFields)
disp('--- STAddrLogicalExtract: Outputting a different number of addressing fields');
disp(' than you''ve provided');
end
% -- Extract the indices
% - Which field are major?
vbMajorField = [stasSpecification.bMajorField];
vbMinorField = ~vbMajorField;
% - Count bits for the minor fields
if (any(vbMinorField))
nMinorBits = sum([stasSpecification(find(~vbMajorField)).nWidth]);
else
nMinorBits = 0;
end
% - Separate the major and minor fields
nMajorAddress = fix(addrLog);
nMinorAddress = (addrLog - fix(addrLog)) .* 2^nMinorBits;
nField = 1;
for (nEntryIndex = 1:length(stasSpecification))
if (~stasSpecification(nEntryIndex).bIgnore)
if (vbMajorField(nEntryIndex))
% - Mask off the current address field
varargout{nField} = bitshift(nMajorAddress, 0, stasSpecification(nEntryIndex).nWidth);
% - Shift the rest of the field, truncate the decimal portion
nMajorAddress = fix(nMajorAddress .* 2^(-stasSpecification(nEntryIndex).nWidth));
else
% - Mask off the current address field
varargout{nField} = bitshift(nMinorAddress, 0, stasSpecification(nEntryIndex).nWidth);
% - Shift the rest of the field
nMinorAddress = fix(nMinorAddress .* 2^(-stasSpecification(nEntryIndex).nWidth));
end
nField = nField + 1;
end
end
% --- END of STAddrLogicalExtract.m ---