comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Help with pointers
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Help with pointers [message #91718] Fri, 14 August 2015 07:36 Go to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Hi

I return a 2D array in a Function (A DOUBLE = Array[216, 216]).

I wanted to return that array as a pointer and I did the following

A_Ptr = PTR_NEW(A, /NO_COPY)

RETURN, A_Ptr

I call this pointer on a different function like this:

Diff = total((A[ind] - B[ind])^2.)

But I got the following error:
"Unable to convert variable to type pointer."

I typed help, A, B
<PtrHeapVar9> DOUBLE = Array[216, 216]
B FLOAT = Array[216, 216]

I tried this as well Diff = total((*A[ind] - B[ind])^2.) but still doesn't work.

Can anyone please help with this?
Re: Help with pointers [message #91722 is a reply to message #91718] Fri, 14 August 2015 08:39 Go to previous messageGo to next message
zacharyanorman is currently offline  zacharyanorman
Messages: 17
Registered: July 2015
Junior Member
Your error is probably coming from referencing A when you should be referencing *A_ptr, which now contains the values of A. Here is an example of how to do this:


a = findgen(216,216)
b = 1.1*findgen(216,216)
A_ptr = ptr_new(a,/no_copy)
diff = total (*A_ptr - b)
print, diff
Re: Help with pointers [message #91724 is a reply to message #91722] Fri, 14 August 2015 08:52 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
This is in function 1

A_Ptr = PTR_NEW(A, /NO_COPY)

RETURN, A_Ptr

This is in function 2, A, B, ind

Diff = total((A[ind] - B[ind])^2.)
Re: Help with pointers [message #91725 is a reply to message #91724] Fri, 14 August 2015 09:30 Go to previous messageGo to next message
zacharyanorman is currently offline  zacharyanorman
Messages: 17
Registered: July 2015
Junior Member
If you just have one index that you are taking the difference of, you need to use parenthesis around the pointer to access that index. Here is an example:

a = findgen(216,216)
b = 1.1*findgen(216,216)
A_ptr = ptr_new(a,/no_copy)
ind = 5
diff = (*A_ptr)[ind]-b[ind]
print, diff
Re: Help with pointers [message #91732 is a reply to message #91725] Mon, 17 August 2015 01:44 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
That was very useful.

Got another error when I am calling function 1 (the function where I returned the array as pointer) in another function.

"Pointer expression not allowed in this context: <POINTER (<PtrHeapVar20>)>."

Happens to know what does this mean?
Re: Help with pointers [message #91733 is a reply to message #91732] Mon, 17 August 2015 09:13 Go to previous message
zacharyanorman is currently offline  zacharyanorman
Messages: 17
Registered: July 2015
Junior Member
Your best bet would be to go to the line where it says the error is coming from and see what the code is. Then you can do a HELP on the arguments for that line of code and see which one is incorrect. Maybe you are trying to use the pointer as the array, when you need to also use the asterisk (*) to properly get the pointer contents.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Write 3dimensional array as bsq-file without using ENVI Methods
Next Topic: to create & overlay a polygon shape file

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:09:20 PDT 2025

Total time taken to generate the page: 0.00487 seconds