1 | function varargout = setgolden(varargin) |
---|
2 | %SETGOLDEN - Set the golden values |
---|
3 | % [DataStruct, ...] = setgolden(FamilyName, Data, DeviceList) |
---|
4 | % [DataStruct, ...] = setgolden(FamilyName, FileName, DeviceList) |
---|
5 | % [DataStruct, ...] = setgolden(FileName) |
---|
6 | % [DataStruct, ...] = setgolden(DataStruct) |
---|
7 | % [DataStruct, ...] = setgolden(DataStruct1, DataStruct2, ...) |
---|
8 | % |
---|
9 | % INPUTS |
---|
10 | % 1. FamilyName - Family to set the offset field {Default: BPM families} |
---|
11 | % (can be a cell array of families) |
---|
12 | % DataStruct - Data structure input (.FamilyName, .Data, and .DeviceList fields are used) |
---|
13 | % FileName - Data structure input can be in a file |
---|
14 | % 2. Data - Data vector to set |
---|
15 | % 3. DeviceList - Device list to change of the golden parameters |
---|
16 | % |
---|
17 | % OUTPUTS |
---|
18 | % 1. DataStruct - The data structure with the new golden parameters in the .Data field |
---|
19 | % |
---|
20 | % NOTES |
---|
21 | % 1. The golden values are changed for the present Matlab session only. They are |
---|
22 | % not saved for future sessions. The golden orbit is usually set in the |
---|
23 | % one of the initialization files (like setoperationalmode). |
---|
24 | % 2. This function calls setfamilydata. |
---|
25 | % |
---|
26 | % See Also savegoldenorbit, getgolden, plotgoldenorbit |
---|
27 | |
---|
28 | % |
---|
29 | % Written by Gregory J. Portmann |
---|
30 | % Modifid by Laurent S. Nadolski |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | Family = ''; |
---|
35 | FileName = ''; |
---|
36 | |
---|
37 | if nargin == 0 |
---|
38 | DirName = getfamilydata('Directory','BPMData'); |
---|
39 | [FileName, DirName] = uigetfile([DirName,filesep,'BPMGolden*.mat'], 'Select a data file:'); |
---|
40 | |
---|
41 | if FileName == 0 |
---|
42 | return; |
---|
43 | end |
---|
44 | |
---|
45 | FileName = [DirName, FileName]; |
---|
46 | end |
---|
47 | |
---|
48 | |
---|
49 | if nargin >= 1 |
---|
50 | if iscell(varargin{1}) |
---|
51 | Family = varargin{1}; |
---|
52 | elseif isstruct(varargin{1}) |
---|
53 | Family = {varargin{1}.FamilyName}; |
---|
54 | varargout{1} = varargin{1}; |
---|
55 | elseif isfamily(varargin{1}) |
---|
56 | Family{1} = {varargin{1}}; |
---|
57 | varargout{1}.FamilyName = varargin{1}; |
---|
58 | elseif isstr(varargin{1}) |
---|
59 | FileName = varargin{1}; |
---|
60 | else |
---|
61 | error('Input #1 unknown type: Family or Filename expected.'); |
---|
62 | end |
---|
63 | end |
---|
64 | |
---|
65 | if nargin >= 2 |
---|
66 | if isstruct(varargin{2}) |
---|
67 | Family = [Family; {varargin{2}.FamilyName}]; |
---|
68 | varargout{2} = varargin{2}; |
---|
69 | elseif isstr(varargin{2}) |
---|
70 | FileName = varargin{2}; |
---|
71 | elseif isnumeric(varargin{2}) |
---|
72 | varargout{1}.Data = varargin{2}; |
---|
73 | elseif isempty(varargin{2}) |
---|
74 | %DirName = getfamilydata('Directory','BPMData'); |
---|
75 | DirName = getfamilydata('Directory','DataRoot'); |
---|
76 | [FileName, DirName] = uigetfile([DirName,filesep,'*.mat'], 'Select data file:'); |
---|
77 | if FileName == 0 |
---|
78 | return; |
---|
79 | end |
---|
80 | FileName = [DirName, FileName]; |
---|
81 | else |
---|
82 | error('Input #2 unknown type: Data or Filename expected.'); |
---|
83 | end |
---|
84 | end |
---|
85 | |
---|
86 | |
---|
87 | DeviceListFlag = 0; |
---|
88 | if nargin >= 3 |
---|
89 | if isstruct(varargin{3}) |
---|
90 | Family = [Family; {varargin{3}.FamilyName}]; |
---|
91 | varargout{3} = varargin{3}; |
---|
92 | elseif isnumeric(varargin{3}) |
---|
93 | DeviceList = varargin{3}; |
---|
94 | if ~isfield(varargin{1}, 'DeviceList') |
---|
95 | % Laurent ligne commente la suivante |
---|
96 | % varargin{1}.DeviceList = varargin{3}; |
---|
97 | % Laurent ligne suivante |
---|
98 | varargout{1}.DeviceList = varargin{3}; |
---|
99 | end |
---|
100 | DeviceListFlag = 1; |
---|
101 | else |
---|
102 | error('Input #3 unknown type: DeviceList expected.'); |
---|
103 | end |
---|
104 | end |
---|
105 | |
---|
106 | |
---|
107 | % Extra structures can be passed on |
---|
108 | for i = 4:nargin |
---|
109 | if isstruct(varargin{i}) |
---|
110 | Family = [Family; {varargin{i}.FamilyName}]; |
---|
111 | varargout{i} = varargin{i}; |
---|
112 | end |
---|
113 | end |
---|
114 | |
---|
115 | |
---|
116 | if ~isempty(FileName) |
---|
117 | if isempty(Family) |
---|
118 | Family = findmemberof('BPM'); |
---|
119 | if isempty(Family) |
---|
120 | Family = {gethbpmfamily; getvbpmfamily}; |
---|
121 | end |
---|
122 | end |
---|
123 | end |
---|
124 | |
---|
125 | |
---|
126 | for i = 1:length(Family) |
---|
127 | if ~isempty(FileName) |
---|
128 | if DeviceListFlag |
---|
129 | varargout{i} = getdata(Family{i}, DeviceList, 'Struct', FileName); |
---|
130 | else |
---|
131 | varargout{i} = getdata(Family{i}, 'Struct', FileName); |
---|
132 | end |
---|
133 | end |
---|
134 | |
---|
135 | if DeviceListFlag |
---|
136 | [iFound, iNotFound] = findrowindex(DeviceList, varargout{i}.DeviceList); |
---|
137 | if ~isempty(iNotFound) |
---|
138 | error('Not all the devices are in the data set.'); |
---|
139 | end |
---|
140 | varargout{i}.Data = varargout{i}.Data(iFound,:); |
---|
141 | varargout{i}.DeviceList = varargout{i}.DeviceList(iFound,:); |
---|
142 | end |
---|
143 | |
---|
144 | if size(varargout{i}.Data,1) ~= size(varargout{i}.DeviceList,1) |
---|
145 | error('The size of the data does not equal the number of devices.'); |
---|
146 | end |
---|
147 | |
---|
148 | setfamilydata(varargout{i}.Data, varargout{i}.FamilyName, 'Golden', varargout{i}.DeviceList); |
---|
149 | end |
---|