Basic Programming Issue

Since I am new to Igor Pro, I have been passing through the Image Processing example experiment. I attempted to copy and paste a section of the tutorial code in a procedure file of my own in order to use it in another experiment. However, for some reason the code will not compile even though it is copied and pasted straight from the tutorial. Even stranger is that executing each line of code individually successfully carries out the procedure, yet executing the function does not. I do not understand why the code will not compile in light of the fact that it is clearly functioning. The following is the working procedure and the associated compilation error messages:

Function AnalyzeParticles()
     TutorialCleanup() 
     Duplicate/O root:images:screws screws     
     NewImage screws
     screws=screws==163 ? 255:0    
     ImageMorphology /O/I=2/E=1 binarydilation screws
     ImageMorphology /O/I=2/E=1 erosion screws
     ImageAnalyzeParticles/E/W/Q/M=3/A=5/F/B stats, screws  
     NewImage root:images:screws   
     AutoPositionWindow/E $WinName(0,1)
     AppendToGraph/T W_BoundaryY vs W_BoundaryX
     AppendToGraph/T W_SpotY vs W_SpotX
     Duplicate/O w_spotx w_index
     w_index=p
     ModifyGraph mode(W_SpotY)=3
     ModifyGraph textMarker(W_SpotY)={w_index,"default",1,0,5,0.00,0.00}
     ModifyGraph msize(W_SpotY)=6
     Display/W=(23.4,299.6,297,511.4) W_ImageObjArea vs W_ImageObjPerimeter
     ModifyGraph mode=3,textMarker(W_ImageObjArea)={w_index,"default",0,0,5,0.00,0.00}
     ModifyGraph msize=6
     AutoPositionWindow/E $WinName(0,1)
     Make/O/N=(DimSize(M_Moments,0)) ecc
     ***ecc=sqrt(1-M_Moments[p][3]^2/M_Moments[p][2]^2)
     Display /W=(23.4,299.6,297,511.4) ecc
     ModifyGraph mode=3,textMarker(ecc)={w_index,"default",0,0,5,0.00,0.00}
     ModifyGraph msize=6
     AutoPositionWindow/E $WinName(0,1)
     ***imageAnalyzeParticles /L=(w_spotX[9],w_spotY[9]) mark screws
     NewImage M_ParticleMarker
     displayColorClasses()
End

***indicate the lines of code causing the problem

Error message 1:
unknown/inappropriate name or symbol
Error in Procedure:AnalyzeParticles()
ecc=sqrt(1-M_Moments[p][3]^2/M_Moments[p][2]^2)

Error message 2:
unknown/inappropriate name or symbol
Error in Procedure:AnalyzeParticles()
imageAnalyzeParticles /L=(w_spotX[9],w_spotY[9]) mark screws


Does anyone have any idea what could be the cause of this? Thank you all in advance.

-Jrsocas
The code in question is expected to be run in the Tutorial experiment. The experiment contains (in the main procedure window) a number of functions that are used in the code as well as sample image data arranged in specific data folders.

I recommend that you try the segments that are of interest to you while running the Tutorial experiment. After that extract only the relevant commands and use those in your code. Determining the relevant commands may be difficult at first but it is an essential step in understanding how to use IGOR.

A.G.
WaveMetrics, Inc.
You are also missing some concepts about accessing waves and global variables from functions. To learn about this execute:
DisplayHelpTopic "Accessing Global Variables And Waves"