2

Is there a way to get the value of an array to the shape of a variable? Even when I select a single value of an array, say A(1:1, 1:1), it still complains when I compile and want to assign this to a variable:

Error: Incompatible ranks 0 and 1 in assignment at (1)

The goal in the end is something like this:

H = MAXVAL(matrix) - epsilon
IF ( matrix(i:i, i:i) >= H ) THEN

... but I cannot make this comparison because H is a variable and matrix(i:i, i:i) a 1x1 array. Is the only possibility for this to work to make H and array, too?

Thank you for your help!

1 Answer 1

4

Do not specify a range, use a single element:

A(1,1)=1

Your statement would then read:

H = MAXVAL(matrix) - epsilon
IF ( matrix(i, i) >= H ) THEN

Background:

Fortran allows you to work on sub-arrays like:

A(1:10,2:5)

which would be a 10x4 array. So A(1:1,1:1) is in fact an array (1x1) (as you noted). A(1,1), on the other hand, is a scalar and can be treated as such.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That worked! Guess the last time I tried it this way around and got an error, I was actually comparing with another array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.