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

Home » Public Forums » archive » pointer problems
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
pointer problems [message #66274] Thu, 07 May 2009 11:55 Go to next message
tkg is currently offline  tkg
Messages: 2
Registered: May 2009
Junior Member
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

npixels can range anywhere from fewer than 100 to 200+ and the xy
pairs can be a few pair up to a few hundred.

I find that afer a few iterations of the loop (actually ten iterations
with the test data i'm using). previously allocated heap pointers are
losing their values and become undefined. This would seem to indicate
memory allocation problems (the heap pointers are being overwritten by
some other portion of the code) , but I'm not sure how to go about
troubleshooting it or what I might do to avoid the overwrites. There
are no other pointers used anywhere else in the code.

If anyone has a clue as to what the problem might be or a suggestion
for a better way to do this, I'd appreciate the help.

Thanks.
Tom
Re: pointer problems [message #66453 is a reply to message #66274] Fri, 08 May 2009 11:20 Go to previous message
R.G. Stockwell is currently offline  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
Re: pointer problems [message #66459 is a reply to message #66274] Fri, 08 May 2009 05:10 Go to previous message
tkg is currently offline  tkg
Messages: 2
Registered: May 2009
Junior Member
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
Re: pointer problems [message #66467 is a reply to message #66274] Thu, 07 May 2009 20:02 Go to previous message
R.G. Stockwell is currently offline  R.G. Stockwell
Messages: 363
Registered: July 1999
Senior Member
<tkg@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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: P value for the regression analysis?
Next Topic: Re: best image plotting routine

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

Current Time: Wed Oct 08 13:36:34 PDT 2025

Total time taken to generate the page: 0.00734 seconds