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

Home » Public Forums » archive » Re: For loop avoidance - getting indices of real space
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: For loop avoidance - getting indices of real space [message #81161 is a reply to message #81158] Fri, 24 August 2012 02:32 Go to previous message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le jeudi 23 août 2012 22:58:48 UTC+2, simu...@gmail.com a écrit :
> I have read and re-read until cross-eyed this post: http://www.idlcoyote.com/tips/forloops.html
>
>
>
> And yet, I still can't quite grasp at how I can solve my for loop problem. I think it might involve the use of modulo (MOD), but I'm not sure how. My question is, how can you grab the indices (i,j,k) of a 3D array in real space, and throw them into basically 3 1D arrays that is just a list of all the cells in the "proper" order (column-major).
>
>
>
> Here is an example of what I mean:
>
>
>
> pro testreader
>
>
>
> xcells=15
>
> ycells=10
>
> zcells=20
>
> ncells=xcells*ycells*zcells
>
>
>
> data=dindgen(xcells,ycells,zcells)
>
> coord=intarr(ncells,3)
>
>
>
> index=0L
>
> for k=0,zcells do begin
>
> for j=0,ycells do begin
>
> for i = 0,xcells do begin
>
> coord(index,0)=i
>
> coord(index,1)=j
>
> coord(index,2)=k
>
> index=index+1
>
> endfor
>
> endfor
>
> endfor
>
>
>
> end
>
>
>
> This is a really simple version of a complex problem I have. I have sets of different size boxes from an AMR MHD code, and I need to keep track of their indices, but I just want a list of all of the cells, not to drag around a bunch of smaller arrays or try to concatenate them into one giant sparse array (waste of space). I'm certain that someone must have had this problem before, but I can't find any other suggestions on this forum.

If I understand well your problem, a solution might be:

IDL> coord = [ [lindgen(xcells)#replicate(1,ycells*zcells)], $
IDL> [lindgen(ycells)#replicate(1,xcells*zcells)], $
IDL> [lindgen(zcells)#replicate(1,xcells*ycells)] ]
IDL> coord = reform(coord,ncells,3,/OVER)

alain.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: How would you measure the range of density on a graph using IDL?
Next Topic: Re: image interplate and overlay lat/lon?

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

Current Time: Thu Oct 09 13:39:32 PDT 2025

Total time taken to generate the page: 0.64120 seconds