Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在fortran中索引用户定义的类型_Fortran - Fatal编程技术网

在fortran中索引用户定义的类型

在fortran中索引用户定义的类型,fortran,Fortran,简而言之,我可以在fortran(任何fortran标准)中执行类似的操作吗 是的,当然可以(在f90+中) 嗯,你为什么不试试呢?我问错了问题:)我看到答案后意识到了这一点。所以我接受了给出的答案。。 type(my_array), dimension(:,:), allocatable :: a type(my_array), dimension(5,5) :: b allocate(a(3, 3)) a = b(1:3, 1:3) $ cat foo.f90 program foo im

简而言之,我可以在fortran(任何fortran标准)中执行类似的操作吗

是的,当然可以(在f90+中)


嗯,你为什么不试试呢?我问错了问题:)我看到答案后意识到了这一点。所以我接受了给出的答案。。
type(my_array), dimension(:,:), allocatable :: a
type(my_array), dimension(5,5) :: b
allocate(a(3, 3))
a = b(1:3, 1:3)
$ 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
$