Reputation: 1378
I'm using an old fortran script (accessible here). I'm receiving the following warnings (line#192, 233-235). Is there a way to fix it? I'm using gfortran 6 on my mac.
Ms-MacBook-Pro-2:~ Tonoy$ gfortran -g -fcheck=all -Wall mrtm.f
mrtm.f:192:8:
N=COL/DX
1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mrtm.f:233:10:
NKK=TPRINT/DT+0.50D0
1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mrtm.f:234:10:
KLM=TTOTAL/DT+0.50D0
1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mrtm.f:235:9:
KK=KLM/NKK+0.5D0
1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
Upvotes: 2
Views: 5272
Reputation: 94
It looks like the variables N, NKK, KLM, and KK are all being implicitly declared as integers. The right hand side of the assignment, however, includes numbers that are explicitly REAL*8. So essentially what is happening is the compiler is evaluating the right hand side of each of these lines as a REAL*8, but then trying to assign the resulting value to an integer. If any non-zero digits live after the decimal point, they will be lost in this conversion/assignment.
In the assignment, the compiler will simply ignore the decimal point and any digits that come thereafter. In a lot of old fortran code, this was the expected behavior, and the code consequently is doing what it was intended to do.
If you simply want to get rid of the compile warnings, you can encapsulate the right hand side of the assignment with an INT, i.e.
N=INT(COL/DX)
NKK=INT(TPRINT/DT+0.50D0)
KLM=INT(TTOTAL/DT+0.50D0)
KK=INT(KLM/NKK+0.5D0)
Upvotes: 5