fortransubroutine

How to understand a subroutine without argument and bracket in Fortran


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.


Solution

  • 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 end can be used instead of end subroutine and that if you use the full end subroutine you can also add the name of the subroutine after 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 word subroutine and if you did you could also add the name. But in some locations you had to use the full end subroutine. Namely in module and internal procedures.

    In Fortran 2008 this restriction was removed and you can use just end also for module and internal procedures.

    For functions it is similar. Only end up to Fortran 77. In Fortran 90-2003 end function is required for module and internal functions. In Fortran 2008 you can use just end also for these.