1

I have a rank one array given by

COMPLEX(KIND = DBL),DIMENSION(DIMJ)::INITIALSTATE

How can I covert its rank to

DIMENSION(DIMJ,1)

so I can perform matrix operations on it -- transpose etc.

Note that the change is trivial. In both cases, we have a column vector. But Fortran won't trasnpose the array in the first form. Assume that DIMJ is an initialized integer.

Also, as obvious, I'd like the complex numbers to remain intact in the right positions after the manipulation.

Is it possible to perform such an operation in fortran?

Junaid Aftab
  • 131
  • 3
  • 2
    *In both cases, we have a column vector.* Not really. In Fortran a rank-1 array is neither a column- nor a row-vector, or it is both a column- and a row-vector. In cases such as calls to the intrinsic `matmul` a rank-1 array is treated as required (as either a column or a row) to make it conformable for matrix multiplication with the other argument. – High Performance Mark Aug 31 '16 at 06:52
  • Possible duplicate of [broadcast an array to different shape (adding "fake" dimensions)](http://stackoverflow.com/questions/14669006/broadcast-an-array-to-different-shape-adding-fake-dimensions) – francescalus Aug 31 '16 at 07:52

1 Answers1

1

If you just want a temporary read-only version of the array, you can always use RESHAPE:

TRANSPOSEDSTATE = transpose(reshape(INITIALSTATE, (/ DIMJ, 1 /)))

But this doesn't change the shape of the INITIALSTATE variable. Also, that is the same as

TRANSPOSEDSTATE = reshape(INITIALSTATE, (/ 1, DIMJ /))

no transpose needed.

chw21
  • 7,970
  • 1
  • 16
  • 31