Home > mml > maxpv.m

maxpv

PURPOSE ^

MAXPV - Maximum value of a process variable

SYNOPSIS ^

function [Data, ErrorFlag] = maxpv(varargin)

DESCRIPTION ^

MAXPV - Maximum value of a process variable
  [MaxPV, ErrorFlag] = maxpv(Family, Field, DeviceList)
  [MaxPV, ErrorFlag] = maxpv(Family, DeviceList)      (Field will default to 'Setpoint')

  INPUTS
  1. Family - Family Name 
              Data Structure
              Accelerator Object
  2. Field - Accelerator Object field name ('Monitor', 'Setpoint', etc) {'Monitor'}
  3. DeviceList ([Sector Device #] or [element #]) {Default: whole family}
  4. 'Physics'  - Use physics  units (optional override of units)
     'Hardware' - Use hardware units (optional override of units)
  5. 'Numeric' - Numeric output {Default}
     'Struct'  - Data structure output

  OUTPUTS
  1. MaxPV = Maximum value corresponding to the Family, Field, and DeviceList
 
  NOTES
  1. If Family is a cell array, then DeviceList and Field can also be a cell arrays

  Also see minpv, getfamilydata(Family, Field, 'Range')

  Written by Greg Portmann

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Data, ErrorFlag] = maxpv(varargin)
0002 %MAXPV - Maximum value of a process variable
0003 %  [MaxPV, ErrorFlag] = maxpv(Family, Field, DeviceList)
0004 %  [MaxPV, ErrorFlag] = maxpv(Family, DeviceList)      (Field will default to 'Setpoint')
0005 %
0006 %  INPUTS
0007 %  1. Family - Family Name
0008 %              Data Structure
0009 %              Accelerator Object
0010 %  2. Field - Accelerator Object field name ('Monitor', 'Setpoint', etc) {'Monitor'}
0011 %  3. DeviceList ([Sector Device #] or [element #]) {Default: whole family}
0012 %  4. 'Physics'  - Use physics  units (optional override of units)
0013 %     'Hardware' - Use hardware units (optional override of units)
0014 %  5. 'Numeric' - Numeric output {Default}
0015 %     'Struct'  - Data structure output
0016 %
0017 %  OUTPUTS
0018 %  1. MaxPV = Maximum value corresponding to the Family, Field, and DeviceList
0019 %
0020 %  NOTES
0021 %  1. If Family is a cell array, then DeviceList and Field can also be a cell arrays
0022 %
0023 %  Also see minpv, getfamilydata(Family, Field, 'Range')
0024 %
0025 %  Written by Greg Portmann
0026 
0027 
0028 % Input parsing
0029 UnitsFlagCell = {};
0030 StructOutputFlag = 0;
0031 for i = length(varargin):-1:1
0032     if isstruct(varargin{i})
0033         % Ignor structures
0034     elseif iscell(varargin{i})
0035         % Ignor cells
0036     elseif strcmpi(varargin{i},'struct')
0037         StructOutputFlag = 1;
0038         varargin(i) = [];
0039     elseif strcmpi(varargin{i},'numeric')
0040         StructOutputFlag = 0;
0041         varargin(i) = [];
0042     elseif strcmpi(varargin{i},'simulator') || strcmpi(varargin{i},'model') || strcmpi(varargin{i},'Online') || strcmpi(varargin{i},'Manual')
0043         % Remove and ignor
0044         varargin(i) = [];
0045     elseif strcmpi(varargin{i},'physics')
0046         UnitsFlagCell = {'Physics'};
0047         varargin(i) = [];
0048     elseif strcmpi(varargin{i},'hardware')
0049         UnitsFlagCell = {'Hardware'};
0050         varargin(i) = [];
0051     end
0052 end
0053 
0054 if isempty(varargin)
0055     error('Must have at least a family name input');
0056 end
0057 
0058 
0059 %%%%%%%%%%%%%%%%%%%%%
0060 % Cell Array Inputs %
0061 %%%%%%%%%%%%%%%%%%%%%
0062 if iscell(varargin{1})
0063     for i = 1:length(varargin{1})
0064         if length(varargin) < 2
0065             [Data{i}, ErrorFlag{i}] = maxpv(varargin{1}{i}, UnitsFlagCell{:});
0066         elseif length(varargin) < 3
0067             if iscell(varargin{2})
0068                 [Data{i}, ErrorFlag{i}] = maxpv(varargin{1}{i}, varargin{2}{i}, UnitsFlagCell{:});
0069             else
0070                 [Data{i}, ErrorFlag{i}] = maxpv(varargin{1}{i}, varargin{2}, UnitsFlagCell{:});
0071             end
0072         else
0073             if iscell(varargin{3})
0074                 [Data{i}, ErrorFlag{i}] = maxpv(varargin{1}{i}, varargin{2}{i}, varargin{3}{i}, UnitsFlagCell{:});
0075             else
0076                 [Data{i}, ErrorFlag{i}] = maxpv(varargin{1}{i}, varargin{2}{i}, varargin{3}, UnitsFlagCell{:});
0077             end
0078         end
0079     end
0080     return
0081 end
0082 
0083 
0084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0085 % Parse Family, Field, DeviceList %
0086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0087 [Family, Field, DeviceList, UnitsFlag] = inputparsingffd(varargin{:});
0088 
0089 
0090 % Units flag
0091 if isempty(UnitsFlagCell)
0092     % For structure inputs, use the units in the structure (from inputparsingffd)
0093     % Else, get the default family value
0094     if isempty(UnitsFlag)
0095         UnitsFlag = getunits(Family);
0096     end
0097 else
0098     % Input override has priority
0099     UnitsFlag = UnitsFlagCell{1};
0100 end
0101 
0102 
0103 % Default field is Setpoint
0104 if isempty(Field)
0105     Field = 'Setpoint';
0106 end
0107 
0108 
0109 %%%%%%%%%%%%
0110 % Get data %
0111 %%%%%%%%%%%%
0112 [Data, ErrorFlag] = getfamilydata(Family, Field, 'Range', DeviceList);
0113 if isempty(Data)
0114     % Try the .Setpoint range (this maynot be such a good ideal)
0115     [Data, ErrorFlag] = getfamilydata(Family, 'Setpoint', 'Range', DeviceList);
0116     if isempty(Data)
0117         % Could check HOPR here if using epics
0118         error(sprintf('%s.%s maximum setpoint limit not known, .Range field missing.', Family, Field));
0119     end
0120 end
0121 Data = Data(:,2);
0122 
0123 
0124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0125 % Change to physics units if requested %
0126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0127 if strcmpi(UnitsFlag,'Physics')
0128     Data = hw2physics(Family, Field, Data, DeviceList);
0129 end
0130 
0131 
0132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0133 % Return a data structure if requested %
0134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0135 if StructOutputFlag
0136     DataNumeric = Data;
0137     Data = family2datastruct(Family, Field, DeviceList, UnitsFlag);
0138     Data.Data = DataNumeric;
0139     Data.DataDescriptor = sprintf('%s.%s Minimum', Family, Field);
0140     Data.CreatedBy = 'maxpv';
0141 end

Generated on Mon 21-May-2007 15:29:18 by m2html © 2003