source: MML/trunk/mml/getrunflag.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: 4.7 KB
Line 
1function [RunFlag, Delta, Tol] = getrunflag(varargin)
2%GETRUNFLAG - Returns position if the device is in the process of changing a setpoint
3%  If using family name, field, device list method,
4%  [RunFlag, Delta, Tol] = getrunflag(Family, Field, DeviceList)
5%  [RunFlag, Delta, Tol] = getrunflag(Family, DeviceList) 
6%
7%  If using channel name method,
8%  [RunFlag, Delta] = getrunflag(ChannelNames)
9%
10%  INPUTS
11%  1. Family - Family Name
12%              Accelerator Object
13%     ChannelName - Channel/TANGO access channel name
14%                   Matrix of channel/TANGO names
15%  2. Field - Field name  {Default: 'Setpoint')
16%  3. DeviceList - [Sector Device #] or [element #] list {Default or empty list: whole family}
17%
18%  OUTPUTS
19%  1. RunFlag - 1 if monitor has not reached the setpoint (Column vector)
20%               0 if the monitor and the setpoint are within tolerance (Column vector)
21%               [] runflag not found
22%  2. Delta - Diffence between where it is and where is should be.
23%  3. Tol - Allowed tolerance between the setpoint and the monitor
24%
25%  Note: If inputs are cell arrays, then outputs are cell arrays.
26
27%
28%  Written by Gregory J. Portmann
29%  Modified by Laurent S. Nadolski
30
31if nargin == 0,
32    error('Must have at least one input (Family or Channel/Tango Name).');
33end
34
35
36%%%%%%%%%%%%%%%%%%%%%
37% Cell Array Inputs %
38%%%%%%%%%%%%%%%%%%%%%
39if iscell(varargin{1})
40    % Cell arrays
41    for i = 1:length(varargin{1})
42        if nargin < 2
43            [RunFlag{i}, Delta{i}, Tol{i}] = getrunflag(varargin{1}{i});
44        elseif nargin < 3
45            if iscell(varargin{2})
46                [RunFlag{i}, Delta{i}, Tol{i}] = getrunflag(varargin{1}{i}, varargin{2}{i});
47            else
48                [RunFlag{i}, Delta{i}, Tol{i}] = getrunflag(varargin{1}{i}, varargin{2});
49            end
50        else
51            if iscell(varargin{3})
52                [RunFlag{i}, Delta{i}, Tol{i}] = getrunflag(varargin{1}{i}, varargin{2}{i}, varargin{3}{i});
53            else
54                [RunFlag{i}, Delta{i}, Tol{i}] = getrunflag(varargin{1}{i}, varargin{2}{i}, varargin{3});
55            end
56        end
57    end
58    return
59end
60
61
62%%%%%%%%%%%%%%%%%%%%%%
63% Common Name Inputs %
64%%%%%%%%%%%%%%%%%%%%%%
65if isempty(varargin{1})
66    % Common names with no family name
67    if nargin < 2
68        error('If Family=[], 2 inputs are required.');
69    end
70    CommonNames = varargin{3};
71    for i = 1:size(CommonNames,1)
72        Family = common2family(CommonNames(i,:));
73        [FamilyIndex, ACCELERATOR_OBJECT] = isfamily(Family);
74        DeviceList = common2dev(CommonNames(i,:), ACCELERATOR_OBJECT);
75        if isempty(DeviceList) | isempty(DeviceList)
76            error('Common name could not be converted to a Family and DeviceList.');
77        end
78        [RunFlag(i,:), Delta(i,:), Tol(i,:)] = getrunflag(Family, DeviceList);
79    end
80    return
81end
82
83
84%%%%%%%%%%%%%%%%%%%%%%%
85% Channel Name Inputs %
86%%%%%%%%%%%%%%%%%%%%%%%
87if ~isfamily(varargin{1}(1,:))
88    % Channel name method
89    % Try to convert to a family and device
90    ChannelNames = varargin{1};
91    for i = 1:size(ChannelNames,1)
92        Family = tango2family(ChannelNames(i,:));
93        [FamilyIndex, ACCELERATOR_OBJECT] = isfamily(Family);
94        DeviceList = tango2dev(ChannelNames(i,:), ACCELERATOR_OBJECT);
95        if isempty(DeviceList) | isempty(DeviceList)
96            error('Tango name could not be converted to a Family and DeviceList.');
97        end
98        [RunFlag(i,:), Delta(i,:), Tol(i,:)] = getrunflag(Family, DeviceList);
99    end
100    return
101end
102
103
104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105% Parse Family, Field, DeviceList %
106%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107[Family, Field, DeviceList, UnitsFlag] = inputparsingffd(varargin{:});
108
109% Default field is Setpoint
110if isempty(Field)
111    Field = 'Setpoint';
112end
113
114
115%%%%%%%%%%%%
116% Get data %
117%%%%%%%%%%%%
118RunFlag = [];
119Delta = [];
120Tol = [];
121
122% 1. Look for a .RunFlagFcn function
123RunFlagFcn = getfamilydata(Family, Field, 'RunFlagFcn');
124if ~isempty(RunFlagFcn)
125    [RunFlag, Delta, Tol] = feval(RunFlagFcn, Family, Field, DeviceList);
126    return
127end
128
129
130% 2. If Field = 'Setpoint', base on SP-AM tolerance
131if strcmp(Field, 'Setpoint')
132    % Base runflag on abs(Setpoint-Monitor) > Tol
133    Tol = family2tol(Family, Field, DeviceList, 'Hardware');
134    if isempty(Tol)
135        return;
136    end
137
138    % Use the "real" Setpoint value
139    SP  = getpv(Family, 'Setpoint', DeviceList, 'Hardware');
140    if isempty(SP)
141        return;
142    end
143    %SP = raw2real(Family, 'Monitor', SP, DeviceList); % Laurent
144
145    % Use the "real" Monitor value
146    AM  = getpv(Family, 'Monitor', DeviceList, 'Hardware');
147    if isempty(AM)
148        return;
149    end
150    %AM = raw2real(Family, 'Monitor', AM, DeviceList); % Laurent
151   
152    RunFlag = abs(SP-AM) > Tol;
153    %fprintf('SP=%f AM=%f\n', SP,AM)
154    Delta = SP-AM;
155end
156   
157
Note: See TracBrowser for help on using the repository browser.