source: MML/trunk/mml/calceta.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.7 KB
Line 
1function [d, Dy] = calceta(d, varargin)
2%CALCETA - Calculates the dispersion function in physics or hardware units
3%  d=calceta(d,'Hardware')     Calculates dispersion in hardware units (converts if necessary)
4%  d=calceta(d,'Physics')      Calculates dispersion in physics  units (converts if necessary)
5%
6%  When not using structure inputs, assumptions have to be made about the units
7%  This function assumes that hardware units are mm/MHz and physics units are meters/Hz
8%  [Dx,Dy]=calceta(Dx,Dy,'Physics',mcf,rf)  Converts Dx,Dy from mm/MHz to m/(dp/p)
9%                                           ie, was measured using [Dx, Dy] = measdisp('Hardware')
10%  [Dx,Dy]=calceta(Dx,Dy,'Hardware',mcf,rf) Converts Dx,Dy from m/(dp/p) to mm/MHz
11%                                           ie, was measured using [Dx, Dy] = measdisp('Physics')
12%
13%  INPUTS
14%  1. d (dispersion structure) or Dx and Dy (vectors) as measure by measdisp
15%  2. 'Physics'  is a flag to plot dispersion function in physics units
16%     'Hardware' is a flag to plot dispersion function in hardware units
17%     ('Eta' can be used instead of 'Physics')
18%  3. mcf = momentum compaction factor (linear)
19%  4. rf  = rf frequency (MHz)
20%     rf and mcf input are only for nonstructure inputs when using the 'Physics' flag
21%
22%  OUTPUT
23%  1. d or [Dx, Dy] is dispersion function with new units
24%
25%  Note: 'Hardware' and 'Physics' are not case sensitive
26%
27%  See also measdisp, plotdisp
28%
29%  J. Corbett and G. Portmann (August 2003)
30
31
32UnitsFlag = '';
33MCF = [];
34RF0 = [];
35if nargin > 1
36    % Look if 'physics' or 'eta' are on the input line
37    for i = length(varargin):-1:1
38        if strcmpi(varargin{i},'eta') | strcmpi(varargin{i},'physics')
39            UnitsFlag = 'Physics';
40            if length(varargin) >= i+1
41                if isnumeric(varargin{i+1})
42                    MCF = varargin{i+1};
43                    if length(varargin) >= i+2
44                        if isnumeric(varargin{i+2})
45                            RF0 = varargin{i+2};
46                        end
47                    end
48                end
49            end
50        elseif strcmpi(varargin{i},'Hardware')
51            UnitsFlag = 'Hardware';
52            varargin(i) = [];   
53        elseif isempty(varargin{i})
54            % Remove empty
55            varargin(i) = [];   
56        else
57            if ischar(varargin{i}) 
58                % Unknown string input
59                fprintf('   WARNING:  Unknown input ''%s''ignored\n', varargin{i});
60                varargin(i) = [];
61            end
62        end
63    end
64end
65
66if isempty(UnitsFlag)
67    error('No units string input (Hardware or Physics)');
68end
69
70% Check if the input is a structure
71if isstruct(d)
72    if length(d) ~= 2
73        error('Supply proper structure array to calceta');
74    end
75   
76    MCF = d(1).MCF;
77   
78    if strcmpi(UnitsFlag,'Physics') & strcmpi(d(1).Units,'Hardware')
79        % Change to physics units
80        d = hw2physics(d);
81       
82        % Change to denominator to energy shift (dp/p)
83        RF0 = d(1).Actuator.Data;   
84        RF0 = RF0(1);  % Just in case someone has a vector for multiple cavities
85        d(1).Data = -RF0 * MCF * d(1).Data;
86        d(2).Data = -RF0 * MCF * d(2).Data;
87       
88        d(1).UnitsString = [d(1).Monitor.UnitsString,'/(dp/p)'];
89        d(2).UnitsString = [d(2).Monitor.UnitsString,'/(dp/p)'];
90    end
91   
92    if strcmpi(UnitsFlag,'Hardware') & strcmpi(d(1).Units,'Physics')
93        % Change to denominator to RF change
94        RF0 = d(1).Actuator.Data;   
95        RF0 = RF0(1);  % Just in case someone has a vector for multiple cavities
96        d(1).Data = d(1).Data / (-RF0 * MCF);
97        d(2).Data = d(2).Data / (-RF0 * MCF);
98       
99        % Change to hardware units
100        d = physics2hw(d);
101       
102        d(1).UnitsString = [d(1).Monitor.UnitsString,'/',d(1).Actuator.UnitsString];
103        d(2).UnitsString = [d(2).Monitor.UnitsString,'/',d(2).Actuator.UnitsString];
104    end
105    Dy = d(2).Data;
106   
107else
108    % Non structure inputs
109    Dx = d;
110    Dy = varargin{1};
111   
112    if strcmpi(UnitsFlag,'Physics')
113        % Convert to physics units
114        if ~isempty(RF0) & ~isempty(MCF)
115            % Change units to meters/(dp/p)
116            Dx = -RF0(1) * MCF * Dx / 1000;
117            Dy = -RF0(1) * MCF * Dy / 1000;
118        else
119            error('MCF and RF frequency not input');
120        end     
121    elseif strcmpi(UnitsFlag,'Hardware')
122        % Convert to hardware units
123        if ~isempty(RF0) & ~isempty(MCF)
124            % Change units to mm/MHz
125            Dx = 1000 * Dx / (-RF0(1) * MCF);
126            Dy = 1000 * Dy / (-RF0(1) * MCF);
127        else
128            error('MCF and RF frequency not input');
129        end     
130    else
131        error('Output units unknown');
132    end
133   
134    d = Dx;
135end
Note: See TracBrowser for help on using the repository browser.