jeyadev@wrc.xerox.com (Surendar Jeyadev) writes:
> In article <mgs-52612D.20571630111999@news.silcom.com>,
> Mike Schienle <mgs@ivsoftware.com> wrote:
>>
>> You can probably find more than you wanted to know abot row and column
>> order by visiting the IDL FAQ at <http://www.ivsoftware.com:8000/FAQ/>.
>> Select the "Search FAQ" button. Enter the word "major" in the "Question"
>> field and press the "Start Search" button. You'll be treated to a fairly
>> detailed discussion on column- and row-major, as well as memory access
>> into the arrays.
> Found it, at last, by listing all the questions, but I know all *that*
> stuff.
> My question was what happens beyond 2 dimensions and how REFORM treats
> a 2d to 3d coversion. I will simplify my question in the hope that some
> kind soul will help me out.
> Let us say that I have the data file
> 1 13
> 2 14
> 3 15
> 4 16
> 5 17
> 6 18
> 7 19
> 8 20
> 9 21
> 10 22
> 11 23
> 12 24
> and that the first column represents data for a variable that is defined
> on a 3 x 4 (i.e. 3 column and 4 rows) grid and the second column is for
> another variable on the same grid. Assume that the data is stored in the
> the array odat(2,12).
> What is I want to do is the following: I want to create a 3 data array
> with two planes of 3 x 4 elements so that each plane contains the the data
> for one variable.
> The REAL QUESTION: The command
> data = reform(odat,2,3,4)
> seems to do the job. For example
> WAVE> a = data(0,*,*)
> WAVE> info, a
> A INT = Array(1, 3, 4)
> WAVE> a = reform(a)
> WAVE> info, a
> A INT = Array(3, 4)
> WAVE> print, a
> 1 2 3
> 4 5 6
> 7 8 9
> 10 11 12
> which is exactly what I want. Now, what I would like to know is why the
> number of planes (2) had to be the *first* index in the reform statement.
> thanks
> --
> Surendar Jeyadev jeyadev@wrc.xerox.com
Surendar:
The basic answer is as follows. Your odat(2,12) array is really stored as a
series of numbers. You can see the way the array is stored by the command
IDL> print,odat(*)
1 13 2 14 3 15 4 16 5
17 6 18 7 19 8 20 9 21
10 22 11 23 12 24
By formatting this into a (2,12) array, you tell IDL to organize it into the
indices
odat(0,0) = 1
odat(1,0) = 13
odat(0,1) = 2
odat(1,1) = 14
odat(0,2) = 3
odat(1,2) = 15
odat(0,3) = 4
etc.
If you then reformat it into a (2,3,4) array, it will be stored as
odat(0,0,0) = 1
odat(1,0,0) = 13
odat(0,1,0) = 2
odat(1,1,0) = 14
odat(0,2,0) = 3
odat(1,2,0) = 15
odat(0,0,1) = 4
etc.
The leftmost index always increases most rapidly, and the rightmost index
always increases most slowly. The REFORM() function doesn't rearrange the
numbers in memory--it just changes how they're interpreted.
William Thompson
|