I am trying to define a array of arrays. I have defined:
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/))
I want to define an array, say, s(3), of which, (x/y/z) are components, i.e.
s(1)=x
s(2)=y
and s(3)=z
how can I achieve that?
You can always use pointers (in Fortran 95)
It will print
I was unable to find an eBook to the hard copy of my Fortan 77 book to provide you. However, this should prove useful to you:
http://www.owlnet.rice.edu/~ceng303/manuals/fortran/FOR5_3.html
The simplest approach might be to define
s
as a rank-3 array, perhapsand then you can write statements such as
This is the 'natural' way to implement an array of arrays in Fortran. An alternative, which might appeal to you more would be something like:
If you don't like the wordiness of
s(1)%elements = x
you could redefine the operation=
for your typetwodarray
, I don't have time right now to write that code for you.