Reputation: 35
I have a fortran code being compiled in gfortran (several thousand lines so I'll try to post the important lines) that 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? Thanks!
Upvotes: 3
Views: 5176
Reputation: 50937
It's an excellent idea to get rid of all warnings, even minor ones -- even if only so that when you do get more significant issues, you see them rather than having the output swamped by little things.
In this case, the warning message is fairly clear; you're assigning a double to an integer. The dint
intrinsic truncates, but it doesn't convert types; so you're assigning a double precision value that's had it's value truncated to an integer. You could rightly note that the intrinsic is confusingly named, but...
If you want to do the conversion as well as the truncation, idint
actually converts to an integer.
So for instance 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 this one is fine:
program foo
integer :: nrev
double precision :: t_ref
t_ref = 1.
nrev = idint(t_ref)
end program foo
as we see:
$ gfortran -o foo foo.f90 -Wall -std=f95
$
Upvotes: 4