in reply to 1d array into 3d
The solution you've added to the end of your post is correct. To avoid making it seem (slightly) more complicated than it is, I'd just start counting at 1 in all the for-loops (not tested):
do k = 1, nz, 1 do j = 1, ny, 1 do i = 1, nx, 1 x = i + nx * (j - 1) + (nx*ny) * (k - 1) threeDarray(i,j,k) = oneDarray(x) enddo enddo enddo
The way you're varying the leftmost index fastest, goes well with Fortran's column-major order for storing multidimensional arrays.
|
|---|