shintaroid
shintaroid

Reputation: 1655

How to automatically convert a Fortran90 program whose variables are in double precision into real?

everyone

I have a Fortran90 program, and the variables are in double precision or complex*16, now I have to write another program whose variables are in real or complex, and all other things are the same as the original program.

The straightforward way is to rewrite every declaration, but I'm wondering if there are other simpler ways to achieve this, I'm using gfortran as the compiler.

Thanks

Upvotes: 0

Views: 528

Answers (1)

Bálint Aradi
Bálint Aradi

Reputation: 3812

Probably the cleanest (althoug not the easiest) way would be to rewrite your program to have adjustable precision for the variables:

program test
  implicit none

  integer, parameter :: rp = kind(1.0d0)
  real(rp) :: myreal
  complex(rp) :: mycomplex

By setting the parameter rp (real precision) to kind(1.0) instead of kind(1.0d0) you can switch from double to single. Alternatively, with fortran 2003 compatible compilers you can also use the names real64 and real32 after invoking the iso_fortan_env module. (UPDATE: it needs a fortran 2008 compatible compiler, not fortran 2003, see the comment of IanH).

Upvotes: 2

Related Questions