1 | function [TangoNames, ErrorFlag] = common2tango(CommonNames, Field, Family); |
---|
2 | %COMMON2TANGO - Converts common name to TANGO name |
---|
3 | % [TangoNames, ErrorFlag] = common2tango(CommonNames, Field, Family) |
---|
4 | % |
---|
5 | % INPUTS |
---|
6 | % 1. CommonNames = List of common names (string, matrix, cell array) |
---|
7 | % 2. Field = Accelerator Object field name ('Monitor', 'Setpoint', etc) {'Monitor'} |
---|
8 | % 3. Family = Family Name |
---|
9 | % Accelerator Object |
---|
10 | % Cell Array of Accelerator Objects or Family Names |
---|
11 | % [] search all families {default} |
---|
12 | % |
---|
13 | % OUTPUTS |
---|
14 | % 1. TangoNames = Channel name corresponding to the common name |
---|
15 | % If the common name cannot be found an empty strings |
---|
16 | % (or a blank string for matrix inputs) is returned |
---|
17 | % 2. ErrorFlag = Number of errors found |
---|
18 | % |
---|
19 | % NOTES |
---|
20 | % 1. CommonNames can be a cell array when Field and Family are not |
---|
21 | % 2. Returns only status 1 devices -- See StatusFlag (not done) |
---|
22 | % |
---|
23 | % EXAMPLES |
---|
24 | % 1. common2tango('BPMx001') |
---|
25 | % |
---|
26 | % See also tango2common |
---|
27 | |
---|
28 | % |
---|
29 | % Written by Laurent S. Nadolski |
---|
30 | |
---|
31 | % Status input |
---|
32 | StatusFlag = 1; % Only return good status devices |
---|
33 | |
---|
34 | if nargin < 1 |
---|
35 | error('Must have at least 1 input (''CommonNames'')'); |
---|
36 | end |
---|
37 | if nargin < 2 |
---|
38 | Field = 'Monitor'; |
---|
39 | end |
---|
40 | if isempty(Field) |
---|
41 | Field = 'Monitor'; |
---|
42 | end |
---|
43 | if nargin < 3 |
---|
44 | Family = []; |
---|
45 | end |
---|
46 | |
---|
47 | |
---|
48 | % Cell inputs |
---|
49 | if iscell(CommonNames) |
---|
50 | if iscell(Family) |
---|
51 | if length(Family) ~= length(CommonNames) |
---|
52 | error('Family and CommonNames must be the same size cell arrays.'); |
---|
53 | end |
---|
54 | end |
---|
55 | if iscell(Field) |
---|
56 | if length(Field) ~= length(CommonNames) |
---|
57 | error('Field and CommonNames must be the same size cell arrays.'); |
---|
58 | end |
---|
59 | end |
---|
60 | |
---|
61 | for i = 1:length(CommonNames) |
---|
62 | if iscell(Family) |
---|
63 | if iscell(Field) |
---|
64 | [TangoNames{i}, ErrorFlag{i}] = common2tango(CommonNames{i}, Field{i}, Family{i}); |
---|
65 | else |
---|
66 | [TangoNames{i}, ErrorFlag{i}] = common2tango(CommonNames{i}, Field, Family{i}); |
---|
67 | end |
---|
68 | else |
---|
69 | if iscell(Field) |
---|
70 | [TangoNames{i}, ErrorFlag{i}] = common2tango(CommonNames{i}, Field{i}, Family); |
---|
71 | else |
---|
72 | [TangoNames{i}, ErrorFlag{i}] = common2tango(CommonNames{i}, Field, Family); |
---|
73 | end |
---|
74 | end |
---|
75 | end |
---|
76 | return |
---|
77 | end |
---|
78 | % End cell input |
---|
79 | |
---|
80 | |
---|
81 | % If Family=[], search all families |
---|
82 | ErrorFlag = 0; |
---|
83 | if isempty(Family) |
---|
84 | TangoNames = []; |
---|
85 | FamilyList = getfamilylist; |
---|
86 | |
---|
87 | for i = 1:size(CommonNames,1) |
---|
88 | Name = deblank(CommonNames(i,:)); |
---|
89 | Found = 0; |
---|
90 | for j = 1:size(FamilyList, 1) |
---|
91 | TangoName = common2tango(Name, Field, deblank(FamilyList(j,:))); |
---|
92 | if ~isempty(TangoName) |
---|
93 | Found = 1; |
---|
94 | break |
---|
95 | end |
---|
96 | end |
---|
97 | if Found |
---|
98 | NewTangoName = TangoName; |
---|
99 | else |
---|
100 | NewTangoName = ' '; |
---|
101 | ErrorFlag = ErrorFlag + 1; |
---|
102 | end |
---|
103 | TangoNames = strvcat(TangoNames, NewTangoName); |
---|
104 | end |
---|
105 | TangoNames = deblank(TangoNames); |
---|
106 | return |
---|
107 | end |
---|
108 | % End all family search |
---|
109 | |
---|
110 | |
---|
111 | % Common2Tango for scalar inputs |
---|
112 | ErrorFlag = 0; |
---|
113 | TangoNames = []; |
---|
114 | for i = 1:size(CommonNames,1) |
---|
115 | Name = deblank(CommonNames(i,:)); |
---|
116 | CommonNamesTotal = getfamilydata(Family, 'CommonNames'); |
---|
117 | |
---|
118 | [name,j,k] = intersect(Name, CommonNamesTotal, 'rows'); |
---|
119 | |
---|
120 | if isempty(name) & length(Name)~=size(CommonNamesTotal) |
---|
121 | Name = [repmat(' ',size(Name,1),size(CommonNamesTotal,2)-size(Name,2)) Name]; |
---|
122 | [name,j,k] = intersect(Name, CommonNamesTotal, 'rows'); |
---|
123 | end |
---|
124 | |
---|
125 | if isempty(name) |
---|
126 | Name = deblank(CommonNames(i,:)); |
---|
127 | if length(Name)~=size(CommonNamesTotal) |
---|
128 | Name = [Name repmat(' ',size(Name,1),size(CommonNamesTotal,2)-size(Name,2))]; |
---|
129 | [name,j,k] = intersect(Name, CommonNamesTotal, 'rows'); |
---|
130 | end |
---|
131 | end |
---|
132 | |
---|
133 | if ~isempty(k) |
---|
134 | TangoNamesTotal = getfamilydata(Family, Field, 'TangoNames'); |
---|
135 | |
---|
136 | if isempty(TangoNamesTotal) |
---|
137 | NewTangoName = ' '; |
---|
138 | ErrorFlag = ErrorFlag + 1; |
---|
139 | else |
---|
140 | if size(TangoNamesTotal,1) == 1 |
---|
141 | NewTangoName = TangoNamesTotal; |
---|
142 | else |
---|
143 | NewTangoName = TangoNamesTotal(k,:); |
---|
144 | end |
---|
145 | end |
---|
146 | else |
---|
147 | NewTangoName = ' '; |
---|
148 | ErrorFlag = ErrorFlag + 1; |
---|
149 | end |
---|
150 | TangoNames = strvcat(TangoNames, NewTangoName); |
---|
151 | end |
---|
152 | |
---|
153 | TangoNames = deblank(TangoNames); |
---|
154 | |
---|
155 | % if ~isempty(TangoNames) |
---|
156 | % if (StatusFlag) |
---|
157 | % if ~exist('DeviceList') |
---|
158 | % Status = getfamilydata(Family,'Status'); |
---|
159 | % else |
---|
160 | % Status = getfamilydata(Family,'Status', DeviceList); |
---|
161 | % end |
---|
162 | % TangoNames = TangoNames(find(Status)); |
---|
163 | % end |
---|
164 | % end |
---|