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

Home » Public Forums » archive » Re: array subscripting problem
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: array subscripting problem [message #43424 is a reply to message #43423] Mon, 11 April 2005 07:34 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Martin writes:

> Thanks David, could you expand on that a bit?
>
> I realise it's still only breakfast time over there!

I really need to fix my coffee before I look at the newsgroup. :-(

You wanted to know how to keep array subscripts from going
negative. If you compare the subscript with 0 and choose
the larger of the two with the "greater than" operator,
you will have achieved your goal. I'm not saying it will
be *correct*, but I am saying it will *not be negative*. :-)

Similarly, you can fix problems on the other end by using
the "less than" operator and checking that the index is
smaller than the size of the array.

array = indgen(100)
s = Size(array, /Dimensions)
print, array[0 > j < (s[0]-1)]

This will keep your index between the allowed indices of
the array. Be *sure* to include those parentheses! Leaving
them off is one of the classic gotchas.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: vector matrix multipication
Next Topic: Re: vector matrix multipication

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

Current Time: Sun Nov 30 23:43:53 PST 2025

Total time taken to generate the page: 0.72339 seconds