[4] | 1 | function [DataStruct, ErrorFlag] = family2datastruct(varargin) |
---|
| 2 | %FAMILY2DATASTRUCTURE - Returns a datastructure corresponding to a Family |
---|
| 3 | % [DataStruct, ErrorFlag] = family2datastruct(Family, Field, DeviceList) |
---|
| 4 | % [DataStruct, ErrorFlag] = family2datastruct(Family, DeviceList) (Field will default to 'Monitor') |
---|
| 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 | % |
---|
| 15 | % OUTPUTS |
---|
| 16 | % 1. DataStruct = Date structure corresponding to the Family, Field, and DeviceList |
---|
| 17 | % |
---|
| 18 | % NOTES |
---|
| 19 | % 1. If Family is a cell array, then DeviceList and Field can also be a cell arrays |
---|
| 20 | % |
---|
| 21 | % See Also builddatastruct |
---|
| 22 | |
---|
| 23 | % Written by Gregory J. Portmann |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | %%%%%%%%%%%%%%%%% |
---|
| 27 | % Input Parsing % |
---|
| 28 | %%%%%%%%%%%%%%%%% |
---|
| 29 | UnitsFlagCell = {}; |
---|
| 30 | for i = length(varargin):-1:1 |
---|
| 31 | if isstruct(varargin{i}) |
---|
| 32 | % ignore structures |
---|
| 33 | elseif iscell(varargin{i}) |
---|
| 34 | % ignore cells |
---|
| 35 | elseif strcmpi(varargin{i},'struct') |
---|
| 36 | % Remove and ignore |
---|
| 37 | varargin(i) = []; |
---|
| 38 | elseif strcmpi(varargin{i},'numeric') |
---|
| 39 | % Remove and ignore |
---|
| 40 | varargin(i) = []; |
---|
| 41 | elseif strcmpi(varargin{i},'simulator') || strcmpi(varargin{i},'model') || strcmpi(varargin{i},'Online') || strcmpi(varargin{i},'Manual') |
---|
| 42 | % Remove and ignore |
---|
| 43 | varargin(i) = []; |
---|
| 44 | elseif strcmpi(varargin{i},'physics') |
---|
| 45 | UnitsFlagCell = {'Physics'}; |
---|
| 46 | varargin(i) = []; |
---|
| 47 | elseif strcmpi(varargin{i},'hardware') |
---|
| 48 | UnitsFlagCell = {'Hardware'}; |
---|
| 49 | varargin(i) = []; |
---|
| 50 | end |
---|
| 51 | end |
---|
| 52 | |
---|
| 53 | if isempty(varargin) |
---|
| 54 | error('Must have at least a family name input'); |
---|
| 55 | end |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | %%%%%%%%%%%%%%%%%%%%% |
---|
| 59 | % Cell Array Inputs % |
---|
| 60 | %%%%%%%%%%%%%%%%%%%%% |
---|
| 61 | if iscell(varargin{1}) |
---|
| 62 | for i = 1:length(varargin{1}) |
---|
| 63 | if length(varargin) < 2 |
---|
| 64 | [DataStruct{i}, ErrorFlag{i}] = family2datastruct(varargin{1}{i}, UnitsFlagCell{:}); |
---|
| 65 | elseif length(varargin) < 3 |
---|
| 66 | if iscell(varargin{2}) |
---|
| 67 | [DataStruct{i}, ErrorFlag{i}] = family2datastruct(varargin{1}{i}, varargin{2}{i}, UnitsFlagCell{:}); |
---|
| 68 | else |
---|
| 69 | [DataStruct{i}, ErrorFlag{i}] = family2datastruct(varargin{1}{i}, varargin{2}, UnitsFlagCell{:}); |
---|
| 70 | end |
---|
| 71 | else |
---|
| 72 | if iscell(varargin{2}) |
---|
| 73 | if iscell(varargin{3}) |
---|
| 74 | [DataStruct{i}, ErrorFlag{i}] = family2datastruct(varargin{1}{i}, varargin{2}{i}, varargin{3}{i}, UnitsFlagCell{:}); |
---|
| 75 | else |
---|
| 76 | [DataStruct{i}, ErrorFlag{i}] = family2datastruct(varargin{1}{i}, varargin{2}{i}, varargin{3}, UnitsFlagCell{:}); |
---|
| 77 | end |
---|
| 78 | else |
---|
| 79 | if iscell(varargin{3}) |
---|
| 80 | [DataStruct{i}, ErrorFlag{i}] = family2datastruct(varargin{1}{i}, varargin{2}, varargin{3}{i}, UnitsFlagCell{:}); |
---|
| 81 | else |
---|
| 82 | [DataStruct{i}, ErrorFlag{i}] = family2datastruct(varargin{1}{i}, varargin{2}, varargin{3}, UnitsFlagCell{:}); |
---|
| 83 | end |
---|
| 84 | end |
---|
| 85 | end |
---|
| 86 | end |
---|
| 87 | return |
---|
| 88 | end |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 92 | % Parse Family, Field, DeviceList % |
---|
| 93 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 94 | [Family, Field, DeviceList, UnitsFlag] = inputparsingffd(varargin{:}); |
---|
| 95 | |
---|
| 96 | % Units flag |
---|
| 97 | if isempty(UnitsFlagCell) |
---|
| 98 | % For structure inputs, use the units in the structure (from inputparsingffd) |
---|
| 99 | % Else, get the default family value |
---|
| 100 | if isempty(UnitsFlag) |
---|
| 101 | UnitsFlag = getunits(Family); |
---|
| 102 | end |
---|
| 103 | else |
---|
| 104 | % Input override has priority |
---|
| 105 | UnitsFlag = UnitsFlagCell{1}; |
---|
| 106 | end |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | % Default field is Setpoint |
---|
| 110 | if isempty(Field) |
---|
| 111 | Field = 'Monitor'; |
---|
| 112 | end |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | if isempty(UnitsFlag) |
---|
| 117 | UnitsFlag = getfamilydata(Family, Field, 'Units'); |
---|
| 118 | end |
---|
| 119 | if isempty(UnitsFlag) |
---|
| 120 | error('Cannot find the units type'); |
---|
| 121 | end |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | %%%%%%%%%%%% |
---|
| 126 | % Get data % |
---|
| 127 | %%%%%%%%%%%% |
---|
| 128 | ErrorFlag = 0; |
---|
| 129 | DataStruct.Data = []; % Gets filed with NaN later |
---|
| 130 | DataStruct.FamilyName = Family; |
---|
| 131 | DataStruct.Field = Field; |
---|
| 132 | if isempty(DeviceList) |
---|
| 133 | DataStruct.DeviceList = family2dev(Family); |
---|
| 134 | else |
---|
| 135 | DataStruct.DeviceList = DeviceList; |
---|
| 136 | end |
---|
| 137 | DataStruct.Data = ones(size( DataStruct.DeviceList,1),1) * NaN; |
---|
| 138 | DataStruct.Status = family2status(Family, DataStruct.DeviceList); |
---|
| 139 | DataStruct.Mode = getmode(Family, Field); |
---|
| 140 | DataStruct.t = []; |
---|
| 141 | DataStruct.tout = []; |
---|
| 142 | DataStruct.DataTime = []; |
---|
| 143 | DataStruct.TimeStamp = []; |
---|
| 144 | |
---|
| 145 | DataStruct.Units = UnitsFlag; |
---|
| 146 | if strcmpi(UnitsFlag,'Hardware') |
---|
| 147 | DataStruct.UnitsString = getfamilydata(Family, Field, 'HWUnits'); |
---|
| 148 | elseif strcmpi(UnitsFlag,'Physics') |
---|
| 149 | DataStruct.UnitsString = getfamilydata(Family, Field, 'PhysicsUnits'); |
---|
| 150 | else |
---|
| 151 | error('Units unknown'); |
---|
| 152 | end |
---|
| 153 | DataStruct.DataDescriptor = ''; |
---|
| 154 | DataStruct.CreatedBy = 'family2datastruct'; |
---|
| 155 | |
---|