Description
I built each of the nine examples using the NAG compiler with the -dusty option, and obtained normal output. Next, I added the -O2 option to see if the results remained the same. In many of the examples, that was the case. However, for the `lsodes' example, the run stopped with errors. I got the absurd output:
Run with mf = 11. Input work lengths lrw, liw = 1000 90
DLSODES- RWORK length insufficient (for Subroutine ODRV).
Length needed is .ge. LENRW (=I1), exceeds LRW (=I2)
In above message, I1 = 245 I2 = 1000
It took some effort to track the cause of this mishap to the declaration in `mdi.inc':
subroutine mdi(N,Ia,Ja,Max,V,L,Head,Last,Next,Mark,Tag,Flag)
...
integer,intent(out) :: Flag
A peculiar property of Intent(Out) is that such a variable becomes undefined at subprogram entry, and the user must define the argument before returning from the subprogram. In this case, the variable flag
is assigned a value only when a condition is satisfied. Otherwise, it becomes undefined. Normally, compilers do not emit code to make this undefinition happen, so we do not notice the error. In the present example and with one compiler, the consequences were catastrophic.
This problem did not occur in Fortran 77 since there was no Intent attribute to worry about. When a code polishing tool outputs Intent(out), it is usually advisable to remove the Intent attribute unless one can establish that redefinition will definitely occur before subroutine exit.
Once I removed Intent(out) for the 'flag' argument, the program ran normally.
There are several other instances of Intent(out) in the *.inc files. They may bite us one day.