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

Home » Public Forums » archive » Re: WHERE approaching Flatland
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
Re: WHERE approaching Flatland [message #34083] Wed, 19 February 2003 04:50
Haje Korth is currently offline  Haje Korth
Messages: 651
Registered: May 1997
Senior Member
I always use the function WHERETOMULTI below. (Sorry about the line spacing)

Haje

;************************ Beginning of wheretomulti.pro
************************


PRO WhereToMulti, Array, Indices, Col, Row, Frame

;+

; NAME: wheretomulti.pro

;

; FUNCTION: Convert WHERE output to 2d or 3d indices

;

; USAGE: WhereToMulti, Array, Indices, Col, Row, Frame

;

; INPUT ARGUMENTS:

; Array: the array that was WHERE'd

; Indices: the indices returned by WHERE

;

; OUTPUT ARGUMENTS:

; Col: Indices to first dimension.

; Row: Indices to second dimension.

; Frame: Indices to third dimension. Returned only for 3-d array.

;

; OPTIONAL ARGUMENTS:

;

; KEYWORDS:

;

; REQUIRED MODULES:

;

; SIDE EFFECTS:

;

; ERROR HANDLING:

; If Array is not a vector or matrix, all return values are set to zero

; and a message is written to the screen.

;

; NOTES:

;

; HISTORY:

; 1998 Sept 15 J.L.Saba Developed based on code from David Fanning's

; web site.

;

;- End of
prologue ------------------------------------------------------------ -


s = SIZE ( Array )


NCol = s[1]

Col = Indices MOD NCol


IF s[0] EQ 2 THEN BEGIN ; 2-d array

Row = Indices / NCol

ENDIF ELSE IF s[0] EQ 3 THEN BEGIN ; 3-d array

NRow = s(2)

Row = ( Indices / NCol ) MOD NRow

Frame = Indices / ( NRow * NCol )

ENDIF ELSE BEGIN ; neither 2d or 3d

Col = 0

Row = 0

Frame = 0

PRINT, 'WhereToMulti called with bad input. Array not a vector or matrix.'

HELP, Array

ENDELSE


RETURN

END


;*************************** End of wheretomulti.pro
***************************






--
Dr. Haje Korth
Space Physics Group
The Johns Hopkins University
Applied Physics Laboratory
MS MP3-E128
11100 Johns Hopkins Road
Laurel, MD 20723-6099
USA
Phone: 240-228-4033 (Washington), 443-778-4033 (Baltimore)
Fax: 240-228-0386 (Washington), 443-778-0386 (Baltimore)


"Sean Raffuse" <sean@me.wustl.edu> wrote in message
news:b2u1d0$1nc$1@newsreader.wustl.edu...
> Hello,
>
> Is there are 2-d version of where?
>
> I would like to do this:
>
> bad = where(Array[*,*,0] GT Array[*,*,5])
>
> Array[bad,1:5] = Array[bad,0]
>
> I know that doesn't work, but after having spent some time with IDL, I'm
> allergic to loops.
>
> Thanks in advance,
>
> Sean
>
>
>
Re: WHERE approaching Flatland [message #34090 is a reply to message #34083] Tue, 18 February 2003 13:48 Go to previous message
Wonko[3] is currently offline  Wonko[3]
Messages: 9
Registered: February 2003
Junior Member
sean@me.wustl.edu (Sean Raffuse) wrote:

> Is there are 2-d version of where?

> I would like to do this:

> bad = where(Array[*,*,0] GT Array[*,*,5])

> Array[bad,1:5] = Array[bad,0]

I do these things like this:

xy = (size(Array,/dim))[0] * (size(Array,/dim))[1]
for i = 1, 5 do Array[ bad + i*xy ] = Array[bad]

> I know that doesn't work, but after having spent some time with IDL,
> I'm allergic to loops.

Ummm... this should work:

n = n_elements( bad )
Array[ rebin(bad,n,5) + transpose(rebin((lindgen(5)+1)*xy,5,n)) ] =
rebin( array[bad], n, 5 )

Alex
--
Alex Schuster Wonko@wonkology.org PGP Key available
alex@pet.mpin-koeln.mpg.de
Re: WHERE approaching Flatland [message #34094 is a reply to message #34090] Tue, 18 February 2003 12:15 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Sean Raffuse (sean@me.wustl.edu) writes:

> Is there are 2-d version of where?
>
> I would like to do this:
>
> bad = where(Array[*,*,0] GT Array[*,*,5])
>
> Array[bad,1:5] = Array[bad,0]
>
> I know that doesn't work, but after having spent some time with IDL, I'm
> allergic to loops.

I think maybe you want to re-read that thread from a week
or so ago, entitled "Interesting Where Function Gotcha".

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: UNIQ without SORT
Next Topic: differences idl5.5 and idl5.6

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

Current Time: Wed Oct 08 11:32:15 PDT 2025

Total time taken to generate the page: 0.00687 seconds