source: MML/trunk/mml/getoffset.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: 5.1 KB
Line 
1function Data = getoffset(varargin)
2%GETOFFSET - Returns the offset values for a family
3%  Offset = getoffset(Family, Field, DeviceList)
4%  Offset = getoffset(Family, DeviceList)
5%  Offset = getoffset(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. 'Physics'  - Use physics  units (optional override of units)
14%     'Hardware' - Use hardware units (optional override of units)
15%  5. 'Struct'  - Return a data structure
16%     'Numeric' - Return numeric outputs  {Default}
17%     'Object'  - Return a accelerator object (AccObj)
18%
19%  OUTPUTS
20%  1. Offset - Offset value for the family {Default: 0}
21%
22%  NOTES
23%  1. If Family is a cell array, then DeviceList can also be a cell arrays
24%  2. The offset orbit must be stored in hardware units.
25%
26%  See also getfamilydata, getgolden, raw2real, real2raw
27%
28%  Written by Greg Portmann
29
30
31%%%%%%%%%%%%%%%%%
32% Input Parsing %
33%%%%%%%%%%%%%%%%%
34UnitsFlagCell = {};
35StructOutputFlag = 0;
36ObjectOutputFlag = 0;
37for i = length(varargin):-1:1
38    if isstruct(varargin{i})
39        % Ignor structures
40    elseif iscell(varargin{i})
41        % Ignor cells
42    elseif strcmpi(varargin{i},'struct')
43        StructOutputFlag = 1;
44        varargin(i) = [];
45    elseif strcmpi(varargin{i},'numeric')
46        StructOutputFlag = 0;
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    elseif strcmpi(varargin{i},'Object')
58        ObjectOutputFlag = 1;
59        StructOutputFlag = 1;
60        varargin(i) = [];
61    end
62end
63
64if isempty(varargin)
65    error('Must have at least a family name input');
66end
67
68
69%%%%%%%%%%%%%%
70% Cell input %
71%%%%%%%%%%%%%%
72if iscell(varargin{1})
73    for i = 1:length(varargin{1})
74        if length(varargin) < 2
75            Data{i} = getoffset(varargin{1}{i}, UnitsFlagCell{:});
76        elseif length(varargin) < 3
77            if iscell(varargin{2})
78                Data{i} = getoffset(varargin{1}{i}, varargin{2}{i}, UnitsFlagCell{:});
79            else
80                Data{i} = getoffset(varargin{1}{i}, varargin{2}, UnitsFlagCell{:});
81            end
82        else
83            if iscell(varargin{3})
84                Data{i} = getoffset(varargin{1}{i}, varargin{2}{i}, varargin{3}{i}, UnitsFlagCell{:});
85            else
86                Data{i} = getoffset(varargin{1}{i}, varargin{2}{i}, varargin{3}, UnitsFlagCell{:});
87            end
88        end
89    end
90    return
91end
92
93
94%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95% Parse Family, Field, DeviceList %
96%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97[Family, Field, DeviceList, UnitsFlag] = inputparsingffd(varargin{:});
98
99
100% Units flag
101if isempty(UnitsFlagCell)
102    % For structure inputs, use the units in the structure (from inputparsingffd)
103    % Else, get the default family value
104    if isempty(UnitsFlag)
105        UnitsFlag = getunits(Family);
106    end
107else
108    % Input override has priority
109    UnitsFlag = UnitsFlagCell{1};
110end
111
112
113% Default field is Monitor for BPMs else Setpoint
114if isempty(Field)
115    if ismemberof(Family,'BPM')
116        Field = 'Monitor';
117    else
118        Field = 'Setpoint';
119    end
120end
121
122
123%%%%%%%%%%%%
124% Get data %
125%%%%%%%%%%%%
126
127% 1. Try the AO and AD
128Data = getfamilydata(Family, Field, 'Offset', DeviceList);
129if isempty(Data) && (strcmp(Field, 'Monitor') || strcmp(Field, 'Setpoint'))
130    Data = getfamilydata(Family, 'Offset', DeviceList);
131end
132
133% 2. Then look in PhysData
134if isempty(Data)
135    try
136        Data = getphysdata(Family, Field, 'Offset', DeviceList);
137    catch
138    end
139end
140if isempty(Data) && (strcmp(Field, 'Monitor') || strcmp(Field, 'Setpoint'))
141    try
142        Data = getphysdata(Family, 'Offset', DeviceList);
143    catch
144    end
145end
146
147% Default offset
148if isempty(Data)
149    Data = zeros(size(DeviceList,1),1);
150end
151
152
153if isstruct(Data)
154    Data = Data.Data;
155end
156
157
158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159% Change to physics units if requested %
160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161if strcmpi(UnitsFlag,'Physics')
162    % Offsets in physics units are zero!
163    Data = hw2physics(Family, Field, Data, DeviceList);
164end
165
166
167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168% Return a data structure if requested %
169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170if StructOutputFlag
171    DataNumeric = Data;
172    if isempty(UnitsFlag)
173        Data = family2datastruct(Family, Field, DeviceList);
174    else
175        Data = family2datastruct(Family, Field, DeviceList, UnitsFlag);
176    end
177    Data.Data = DataNumeric;
178    Data.DataDescriptor = sprintf('%s.%s Offset', Family, Field);
179    Data.CreatedBy = 'getoffset';
180
181    % Make the output an AccObj object
182    if ObjectOutputFlag
183        Data = AccObj(Data);
184    end
185end
Note: See TracBrowser for help on using the repository browser.