An 'initial' subroutine is not, unlike a final subroutine, part of a Fortran standard.
In a derived type certain components may have initial values, set by default initialization, such as
type t
integer :: i=5
end type t
type(t) :: x ! x%i has value 5 at this point
However, allocatable array components (along with some other things) may not have default initialization and always start life as unallocated. You will need to have a constructor or some other way of setting such an object up if you wish the component to become allocated.
In the case of the question, one thing to consider is the Fortran 2003+ parameterized type:
type t(n)
integer, len :: n
integer val(n)
end type
type(t(5)) :: x ! x%val is an array of shape [5]
This naturally isn't the same this as an allocatable array component with an "initial" shape, but if you just want the component to be run-time initial customizable shape this could suffice.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…