Arrays fortran中的数组

Arrays fortran中的数组,arrays,fortran,fortran90,Arrays,Fortran,Fortran90,我试图定义一个数组的数组。 我定义了: 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)

我试图定义一个数组的数组。 我定义了:

  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

我怎样才能做到这一点

我找不到我的Fortan 77书籍硬拷贝的电子书提供给你。 但是,这应该对您有用:


最简单的方法可能是将
s
定义为秩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
重新定义操作
=
,我现在没有时间为您编写代码。

您可以始终使用指针(在Fortran 95中)

它会打印出来

       0           0           0
       0           0
       0
       0           0           0
       0           0
       0