I am trying to create a subroutine which reads a netCDF variable and automatically allocates the necessary space. There are many possible combinations of ranks and types, therefore, I want to use an interface which handles the types and an assumed rank array to handle the ranks.
It does work as intended with the GNU Fortran (GCC) 10.2.0, but on the target system I have to use Intel Fortran Version 126.96.36.1994 Build 20200925_000000 (Intel/2020.4.304-GCC-9.3.0) and that gives me the following error message:
error #8306: Associate name defined in ASSOCIATE or SELECT TYPE statements doesn't have ALLOCATABLE or POINTER attribute.
Minimal example which works with gfortran but not with ifort:
module m contains subroutine alloc(var) integer, dimension(..), allocatable :: var select rank(var) rank(1) allocate(var(2)) rank(2) allocate(var(2, 2)) ! rank(3) etc... end select end subroutine alloc end module
In this case ifort throws an error for each allocate, but as far as I can tell, 'var' has the allocatable attribute... and gfortran does not complain at all.
I think there are two possibilities:
a) this is a bug/missing feature (which may be fixed/added in a more recent version)
b) the code is against the standard an gfortran shouldn't compile it
The only workaround I see is to blow up my interface and write a subroutine for every combination of rank and type (I am already using 'include'), but I hope there may be a more elegant way to solve this issue. Maybe I can somehow build this part separately with gfortran, but I never tried something like this.
I attached two source files containing the code above and a minimal program which uses the 'alloc' routine. Just to clarify: Like in 'a.f90' the real programm will pass the allocatable array to 'alloc' with the correct number of dimensions.
If you're able to, please submit a support request at Intel Online Service Center: https://supporttickets.intel.com/servicecenter?lang=en-US
and ask for clarification vis-a-vis the Fortran standard. Prima facie, gfortran appears conformant, the standard does not include "SELECT RANK" statement in the restriction on the ALLOCATABLE attribute with the `associate-name`:
More relevant is this:
188.8.131.52 Attributes of a SELECT RANK associate name
3 The associating entity has the ALLOCATABLE, POINTER, or TARGET attribute if the selector has that attribute. The other attributes of the associating entity are described in 184.108.40.206.
Thank you very much for having a look at it.
So I have to implement a workaround for this... I think I can reduce the amount of subroutines by only implementing the combinations of rank and data type which are needed right now.