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!
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.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments