source: MML/trunk/mml/channel2dev.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 3.7 KB
Line 
1function [DeviceList, FamilyName, Field, ErrorFlag] = channel2dev(ChannelNames, FamilyList)
2%CHANNEL2DEV - Converts a channel name list to a device list
3%  [DeviceList, Family, Field, ErrorFlag] = channel2dev(ChannelNames, Family)
4%
5%  INPUTS
6%  1. ChannelNames - List of channel names (string, matrix, cell array)
7%  2. Family - Family Names to to limit search (string or cell of strings)
8%              Accelerator Object
9%              '' search all families {Default}
10%
11%  OUTPUTS
12%  1. DeviceList - DeviceList corresponding to the common name
13%                  If no common names are found, an empty matrix is returned
14%                  If only some common names are not found, [NaN NaN] will be
15%                  inserted into the device list where they are not found.
16%  2. Family - Family Name (since input Family can be empty)
17%              If the channel name cannot be found an empty strings
18%              (or a blank string for matrix inputs) is returned
19%  3. Field - Field Name
20%  4. ErrorFlag - Number of errors found
21%
22%  See also channel2family, family2dev, common2channel
23%
24%  Written by Greg Portmann
25
26
27ErrorFlag = 0;
28
29
30if nargin < 1
31    error('Must have 1 input (''ChannelNames'')');
32end
33if nargin < 2
34    FamilyList = '';
35end
36
37% Cell inputs
38if iscell(ChannelNames)
39    if iscell(FamilyList)
40        if length(FamilyList) ~= length(ChannelNames)
41            error('Family and ChannelNames must be the same size cell arrays.');
42        end
43    end
44   
45    for i = 1:length(ChannelNames)
46        if iscell(FamilyList)
47            [DeviceList{i}, ErrorTmp] = channel2dev(ChannelNames{i}, FamilyList{i});
48        else
49            [DeviceList{i}, ErrorTmp] = channel2dev(ChannelNames{i}, FamilyList);
50        end
51        ErrorFlag = ErrorFlag | ErrorTmp;
52    end
53    return;
54end
55% End cell input
56
57
58
59% Determine what is in Input #2
60if isstruct(FamilyList)
61    if isfield(FamilyList,'FamilyName') & isfield(FamilyList,'Field')
62        % Data structure input - select the FamilyName from the structure
63        AO = getao;
64        FamilyCell = {FamilyList.FamilyName};
65    else
66        % AO structure input
67        FamilyCell = {FamilyList.FamilyName};
68        AO.(FamilyCell{1}) = FamilyList;
69    end
70elseif isempty(FamilyList)
71    % Search in all families
72    AO = getao;
73    FamilyCell = fieldnames(AO);
74elseif iscell(FamilyList)
75    % Search in all families in FamilyList
76    AO = getao;
77elseif ischar(FamilyList)
78    % Only search in one family
79    AO = getao;
80    FamilyCell = {FamilyList};
81end
82
83
84
85% Start the search
86FamilyName = '';
87Field = '';
88DeviceList = [];
89
90
91for i = 1:size(ChannelNames,1)
92    Found = 0;
93    for j = 1:length(FamilyCell)
94        FamilyTest = deblank(FamilyCell{j});
95        Fields = fieldnames(AO.(FamilyTest));
96        for k = 1:length(Fields)
97            if isfield(AO.(FamilyTest).(Fields{k}), 'ChannelNames')
98                ChannelNamesTotal = AO.(FamilyTest).(Fields{k}).ChannelNames;
99
100                Name = deblank(ChannelNames(i,:));
101                [name,jj,n] = intersect(Name, ChannelNamesTotal, 'rows');
102               
103                if ~isempty(n)
104                    Found = 1;
105                    break
106                end
107            end
108        end
109        if Found
110            break
111        end
112    end
113
114    if Found
115        FamilyName = strvcat(FamilyName, FamilyTest);
116        Field = strvcat(Field, Fields{k});
117        DeviceList = [DeviceList; AO.(FamilyTest).DeviceList(n,:)];
118    else
119        FamilyName = strvcat(FamilyName, ' ');
120        Field = strvcat(Field, ' ');
121        DeviceList = [DeviceList; [NaN NaN]];
122        ErrorFlag = ErrorFlag + 1;
123    end
124end
125
126
127FamilyName = deblank(FamilyName);
128Field = deblank(Field);
129
130if all(isnan(DeviceList))
131    DeviceList = [];
132end
Note: See TracBrowser for help on using the repository browser.