简而言之,我可以在fortran(任何fortran标准)中做这样的事情
type(my_array), dimension(:,:), allocatable :: a
type(my_array), dimension(5,5) :: b
allocate(a(3, 3))
a = b(1:3, 1:3)
答案 0 :(得分:5)
是的,当然可以(在f90 +中)。
$ cat foo.f90
program foo
implicit none
type :: my_array
integer :: i
end type my_array
type(my_array), dimension(:,:), allocatable :: a
type(my_array), dimension(5,5) :: b
integer :: i, j
do i = 1, 5
do j = 1, 5
b(j,i)%i = 10*i + j
end do
end do
allocate(a(3, 3))
a = b(1:3, 1:3)
write(*,"(3i3)") a
end program foo
$ gfortran foo.f90 -o foo
$ ./foo
11 12 13
21 22 23
31 32 33
$