Fortran: Possible cost change

I have fortran code compiled in gfortran (several thousand lines so I will try to post the important lines) which gives me:

nrev(isat)=dint((t_ref-t_in)/zper)+1
           1
Warning:Possible change of value in conversion from REAL(8) to INTEGER(4) at (1)

      

They are initialized as:

integer*4  nrev(nmaxsat)
integer*4  isat
real*8     t_ref
real*8     t_in
real*8     zper

      

Any ideas on how to fix this? Thank!

+3


source to share


1 answer


It's a great idea to get rid of all warnings, even minor ones, even if only when you have more serious problems, you see them, and do not output the data because of little things.

In this case, the warning message is clear enough; you are assigning a double integer. dint

built-in truncations, but it does not convert types; so you are assigning a double precision value that is truncated to an integer value. You can rightly point out that the internal name is confusing, but ...

If you want to do the conversion as well as truncation, it idint

actually converts to an integer.

So, for example, this program

program foo

    integer :: nrev
    double precision :: t_ref

    t_ref  = 1.

    nrev = dint(t_ref)

end program foo

      

creates the same warning:



$ gfortran -o foo foo.f90 -Wall -std=f95
foo.f90:8.11:

    nrev = dint(t_ref)
           1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1)

      

But it's good:

program foo

    integer :: nrev
    double precision :: t_ref

    t_ref  = 1.

    nrev = idint(t_ref)

end program foo

      

as we can see:

$ gfortran -o foo foo.f90 -Wall -std=f95
$ 

      

+4


source







All Articles