[英]Allocate only one dimension for a 2D array in fortran
假设我有一个二维数组A(:,2),其中只有第一维的大小是未知的。 是否可以仅分配A的第一维? 如果不是,我每次都必须通过将A视为A(:, :)来使用“ allocate(A(n,2))”。
如果第二维始终为2,则可以创建具有两个变量的数据类型,然后分配它们的数组:
program main
implicit none
type two_things
integer :: first
integer :: second
end type two_things
type(two_things), dimension(:), allocatable :: A
allocate(A(100))
A(1)%first = 1
A(1)%second = 2
print*, A(1)%first, A(1)%second, shape(A)
deallocate(A)
end program main
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.