为什么在 Fortran 程序中使用 shape(2) 不打印任何内容?
Why does using shape(2) in fortran programs not print anything?
考虑以下短程序 (Fortran95):
write(*,*) shape(2)
end
我用 Fortran 编译器 (gfortran 4.8.2) 和 Absoft Pro Fortran 13.0.0 (mac) 尝试了 运行,得到以下结果:
local $./a.out
local $
更新:还尝试了 gfortran 4.4.7(linux 结果相同。
这里是what documentation of shape in gfortran says:
RESULT = SHAPE(SOURCE [, KIND])
Arguments:
SOURCE Shall be an array or scalar of any type. If SOURCE is a pointer it must be associated and allocatable arrays must be allocated.
Return value:
An INTEGER array of rank one with as many elements as SOURCE has dimensions. The elements of the resulting array correspond to the extend of SOURCE along the respective dimensions. If SOURCE is a scalar, the result is the rank one array of size zero. If KIND is absent, the return value has the default integer kind otherwise the specified kind.
换句话说,我只看到一个换行符而不是一个结果。它不应该告诉我形状是1吗?
它正确打印了大小为零的数组 shape
returns 的所有元素。打印长度为零的数组会导致打印零个数字。
1是秩(维数),不是长度。也就是说,结果不是标量、矩阵或某些高阶数组。它是一个向量。它恰好是一个没有元素的向量。
考虑以下短程序 (Fortran95):
write(*,*) shape(2)
end
我用 Fortran 编译器 (gfortran 4.8.2) 和 Absoft Pro Fortran 13.0.0 (mac) 尝试了 运行,得到以下结果:
local $./a.out
local $
更新:还尝试了 gfortran 4.4.7(linux 结果相同。
这里是what documentation of shape in gfortran says:
RESULT = SHAPE(SOURCE [, KIND])
Arguments:
SOURCE Shall be an array or scalar of any type. If SOURCE is a pointer it must be associated and allocatable arrays must be allocated.Return value:
An INTEGER array of rank one with as many elements as SOURCE has dimensions. The elements of the resulting array correspond to the extend of SOURCE along the respective dimensions. If SOURCE is a scalar, the result is the rank one array of size zero. If KIND is absent, the return value has the default integer kind otherwise the specified kind.
换句话说,我只看到一个换行符而不是一个结果。它不应该告诉我形状是1吗?
它正确打印了大小为零的数组 shape
returns 的所有元素。打印长度为零的数组会导致打印零个数字。
1是秩(维数),不是长度。也就是说,结果不是标量、矩阵或某些高阶数组。它是一个向量。它恰好是一个没有元素的向量。