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

Home » Public Forums » archive » get IDL to issue warning or throw error for mismatched arrays
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
get IDL to issue warning or throw error for mismatched arrays [message #93331] Thu, 16 June 2016 07:59 Go to next message
Markus Schmassmann is currently offline  Markus Schmassmann
Messages: 129
Registered: April 2016
Senior Member
is there any way to get IDL to issue a warning or throw an error in for
mismatched arrays like those below?

indgen(2,2)+indgen(3,3)
Re: get IDL to issue warning or throw error for mismatched arrays [message #93334 is a reply to message #93331] Thu, 16 June 2016 09:43 Go to previous messageGo to next message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
On Thursday, 16 June 2016 07:59:02 UTC-7, Markus Schmassmann wrote:
> is there any way to get IDL to issue a warning or throw an error in for
> mismatched arrays like those below?
>
> indgen(2,2)+indgen(3,3)

Hi Markus,

Here is the behaviour we see, that the result is the size of the "overlapping" of the two arrays:

IDL> help,indgen(2,2)+indgen(3,3)
<Expression> INT = Array[2, 2]


I was hopeful that COMPILE_OPT STRICTARRSUBS would help. Here's what it does, before:

IDL> a=indgen(5)
IDL> a[[3,4,5,6]]
3 4 4 4

... and after:

IDL> compile_opt strictarrsubs
IDL> a[[3,4,5,6]]
% Array used to subscript array contains out of range subscript: A.
% Execution halted at: $MAIN$

So, the STRICTARRSUBS is making a difference in that regard, but...

IDL> help,indgen(2,2)+indgen(3,3)
<Expression> INT = Array[2, 2]

It does not change the behaviour with different-shaped arrays. If you have to test arrays a and b for differing shape, a simple check is:

IF ~Array_Equal(Size(a, /DIMENSIONS), Size(b, /DIMENSIONS)) THEN ...

Hope this helps,
-Dick

Dick Jackson Software Consulting Inc.
Victoria, BC, Canada --- http://www.d-jackson.com
Re: get IDL to issue warning or throw error for mismatched arrays [message #93340 is a reply to message #93334] Fri, 17 June 2016 05:50 Go to previous messageGo to next message
Markus Schmassmann is currently offline  Markus Schmassmann
Messages: 129
Registered: April 2016
Senior Member
On 06/16/2016 06:43 PM, Dick Jackson wrote:
> On Thursday, 16 June 2016 07:59:02 UTC-7, Markus Schmassmann wrote:
>> is there any way to get IDL to issue a warning or throw an error in
>> for mismatched arrays like those below?
>>
>> indgen(2,2)+indgen(3,3)
> Here is the behaviour we see, that the result is the size of the
> "overlapping" of the two arrays: IDL> help,indgen(2,2)+indgen(3,3)
> <Expression> INT = Array[2, 2]
>
> I was hopeful that COMPILE_OPT STRICTARRSUBS would help. [...]
> but...
>
> IDL> help,indgen(2,2)+indgen(3,3) <Expression> INT = Array[2, 2]
>
> It does not change the behaviour with different-shaped arrays. If
> you have to test arrays a and b for differing shape, a simple check
> is:
>
> IF ~Array_Equal(Size(a, /DIMENSIONS), Size(b, /DIMENSIONS)) THEN ...
>
> Hope this helps,
unfortunately this is not news for me, I'm just looking for a way to
catch my own programming errors without many otherwise unnecessary tests
Re: get IDL to issue warning or throw error for mismatched arrays [message #94046 is a reply to message #93331] Wed, 04 January 2017 19:25 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Thursday, June 16, 2016 at 10:59:02 AM UTC-4, Markus Schmassmann wrote:
> is there any way to get IDL to issue a warning or throw an error in for
> mismatched arrays like those below?
>
> indgen(2,2)+indgen(3,3)

Just letting off steam here. I know that IDL does not have the ability to throw a warning for mismatched arrays. But I just embarrassed myself by reporting results based on a division y = a/b where a,b were both supposed to be 4096 x 4096 arrays. But I forgot to trim variable b from size 4100 x 4100 so I was dividing different sized arrays (and not getting any error from IDL).

I suppose there are times when one wants to divide different size arrays. I just can't think of any.
Re: get IDL to issue warning or throw error for mismatched arrays [message #94047 is a reply to message #93331] Thu, 05 January 2017 15:12 Go to previous messageGo to next message
Bill Nel is currently offline  Bill Nel
Messages: 31
Registered: October 2010
Member
On Thursday, June 16, 2016 at 10:59:02 AM UTC-4, Markus Schmassmann wrote:
> is there any way to get IDL to issue a warning or throw an error in for
> mismatched arrays like those below?
>
> indgen(2,2)+indgen(3,3)

I call the following routine, if there's any doubt about the size of the arrays I'm using:

;+
;**************************************************
FUNCTION ArrayTruncation, a, b, c, d
;**************************************************
;~ Detects whether array operations on a set of variables causes silent truncation. [Programming]
;
; IDL silently truncates the results of array operations to the smaller of the
; array operands. This is almost never what I want! It's particularly insidious
; when one of the operands is a one-element array produced by something like where().
;
; This routine detects such array truncation. It may be called with two, three or four arguments.
;
; Examples
; IDL> print, ArrayTruncation( [1,2,3], 4)
; 0
; IDL> print, ArrayTruncation( [1,2,3], [4])
; 1
; IDL> print, ArrayTruncation( [1,2,3], [4,5,6], 7)
; 0
; IDL> print, ArrayTruncation( [1,2,3], [6], 7)
; 1
; IDL> print, ArrayTruncation( [1,2,3], [6], 7, [4,5,6])
; 1
;
; Notes;
; 1) The method is to check whether the sum of the arguments has the same number of elements as the
; argument with the largest number of elements.
;
; See also:
;-

; Modification history:
;
; Oct 30 2007 W. Rigby, original.
; May 23 2008 changed oneliner category.
; Mar 11 2009 changed oneliner.
; Jul 27 2011 added a fourth argument
; Sep 16 2016 tweaked error messages

compile_opt DEFINT32, STRICTARRSUBS, STRICTARR

On_Error, !my_on_error

MsgPrefix = "[ArrayTruncation] "

case n_params() of
2: begin
na = n_elements(a)
nb = n_elements(b)
if ((na EQ 0) || (nb EQ 0)) then Message, /noname, MsgPrefix + "One or more of the arguments is undefined"
result = ( n_elements(a + b) NE max( [na, nb]))
end

3: begin
na = n_elements(a)
nb = n_elements(b)
nc = n_elements(c)
if ((na EQ 0) || (nb EQ 0) || (nc EQ 0)) then Message, /noname, MsgPrefix + "One or more of the arguments is undefined"
result = ( n_elements(a + b + c) NE max( [na, nb, nc]))
end

4: begin
na = n_elements(a)
nb = n_elements(b)
nc = n_elements(c)
nd = n_elements(d)
if ((na EQ 0) || (nb EQ 0) || (nc EQ 0) || (nd EQ 0)) then Message, /noname, MsgPrefix + "One or more of the arguments is undefined"
result = ( n_elements(a + b + c + d) NE max( [na, nb, nc, nd]))
end

else: Message, /noname, "Usage: ArrayTruncation(a, b [c [d]])"
endcase

return, result

end
Re: get IDL to issue warning or throw error for mismatched arrays [message #94048 is a reply to message #93331] Fri, 06 January 2017 05:21 Go to previous message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le jeudi 16 juin 2016 16:59:02 UTC+2, Markus Schmassmann a écrit :
> is there any way to get IDL to issue a warning or throw an error in for
> mismatched arrays like those below?
>
> indgen(2,2)+indgen(3,3)

You might use the list::ToArray() method, and throw the error :

IDL> help, (list(indgen(2,2),indgen(3,3))).ToArray()
% LIST::TOARRAY: Unable to concatenate arrays: Element 1
% Execution halted at: $MAIN$

while :

IDL> help, (list(indgen(2,2),indgen(2,2))).ToArray()
<Expression> INT = Array[2, 2, 2]

Cheers,
alx.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL 8,2 cannot call ENVI function
Next Topic: Mismatch between video frame dimensions and stream using Coyote graphics

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

Current Time: Wed Oct 08 13:32:44 PDT 2025

Total time taken to generate the page: 0.00683 seconds