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

Home » Public Forums » archive » Re: 3D-coordinates of index returned MAX()
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: 3D-coordinates of index returned MAX() [message #34697 is a reply to message #34694] Sun, 06 April 2003 13:28 Go to previous messageGo to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
"David Fanning" <david@dfanning.com> wrote in message
news:MPG.18fa35faf111256f989b36@news.frii.com...
> Here is a reference:
>
> http://www.dfanning.com/tips/where_to_2d.html

Noting that the wheretomulti routine referred to on that page...

http://www.dfanning.com/tip_examples/wheretomulti.pro

...handles only 2D and 3D arrays, I wrote a version to handle any array
dimensionality. I called it MGH_INDN (heaven knows why). Source code is
included below my sig and there is (or will be) a copy included in the
Motley library @

http://www.dfanning.com/hadfield/README.html

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)


--- mgh_indn.pro ---
;+
; NAME:
; MGH_INDN
;
; PURPOSE:
; Convert a 1-D array index (as returned, for example, by the
; WHERE function) to an n-dimensional index
;
; CALLING SEQUENCE:
; result = MGH_INDN(ind1, dim)
;
; POSITIONAL PARAMETERS:
; ind1 (input, compulsory, integer, scalar)
; 1-D array index
;
; dim (input, compulsory, integer, vector)
; Dimensions of array for which n-dimensional index is required.
;
; RETURN VALUE:
; The function returns an integer vector, with the same number of
; elements as the dim argument, containing indices into the
; multi-dimensional array.
;
;########################################################### ################
;
; This software is provided subject to the following conditions:
;
; 1. NIWA makes no representations or warranties regarding the
; accuracy of the software, the use to which the software may
; be put or the results to be obtained from the use of the
; software. Accordingly NIWA accepts no liability for any loss
; or damage (whether direct of indirect) incurred by any person
; through the use of or reliance on the software.
;
; 2. NIWA is to be acknowledged as the original author of the
; software where the software is used or presented in any form.
;
;########################################################### ################
;
; MODIFICATION HISTORY:
; Mark Hadfield, 2003-02:
; Written.
;-
function mgh_indn, ind1, dim

compile_opt DEFINT32
compile_opt STRICTARR

if n_elements(ind1) ne 1 then $
message, 'A single 1-D index is required'

if n_elements(dim) eq 0 then $
message, 'A list of dimensions is required'

n_dim = n_elements(dim)

result = lonarr(n_dim)

n = ind1

for i=0,n_dim-1 do begin

result[i] = n mod dim[i]

n = n / dim[i]

endfor

if n gt 0 then $
message, 'There''s some left over!'

return, result

end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL objected oriented question
Next Topic: how to create .exe

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

Current Time: Wed Oct 08 19:29:05 PDT 2025

Total time taken to generate the page: 0.00522 seconds