typesfortrangfortranfortran2003

Problems with parametrized derived types in Fortran 2003


I'm teaching myself Fortran 2003 to use for a research project I'm currently working on. I'm used to Fortran 90, but this project requires the use of parametrized types, and so I'm moving on to 2003.

I was following this site's description of how to define a parametrized type, and wrote a very simple example program based on the site's example to test it out:

module example
implicit none

  type :: param_matrix(k,a,b)
     integer, kind :: k
     integer, len :: a
     integer, len :: b
     real(kind=k), dimension(a,b) :: m
  end type param_matrix

end module example

When I compile this with the command

gfortran -c test.F03

I get the errors

test.F03:4.2:

  type :: param_matrix(k, a, b)

  1

Error: Unclassifiable statement at (1)

test.F03:5.13:

     integer, kind :: k

             1

Error: Invalid character in name at (1)

test.F03:6.13:

     integer, len :: a

             1

Error: Invalid character in name at (1)

test.F03:7.13:

     integer, len :: b

             1

Error: Invalid character in name at (1)

test.F03:8.16:

     real(kind=k), dimension(a,b) :: m

                1

Error: Symbol 'k' at (1) has no IMPLICIT type

test.F03:9.5:

  end type param_matrix

     1

Error: Expecting END MODULE statement at (1)

When I remove the parametrized parts of the formula, it compiles fine (that is, it recognizes the type). It seems to be having particular trouble with anything specific to Fortran 2003, but when I run with the command

-std=f2003

it still has the same problems. What might be going on?


Solution

  • Parameterized derived types are not yet implemented in gfortran:

    https://gcc.gnu.org/wiki/OOP (see Unimplemented features)

    Currently, only Cray, PGI, and IBM Fortran compilers support this feature:

    http://fortranwiki.org/fortran/show/Fortran+2003+status