source: MML/trunk/mml/findrf.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: 3.7 KB
Line 
1function [DeltaRF, HCMEnergyChangeTotal, DeltaL] = findrf(varargin)
2%FINDRF - Finds the RF frequency that minimizes the energy change due
3%         to the horizonal correctors after the next orbit correction.
4%         Hopefully this method also finds an optimal RF frequency setting.
5%         As with anything, you should know what you are doing before
6%         running this function.  How the optimal RF frequency setpoint
7%         is found usually depends the type of accelerator.
8%
9%  INPUTS (optional)
10%  1. 'Display' - Plot orbit information {Default unless there are outputs variables}
11%     'NoDisplay' - No plot
12%  2. 'SetRF'   - Set the RF frequency (prompts for a setpoint change if 'Display' is on)
13%     'NoSetRF' - No RF frequency setpoint change
14%  3. 'Position' {Default} or 'Phase' for the x-axis units (if display is on)
15%  4. 'Online', 'Model', 'Manual', 'Hardware', 'Physics', etc. (the usual Units and Mode flags)
16%
17%  OUTPUTS
18%  1. DeltaRF - Half the RF change that equates to the energy change of the horizontal correctors
19%               This is a guess that seems to come close.  Iterating with orbit correction is required.
20%               The exact scaling will depend on the accelerator (.35 workd well at the ALS).  It's
21%               better to use orbitcorrectionmethods with the RF frequency restricted to not change the energy.
22%  2. DeltaEnergy - Total energy change due to the horizontal correctors
23%  3. DeltaL - Path length change that equates to the total energy change (DeltaEnergy)
24%
25%  NOTES
26%  1. Uses plotcm
27%
28%  See also rmdisp, plotcm, findrf1, orbitcorrectionmethods
29%
30%  Written by Greg Portmann
31
32
33if nargout == 0
34    DisplayFlag = 'Display';
35else
36    DisplayFlag = 'NoDisplay';
37end
38XAxisFlag = 'Position';
39ChangeRFFlag = 1;
40
41
42% Input parsing
43InputFlags = {};
44for i = length(varargin):-1:1
45    if isstruct(varargin{i})
46        % Ignor structures
47    elseif iscell(varargin{i})
48        % Ignor cells
49    elseif strcmpi(varargin{i},'struct')
50        % Just remove
51        varargin(i) = [];
52    elseif strcmpi(varargin{i},'numeric')
53        % Just remove
54        varargin(i) = [];
55    elseif strcmpi(varargin{i},'Position')
56        XAxisFlag = 'Position';
57        varargin(i) = [];
58    elseif strcmpi(varargin{i},'Phase')
59        XAxisFlag = 'Phase';
60        varargin(i) = [];
61    elseif strcmpi(varargin{i},'SetRF')
62        ChangeRFFlag = 1;
63        varargin(i) = [];
64    elseif strcmpi(varargin{i},'NoSetRF')
65        ChangeRFFlag = 0;
66        varargin(i) = [];
67    elseif strcmpi(varargin{i},'Display')
68        DisplayFlag = 'Display';
69        varargin(i) = [];
70    elseif strcmpi(varargin{i},'NoDisplay')
71        DisplayFlag = 'NoDisplay';
72        varargin(i) = [];
73    end
74end
75
76[DeltaRF, HCMEnergyChangeTotal, DeltaL] = plotcm(varargin{:}, DisplayFlag);
77DeltaRF = DeltaRF/2;
78
79
80% Set the RF frequency
81if ChangeRFFlag
82    if ~isempty(DeltaRF)
83        % Half the energy change seems to be a good RF change
84
85        if DisplayFlag
86            [RFUnits, RFUnitsString] = getunits('RF');
87            answer = inputdlg({strvcat(strvcat(sprintf('Recommend change in RF is %g %s (half the energy change is a guess)', DeltaRF, RFUnitsString), '  '), 'Change the RF frequency?')},'FINDRF',1,{sprintf('%g',DeltaRF)});
88            if isempty(answer)
89                fprintf('   No change was made to the RF frequency.\n');
90                return
91            end
92            DeltaRF = str2num(answer{1});
93        end
94        steprf(DeltaRF, varargin{:});
95        if DisplayFlag
96            fprintf('   RF frequency change by %f %s.\n', DeltaRF, RFUnitsString);
97        end
98    else
99        if DisplayFlag
100            error('RF frequency not changed because of a problem converting the units for dispersion and orbit to RF frequency.');
101        end
102    end
103end
104
105
Note: See TracBrowser for help on using the repository browser.