source: MML/trunk/mml/getramprate.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 5.5 KB
Line 
1function RampRate = getramprate(varargin)
2%GETRAMPRATE - Returns the ramp rate for a family
3%  RampRate = getramprate(Family, Field, DeviceList)
4%  RampRate = getramprate(Family, Field)
5%
6%  INPUTS
7%  1. Family - Family Name
8%              Data Structure
9%              Accelerator Object
10%  2. Field - Accelerator Object field name ('Monitor', 'Setpoint', etc) {Default: 'Setpoint'}
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%
15%  OUTPUTS
16%  1. RampRate - Ramp rate for the family
17%
18%  NOTES
19%  1. If the ramprate is not known, then pick a value should be used that makes the delay when 
20%     waiting one tolerance step resonable.   That is, Tol = family2tol is used by setpv and steppv
21%     when the WaitFlag = -2.  After the setpoint is within tolerance, an extra delay of
22%     Tol / RampRate is done. 
23%  2. If Family is a cell array, then DeviceList and Field can also be a cell arrays
24%
25%  Written by Greg Portmann
26
27
28%%%%%%%%%%%%%%%%%
29% Input Parsing %
30%%%%%%%%%%%%%%%%%
31UnitsFlagCell = {};
32for i = length(varargin):-1:1
33    if isstruct(varargin{i})
34        % Ignor structures
35    elseif iscell(varargin{i})
36        % Ignor cells
37    elseif strcmpi(varargin{i},'struct')
38        % Remove and ignor
39        varargin(i) = [];
40    elseif strcmpi(varargin{i},'numeric')
41        % Remove and ignor
42        varargin(i) = [];
43    elseif strcmpi(varargin{i},'simulator') || strcmpi(varargin{i},'model') || strcmpi(varargin{i},'Online') || strcmpi(varargin{i},'Manual')
44        % Remove and ignor
45        varargin(i) = [];
46    elseif strcmpi(varargin{i},'physics')
47        UnitsFlagCell = {'Physics'};
48        varargin(i) = [];
49    elseif strcmpi(varargin{i},'hardware')
50        UnitsFlagCell = {'Hardware'};
51        varargin(i) = [];
52    end
53end
54
55if isempty(varargin)
56    error('Must have at least a family name input');
57end
58
59
60%%%%%%%%%%%%%%%%%%%%%
61% Cell Array Inputs %
62%%%%%%%%%%%%%%%%%%%%%
63if iscell(varargin{1})
64    for i = 1:length(varargin{1})
65        if length(varargin) < 2
66            RampRate{i} = getramprate(varargin{1}{i}, UnitsFlagCell{:});
67        elseif length(varargin) < 3
68            if iscell(varargin{2})
69                RampRate{i} = getramprate(varargin{1}{i}, varargin{2}{i}, UnitsFlagCell{:});
70            else
71                RampRate{i} = getramprate(varargin{1}{i}, varargin{2}, UnitsFlagCell{:});
72            end
73        else
74            if iscell(varargin{3})
75                RampRate{i} = getramprate(varargin{1}{i}, varargin{2}{i}, varargin{3}{i}, UnitsFlagCell{:});
76            else
77                RampRate{i} = getramprate(varargin{1}{i}, varargin{2}{i}, varargin{3}, UnitsFlagCell{:});
78            end
79        end
80    end
81    return
82end
83
84
85%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86% Parse Family, Field, DeviceList %
87%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88[Family, Field, DeviceList, UnitsFlag] = inputparsingffd(varargin{:});
89
90% Units flag
91if 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
97else
98    % Input override has priority
99    UnitsFlag = UnitsFlagCell{1};
100end
101
102
103% Default field is Setpoint
104if isempty(Field)
105    Field = 'Setpoint';
106end
107
108
109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110% Look for the data in the following order %                                         
111% 1. RampRateFcn                           %
112% 2. Channelname (if Field = 'Setpoint')   %
113% 3. Constant in the AO                    %
114% 4. Physdata file                         %
115%                                          %
116% Note: Data is stored in hardware units   %
117%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
119% 1. Look for a .RampRateFcn function
120RampRateFcn = getfamilydata(Family, Field, 'RampRateFcn');
121if ~isempty(RampRateFcn)
122    RampRate = feval(RampRateFcn, Family, Field, DeviceList);
123   
124    % Change to physics units if requested
125    if strcmpi(UnitsFlag,'Physics')
126        RampRate = hw2physics(Family, Field, RampRate, DeviceList);
127    end
128    return
129end
130
131% 2. Channelname
132if strcmp(Field, 'Setpoint')
133    AORampRate = getfamilydata(Family, 'RampRate');
134    if ~isempty(AORampRate)
135        if isfield(AORampRate, 'ChannelNames') || isfield(AORampRate, 'SpecialFunction') || isfield(AORampRate, 'SpecialFunctionGet') 
136            RampRate = getpv(Family, 'RampRate', DeviceList);
137   
138            % Change to physics units if requested
139            if strcmpi(UnitsFlag,'Physics')
140                RampRate = hw2physics(Family, Field, RampRate, DeviceList);
141            end
142            return
143        end
144    end
145end
146
147
148% 3. Constant in the AO
149RampRate = getfamilydata(Family, Field, 'RampRate', DeviceList);
150if isempty(RampRate) && (strcmp(Field, 'Monitor') || strcmp(Field, 'Setpoint'))
151    RampRate = getfamilydata(Family, 'RampRate', DeviceList);
152end
153
154% Change to physics units if requested
155if strcmpi(UnitsFlag,'Physics')
156    RampRate = hw2physics(Family, Field, RampRate, DeviceList);
157end
158if ~isempty(RampRate) && isnumeric(RampRate)
159    return
160end
161
162
163% 4. Physdata file
164try
165    RampRate = getphysdata(Family, Field, 'RampRate', DeviceList);
166    if isempty(RampRate) && (strcmp(Field, 'Monitor') || strcmp(Field, 'Setpoint'))
167        RampRate = getphysdata(Family, 'RampRate', DeviceList);
168    end
169
170    % Change to physics units if requested
171    if strcmpi(UnitsFlag,'Physics')
172        RampRate = hw2physics(Family, Field, RampRate, DeviceList);
173    end
174catch
175    RampRate = [];
176end
177
178
Note: See TracBrowser for help on using the repository browser.