1 | function [BPM1, BPM2, FileName]=getbpm(varargin); |
---|
2 | %GETBPM - Returns the horizontal and vertical orbit |
---|
3 | % BPM = getbpm(Dimension, BPMList); |
---|
4 | % [BPMx, BPMy, FileName] = getbpm(Dimension=1='x'='h', BPMListx, BPMListy); |
---|
5 | % [BPMy, BPMx, FileName] = getbpm(Dimension=2='y'='v', BPMListy, BPMListx); |
---|
6 | % |
---|
7 | % INPUTS |
---|
8 | % 1. Dimension = 1, 'x', 'h' - First Output Horizontal, Second Vertical |
---|
9 | % 2, 'z', 'y', 'v' - First Output Vertical, Second Horizontal |
---|
10 | % else - defaults to Dimension=1 |
---|
11 | % 2. BPMlistx = Horizontal BPM device list (default: all BPMs) |
---|
12 | % 3. BPMlisty = Vertical BPM device list (default: all BPMs) |
---|
13 | % 4. 'Struct' will return a data structure |
---|
14 | % 'Numeric' will return a vector output {default} |
---|
15 | % 5. 'NoArchive' - No file archive {Default} |
---|
16 | % 'Archive' - Save a BPM data structure to \<DataRoot>\BPM\<BPMArchiveFile><Date><Time>.mat |
---|
17 | % To change the filename, included the filename after the 'Archive', '' to browse |
---|
18 | % |
---|
19 | % OUTPUTS |
---|
20 | % 1. BPM1 - Horizontal orbit vector or data structures |
---|
21 | % 2. BPM2 - vertical orbit vector or data structures |
---|
22 | % 3. Filename - Output filename if archived |
---|
23 | % |
---|
24 | % NOTE |
---|
25 | % 1. 'Struct', 'Numeric', and 'Archive' are not case sensitive |
---|
26 | % 2. All inputs are optional |
---|
27 | % 3. This function is usually used when it is useful to make Dimension a variable |
---|
28 | % |
---|
29 | % See also getx, getz, getbpm, getam, getpv |
---|
30 | |
---|
31 | % |
---|
32 | % Written by Gregory J. Portmann |
---|
33 | % Modified by Laurent S. Nadolski |
---|
34 | |
---|
35 | % [BPM1, BPM2]=getbpm(Dim, BPMlist, BPMlist2, 'struct', 'archive'); |
---|
36 | |
---|
37 | |
---|
38 | % Get input flags |
---|
39 | StructOutputString = 'numeric'; |
---|
40 | ArchiveFlag = 0; |
---|
41 | FileName = -1; |
---|
42 | for i = length(varargin):-1:1 |
---|
43 | if strcmpi(varargin{i},'struct') |
---|
44 | StructOutputString = 'struct'; |
---|
45 | varargin(i) = []; |
---|
46 | elseif strcmpi(varargin{i},'numeric') |
---|
47 | StructOutputString = 'numeric'; |
---|
48 | varargin(i) = []; |
---|
49 | elseif strcmpi(varargin{i},'archive') |
---|
50 | ArchiveFlag = 1; |
---|
51 | if length(varargin) > i |
---|
52 | % Look for a filename as the next input |
---|
53 | if ischar(varargin{i+1}) |
---|
54 | FileName = varargin{i+1}; |
---|
55 | varargin(i+1) = []; |
---|
56 | end |
---|
57 | end |
---|
58 | varargin(i) = []; |
---|
59 | end |
---|
60 | end |
---|
61 | |
---|
62 | |
---|
63 | % Get the dimension |
---|
64 | if length(varargin) == 0 |
---|
65 | Dim = 1; |
---|
66 | else |
---|
67 | Dim = varargin{1}; |
---|
68 | end |
---|
69 | |
---|
70 | if isstr(Dim) |
---|
71 | if strcmpi(Dim,'X') |
---|
72 | Dim = 1; |
---|
73 | elseif strcmpi(Dim,'Z') || strcmpi(Dim,'Y') |
---|
74 | Dim = 2; |
---|
75 | elseif strcmpi(Dim,'H') |
---|
76 | Dim = 1; |
---|
77 | elseif strcmpi(Dim,'V') |
---|
78 | Dim = 2; |
---|
79 | else |
---|
80 | Dim = 1; |
---|
81 | end |
---|
82 | end |
---|
83 | |
---|
84 | if (Dim == 2) |
---|
85 | if length(varargin) < 2 |
---|
86 | BPMlist = family2dev(getvbpmfamily); |
---|
87 | else |
---|
88 | BPMlist = varargin{2}; |
---|
89 | end |
---|
90 | if isempty(BPMlist) |
---|
91 | BPMlist = family2dev(getvbpmfamily); |
---|
92 | end |
---|
93 | BPM1 = gety(BPMlist, StructOutputString); |
---|
94 | else |
---|
95 | if length(varargin) < 2 |
---|
96 | BPMlist = family2dev(gethbpmfamily); |
---|
97 | else |
---|
98 | BPMlist = varargin{2}; |
---|
99 | end |
---|
100 | if isempty(BPMlist) |
---|
101 | BPMlist = family2dev(gethbpmfamily); |
---|
102 | end |
---|
103 | BPM1 = getx(BPMlist, StructOutputString); |
---|
104 | end |
---|
105 | |
---|
106 | if nargout >= 2, |
---|
107 | if (Dim == 2) |
---|
108 | if length(varargin) < 3 |
---|
109 | BPMlist2 = family2dev(gethbpmfamily); |
---|
110 | else |
---|
111 | BPMlist2 = varargin{3}; |
---|
112 | end |
---|
113 | if isempty(BPMlist2) |
---|
114 | BPMlist2 = family2dev(gethbpmfamily); |
---|
115 | end |
---|
116 | BPM2 = getx(BPMlist2, StructOutputString); |
---|
117 | else |
---|
118 | if length(varargin) < 3 |
---|
119 | BPMlist2 = family2dev(getvbpmfamily); |
---|
120 | else |
---|
121 | BPMlist2 = varargin{3}; |
---|
122 | end |
---|
123 | if isempty(BPMlist2) |
---|
124 | BPMlist2 = family2dev(getvbpmfamily); |
---|
125 | end |
---|
126 | BPM2 = gety(BPMlist2, StructOutputString); |
---|
127 | end |
---|
128 | end |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | % Archive data structure |
---|
133 | if ArchiveFlag |
---|
134 | if isempty(FileName) |
---|
135 | FileName = appendtimestamp(getfamilydata('Default', 'BPMArchiveFile'), clock); |
---|
136 | DirectoryName = getfamilydata('Directory','BPMData'); |
---|
137 | if isempty(DirectoryName) |
---|
138 | DirectoryName = [getfamilydata('Directory','DataRoot') 'BPM', filesep]; |
---|
139 | end |
---|
140 | |
---|
141 | % Make sure default directory exists |
---|
142 | DirStart = pwd; |
---|
143 | [DirectoryName, ErrorFlag] = gotodirectory(DirectoryName); |
---|
144 | cd(DirStart); |
---|
145 | |
---|
146 | [FileName, DirectoryName] = uiputfile('*.mat', 'Save BPM File to ...', [DirectoryName FileName]); |
---|
147 | if FileName == 0 |
---|
148 | FileName = ''; |
---|
149 | return |
---|
150 | end |
---|
151 | FileName = [DirectoryName, FileName]; |
---|
152 | elseif FileName == -1 |
---|
153 | FileName = appendtimestamp(getfamilydata('Default', 'BPMArchiveFile'), clock); |
---|
154 | DirectoryName = getfamilydata('Directory','BPMData'); |
---|
155 | if isempty(DirectoryName) |
---|
156 | DirectoryName = [getfamilydata('Directory','DataRoot') 'BPM', filesep]; |
---|
157 | end |
---|
158 | FileName = [DirectoryName, FileName]; |
---|
159 | end |
---|
160 | |
---|
161 | % If the filename contains a directory then make sure it exists |
---|
162 | [DirectoryName, FileName, Ext] = fileparts(FileName); |
---|
163 | DirStart = pwd; |
---|
164 | [DirectoryName, ErrorFlag] = gotodirectory(DirectoryName); |
---|
165 | BPMxData = getx('struct'); |
---|
166 | BPMyData = gety('struct'); |
---|
167 | save(FileName, 'BPMxData', 'BPMyData'); |
---|
168 | fprintf(' BPM data saved to %s.mat\n', [DirectoryName FileName]); |
---|
169 | if ErrorFlag |
---|
170 | fprintf(' Warning: %s was not the desired directory\n', DirectoryName); |
---|
171 | end |
---|
172 | cd(DirStart); |
---|
173 | FileName = [DirectoryName FileName]; |
---|
174 | end |
---|
175 | if FileName == -1 |
---|
176 | FileName = ''; |
---|
177 | end |
---|
178 | |
---|
179 | |
---|