Argument flag of MDI() may be left undefined
Closed this issue · 2 comments
Subroutine MD calls subroutine MDI, and one of the arguments is the variable FLAG. Immediately after return from the call to MDI, in MD a test is made for the FLAG not equal to zero. However, because in MDI the variable FLAG is set inside an IF block, under some circumstances (such as example/lsodes.f90 and example/lsodis.f90, both with MF = 11), the condition for executing the IF block is not satisfied, and FLAG remains undefined. Oddly enough, the code in MDI is such that FLAG gets defined only when there is insufficient storage space provided for the solution to proceed!
The fix (if needed): set IFLAG = 0 as the first executable statement in file src/M_da1/MDI.inc.
Although not set private, mdi is only called by md, which is only called by odrv. odrv unconditionally sets the flag.
If there a call not going through odrv? I do not see it. Perhaps to clarify that mdi should be explicitly declared private or be a contained procedure.
Ah, I see your point. So FLAG is sticky, and should have been set to zero before being sent as an argument through a series of calls. If any of the subroutines it passes through finds an error, it sets a nonzero value, wiping out any previously set value, zero or not. Consequently, any caller that passes along FLAG (name gets changed sometimes between routines) should check and act on a non-zero value immediately.
I misread the usage of FLAG based on the comments at the start of ODRV, etc., in the original sources from LLNL, as well, which could be read as saying that FLAG would be set to zero if a routine with an xxFLAG in its dummy argument list -- for example, MDI -- is called and does not detect any new error. To me it remains a bit unclear as to where the originating flag variable is declared, initialized and tested.