next up previous contents
Next: Optional Arguments Up: More on Procedures Previous: Required Interfaces   Contents

Keyword Arguments

Normal argument correspondence is performed by position ( actual argument corresponds to dummy argument). F90 allows us to circumvent this ``fixed form'' limitation. The arguments can be specified in any order, provided they are labeled by appropriate keywords at the site of call. A keyword is the name of the dummy variable in the procedure declaration (followed by an sign); using keywords is necessary for the compiler to resolve the argument correspondence, if they are given out of order. Moreover, if a procedure has a long list of similar type arguments (say, 10 integer arguments) the use keywords greatly improves readability.

For example, the ``Polar-to-Cartesian'' subroutine

subroutine polar2cart(r, theta, x, y)
  real, intent(in)  :: r, theta
  real, intent(out) :: x, y
   ...
end subroutine polar2cart
can be called as
call polar2cart(1.0, 30.0, c1, c2)
or as
call polar2cart(r=1.0, theta=30.0, x=c1, y=c2)
or as
call polar2cart(x=c1, y=c2, r=1.0, theta=30.0)



Adrian Sandu 2001-08-26