Retrieving Curve Fit coeficients in procedure

Hello,

I have written a script which automatically loads a sequence of spectra and fits gaussians to them. At each interation of while a new spectrum is fitted. I need to store information from the fitting coeficients, which are stored in W_coef wave. However, I cannot do it. I can make a graph with the fitted wave, but I cannot manipulate the coeficients one. Here is how I have been doing it.
The error I get is that the wave doesnt existe. But shouldn't it be created after the fit? And If I run the procedure 2 times it works. It really is a mistery to me!!!
Thanks for any inputs,

Luiz

#pragma rtGlobals=1 // Use modern global access method.
Function FittingSpectra(,) // this is supposed to run after FileImport()
Variable i = 0
Variable numspect
string teste
Wave W_coef
//Wave W_sigma

Prompt numspect, "How many spectra are there?"
DoPrompt "Enter Values", numspect
Make/N = (numspect,2)/D Widths
Make/N = (numspect,2)/D Amplitdutes

do
//This fits a gaussian to ywave
CurveFit gauss $("wave"+num2str(i+1))[230,270]/X=$("wave"+num2str(i)) /D
Display $("fit_"+"wave"+num2str(i+1))
Display W_coef
Widths[i/2][0] = W_coef[3]
i = i+2
while (i < (2*numspect-1))

End
In order to access the coefficient wave created by the fit, use a Wave statement:

Wave W_coef

right after the call to CurveFit. The Wave statement has two effects:

1) At compile time, it tells Igor's compiler that "W_coef" is the name of a wave. Otherwise, the compiler doesn't know what that name refers to. The Display operation doesn't need this because it can only take a wave as input, so it just assumes that it is the name of a wave.

2) At run time, it tells Igor to go look for a wave called "W_coef". It connects the real wave with a local symbolic name, "W_coef" that just happens to be the same name as the real name of the wave.

To read more about WAVE statements, execute this Igor command:

DisplayHelpTopic "Wave References"

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com