Indexing IDL matrices with vectors: some unexpected behavior for out of range values

IDL is not the most used language around, many of you might not even have heard of it. Mind you that by IDL I mean the Interactive Data Language, and not the Interface Description Language, which many more people know. IDL is stil used a lot in some scientific applications, for example in astronomy and remote sensing. IDL has some quirks which might catch you off guard. I just encountered one of those, which I would like to share. Note that this is valid for version 7 of IDL, which is not the latest one.

Assume we have the following matrix:

We can index this matrix in the following manner, observe that IDL indexing starts at zero:

Providing an invalid index nicely leads to an exception:

IDL is also vectorized, so we can pass vectors of indices to extract multiple values in one go:

But now comes the problem. Let’s pass some out of range indices as vectors:

In stead of throwing an exception, IDL happily returns the last valid value in that dimension, or in this case a pair of dimensions, i.e. 23. So, beware, when passing vectors of indices to an IDL array there is no out of range checking: you are on your own :).

Tagged with: , ,
Posted in IDL

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see