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

Home » Public Forums » archive » negative array index in IDL8
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
negative array index in IDL8 [message #86374] Fri, 01 November 2013 10:38 Go to next message
chuxiangning is currently offline  chuxiangning
Messages: 17
Registered: September 2012
Junior Member
Hi All,
My first noobie post here. I wanted to turn off negative index in the following commands. New IDL return error for x[[-1,-2]], but not for x[-1]. Is there anyway that I can turn off the negative indexing completely?
Thank you in advance!


pro test_negative_index
COMPILE_OPT STRICTARRSUBS
x=INDGEN(10)
print,x[-1]
print,x[[-1,-2]]
end

Here is the result I got:
% Compiled module: TEST_NEGATIVE_INDEX.
9
% Array used to subscript array contains out of range subscript: X.
% Execution halted at: TEST_NEGATIVE_INDEX 6
Re: negative array index in IDL8 [message #86375 is a reply to message #86374] Fri, 01 November 2013 11:55 Go to previous messageGo to next message
suicidaleggroll is currently offline  suicidaleggroll
Messages: 14
Registered: September 2013
Junior Member
On Friday, November 1, 2013 11:38:03 AM UTC-6, chu xiangning wrote:
> Hi All,
>
> My first noobie post here. I wanted to turn off negative index in the following commands. New IDL return error for x[[-1,-2]], but not for x[-1]. Is there anyway that I can turn off the negative indexing completely?
>
> Thank you in advance!
>
>
>
>
>
> pro test_negative_index
>
> COMPILE_OPT STRICTARRSUBS
>
> x=INDGEN(10)
>
> print,x[-1]
>
> print,x[[-1,-2]]
>
> end
>
>
>
> Here is the result I got:
>
> % Compiled module: TEST_NEGATIVE_INDEX.
>
> 9
>
> % Array used to subscript array contains out of range subscript: X.
>
> % Execution halted at: TEST_NEGATIVE_INDEX 6

I'm following this thread with hopeful anticipation.

A lot of my colleagues (who are no longer here) used to write IDL code assuming that a negative index would cause an error. So for example if they used a where statement to find some match, rather than checking the number of matches and erroring if there were none, they would just directly subscript the array with the output, counting on the fact that IDL would crash with the negative subscript.

Bad programming practices aside, all of these programs now result in unpredictable behaviour in IDL8. Rather than combing through all of our old programs line by line to find these problems, it would be nice to add an option to turn off negative subscripting, since we never use it anyway for backwards compatibility.
Re: negative array index in IDL8 [message #86376 is a reply to message #86375] Fri, 01 November 2013 12:03 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
suicidaleggroll@gmail.com writes:

> I'm following this thread with hopeful anticipation.

"Get used to disappointment."

Wesley, The Princess Bride


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: negative array index in IDL8 [message #86377 is a reply to message #86376] Fri, 01 November 2013 13:05 Go to previous messageGo to next message
chuxiangning is currently offline  chuxiangning
Messages: 17
Registered: September 2012
Junior Member
Hi David,
So I assume there is no solution to this question yet, since you are the most experienced person in IDL. It seems I don't have to hunt the answer in IDL help forum either. Thanks all the same!
Best,
Xiangning Chu
On Friday, November 1, 2013 12:03:32 PM UTC-7, David Fanning wrote:
> suicidaleggroll@gmail.com writes:
>
>
>
>> I'm following this thread with hopeful anticipation.
>
>
>
> "Get used to disappointment."
>
>
>
> Wesley, The Princess Bride
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: negative array index in IDL8 [message #86378 is a reply to message #86377] Fri, 01 November 2013 13:31 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
chu xiangning writes:

> So I assume there is no solution to this question yet, since you are the most experienced person in IDL. It seems I don't have to hunt the answer in IDL help forum either. Thanks all the same!

Oh, I'm not even close to the most experienced person in IDL. I am
probably the person with most experience in IDL that hasn't managed to
turn that into a paying job. But, such is life, I guess. ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: negative array index in IDL8 [message #86379 is a reply to message #86377] Fri, 01 November 2013 15:18 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
Not the answer to the question you are asking, but if you are only using IDL8 or above, you could mindlessly add /NULL to all your WHERE() statements ( or write a simple script to do this). This is likely easier than adding tests for negative indices. --Wayne
Re: negative array index in IDL8 [message #86380 is a reply to message #86379] Fri, 01 November 2013 19:38 Go to previous messageGo to next message
chuxiangning is currently offline  chuxiangning
Messages: 17
Registered: September 2012
Junior Member
On Friday, November 1, 2013 3:18:24 PM UTC-7, wlandsman wrote:
> Not the answer to the question you are asking, but if you are only using IDL8 or above, you could mindlessly add /NULL to all your WHERE() statements ( or write a simple script to do this). This is likely easier than adding tests for negative indices. --Wayne

Thanks for the solution. It is ok for new codes. It is all the codes and packages already written that might return wrong results with IDL 8. And we can afford to change them. One simple solution is 'don't buy IDL 8'.
Re: negative array index in IDL8 [message #86381 is a reply to message #86380] Sat, 02 November 2013 06:42 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
I was thinking of a global search and replace of " WHERE( " with " WHERE( /NULL, " in all your old code.


On Friday, November 1, 2013 10:38:34 PM UTC-4, chu xiangning wrote:

>
> Thanks for the solution. It is ok for new codes. It is all the codes and packages already written that might return wrong results with IDL 8. And we can afford to change them. One simple solution is 'don't buy IDL 8'.
Re: negative array index in IDL8 [message #86382 is a reply to message #86380] Sat, 02 November 2013 07:43 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
chu xiangning writes:

> On Friday, November 1, 2013 3:18:24 PM UTC-7, wlandsman wrote:
>> Not the answer to the question you are asking, but if you are only using IDL8 or above, you could mindlessly add /NULL to all your WHERE() statements ( or write a simple script to do this). This is likely easier than adding tests for negative indices. --Wayne
>
> Thanks for the solution. It is ok for new codes. It is all the codes and packages already written that might return wrong results with IDL 8. And we can afford to change them. One simple solution is 'don't buy IDL 8'.

Yes, this will work for awhile, but not for too much longer. Sooner or
later someone you know who uses your software will have IDL 8 and then
the problem will reappear. :-)

This was a controversial decision when it was first contemplated. But,
put yourself in the place of the IDL developers. You want to make your
software fresh and relevant, and you want it to have some of the same
kind of features newer programming languages have. Here is a change you
can make that will make a great many people pleased and it can be done
without harming backwards compatibility for most of the programmers you
know personally (i.e., those professional programmers that understand
how the Where function works and don't rely on IDL errors to do their
programming for them).

What would you have done? It's a pretty close call for me. But, I
understand why you might decide not to let past bad programming
practices interfere with your need to improve the language. I don't hold
this decision against the folks at ExelisVis. And, in the positive
column, giving people incentive to write programs correctly might
actually pay off in the long run. ;-)

I say use a Grep program to search for instances of Where in your IDL
program library and spend a half a day fixing the damn things. It will
cost you half a day now, but you will be glad you did it for a long,
long time.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: negative array index in IDL8 [message #86475 is a reply to message #86382] Tue, 12 November 2013 12:21 Go to previous message
chuxiangning is currently offline  chuxiangning
Messages: 17
Registered: September 2012
Junior Member
On Saturday, November 2, 2013 7:43:28 AM UTC-7, David Fanning wrote:
Thanks for your response. Considering the huge amount of libraries out there, I have to adhere to IDL 7 after all efforts.

> chu xiangning writes:
>
>
>
>> On Friday, November 1, 2013 3:18:24 PM UTC-7, wlandsman wrote:
>
>>> Not the answer to the question you are asking, but if you are only using IDL8 or above, you could mindlessly add /NULL to all your WHERE() statements ( or write a simple script to do this). This is likely easier than adding tests for negative indices. --Wayne
>
>>
>
>> Thanks for the solution. It is ok for new codes. It is all the codes and packages already written that might return wrong results with IDL 8. And we can afford to change them. One simple solution is 'don't buy IDL 8'.
>
>
>
> Yes, this will work for awhile, but not for too much longer. Sooner or
>
> later someone you know who uses your software will have IDL 8 and then
>
> the problem will reappear. :-)
>
>
>
> This was a controversial decision when it was first contemplated. But,
>
> put yourself in the place of the IDL developers. You want to make your
>
> software fresh and relevant, and you want it to have some of the same
>
> kind of features newer programming languages have. Here is a change you
>
> can make that will make a great many people pleased and it can be done
>
> without harming backwards compatibility for most of the programmers you
>
> know personally (i.e., those professional programmers that understand
>
> how the Where function works and don't rely on IDL errors to do their
>
> programming for them).
>
>
>
> What would you have done? It's a pretty close call for me. But, I
>
> understand why you might decide not to let past bad programming
>
> practices interfere with your need to improve the language. I don't hold
>
> this decision against the folks at ExelisVis. And, in the positive
>
> column, giving people incentive to write programs correctly might
>
> actually pay off in the long run. ;-)
>
>
>
> I say use a Grep program to search for instances of Where in your IDL
>
> program library and spend a half a day fixing the damn things. It will
>
> cost you half a day now, but you will be glad you did it for a long,
>
> long time.
>
>
>
> Cheers,
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: derivative function in IDL similar as DIFF in matlab
Next Topic: covariance matrix

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

Current Time: Wed Oct 08 15:48:48 PDT 2025

Total time taken to generate the page: 0.00660 seconds