Stein
Stein

Reputation: 3277

gfortran mixes up types of real

I want to compile a large code and it throws this error:

/Users/redies/fleur/types/types_lapw.F90:178:47:

     CALL boxdim(cell%bmat,arltv1,arltv2,arltv3)
                                               1
Error: Type mismatch in argument 'bmat' at (1); passed REAL(4) to REAL(8)
/Users/redies/fleur/types/types_lapw.F90:69:47:

     CALL boxdim(cell%bmat,arltv1,arltv2,arltv3)
                                               1
Error: Type mismatch in argument 'bmat' at (1); passed REAL(4) to REAL(8)
make[2]: *** [CMakeFiles/fleur_MPI.dir/types/types_lapw.F90.o] Error 1
make[1]: *** [CMakeFiles/fleur_MPI.dir/all] Error 2
make: *** [all] Error 2

in the function boxdim the first variable is given as

  REAL,    INTENT (IN)  :: bmat(3,3)

The boxdim function is given in an *.f-file. The type cell is given as (in *.f90-file):

  TYPE t_cell
     !name of 2D-lattice type
     CHARACTER*3::latnam
     !vol of dtilde box
     REAL::omtil
     !2D area
     REAL::area
     !bravais matrix
     REAL::amat(3,3)
     !rez. bravais matrx
     REAL::bmat(3,3)
     !square of bbmat
     REAL::bbmat(3,3)
     !d-value
     REAL::z1
     !volume of cell
     REAL::vol
     !volume of interstitial
     REAL::volint
     REAL:: c
  END TYPE t_cell

everything is compiled with the -fdefault-real-8 option. If I set bmat in t_cell to

REAL(8) :: bmat

it compiles fine. Why does gfortran ignore the -fdefault-real-8 for some files? This error does not appear if I work on a fresh clone from the git repo, it starts to appear after I work on this repo for a while.

I am totally baffeled by this bug. My gfortran version is GNU Fortran (Homebrew GCC 8.2.0) 8.2.0 on MacOS, but I have the same error on 7.2.0 on Ubuntu.

P.S. the whole code compiles just fine in ifort

Upvotes: 2

Views: 849

Answers (1)

Scientist
Scientist

Reputation: 1835

As mentioned in the first comment, why not resolve your problem altogether by simply declaring the kinds of reals you need according to portable modern Fortran rules:

module t_cell_mod

    use, intrinsic :: iso_fortran_env, only: RK => real64
    implicit none

    type t_cell

        !name of 2D-lattice type
        CHARACTER(len=3) :: latnam

        !vol of dtilde box
        real(RK) :: omtil

        !2D area
        real(RK) :: area

        !bravais matrix
        real(RK) :: amat(3,3)

        !rez. bravais matrx
        real(RK) :: bmat(3,3)

        !square of bbmat
        real(RK) :: bbmat(3,3)

        !d-value
        real(RK) :: z1

        !volume of cell
        real(RK) :: vol

        !volume of interstitial
        real(RK) :: volint
        real(RK) :: c

    end type t_cell

end module t_cell_mod

if you need any other real kind, simply point RK to other kinds (real32, real128), instead of playing with compiler options. REAL(8) :: bmat is not portable.

Upvotes: 1

Related Questions