source: MML/trunk/mml/setoffset.m @ 4

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

Initial import--MML version from SOLEIL@2013

File size: 4.3 KB
Line 
1function varargout = setoffset(varargin)
2%SETOFFSET - Set the offset
3%  [DataStruct, ...] = setoffset(FamilyName, Data, DeviceList)
4%  [DataStruct, ...] = setoffset(FamilyName, FileName, DeviceList)
5%  [DataStruct, ...] = setoffset(FileName)
6%  [DataStruct, ...] = setoffset(DataStruct)
7%  [DataStruct, ...] = setoffset(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 offset
16%
17%  OUTPUTS
18%  1. DataStruct - The data structure with the new offset in the .Data field
19%
20%  NOTES
21%  1. The offset values are changed for the present Matlab session.  They are
22%     not saved for future sessions.  The offset orbit is usually set in the
23%     one of the initialization files (like setoperationalmode).
24%  2. This function calls setfamilydata.
25%
26%  See Also getoffset, saveoffsetorbit, plotoffsetorbit
27
28%
29%  Written by Gregory J. Portmann
30%  Modified by Laurent S. Nadolski
31
32BPMFamily = {gethbpmfamily; getvbpmfamily};
33
34Family = '';
35FileName = '';
36
37if nargin == 0
38    DirName = getfamilydata('Directory','BPMData');
39    [FileName, DirName] = uigetfile([DirName,filesep,'BPMOffset*.mat'], 'Select a data file:');
40
41    if FileName == 0
42        return;
43    end
44
45    FileName = [DirName, FileName];
46end
47
48
49if 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
63end
64
65if 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
84end
85
86
87DeviceListFlag = 0;
88if 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            varargout{1}.DeviceList = varargin{3};
96        end
97        DeviceListFlag = 1;
98    else
99        error('Input #3 unknown type: DeviceList expected.');
100    end
101end
102
103
104% Extra structures can be passed on
105for i = 4:nargin
106    if isstruct(varargin{i})
107        Family = [Family; {varargin{i}.FamilyName}];
108        varargout{i} = varargin{i};
109    end
110end
111
112   
113if ~isempty(FileName)
114    if isempty(Family)
115        Family = findmemberof('BPM');
116        if isempty(Family)
117            Family = BPMFamily;
118        end
119    end
120end
121
122
123for i = 1:length(Family)
124    if ~isempty(FileName)
125        if DeviceListFlag
126            varargout{i} = getdata(Family{i}, DeviceList, 'Struct', FileName);
127        else
128            varargout{i} = getdata(Family{i}, 'Struct', FileName);
129        end
130    end
131
132    if DeviceListFlag
133        [iFound, iNotFound] = findrowindex(DeviceList, varargout{i}.DeviceList);
134        if ~isempty(iNotFound)
135            error('Not all the devices are in the data set.');
136        end
137        varargout{i}.Data = varargout{i}.Data(iFound,:);
138        varargout{i}.DeviceList = varargout{i}.DeviceList(iFound,:);
139    end
140
141    if size(varargout{i}.Data,1) ~= size(varargout{i}.DeviceList,1)
142        error('The size of the data does not equal the number of devices.');
143    end
144   
145    setfamilydata(varargout{i}.Data, varargout{i}.FamilyName, 'Offset', varargout{i}.DeviceList);
146end
147
148
Note: See TracBrowser for help on using the repository browser.