Reputation: 401
Suppose I have a 2D array A(:,2) where only the size of first dimension is unknown. Is it possible to allocate only for the first dimension of A ? If not, I have to go with " allocate(A(n,2)) " each time by treating A as A(:,:).
Upvotes: 1
Views: 2226
Reputation: 166
If the second dimension is always of size 2, you could create a data type with two variables and then allocate an array of them:
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
Upvotes: 4