[英]FORTRAN - Assigning an array value to variable
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: 即使我选择一个数组的单个值,例如A(1:1, 1:1)
,当我编译并将其分配给变量时,它仍然会抱怨:
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. ...但是我无法进行比较,因为H是一个变量,而matrix(i:i, i:i)
是一个1x1数组。 Is the only possibility for this to work to make H and array, too? 这也是制作H和数组的唯一可能性吗?
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: Fortran允许您处理以下子阵列:
A(1:10,2:5)
which would be a 10x4
array. 这将是一个10x4
数组。 So A(1:1,1:1)
is in fact an array (1x1) (as you noted). 因此, A(1:1,1:1)
实际上是一个数组(1x1)(如您所述)。 A(1,1)
, on the other hand, is a scalar and can be treated as such. 另一方面, A(1,1)
是一个标量,可以这样处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.