Re: Pointer Type Question [message #46505] |
Sun, 27 November 2005 06:39  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
IDLmastertobe writes:
> I am implementing something that can keep a copy of original data and reuse
> the original data later on.
>
> if(size(ydata, /n_dimensions) eq 3) then begin
> if(!firsty eq 1) then begin
> *yarr = ydata
> !firsty=0
> endif
> ydata = smooth(*yarr, [1, !smo, !smo])
> oyimage->SetProperty, data = ydata
> endif
>
> ydata has the original data I want to keep. After the first iteration,
> ydata will be overwritten. Therefore, I am tyring to get ydata to be
> copied by *yarr in the first iteration and afterwards I will "reload"
> *yarr into ydata so that the original data will be used every time. since
> I have no information in advance about the size of the ydata, I am using a
> dynamic variable that can copy ydata regardless type and size. I am using
> pointer, and I declare the *yarr point in a function that calls the above
> procedure as follows:
>
> yarr = ptr_new(/allocate_heap)
>
> but i get a error message "Pointer type required in this context: YARR."
> Does anyone know why?
Mr IDLmasterobe, no one knows why. As a computer programmer
it is your job to *find out* why. These are the kinds of
problems computer programmers deal with 15-20 times a day.
No one writes a program perfectly. (I came close once,
but it was a five liner.) We all have to learn to debug
what we have written.
So, what are the possibilities? (1) yarr is a pointer. This
is unlikely, since IDL is complaining about it. (2) yarr is
*not* a pointer. Then what is it? Have you looked? That might
give you a clue to how it got to be something that surprises you.
Can you find a place in your program flow where it *was* a pointer?
Then what happens between where it was a pointer and what it is now?
You might have to learn how to stop your program and step through
it, so you can see how and when it changes from one thing to
another.
My guess, just from observing your programming style from the
past month or so, is that yarr is a undefined variable when it
gets to this part of the program. If it is, then you have to
ask yourself the question "how did it get to be that way?"
Did you make an assumption about the variable? Did you forget
to pass it to the program? Did you misspell its name somewhere?
The possibilities are nearly endless. But in the end, it is
going to be a bug in your program (either in design or implementation)
that needs to be fixed. If you are going to be a programmer,
you are going to have to learn to do the fixing yourself.
Otherwise, you will *never* get a program working! :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Pointer Type Question [message #46592 is a reply to message #46505] |
Mon, 28 November 2005 06:43  |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
David Fanning wrote:
> that needs to be fixed. If you are going to be a programmer,
> you are going to have to learn to do the fixing yourself.
> Otherwise, you will *never* get a program working! :-)
>
I think what David is trying to say is that you should get a book about
the basics of IDL. He is just too modest to recommend his own (I can
recommend it, along with Liam Gumley's).
Benjamin
|
|
|