index out of range

I am trying to modify a code for normalisation in igor 7. This code works was originally written in Igor4 and works fine with Igor6. But the same code generates the error "Index out of the range of wave Image" in Igor 7. I had carried out the necessary changes that was prescribed for Igor 7 but still the error generates. This error is not generated during the compiling the procedure but only during the execution of the procedure. the code is given below:


I would be grateful for the suggestions. I am also attaching the full procedure.
case "Norm X":
        rngopt=1
        yrng=ImgRange( 1, df+"y12_norm")
        Prompt yrng, "X Norm:  y1,y2"
        Prompt rngopt, "Norm X option:", popup, "None;Full Y"
        DoPrompt "X Norm Y-range", yrng, rngopt
            if (rngopt==2)
                yrng=ImgRange( 1, "image")  //or "axes"
            endif
            string/G $(df+"y12_norm")=yrng
            if (V_flag==1)
                SetDataFolder $curr
                abort
            endif
        variable y1, y2
        y1=NumFromList(0, yrng,",")
        y2=NumFromList(1, yrng,",")

        //Cursor/P A, profileV_y, x2pnt( Image, y1)
        //Cursor/P B, profileV_y, x2pnt( Image, y2)
       
        make/o/n=(nx) xtmp
        SetScale/P x xmin, xinc, "" xtmp
        // different methods of normalizing? NormImg in image_util??
        xtmp = AREA2D( Image, 1, y1, y2, x )
        Image /= xtmp[p]
        cmd="Image /= xtmp[p]"
        if (lockColors==0)
             AdjustCT()
        endif
        break


(igor tags added by John Weeks)
Hi,

First, if you use the igor tags, your code will be more readable on the forum. Is it possible some of it is missing as it is currently displayed. For example, what is the function adjustCT? This looks like it's missing or maybe it's in another procedure you use?

I think we need a bit more info to help. If you turn on the debugger, on what line is the Out of Range error thrown?
"I am attaching the full procedure"
Well, that's not a full function or macro that we could run. For instance, the definition of the variable "nx" is not within the code you posted.

When a run-time error occurs, it should tell you which line has the error. My guess is that is is the line Image /= xtmp[p]. My guess is that p is too big for xtmp.

You can get a better idea of what's going wrong using Igor's symbolic debugger: DisplayHelpTopic "The Debugger". Right-click in your procedure window and select "Enable Debugger". Right-click again and select "Debug on Error". Now run the procedure.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thank you sjr51 and John Weeks for your suggestions. I am totally new to Igor and this forum as well and trying to learn to work with the software. I will do what you suggested and get back. Thanks again.
That's a lot of code! Too much for us to analyze for you. But the screen shot you attached shows that you have the information required to figure out what's wrong.

No doubt the Index Out of Range error is coming from the use of the wave "img". The debugger is showing you that the value of axis is 1, so it must be img(y0)(x) that is going wrong. In the list "user-defined variables" you need to drage the divider between Value and Type to the right so that you can see the full information about img. You need to know the X and Y scaling of img, and compare that to the values of y0 and x. The value of y0 is 65- is that within the range of values allowed by the X scaling of img?

It appears that the SetScale operation just above the line flagged with the error should make indexing by "x" OK, except for one thing- it sets the X scaling regardless of the value of axis. I suspect you need something like this:
    if (axis == 1)
        SetScale/P y DimOffset(img,axis), DimDelta(img,axis), "" tmp
    else
        SetScale/P x DimOffset(img,axis), DimDelta(img,axis), "" tmp
    endif


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thank you John for your help. Though I did not understand fully about what you said, I am trying my best to follow it though. Forgive me if i trouble you some more regarding this due to my ignorance. But one thing I surely did not understand though was this procedure was running fine without any run-time error in Igor 6 but the same procedure was getting errors in Igor 7 even after successfully compiling it. I had also carried out the necessary changes in accordance to Igor 7, still giving me errors Why is it so?

