1 | function Data = rmoffset(varargin) |
---|
2 | %RMOFFSET - Remove the offset values for data set |
---|
3 | % Data = rmoffset(DataStructure) |
---|
4 | % Data = rmoffset(Family, DataIn, DeviceList) |
---|
5 | % Data = rmoffset(Family, Field, DataIn, DeviceList) |
---|
6 | % |
---|
7 | % INPUTS |
---|
8 | % 1. Family - Family Name |
---|
9 | % Data Structure |
---|
10 | % Accelerator Object |
---|
11 | % 2. Field - MML field name ('Monitor', 'Setpoint', etc) {Default: 'Monitor' for BPM, 'Setpoint' for magnet} |
---|
12 | % 3. DataIn - Input data |
---|
13 | % 4. DeviceList ([Sector Device #] or [element #]) {Default: whole family} |
---|
14 | % 5. 'Physics' - Use physics units (optional override of units) |
---|
15 | % 'Hardware' - Use hardware units (optional override of units) |
---|
16 | % 6. 'Struct' - Return a data structure |
---|
17 | % 'Numeric' - Return numeric outputs {Default} |
---|
18 | % 'Object' - Return a accelerator object (AccObj) |
---|
19 | % |
---|
20 | % OUTPUTS |
---|
21 | % 1. Data - Input data with a offset value removed |
---|
22 | % |
---|
23 | % See also rmgolden, getoffset, getgolden |
---|
24 | % |
---|
25 | % Written by Greg Portmann |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | %%%%%%%%%%%%%%%%% |
---|
30 | % Input parsing % |
---|
31 | %%%%%%%%%%%%%%%%% |
---|
32 | UnitsFlagCell = {}; |
---|
33 | StructFlag = 0; |
---|
34 | NumericFlag = 0; |
---|
35 | for i = length(varargin):-1:1 |
---|
36 | if isstruct(varargin{i}) |
---|
37 | % Ignor structures |
---|
38 | elseif iscell(varargin{i}) |
---|
39 | % Ignor cells |
---|
40 | elseif strcmpi(varargin{i},'struct') |
---|
41 | StructFlag = 1; |
---|
42 | NumericFlag = 0; |
---|
43 | varargin(i) = []; |
---|
44 | elseif strcmpi(varargin{i},'numeric') |
---|
45 | StructFlag = 0; |
---|
46 | NumericFlag = 1; |
---|
47 | varargin(i) = []; |
---|
48 | elseif strcmpi(varargin{i},'simulator') || strcmpi(varargin{i},'model') || strcmpi(varargin{i},'Online') || strcmpi(varargin{i},'Manual') |
---|
49 | % Remove and ignor |
---|
50 | varargin(i) = []; |
---|
51 | elseif strcmpi(varargin{i},'physics') |
---|
52 | UnitsFlagCell = {'Physics'}; |
---|
53 | varargin(i) = []; |
---|
54 | elseif strcmpi(varargin{i},'hardware') |
---|
55 | UnitsFlagCell = {'Hardware'}; |
---|
56 | varargin(i) = []; |
---|
57 | end |
---|
58 | end |
---|
59 | |
---|
60 | |
---|
61 | if isempty(varargin) |
---|
62 | error('Must have at least a family name input'); |
---|
63 | elseif iscell(varargin{1}) |
---|
64 | % Cell input |
---|
65 | for i = 1:length(varargin{1}) |
---|
66 | if length(varargin) == 1 |
---|
67 | Data{i} = rmoffset(varargin{1}{i}, UnitsFlagCell{:}); |
---|
68 | elseif length(varargin) == 2 |
---|
69 | Data{i} = rmoffset(varargin{1}{i}, varargin{2}{i}, UnitsFlagCell{:}); |
---|
70 | elseif length(varargin) == 3 |
---|
71 | Data{i} = rmoffset(varargin{1}{i}, varargin{2}{i}, varargin{3}{i}, UnitsFlagCell{:}); |
---|
72 | else |
---|
73 | Data{i} = rmoffset(varargin{1}{i}, varargin{2}{i}, varargin{3}{i}, varargin{4}{i}, UnitsFlagCell{:}); |
---|
74 | end |
---|
75 | end |
---|
76 | return |
---|
77 | end |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
82 | % Family or data structure inputs beyond this point % |
---|
83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
84 | Family = varargin{1}; |
---|
85 | if isstruct(Family) |
---|
86 | if ~NumericFlag |
---|
87 | StructFlag = 1; |
---|
88 | StructOut = Family; |
---|
89 | end |
---|
90 | |
---|
91 | % Data structure inputs |
---|
92 | if length(varargin) < 2 |
---|
93 | if isfield(Family,'Field') |
---|
94 | Field = Family.Field; |
---|
95 | else |
---|
96 | Field = ''; |
---|
97 | end |
---|
98 | end |
---|
99 | if length(varargin) < 3 |
---|
100 | if isfield(Family,'Data') |
---|
101 | Data = Family.Data; |
---|
102 | else |
---|
103 | error('A .Data field must exist for data structure inputs.'); |
---|
104 | end |
---|
105 | end |
---|
106 | if length(varargin) < 4 |
---|
107 | if isfield(Family,'DeviceList') |
---|
108 | DeviceList = Family.DeviceList; |
---|
109 | else |
---|
110 | DeviceList = []; |
---|
111 | end |
---|
112 | end |
---|
113 | if isempty(UnitsFlagCell) |
---|
114 | if isfield(Family,'Units') |
---|
115 | UnitsFlagCell{1} = Family.Units; |
---|
116 | end |
---|
117 | end |
---|
118 | if isfield(Family,'FamilyName') |
---|
119 | Family = Family.FamilyName; |
---|
120 | else |
---|
121 | error('For data structure inputs FamilyName field must exist') |
---|
122 | end |
---|
123 | else |
---|
124 | % Family string input |
---|
125 | if length(varargin) >= 2 && ischar(varargin{2}) |
---|
126 | Field = varargin{2}; |
---|
127 | varargin(2) = []; |
---|
128 | else |
---|
129 | Field = ''; |
---|
130 | end |
---|
131 | if length(varargin) >= 2 |
---|
132 | Setpoints = varargin{2}; |
---|
133 | else |
---|
134 | Setpoints = ''; |
---|
135 | end |
---|
136 | if length(varargin) >= 3 |
---|
137 | DeviceList = varargin{3}; |
---|
138 | else |
---|
139 | DeviceList = []; |
---|
140 | end |
---|
141 | |
---|
142 | StructOut = []; |
---|
143 | end |
---|
144 | |
---|
145 | if isnumeric(Field) |
---|
146 | DeviceList = Data; |
---|
147 | Data = Field; |
---|
148 | Field = ''; |
---|
149 | end |
---|
150 | if isempty(Field) |
---|
151 | if ismemberof(Family,'BPM') || ismemberof(Family,'TUNE') || strcmpi(Family, 'TUNE') |
---|
152 | Field = 'Monitor'; |
---|
153 | else |
---|
154 | Field = 'Setpoint'; |
---|
155 | end |
---|
156 | end |
---|
157 | |
---|
158 | if isempty(DeviceList) |
---|
159 | DeviceList = family2dev(Family); |
---|
160 | end |
---|
161 | if (size(DeviceList,2) == 1) |
---|
162 | DeviceList = elem2dev(Family, DeviceList); |
---|
163 | end |
---|
164 | |
---|
165 | if isempty(Data) || ~isnumeric(Data) |
---|
166 | %error('Data input required'); |
---|
167 | Data = getpv(Family, Field, DeviceList); |
---|
168 | end |
---|
169 | |
---|
170 | if size(Data,1) == 1 |
---|
171 | Data = ones(size(DeviceList,1),1) * Data; |
---|
172 | end |
---|
173 | |
---|
174 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
175 | % CommonName Input: Convert common names to a DeviceList % |
---|
176 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
177 | if ischar(DeviceList) |
---|
178 | DeviceList = common2dev(DeviceList, Family); |
---|
179 | if isempty(DeviceList) |
---|
180 | error('DeviceList was a string but common names could not be found.'); |
---|
181 | end |
---|
182 | end |
---|
183 | |
---|
184 | |
---|
185 | %%%%%%%%%%%% |
---|
186 | % rmoffset % |
---|
187 | %%%%%%%%%%%% |
---|
188 | |
---|
189 | Offset = getoffset(Family, Field, DeviceList, UnitsFlagCell{:}); |
---|
190 | |
---|
191 | for i = 1:size(Data,1) |
---|
192 | Data(i,:) = Data(i,:) - Offset(i,:); |
---|
193 | end |
---|
194 | |
---|
195 | |
---|
196 | if StructFlag |
---|
197 | if isempty(StructOut) |
---|
198 | StructOut = family2datastruct(Family, Field, DeviceList); |
---|
199 | StructOut.DataDescriptor = 'rmoffset'; |
---|
200 | end |
---|
201 | StructOut.Data = Data; |
---|
202 | Data = StructOut; |
---|
203 | end |
---|
204 | |
---|
205 | |
---|