source: MML/trunk/mml/setfamilydata.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: 5.8 KB
Line 
1function setfamilydata(Data, Family, Field1, Field2, DeviceList)
2%SETFAMILYDATA - Sets data associated with accelerator control
3%
4%  When getting data from the accelerator object (AO):
5%  setfamilydata(Data, Family, Field1, Field2, DeviceList)
6%  setfamilydata(Data, Family, Field1, DeviceList)
7%  setfamilydata(Data, Family, Field1)
8%  setfamilydata(Data, Family)
9%
10%  When getting data from the accelerator data stucture (AD):
11%  setfamilydata(Data, Field1)
12%  setfamilydata(Data, Field1, Field2)
13%  setfamilydata(Data, Field1, Field2, Field3)
14%  setfamilydata(Data, Field1, Field2, Field3, Field4)
15%
16%  INPUTS
17%  1. Data = Data to set
18%     AO.Field1.Field2 = Data
19%     AD.Field1.Field2.Field3.Field4 = Data
20%
21%     If DeviceList exists, then Data is indexed according to DeviceList,
22%     AD.Field1(DeviceList) = Data
23%           or
24%     AD.Field1.Field2(DeviceList) = Data
25%                     
26%  2. Family = Family Name
27%              Data Structure (only the FamilyName field is used)
28%              Field
29%              Accelerator Object
30%
31%  3. Field1 = Field name (string)
32%
33%  4. Field2 = Field name (string)
34%
35%  5. DeviceList = Device list for that family
36%
37%  Note #1: The inputs can be cell arrays
38%  Note #2: If Family is a cell array, then DeviceList must also be a cell array,
39%           however, Field1 or Field2 can either be a cell array array or a string.
40%  Note #3: If the field does not exist, then an error will occur
41%
42%  Written by Greg Portmann
43
44
45if nargin < 2
46    error('At least two inputs required');
47end
48
49
50% Cell array input
51if iscell(Family)
52    if nargin >= 3
53        if iscell(Field1)
54            if length(Family) ~= length(Field1)
55                error('If Field1 is a cell array, then must be the same size as Family');
56            end
57        end
58    end
59    if nargin >= 4
60        if iscell(Field2)
61            if length(Family) ~= length(Field2)
62                error('If Field2 is a cell array, then must be the same size as Family');
63            end
64        end
65    end
66    if nargin >= 5
67        if ~iscell(DeviceList)
68            error('If family is a cell array, then DeviceList must be a cell array');
69        end
70        if length(Family) ~= length(DeviceList)
71            error('Family and DeviceList must be the same size cell arrays');
72        end
73    end
74   
75    for i = 1:length(Family)
76        if nargin == 2
77            setfamilydata(Data{i}, Family{i});
78        elseif nargin == 3
79            if iscell(Field1)
80                setfamilydata(Data{i}, Family{i}, Field1{i});
81            else
82                setfamilydata(Data{i}, Family{i}, Field1);
83            end
84        elseif nargin == 4
85            if iscell(Field1)
86                if iscell(Field2)
87                    setfamilydata(Data{i}, Family{i}, Field1{i}, Field2{i});
88                else
89                    setfamilydata(Data{i}, Family{i}, Field1{i}, Field2);
90                end               
91            else
92                if iscell(Field2)
93                    setfamilydata(Data{i}, Family{i}, Field1, Field2{i});
94                else
95                    setfamilydata(Data{i}, Family{i}, Field1, Field2);
96                end               
97            end
98        else
99            if iscell(Field1)
100                if iscell(Field2)
101                    setfamilydata(Data{i}, Family{i}, Field1{i}, Field2{i}, DeviceList{i});
102                else
103                    setfamilydata(Data{i}, Family{i}, Field1{i}, Field2, DeviceList{i});
104                end               
105            else
106                if iscell(Field2)
107                    setfamilydata(Data{i}, Family{i}, Field1, Field2{i}, DeviceList{i});
108                else
109                    setfamilydata(Data{i}, Family{i}, Field1, Field2, DeviceList{i});
110                end               
111            end
112        end
113    end
114    return   
115end 
116% End cell inputs
117
118[FamilyFlag, AO] = isfamily(Family);
119
120if FamilyFlag
121    Family = AO.FamilyName;
122    AO = getao;
123    if nargin == 2
124        % Set the entire family cell to Data
125        AO.(Family) = Data;
126    elseif nargin == 3
127        AO.(Family).(Field1) = Data;
128    elseif nargin == 4
129        if isstr(Field2)
130            AO.(Family).(Field1).(Field2) = Data;
131        else
132            % Field2 is a Element or DeviceList
133            if size(Field2,2) == 1
134                DeviceList = elem2dev(AO.(Family), Field2);
135            else
136                DeviceList = Field2;
137            end
138            if isempty(DeviceList)
139                DeviceList = family2dev(AO.(Family));
140            end
141            DeviceListTotal = getlist(AO.(Family),0);
142            DeviceIndex = findrowindex(DeviceList, DeviceListTotal);
143           
144            % If the number of row doesn't equal the DeviceList, then expand first
145            if size(AO.(Family).(Field1),1) == 1
146                AO.(Family).(Field1) = ones(size(DeviceListTotal,1),1) * AO.(Family).(Field1);
147            end
148           
149            AO.(Family).(Field1)(DeviceIndex,:) = Data;
150        end
151    elseif nargin == 5
152        if size(Field2,2) == 1
153            DeviceList = elem2dev(AO.(Family), DeviceList);
154        end
155        if isempty(DeviceList)
156            DeviceList = family2dev(AO.(Family));
157        end
158        DeviceListTotal = getlist(AO.(Family),0);
159        DeviceIndex = findrowindex(DeviceList, DeviceListTotal);
160
161        % If the number of row doesn't equal the DeviceList, then expand first
162        if size(AO.(Family).(Field1).(Field2),1) == 1
163            AO.(Family).(Field1).(Field2) = ones(size(DeviceListTotal,1),1) * AO.(Family).(Field1).(Field2);
164        end
165
166        AO.(Family).(Field1).(Field2)(DeviceIndex,:) = Data;
167    end
168    setao(AO);
169else
170    % Check the AD
171    AD = getad;
172    if nargin == 2
173        AD.(Family) = Data;
174    elseif nargin == 3
175        AD.(Family).(Field1) = Data;
176    elseif nargin == 4
177        AD.(Family).(Field1).(Field2) = Data;
178    end
179    setad(AD);
180end
181
Note: See TracBrowser for help on using the repository browser.