Fortran Transpose: Transform a 4D Array into 2D

  • Context: Fortran 
  • Thread starter Thread starter Milentije
  • Start date Start date
  • Tags Tags
    Fortran Transpose
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 8K views
Milentije
Messages
47
Reaction score
0
Here is the problem.I have this array zmdsens(iper,i,1,iprd) where iper is period,i site,1 mt function and iprd conductivity.This array stores MT functions for all above mentioned.I need tot find transpose of MT function,but fortran 90 can easily do that only with 2dimensional arrays.How to transform this?
 
Physics news on Phys.org
Milentije said:
Here is the problem.I have this array zmdsens(iper,i,1,iprd) where iper is period,i site,1 mt function and iprd conductivity.This array stores MT functions for all above mentioned.I need tot find transpose of MT function,but fortran 90 can easily do that only with 2dimensional arrays.How to transform this?
This doesn't make much sense. What you are describing as an array - zmdsens - looks like a function call or subroutine call to me.

What does it mean to take the transpose of a function?
What is an MT function?
 
Well I will try to explain more.I have two-dimensional mesh,every cell has conductivity.On the surface I calculate MT functions with respect to conductivity.The reason why we store them in 4-dimensional array is that we measure MT for more periods and sites on the surface.I need transpose of matrix which represents derivatives of MT with respect to conductivity.FORTRAN 90 requires 2d array for such operation.
 
For example we define a 3D array, like f(9, 9, 9). I think transpose f with the second index fixed would be: transpose( f ( :, 1, : ) ). Does this solve your problem?
 
No actually I will try to cope in the different way.Still I have problems how to go from 1d to 2d array,then just use intrinsic transpose.
program io_test
real, dimension(:,:), allocatable :: x
real, dimension(:,:), allocatable :: y
integer :: n
open (unit=99, file='array.txt', status='old', action='read')
read(99, *), n
allocate(x(n))
read(99,*) x
write(*,*) x
y=transpose(x)
write(*,*)y
end
I get this:
ifort -c io.f
io.f(8): error #6792: The rank of the allocate-shape-spec-list differs from the rank of the allocate-object. [X]
allocate(x(n))
------------------^