User raw input

Skargaemer
Posts: 2
Joined: 2008-05-13
Location: United States

Hi there. I'm new to IGOR and I am having some trouble with the very basics of the syntax.

Right now I'm just trying to work on a template for later projects through which the user can specify a starting and ending X-value as well as an X-interval, and given the array of data IGOR will produce a numeric value for the area under the curve. I know that I should be using the 'Area' function as defined by IGOR, but I'm having trouble with the user input.

Could someone please help me out with a small snippet of code that prompts the reader to enter a starting and ending X-value as well as an X-interval? I then need to take that raw input and declare it as a variable that I can then use to calculate the area under the curve. (comments would be appreciated too, so I could follow the process and use it for future use).

Thanks for the help!


jjweimer
Posts: 241
Joined: 2007-08-14
Location: United States

The function below does what I think you want. I do not see how defining an INTERVAL is possible when the start and end are set.

// calculate the area of a SCALED y-wave
// after prompting user for x-start and x-end limits
 
Function CalcArea(ywave)
	wave ywave
 
	// define the start and end variables
 
	variable xs, xe
 
	// define the prompt phrases for the start and end variables
 
	prompt xs, "Start:"
	prompt xe, "End:"
 
	// put up the prompt to get the variables
 
	DoPrompt "Integration Limits", xs, xe
 
	// check the variables are not out of bounds
 
	// is xs less than the starting value of the wave?
 
	if (xs < pnt2x(ywave,0))
		xs = pnt2x(ywave,0)
	endif
 
	// is xe greater than the end value of the wave?
 
	if (xe > pnt2x(ywave,numpnts(ywave)-1))
		xe = pnt2x(ywave,numpnts(ywave)-1)
	endif
 
	// return the area of the wave between the given bounds
 
	return area(ywave,xs,xe)
end

To check this function, do the following on the command line:

make/o/n=100 test
SetScale/P x 21,0.5,"", test
test=1000-20*x+10*x^2
display test
print CalcArea(test)

HTH
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH


[ last edited May 14, 2008 - 07:26 ]

Back to top