Hello!
I was attempting to fit gaussians to some spectral lines and found the procedure gaussfit. In the help file an example procedure is listed (ex_gaussfit.pro). When I ran the program expressly as written I received the following error:
IlseDL> ex_gaussfit
Expected: 4.00000 1.00000 2.00000 1.00000
0.250000 0.0100000
% Keyword parameters not allowed in call.
% Execution halted at: EX_GAUSSFIT 25
C:\RSI\idl\Default\ex_gaussfit.pro
% $MAIN$
In the example, gaussfit is called upon like this:
yfit = GAUSSFIT(x, y, coeff, NTERMS=nterms)
So I tried running it like this:
yfit = GAUSSFIT(x, y, coeff)
Since nterms was an optional input parameter.
I then got the error:
IlseDL> ex_gaussfit
Expected: 4.00000 1.00000 2.00000 1.00000
0.250000 0.0100000
% Attempt to subscript A with is out of range.
% Error occurred at: FUNCT 51 C:\RSI\idl\funct.pro
% CURVEFIT 88 C:\RSI\idl\curvefit.pro
% GAUSSFIT 62 C:\RSI\idl\gaussfit.pro
% EX_GAUSSFIT 25
C:\RSI\idl\Default\ex_gaussfit.pro
% $MAIN$
% Execution halted at: EX_GAUSSFIT 25
C:\RSI\idl\Default\ex_gaussfit.pro
Does anybody have any ideas? I tried creating some random graphs and applying gaussfit to those via the command line but got similar errors. Is it something to do with my IDL? I have 7.0
Thank you.
Ilse Cleeves
pro ex_gaussfit
; Define the independent variable.
n = 101
x = (FINDGEN(n)-(n/2))/4
; Define the coefficients.
a = [4.0, 1.0, 2.0, 1.0, 0.25, 0.01]
print, 'Expected: ', a
z = (x - a[1])/a[2] ; Gaussian variable
!P.MULTI = [0,2,2] ; set up 2x2 plot window
seed = 123321 ; Pick a starting seed value
for nterms=3,6 do begin
; Define the dependent variables. Start with random noise.
y = 0.4*RANDOMN(seed, n)
; Use a switch statement so we fall through to each term.
switch nterms of
6: y = y + a[5]*x^2
5: y = y + a[4]*x
4: y = y + a[3]
3: y = y + a[0]*exp(-z^2/2)
endswitch
; Fit the data to the function, storing coefficients in
; coeff:
yfit = GAUSSFIT(x, y, coeff, NTERMS=nterms)
print, 'Result: ', coeff[0:nterms-1]
; Plot the original data and the fitted curve:
PLOT, x, y, TITLE='nterms='+STRTRIM(nterms,2)
OPLOT, x, yfit, THICK=2
endfor
end
|