1 | function [Data, ErrorFlag] = minpv(varargin) |
---|
2 | %MinPV - Maximum value of a process variable |
---|
3 | % [MinPV, ErrorFlag] = minpv(Family, Field, DeviceList) |
---|
4 | % [MinPV, ErrorFlag] = minpv(Family, DeviceList) (Field will default to 'Setpoint') |
---|
5 | % |
---|
6 | % INPUTS |
---|
7 | % 1. Family - Family Name |
---|
8 | % Data Structure |
---|
9 | % Accelerator Object |
---|
10 | % 2. Field - Accelerator Object field name ('Monitor', 'Setpoint', etc) {'Monitor'} |
---|
11 | % 3. DeviceList ([Sector Device #] or [element #]) {Default: whole family} |
---|
12 | % 4. 'Physics' - Use physics units (optional override of units) |
---|
13 | % 'Hardware' - Use hardware units (optional override of units) |
---|
14 | % 5. 'Numeric' - Numeric output {Default} |
---|
15 | % 'Struct' - Data structure output |
---|
16 | % |
---|
17 | % OUTPUTS |
---|
18 | % 1. MinPV = Minimum value corresponding to the Family, Field, and DeviceList |
---|
19 | % |
---|
20 | % NOTES |
---|
21 | % 1. If Family is a cell array, then DeviceList and Field can also be a cell arrays |
---|
22 | % |
---|
23 | % Also see maxpv, getfamilydata(Family, Field, 'Range') |
---|
24 | % |
---|
25 | % Written by Greg Portmann |
---|
26 | |
---|
27 | |
---|
28 | % Input parsing |
---|
29 | UnitsFlagCell = {}; |
---|
30 | StructOutputFlag = 0; |
---|
31 | for i = length(varargin):-1:1 |
---|
32 | if isstruct(varargin{i}) |
---|
33 | % Ignor structures |
---|
34 | elseif iscell(varargin{i}) |
---|
35 | % Ignor cells |
---|
36 | elseif strcmpi(varargin{i},'struct') |
---|
37 | StructOutputFlag = 1; |
---|
38 | varargin(i) = []; |
---|
39 | elseif strcmpi(varargin{i},'numeric') |
---|
40 | StructOutputFlag = 0; |
---|
41 | varargin(i) = []; |
---|
42 | elseif strcmpi(varargin{i},'simulator') || strcmpi(varargin{i},'model') || strcmpi(varargin{i},'Online') || strcmpi(varargin{i},'Manual') |
---|
43 | % Remove and ignor |
---|
44 | varargin(i) = []; |
---|
45 | elseif strcmpi(varargin{i},'physics') |
---|
46 | UnitsFlagCell = {'Physics'}; |
---|
47 | varargin(i) = []; |
---|
48 | elseif strcmpi(varargin{i},'hardware') |
---|
49 | UnitsFlagCell = {'Hardware'}; |
---|
50 | varargin(i) = []; |
---|
51 | end |
---|
52 | end |
---|
53 | |
---|
54 | if isempty(varargin) |
---|
55 | error('Must have at least a family name input'); |
---|
56 | end |
---|
57 | |
---|
58 | |
---|
59 | %%%%%%%%%%%%%%%%%%%%% |
---|
60 | % Cell Array Inputs % |
---|
61 | %%%%%%%%%%%%%%%%%%%%% |
---|
62 | if iscell(varargin{1}) |
---|
63 | for i = 1:length(varargin{1}) |
---|
64 | if length(varargin) < 2 |
---|
65 | [Data{i}, ErrorFlag{i}] = minpv(varargin{1}{i}, UnitsFlagCell{:}); |
---|
66 | elseif length(varargin) < 3 |
---|
67 | if iscell(varargin{2}) |
---|
68 | [Data{i}, ErrorFlag{i}] = minpv(varargin{1}{i}, varargin{2}{i}, UnitsFlagCell{:}); |
---|
69 | else |
---|
70 | [Data{i}, ErrorFlag{i}] = minpv(varargin{1}{i}, varargin{2}, UnitsFlagCell{:}); |
---|
71 | end |
---|
72 | else |
---|
73 | if iscell(varargin{3}) |
---|
74 | [Data{i}, ErrorFlag{i}] = minpv(varargin{1}{i}, varargin{2}{i}, varargin{3}{i}, UnitsFlagCell{:}); |
---|
75 | else |
---|
76 | [Data{i}, ErrorFlag{i}] = minpv(varargin{1}{i}, varargin{2}{i}, varargin{3}, UnitsFlagCell{:}); |
---|
77 | end |
---|
78 | end |
---|
79 | end |
---|
80 | return |
---|
81 | end |
---|
82 | |
---|
83 | |
---|
84 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
85 | % Parse Family, Field, DeviceList % |
---|
86 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
87 | [Family, Field, DeviceList, UnitsFlag] = inputparsingffd(varargin{:}); |
---|
88 | |
---|
89 | |
---|
90 | % Units flag |
---|
91 | if isempty(UnitsFlagCell) |
---|
92 | % For structure inputs, use the units in the structure (from inputparsingffd) |
---|
93 | % Else, get the default family value |
---|
94 | if isempty(UnitsFlag) |
---|
95 | UnitsFlag = getunits(Family); |
---|
96 | end |
---|
97 | else |
---|
98 | % Input override has priority |
---|
99 | UnitsFlag = UnitsFlagCell{1}; |
---|
100 | end |
---|
101 | |
---|
102 | |
---|
103 | % Default field is Setpoint |
---|
104 | if isempty(Field) |
---|
105 | Field = 'Setpoint'; |
---|
106 | end |
---|
107 | |
---|
108 | |
---|
109 | %%%%%%%%%%%% |
---|
110 | % Get data % |
---|
111 | %%%%%%%%%%%% |
---|
112 | [Data, ErrorFlag] = getfamilydata(Family, Field, 'Range', DeviceList); |
---|
113 | if isempty(Data) |
---|
114 | % Try the .Setpoint range (this maynot be such a good ideal) |
---|
115 | [Data, ErrorFlag] = getfamilydata(Family, 'Setpoint', 'Range', DeviceList); |
---|
116 | if isempty(Data) |
---|
117 | % Could check LOPR here if using EPICs |
---|
118 | error(sprintf('%s.%s minimum setpoint limit not known, .Range field missing.', Family, Field)); |
---|
119 | end |
---|
120 | end |
---|
121 | Data = Data(:,1); |
---|
122 | |
---|
123 | |
---|
124 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
125 | % Change to physics units if requested % |
---|
126 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
127 | if strcmpi(UnitsFlag,'Physics') |
---|
128 | Data = hw2physics(Family, Field, Data, DeviceList); |
---|
129 | end |
---|
130 | |
---|
131 | |
---|
132 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
133 | % Return a data structure if requested % |
---|
134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
135 | if StructOutputFlag |
---|
136 | DataNumeric = Data; |
---|
137 | Data = family2datastruct(Family, Field, DeviceList, UnitsFlag); |
---|
138 | Data.Data = DataNumeric; |
---|
139 | Data.DataDescriptor = sprintf('%s.%s Minimum', Family, Field); |
---|
140 | Data.CreatedBy = 'minpv'; |
---|
141 | end |
---|