source: MML/trunk/mml/at/setatfield.m @ 4

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

Initial import--MML version from SOLEIL@2013

File size: 3.0 KB
Line 
1function 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
23global THERING
24
25if nargin < 3
26    error('Must have at least Family, Field, and Value inputs.');
27end
28
29
30if length(varargin) >= 1
31    ATIndexList = family2atindex(Family, varargin{1});
32else
33    ATIndexList = family2atindex(Family);
34end
35
36if 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
43end
44
45
46% Check the size of Value input
47if 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
54end
55
56
57if 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
69else
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
95end
96
Note: See TracBrowser for help on using the repository browser.