我正在尝试定义一个数组数组。 我已定义:
integer,dimension(2,2):: &
x=reshape(source= (/0,1,1,0/), shape=(/2,2/)), &
y=reshape(source= (/1,0,0,1/), shape=(/2,2/)), &
z=reshape(source= (/1,1,1,1/), shape=(/2,2/))
我想定义一个数组,比如s(3),其中,(x / y / z)是组件,即
s(1)=x
s(2)=y
and s(3)=z
我怎样才能实现这一目标?
答案 0 :(得分:5)
最简单的方法可能是将s
定义为rank-3数组,也许
integer, dimension(3,2,2) :: s
然后你可以编写诸如
之类的陈述s(1,:,:) = x
s(2,:,:) = y
...
这是在Fortran中实现数组数组的“自然”方式。另一种可能对您有吸引力的替代方案可能是:
type :: twodarray
integer, dimension(2,2) :: elements
end type twodarray
type(twodarray), dimension(3) :: s
s(1)%elements = x
如果你不喜欢s(1)%elements = x
的冗长,你可以为你的类型=
重新定义操作twodarray
,我现在没有时间为你编写代码
答案 1 :(得分:0)
我无法在我的Fortran 77书籍的硬拷贝中找到一本电子书来为您提供。 但是,这应该对您有用:
http://www.owlnet.rice.edu/~ceng303/manuals/fortran/FOR5_3.html