Fortran Transpose: Transform a 4D Array into 2D

  • Context: Fortran 
  • Thread starter Thread starter Milentije
  • Start date Start date
  • Tags Tags
    Fortran Transpose
Click For Summary

Discussion Overview

The discussion revolves around the challenge of transposing a 4D array in Fortran, specifically the array zmdsens, which is used to store MT (magnetotelluric) functions related to conductivity measurements across different periods and sites. Participants explore how to transform this 4D array into a 2D array suitable for transposition, as required by Fortran 90.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes the structure of the zmdsens array and expresses the need to transpose it, noting that Fortran 90 only allows transposition for 2D arrays.
  • Another participant questions the initial description, suggesting that the array may resemble a function call and asks for clarification on what an MT function is.
  • A participant attempts to clarify the context by explaining that the 4D array represents MT functions calculated from a 2D mesh of conductivity values, and that the transpose needed is of a matrix representing derivatives of MT with respect to conductivity.
  • One participant proposes a method to transpose a 3D array with a fixed index, suggesting that this might help solve the original problem.
  • A later reply indicates a shift in approach, with a participant sharing a code snippet that attempts to read a 1D array from a file, allocate it, and then transpose it, but encounters an error related to array allocation.

Areas of Agreement / Disagreement

Participants express differing views on the nature of the array and the process of transposition. There is no consensus on how to effectively transform the 4D array into a 2D array for transposition, and the discussion remains unresolved.

Contextual Notes

There are limitations in the understanding of the MT function and the specifics of the array structure, as well as unresolved issues regarding the correct allocation of arrays in Fortran.

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?
 
Technology 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))
------------------^
 

Similar threads

  • · Replies 15 ·
Replies
15
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 10 ·
Replies
10
Views
26K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K