it works after putting 'end subroutine ' in (only warning that nothing in there !)

It would be useful to have a FATAL error that there's no end subroutine, although it does mention in error message MAYBE there is a missing 'end' but as you said it's not referring to any subroutine but to the function.

Looks like x2 mixed up messages to me.
One for Paul&Co to trace

- NOTE -

i) if you move the subroutine definition ABOVE the function definition you get the error message.
*** SUBROUTINE cannot be declared inside PROGRAM block (perhaps missing CONTAINS or END statement?)

which are both logical messages.
Seems to be the presence of the INTEGER function being before the subroutine which is throwing it.
Maybe subroutines are processed first ? Still doesn't explain why it thinks the function is INSIDE the Subroutine, which s the crux of the matter.