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

Home » Public Forums » archive » Padding arrays - vector subscripts not working
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: Padding arrays - vector subscripts not working [message #71647 is a reply to message #71586] Tue, 06 July 2010 13:48 Go to previous messageGo to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
I think this does it, but you should check. I am assuming that both
out and array have the same number of dimensions.

function pad, array, dims

;error checking, etc. removed for more compact newsgroup post

type = size(array, /type)
out = make_array(dims, type=type)

;calculate where to put the original array in the new
sz = size(array, /dimensions)
dimdiff=dims-sz
diff = dimdiff/2

out_strides = [1L, product(dims, /integer, /cumulative)]
out_ind = total(out_strides*diff, /integer) ;starting index where
out is to be set

array_ind=l64indgen(n_elements(array)) ;indexes of array to use in
out
out_ind+=array_ind ;make the index list a contiguous list starting
at out_ind
;if more than 1D, the section of out to be set may not be
contiguous, so make the jumps in the indexes at every dimension
array_strides = [1L, product(sz, /integer, /cumulative)]
for i=1,n_elements(dims)-1 do out_ind+=(array_ind/
array_strides[i])*dimdiff[i-1]*out_strides[i-1]

out[out_ind] = array[array_ind]
return, out
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Subtracting a single variable from an array
Next Topic: Opinions: passing paths, variables, etc. to compiled IDL routine

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

Current Time: Wed Oct 08 17:56:16 PDT 2025

Total time taken to generate the page: 0.00407 seconds