when learning F90, I saw most of tutorials or even some books teach that a subroutine has a format as below:
subroutine process_name (opt_args)
!main_codes_go_here
end subroutine process_name
Yet, I am currently reviewing a model written in F90, which defines many subroutines in separate files that have a format as below:
subroutine process_name
!main_codes_go_here
end
I guess both ways are correct, but I am curious about the reasons (or history) behind the two structures. I would greatly appreciate if anyone can give some explainations? Suggestions about any book on Fortran 90 programming will be awesome as well.
I tried both approach, and they all work.
This is relly just one structure, describable, if needed, by a single EBNF node.
The simple explanation is that if the arguments are empty, the parentheses are optional, that just
endcan be used instead ofend subroutineand that if you use the fullend subroutineyou can also add the name of thesubroutineafter that.However, it is not that simple in the old Fortran 90. And even in Fortran 95 and 2003.
In Fortran 77 and earlier, the only option was just
end. In Fortran 90 you could add the wordsubroutineand if you did you could also add the name. But in some locations you had to use the fullend subroutine. Namely in module and internal procedures.In Fortran 2008 this restriction was removed and you can use just
endalso for module and internal procedures.For functions it is similar. Only
endup to Fortran 77. In Fortran 90-2003end functionis required for module and internal functions. In Fortran 2008 you can use justendalso for these.