Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

general fortran question

siemer_michael
Beginner
772 Views
Hi, I am making the move from matlab to fortran and have what I think is a trivial question for people having used fortran:
Supposed I have a matrix x(N,M,Q) where N,M,Q are the dimensions. Now, I would like to save the third dimension for the first element of the first and second dimension of this matrix in a vector, in matlab I would write
vector=squeeze(x(1,1,:))
vector is then in matlab a Q by 1 vector.
now in fortran if I have
real*8 N,M,Q
double precision, dimension(N,M,Q):: x
double precision, dimension(Q):: vector
and then write
vector=x(1,1,:)
I receive an error message. What is the simplest way of doing in fortran what squeeze is doing for matlab?
Thank you.
0 Kudos
1 Solution
DavidWhite
Valued Contributor II
772 Views
I think you need to use RESHAPE:

vector = RESHAPE (x(1,1,:), (/Q/))

Regards,

David

View solution in original post

0 Kudos
3 Replies
DavidWhite
Valued Contributor II
773 Views
I think you need to use RESHAPE:

vector = RESHAPE (x(1,1,:), (/Q/))

Regards,

David
0 Kudos
IanH
Honored Contributor II
772 Views
The variables for your array dimensions (N, M and Q) should be type integer.

In future posts please quote the actual error message text.
0 Kudos
bmchenry
New Contributor II
772 Views
i was going to say that it needed to be integer too...
however when checking and looking at the Fortran help file for array shape specifiers it states:
"The expressions can have a positive, negative or zero bvalue. If nescessary, the value is converted to an integer"
This appears to be code from a subroutine? which must be called with the arguments N,M,Q
so I'd ventue to guess the subroutine arguments has a type mismatch (the N,M,Q)?
Or
if in a main program then where is N,M,Q values declared?
Is this an assumed shape array (in a subroutine?) or an allocatable array??
if allocatable you need a different declaration (see section in help manual on Declaration for Arrays.


0 Kudos
Reply