replace data path in Fit

Hi guys,

i m almost done with writnig my first own larger procedure. In one Function there is still samething, which doesnt work how it should:


Function fitSpotX()   // find and return x-component of maximum
	// read cursor positions
	Variable Ax=xcsr(A)
	Variable Ay=vcsr(A)
	Variable Bx=xcsr(B)
	Variable By=vcsr(B)
		
	//Fit area between cursors
	CurveFit/Q Gauss2D, :rawData:ONEOUTOFAHUNDRET [Ax,Bx][Ay,By] /D  
	Print "Maximum is at x0=" , K2,"y0=",K4
	
	//return x-coordinate of maximum
	return K2
End


So the data path needs to be generalized. It shall be always the uppermost Graph, so i tried a little with WinName(0,1)
Till now i couldnt find a solution, can anybody help?

Thanks!
Assuming that I understand what you want to do ...

If cursor A is assumed to be on the source wave for the fit in the top graph:

	Wave waveToFit = CsrWaveRef(A)


If the wave to be fit is assumed to be the first wave in the top graph:

	Wave waveToFit = WaveRefIndexed("", 0, 1)


Then use waveToFit as the source wave in your CurveFit command.
Thanks hrodstein,
works perfectly like this:


Function fitSpotX()   // find and return x-component ox maximum
	// read cursor positions
	Variable Ax=xcsr(A)
	Variable Ay=vcsr(A)
	Variable Bx=xcsr(B)
	Variable By=vcsr(B)
	
		//Fit area between cursors
	Wave waveToFit = CsrWaveRef(A)		//Fit will be from graph with cursor
	
	CurveFit/Q Gauss2D waveToFit [Ax,Bx][Ay,By] 
	Print "The center of this spot is at X=" , K2,"Y=",K4
	
	//return x-coordinate of maximum
	return K2
End