negative array index in IDL8 [message #86374] |
Fri, 01 November 2013 10:38  |
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   |
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 #86377 is a reply to message #86376] |
Fri, 01 November 2013 13:05   |
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 #86382 is a reply to message #86380] |
Sat, 02 November 2013 07:43   |
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  |
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.")
|
|
|