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

Home » Public Forums » archive » For loop avoidance - getting indices of real space
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
For loop avoidance - getting indices of real space [message #81163] Thu, 23 August 2012 13:58 Go to next message
simulana is currently offline  simulana
Messages: 15
Registered: August 2012
Junior Member
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.
Re: For loop avoidance - getting indices of real space [message #81226 is a reply to message #81163] Tue, 28 August 2012 14:41 Go to previous messageGo to next message
JDS is currently offline  JDS
Messages: 94
Registered: March 2009
Member
On Thursday, August 23, 2012 4:58:48 PM UTC-4, simu...@gmail.com wrote:
> I have read and re-read until cross-eyed this post: http://www.idlcoyote.com/tips/forloops.html

Just for the record, that particular post was made almost entirely in jest: sometimes a for loop is indeed what you want.

JD
Re: For loop avoidance - getting indices of real space [message #81451 is a reply to message #81226] Fri, 21 September 2012 13:06 Go to previous message
simulana is currently offline  simulana
Messages: 15
Registered: August 2012
Junior Member
On Tuesday, August 28, 2012 5:41:29 PM UTC-4, JDS wrote:
> On Thursday, August 23, 2012 4:58:48 PM UTC-4, simu...@gmail.com wrote:
>
>> I have read and re-read until cross-eyed this post: http://www.idlcoyote.com/tips/forloops.html
>
>
>
> Just for the record, that particular post was made almost entirely in jest: sometimes a for loop is indeed what you want.
>
>
>
> JD

*Almost* entirely you say, but in my case entirely accurate. I reduced the runtime of my code from 10 minutes to 2 minutes by using the above arrays to find my indices instead of for loops, which seems significant to me, considering I need to run it over and over again. I was getting really bored.

In general I find that it's easy to loose focus on a problem if your runtime is approximately between 4 min - 2 hours. You feel like it's too short of a time to switch focus to another project and be productive at all. So, yay for code optimization.

In response to Yngvar:

I also had the problem that I had to add a constant value to each i,j,k specified by another array xBounds that gives the lower left corner of each grid. Since I was basically concatenating all the data from each grid, I could figure out how to add this lower left corner value to each data point before the reform.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Plot Size difference
Next Topic: Escaped Characters in string output

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

Current Time: Wed Oct 08 15:13:47 PDT 2025

Total time taken to generate the page: 0.00410 seconds