source: MML/trunk/mml/gettune.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: 4.0 KB
Line 
1function [Tune, tout, DataTime, ErrorFlag] = gettune(varargin)
2%GETTUNE - Returns the betatron tunes
3%  | Higher Fractional Tune (X) |
4%  |                            | = gettune(t, FreshDataFlag, TimeOutPeriod)
5%  |  Lower Fractional Tune (Y) |
6%
7%  INPUTS
8%  1. t, FreshDataFlag, TimeOutPeriod (see help getpv for details)
9%  2. 'Struct'  - Output will be a response matrix structure
10%     'Numeric' - Output will be a numeric matrix {default}
11%  3. Optional override of the units:
12%     'Physics'  - Use physics  units
13%     'Hardware' - Use hardware units
14%  4. Optional override of the mode:
15%     'Online'    - Get data online 
16%     'Simulator' - Get data on the simulated accelerator using AT
17%     'Model'     - Same as 'Simulator'
18%     'Manual'    - Get data manually
19%
20%  OUTPUTS
21%  1. Fractional tune
22%  2. tout     (see help getpv for details)
23%  3. DataTime (see help getpv for details)
24%  4. ErrorFlag =  0   -> no errors
25%                 else -> error or warning occurred
26%
27%  NOTES
28%  1. An easy way to measure N averaged tunes is mean(gettune(1:2:N)')' (2 seconds between measurements)
29%
30% See also steptune, settune
31
32%
33% Written by Gregory J. Portmann
34% Modified by Laurent S. Nadolski
35
36DisplayFlag = 0;
37for i = length(varargin):-1:1
38    if isstruct(varargin{i})
39        % Ignore structures
40    elseif iscell(varargin{i})
41        % Ignore cells
42    elseif strcmpi(varargin{i},'Display')
43        DisplayFlag = 1;
44        varargin(i) = [];
45    elseif strcmpi(varargin{i},'NoDisplay')
46        DisplayFlag = 0;
47        varargin(i) = [];
48    end
49end
50 
51%% get betatron tunes
52[Tune, tout, DataTime] = getpv('TUNE', 'Monitor', [1 1; 1 2], varargin{:});
53
54%% Complete structure
55if isstruct(Tune)
56    TuneUnitsString = getfamilydata('TUNE','Monitor','HWUnits');
57    if isempty(TuneUnitsString)
58        Tune.UnitsString = 'Fractional Tune';
59    else
60        Tune.UnitsString = TuneUnitsString;
61    end
62    Tune.DataDescriptor = 'TUNE';
63    Tune.CreatedBy = 'gettune';
64end
65
66%% Display to the screen
67if DisplayFlag
68   fprintf('\n  Horizontal Tune = %f\n', Tune(1));
69   fprintf('    Vertical Tune = %f\n\n', Tune(2));
70end
71
72
73% % Get data at every point in time vector, t
74% t_start = gettime;
75% for i = 1:length(t)
76%     T = t(i)-(gettime-t_start);
77%     if T > 0
78%         pause(T);
79%     end
80%     tout(i) = gettime - t_start;
81%     
82%     [Tune(:,i), ErrorFlag] = local_gettune;
83%         
84%     if FreshDataFlag
85%         FreshDataCounter = FreshDataFlag;
86%         t0 = gettime;
87%         Tune0 = Tune(:,i);
88%         while FreshDataCounter
89%             [Tune(:,i), ErrorFlag] = local_gettune;
90%             
91%             if ~any((Tune(:,i)-Tune0)==0)
92%                 FreshDataCounter = FreshDataCounter - 1;
93%             end
94%             
95%             if (gettime-t0)> TimeOutPeriod
96%                 error('Timed out waiting for fresh tune data.');
97%                 %ErrorFlag = 1;
98%                 %break
99%             end
100%         end
101%     end
102% end   
103%
104% % if nargout == 0
105% %     fprintf('\n   Horizontal Tune = %f\n', Tune(1,1));
106% %     fprintf('     Vertical Tune = %f\n\n', Tune(2,1));
107% % end
108%
109%
110%
111% function [Tune, ErrorFlag] = local_gettune
112%
113% ErrorFlag = 0;
114%
115% [FamilyIndex, ACCELERATOR_OBJECT] = isfamily('TUNE');
116%
117% if isfield(ACCELERATOR_OBJECT, 'Mode')
118%     Mode = ACCELERATOR_OBJECT.Mode;
119% else
120%     Mode = 'Online';
121% end
122%
123% if strcmp(lower(Mode),'online')
124%     
125%     RFam = getam('TUNE');
126%         
127% elseif strcmp(lower(Mode),'simulator')
128%     
129%     global THERING
130%     if isempty(THERING)
131%         error('Simulator variable is not setup properly.');
132%     end
133%     
134%     [TD, Tune1] = twissring(THERING,0,1:length(THERING)+1);
135%     Tune = Tune1' + rand(2,1)*.0001;
136%     
137% elseif strcmp(lower(Mode),'manual')
138%     
139%     Tune(1,1) = input('   Input the horizontal tune = ');
140%     Tune(2,1) = input('   Input the vertical   tune = ');
141%
142% elseif strcmp(lower(Mode),'als')
143%     
144%     Tune = gettune_als;
145%
146% else
147%
148%     error(sprintf('Unknown mode for family %s.', ACCELERATOR_OBJECT.FamilyName));
149%     
150% end
Note: See TracBrowser for help on using the repository browser.