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

Home » Public Forums » archive » Re: weird behaviour with cgdemodata
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: weird behaviour with cgdemodata [message #76611] Tue, 21 June 2011 10:53 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeremy Bailin writes:

> I'm sure there's a good reason why this happens, but it has me very confused:
>
> IDL> i = 5
> IDL> print, i, n_elements(cgdemodata(i))
> 4 65536
>
> Okay, that looks fine. Now what if I put that in a for loop?
>
>
> IDL> for i=0,5 do print, i, n_elements(cgdemodata(i))
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> 0 101
> ...repeat ad infinutm, i.e. until you hit Ctrl-C
>
>
> What is going on???

This is one of those "pass by reference" things that
drives you crazy every once in awhile. It turns out
I am actually *changing* the value of the variable
number in the code. (It never occurred to me someone
would call this function in a loop, for God's sake!!)

If you pass the value "i" by value, you should get
what you expect:

IDL> for i=0,5 do print, i, n_elements(cgdemodata(i[0]))
0 101
1 101
2 1681
3 1681
4 65536
5 65536

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Composite images
Next Topic: IDL IMAGE NAVIGATION

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

Current Time: Wed Oct 08 13:33:18 PDT 2025

Total time taken to generate the page: 0.00435 seconds