1 | function Data = getgain(varargin) |
---|
2 | %GETGAIN - Returns the gain for a family |
---|
3 | % Gain = getgain(Family, Field, DeviceList) |
---|
4 | % Gain = getgain(Family, DeviceList) |
---|
5 | % Gain = getgain(Family) |
---|
6 | % |
---|
7 | % INPUTS |
---|
8 | % 1. Family - Family Name |
---|
9 | % Data Structure |
---|
10 | % Accelerator Object |
---|
11 | % 2. Field - Accelerator Object field name ('Monitor', 'Setpoint', etc) {Default: 'Monitor' for BPM, 'Setpoint' for magnet} |
---|
12 | % 3. DeviceList ([Sector Device #] or [element #]) {Default: whole family} |
---|
13 | % 4. 'Numeric' - Numeric output {Default} |
---|
14 | % 'Struct' - Data structure output |
---|
15 | % |
---|
16 | % OUTPUTS |
---|
17 | % 1. Gain - Gain value for the family {Default: 1} |
---|
18 | % |
---|
19 | % NOTES |
---|
20 | % 1. If Family is a cell array, then DeviceList can also be a cell arrays |
---|
21 | % |
---|
22 | % See also: getroll, getcrunch, getfamilydata, getoffset, getgolden, raw2real, real2raw |
---|
23 | % |
---|
24 | % Written by Greg Portmann |
---|
25 | |
---|
26 | |
---|
27 | % 5. 'Physics' - Use physics units (optional override of units) |
---|
28 | % 'Hardware' - Use hardware units (optional override of units) |
---|
29 | |
---|
30 | |
---|
31 | %%%%%%%%%%%%%%%%% |
---|
32 | % Input Parsing % |
---|
33 | %%%%%%%%%%%%%%%%% |
---|
34 | UnitsFlagCell = {}; |
---|
35 | StructOutputFlag = 0; |
---|
36 | for i = length(varargin):-1:1 |
---|
37 | if isstruct(varargin{i}) |
---|
38 | % Ignor structures |
---|
39 | elseif iscell(varargin{i}) |
---|
40 | % Ignor cells |
---|
41 | elseif strcmpi(varargin{i},'struct') |
---|
42 | StructOutputFlag = 1; |
---|
43 | varargin(i) = []; |
---|
44 | elseif strcmpi(varargin{i},'numeric') |
---|
45 | StructOutputFlag = 0; |
---|
46 | varargin(i) = []; |
---|
47 | elseif strcmpi(varargin{i},'simulator') || strcmpi(varargin{i},'model') || strcmpi(varargin{i},'Online') || strcmpi(varargin{i},'Manual') |
---|
48 | % Remove and ignor |
---|
49 | varargin(i) = []; |
---|
50 | elseif strcmpi(varargin{i},'physics') |
---|
51 | UnitsFlagCell = {'Physics'}; |
---|
52 | varargin(i) = []; |
---|
53 | elseif strcmpi(varargin{i},'hardware') |
---|
54 | UnitsFlagCell = {'Hardware'}; |
---|
55 | varargin(i) = []; |
---|
56 | end |
---|
57 | end |
---|
58 | |
---|
59 | if isempty(varargin) |
---|
60 | error('Must have at least a family name input'); |
---|
61 | end |
---|
62 | |
---|
63 | |
---|
64 | %%%%%%%%%%%%%% |
---|
65 | % Cell input % |
---|
66 | %%%%%%%%%%%%%% |
---|
67 | if iscell(varargin{1}) |
---|
68 | for i = 1:length(varargin{1}) |
---|
69 | if length(varargin) < 2 |
---|
70 | Data{i} = getgain(varargin{1}{i}, UnitsFlagCell{:}); |
---|
71 | elseif length(varargin) < 3 |
---|
72 | if iscell(varargin{2}) |
---|
73 | Data{i} = getgain(varargin{1}{i}, varargin{2}{i}, UnitsFlagCell{:}); |
---|
74 | else |
---|
75 | Data{i} = getgain(varargin{1}{i}, varargin{2}, UnitsFlagCell{:}); |
---|
76 | end |
---|
77 | else |
---|
78 | if iscell(varargin{3}) |
---|
79 | Data{i} = getgain(varargin{1}{i}, varargin{2}{i}, varargin{3}{i}, UnitsFlagCell{:}); |
---|
80 | else |
---|
81 | Data{i} = getgain(varargin{1}{i}, varargin{2}{i}, varargin{3}, UnitsFlagCell{:}); |
---|
82 | end |
---|
83 | end |
---|
84 | end |
---|
85 | return |
---|
86 | end |
---|
87 | |
---|
88 | |
---|
89 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
90 | % Parse Family, Field, DeviceList % |
---|
91 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
92 | [Family, Field, DeviceList, UnitsFlag] = inputparsingffd(varargin{:}); |
---|
93 | |
---|
94 | |
---|
95 | % Units flag |
---|
96 | if isempty(UnitsFlagCell) |
---|
97 | % For structure inputs, use the units in the structure (from inputparsingffd) |
---|
98 | % Else, get the default family value |
---|
99 | if isempty(UnitsFlag) |
---|
100 | UnitsFlag = getunits(Family); |
---|
101 | end |
---|
102 | else |
---|
103 | % Input override has priority |
---|
104 | UnitsFlag = UnitsFlagCell{1}; |
---|
105 | end |
---|
106 | |
---|
107 | |
---|
108 | % Default field is Monitor for BPMs else Setpoint |
---|
109 | if isempty(Field) |
---|
110 | if ismemberof(Family,'BPM') |
---|
111 | Field = 'Monitor'; |
---|
112 | else |
---|
113 | Field = 'Setpoint'; |
---|
114 | end |
---|
115 | end |
---|
116 | |
---|
117 | |
---|
118 | %%%%%%%%%%%% |
---|
119 | % Get data % |
---|
120 | %%%%%%%%%%%% |
---|
121 | |
---|
122 | % 1. Try the AO and AD |
---|
123 | Data = getfamilydata(Family, Field, 'Gain', DeviceList); |
---|
124 | if isempty(Data) && (strcmp(Field, 'Monitor') || strcmp(Field, 'Setpoint')) |
---|
125 | Data = getfamilydata(Family, 'Gain', DeviceList); |
---|
126 | end |
---|
127 | |
---|
128 | |
---|
129 | % % 2. Then look in the AT model |
---|
130 | % ATIndexList = family2atindex(Family, DeviceList); |
---|
131 | % for i = 1:length(ATIndexList) |
---|
132 | % if isfield(AT, 'GCR') |
---|
133 | % GCR(i,:) = THERING{ATIndexList(i)}.GCR; |
---|
134 | % else |
---|
135 | % GCR(i,:) = [1 1 0 0]; % [Gx Gy Crunch Roll] |
---|
136 | % end |
---|
137 | % end |
---|
138 | |
---|
139 | |
---|
140 | % 2. Then look in PhysData |
---|
141 | if isempty(Data) |
---|
142 | try |
---|
143 | Data = getphysdata(Family, Field, 'Gain', DeviceList); |
---|
144 | catch |
---|
145 | end |
---|
146 | end |
---|
147 | if isempty(Data) && (strcmp(Field, 'Monitor') || strcmp(Field, 'Setpoint')) |
---|
148 | try |
---|
149 | Data = getphysdata(Family, 'Gain', DeviceList); |
---|
150 | catch |
---|
151 | end |
---|
152 | end |
---|
153 | |
---|
154 | % Default offset |
---|
155 | if isempty(Data) |
---|
156 | Data = ones(size(DeviceList,1),1); |
---|
157 | end |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
162 | % Change to physics units if requested % |
---|
163 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
164 | %if strcmpi(UnitsFlag,'Physics') |
---|
165 | % Data = hw2physics(Family, Field, Data, DeviceList); |
---|
166 | %end |
---|
167 | |
---|
168 | |
---|
169 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
170 | % Return a data structure if requested % |
---|
171 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
172 | if StructOutputFlag |
---|
173 | DataNumeric = Data; |
---|
174 | if isempty(UnitsFlag) |
---|
175 | Data = family2datastruct(Family, Field, DeviceList); |
---|
176 | else |
---|
177 | Data = family2datastruct(Family, Field, DeviceList, UnitsFlag); |
---|
178 | end |
---|
179 | Data.Data = DataNumeric; |
---|
180 | Data.DataDescriptor = sprintf('%s.%s Gain', Family, Field); |
---|
181 | Data.CreatedBy = 'getgain'; |
---|
182 | end |
---|