User raw input
Skargaemer
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!
// 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:
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
May 14, 2008 at 06:26 am - Permalink