[4] | 1 | function ATIndexList = setatfield(Family, Field, Value, varargin) |
---|
| 2 | %SETATFIELD - Set the contents of an AT model field |
---|
| 3 | % ATIndex = setatfield(Family, Field, Value, DeviceList, RowSubIndex, ColSubIndex) |
---|
| 4 | % |
---|
| 5 | % INPUTS |
---|
| 6 | % 1. Family - Family Name |
---|
| 7 | % Accelerator Object |
---|
| 8 | % AT FamName |
---|
| 9 | % 2. Field - AT field name |
---|
| 10 | % 3. Value - New AT value |
---|
| 11 | % 4. DeviceList - [Sector Device #] or [element #] list {Default: whole family} |
---|
| 12 | % Note: if using an AT family name, then DeviceList is an index |
---|
| 13 | % within the AT family. |
---|
| 14 | % 5. RowSubIndex - Row element index within the AT field {Default: the entire field} |
---|
| 15 | % 6. ColSubIndex - Column element index within the AT field {Default: the entire field} |
---|
| 16 | % |
---|
| 17 | % OUTPUTS |
---|
| 18 | % 1. ATIndex - AT index |
---|
| 19 | % |
---|
| 20 | % Written by Greg Portmann |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | global THERING |
---|
| 24 | |
---|
| 25 | if nargin < 3 |
---|
| 26 | error('Must have at least Family, Field, and Value inputs.'); |
---|
| 27 | end |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | if length(varargin) >= 1 |
---|
| 31 | ATIndexList = family2atindex(Family, varargin{1}); |
---|
| 32 | else |
---|
| 33 | ATIndexList = family2atindex(Family); |
---|
| 34 | end |
---|
| 35 | |
---|
| 36 | if isempty(ATIndexList) |
---|
| 37 | % Try an AT family |
---|
| 38 | ATIndexList = findcells(THERING, 'FamName', Family); |
---|
| 39 | ATIndexList = ATIndexList(:); |
---|
| 40 | if length(varargin) >= 1 |
---|
| 41 | ATIndexList = ATIndexList(varargin{1}); |
---|
| 42 | end |
---|
| 43 | end |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | % Check the size of Value input |
---|
| 47 | if size(Value,1) ~= size(ATIndexList,1) |
---|
| 48 | if size(Value,1) == 1 |
---|
| 49 | % Expand Value to as many rows as is in ATIndexList |
---|
| 50 | Value = ones(size(ATIndexList,1),1) * Value; |
---|
| 51 | else |
---|
| 52 | error('Value input have the same number of rows as devices (split magnets are one device).'); |
---|
| 53 | end |
---|
| 54 | end |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | if length(ATIndexList) == 1 |
---|
| 58 | %if isfield(THERING{ATIndexList}, Field) |
---|
| 59 | if length(varargin) == 2 |
---|
| 60 | THERING{ATIndexList}.(Field)(varargin{2},:) = Value; |
---|
| 61 | elseif length(varargin) >= 3 |
---|
| 62 | THERING{ATIndexList}.(Field)(varargin{2},varargin{3}) = Value; |
---|
| 63 | else |
---|
| 64 | THERING{ATIndexList}.(Field) = Value; |
---|
| 65 | end |
---|
| 66 | %else |
---|
| 67 | % THERING{ATIndexList}.(Field) = Value; |
---|
| 68 | %end |
---|
| 69 | else |
---|
| 70 | for i = 1:size(ATIndexList,1) |
---|
| 71 | for j = 1:size(ATIndexList,2) |
---|
| 72 | if ~isnan(ATIndexList(i,j)) |
---|
| 73 | if length(varargin) == 2 |
---|
| 74 | if size(Value,1) == 1 |
---|
| 75 | THERING{ATIndexList(i,j)}.(Field)(varargin{2},:) = Value; |
---|
| 76 | else |
---|
| 77 | THERING{ATIndexList(i,j)}.(Field)(varargin{2},:) = Value(i,:); |
---|
| 78 | end |
---|
| 79 | elseif length(varargin) >= 3 |
---|
| 80 | if size(Value,1) == 1 |
---|
| 81 | THERING{ATIndexList(i,j)}.(Field)(varargin{2},varargin{3}) = Value; |
---|
| 82 | else |
---|
| 83 | THERING{ATIndexList(i,j)}.(Field)(varargin{2},varargin{3}) = Value(i,:); |
---|
| 84 | end |
---|
| 85 | else |
---|
| 86 | if size(Value,1) == 1 |
---|
| 87 | THERING{ATIndexList(i,j)}.(Field) = Value; |
---|
| 88 | else |
---|
| 89 | THERING{ATIndexList(i,j)}.(Field) = Value(i,:); |
---|
| 90 | end |
---|
| 91 | end |
---|
| 92 | end |
---|
| 93 | end |
---|
| 94 | end |
---|
| 95 | end |
---|
| 96 | |
---|