Dear Fortran black-belts and others,
I am trying to understand the rules governing the passing of parameterised derived type variables as arguments into subroutines and functions. Here is an example type definition from my program:
TYPE CoeffPairSpeciesDescr (nSpecies1, nSpecies2, nValuesMax)
C
INTEGER, LEN :: nSpecies1, nSpecies2, nValuesMax
INTEGER :: Species(nSpecies1, nSpecies2)
INTEGER :: nValues
DOUBLE PRECISION :: Value(nValuesMax)
C
END TYPE
After creating the parameterised derived type variable (which I only need to do once, at the start of a program run), I can only find two ways of passing it as an argument to other routines:
(1) By declaring it in the routines like this:
TYPE (CoeffPairSpeciesDescr(:,:,:)), ALLOCATABLE :: AlphaObject
where "AlphaObject" is the parameterised derived type variable.
(2) Or, like this:
TYPE (CoeffPairSpeciesDescr(NA,NB,NC)) :: AlphaObject
where NA, NB, and NC are integers whose values are known (and are the values used when the variable was allocated).
If I change the statement in (1) above to remove "ALLOCATABLE," I get the compiler error message:
test_3.for(133): error #8730: A colon may only be used as a type parameter value in the declaration of an object that has the POINTER or ALLOCATABLE attribute.
I don't understand why this should be. An ordinary array (ie, not a derived type) does not behave in this way. As Steve Lionel explained in a post several years ago:
"That an array is allocatable does not, in itself, change how you pass it to a routine. If you had an F77-style program where you changed one array to be allocatable, and allocated it, you would not have to change any other code in the program."
Why don't parameterised derived types behave in the same way? It seems odd that the parameterised derived type variable apparently has to either be declared as allocatable in every subprogram it is passed to, or declared with explicit values given to the "LEN" attributes. What am I missing?
All explanations gratefully received.
Simon C.