Re: pointer problems [message #66453 is a reply to message #66274] |
Fri, 08 May 2009 11:20   |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
<tkg@lanl.gov> wrote in message
news:4a103767-1b93-4173-a127-54266f79d290@x31g2000prc.google groups.com...
On May 7, 9:02 pm, "R.G. Stockwell" <noemai...@please.com> wrote:
> <t...@lanl.gov> wrote in message
>
> news:e7dfb99c-91cd-483f-93ba-9e13c31f659a@y33g2000prg.google groups.com...
>
>
>
>
>
>> I'm trying to store an array of pixel xy indicies for later output to
>> a text file. The number of xy pairs is different for each array
>> element. I'm trying to use pointers to do this with the following
>> code snippet:
>
>> xy = ptrarr(npixels, /ALLOC)
>
>> for ipixel = 0, npixels - 1 do begin
>
>> ; much snipped code
>
>> indi = where(superMask ne 0, count)
>
>> if (count gt 0) then *xy[ipixel] = array_indices(superMask,
>> indi)
>
>> ; more snipped code
>
>> endfor
>
> You need an else branch to assign the values of
> *xy in the case where count is = 0.
>
> Or else, accessing xy in the future can result in
> "variable is undefined" error messages.
>
> cheers,
> bob
> I saw that possibility and changed the code, but count
> doesn't have a 'zero' case in the test data I've used so far.
> Something else is causing the "variable is undefined" message.
> If this were a C program, I'd suspect a buffer overrun, but,
> being relatively new to IDL programming, I don't know how to
> avoid that in IDL.
.>Thanks,
> Tom
Well, why not check *xy in each iteration of the loop
(just before the endfor)
to make sure each element is indeed getting defined.
for instance: help,ipixel,ind,*xy[ipixel]
Another other code in the snipped parts that is redefining 'ipixel'?
Can you give us the line that causes the 'variable is undefined' message?
cheers,
bob
|
|
|