Best Regards,
Rocky
Igor Pro 6.20 added bounds checking for wave assignments. For example:
#pragma rtGlobals = 3
Make/O test = {0,1}
test[2] = 2  // Assign to a non-existent point - Error in Igor Pro 6.20 or later


You can turn these tests off by using rtGlobals=1 instead of rtGlobals=3. Doing this means that you are ignoring erroneous behavior, so it is not recommended as a long-term solution.

However, the file you posted, Image Tool4042.ipf, uses rtGlobals=1, so that does not explain it. It may be a different error that Igor7 detects but Igor6 did not.

If you can create a simplified, self-contained experiment that illustrates the problem, attach it and I will see if I can figure out what the problem is.
johnweeks wrote:

No doubt the Index Out of Range error is coming from the use of the wave "img". The debugger is showing you that the value of axis is 1, so it must be img(y0)(x) that is going wrong. In the list "user-defined variables" you need to drage the divider between Value and Type to the right so that you can see the full information about img. You need to know the X and Y scaling of img, and compare that to the values of y0 and x. The value of y0 is 65- is that within the range of values allowed by the X scaling of img?

It appears that the SetScale operation just above the line flagged with the error should make indexing by "x" OK, except for one thing- it sets the X scaling regardless of the value of axis. I suspect you need something like this:
    if (axis == 1)
        SetScale/P y DimOffset(img,axis), DimDelta(img,axis), "" tmp
    else
        SetScale/P x DimOffset(img,axis), DimDelta(img,axis), "" tmp
    endif


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


Hi John,

My apologies as I have not been very clear about the problem and that it has been confusing you as well as other experts here due to my presentation of the problem.

I have carried out certain operation called X-normalization which is the part of the procedure that I have attached and I have attached the pics of the results of this operation step-wise.

Capture 1- This is the original image upon which the operation is to be carried out.

Capture 2- The area is selected for which the normalization is to be carried out and is indicated by the dashed lines

Capture 3- This pic indicates the Y-coordinates of the area selected. Here, I press 'Continue' button.

Capture 4- This is where the error is generated. I have dragged the gap between 'value' and 'type' and also the image (I guess
that is the normalized one. My guess could be wrong.)

Capture 5- After I press 'GO' in Capture 4, Capture 5 comes up with the resultant pic and the error in the procedure. But my
guess is that the normalization has been carried out as you can see the difference between Capture 1 and Capture 5.
The graph on the top of the image in both the cases indicates this.

In Capture 3, the coordinates were named as y1 and y2. But in Capture 4, they are named as x1 and x2. Are you saying that the error lies here?
Now, if the resultant image is in accordance with the Normalization operation that I carried out, the what is the error trying to tell me exactly?

Now, the new development is when I changed the pragma rtGlobals from 3 to 1, no error was generated. Does that mean that the result which i got was not in accordance with the Normalization operation that I carried out?

Now, rhodstein mentioned about some erroneous behavior due to change from 3 to 1. I totally agree with him, otherwise, the procedure would not have shown any error.

But, pardon my ignorance, I am still not able to understand this so called erroneous behavior that the procedure is showing due to change from 1 to 3. Even the Igor 7 manual did not mention any error of this kind.

Warm Regards,
Srinivas


Capture1.jpg (152.63 KB) Capture2.JPG (99.29 KB) Capture3.JPG (104.42 KB) Capture4.JPG (135.59 KB) Capture5.JPG (196.66 KB)
You really need to make a change to your SelectNumber code. SelectNumber always evaluates all of its parameters; it doesn't skip evaluating the non-selected numbers. And the non-selected expression can easily be out-or-range:

This code:

    tmp=SelectNumber(axis, img(x)(y), img(y0)(x) )


should be changed to:

    if (axis == 1)
        tmp= img(y0)(x)
    else
        tmp= img(x)(y)
    endif


--Jim Prouty
Software Engineer, WaveMetrics, Inc.