I don't have an explanation for the DLL performance.
Is the expression 'realvar = 31.5' exactly as you have typed ?
If the result of getting to 31.5 has some rounding noise so was less than 31.5, you would get the result 31.
31.5 when converted into a binary real is an exact representation, as there are lots of trailing zeros.
31.5 = 24 + 23 + 22 + 21 +20 + 2(-1)
It should round up to 32.
The following code tries to demonstrate how 31.5 is mostly zeroes, but noise could change that.
real*4 realval
real*8 dblval
integer*4 intval
integer*8 jval
!
1 format (/a)
write (*,1) ' represented as 31.5'
realval = 31.5
intval = nint (realval)
write (*,*) 'realval=',realval
write (*,*) 'intval =',intval
!
write (*,*) ' integer equivalent of real*4'
intval = transfer (realval,intval)
write (*,*) 'intval =',intval
write (*,'(a,o0,a)') ' octal = ',intval, ' shows mostly 0'
!
write (*,1) ' represented as 31.5 less noise'
realval = nearest (realval,-1.0) ! nearest real less than 31.5
intval = nint (realval)
write (*,*) 'realval=',realval
write (*,*) 'intval =',intval
intval = transfer (realval,intval)
write (*,*) 'intval =',intval
write (*,'(a,o0,a)') ' octal = ',intval, ' no longer mostly 0'
!
write (*,1) ' represented as 63.0'
realval = 31.5
realval = realval*2
intval = transfer (realval,intval)
write (*,*) 'intval =',intval
write (*,'(a,o0,a)') ' octal = ',intval, ' shows mostly 0'
!
write (*,1) ' represented as 31.5_8'
dblval = 31.5
intval = nint (dblval)
write (*,*) 'dblval =',dblval
write (*,*) 'intval =',intval
!
write (*,*) ' integer equivalent of real*8'
jval = transfer (dblval,jval)
write (*,*) 'jval =',jval
write (*,'(a,o0,a)') ' octal = ',jval, ' again shows mostly 0'
!
end