making default arguments easier to use



Here is a "discovery" I made. I used to write a lot of "boilerplate"
code such as

if (present(max_rows)) then
max_rows_ = max_rows
else
max_rows_ = 100000
end if

where max_rows is an optional argument. Nowadays I replace the 5 lines
above with just

max_rows_ = default(100000,max_rows)

where default is an interface to a set of functions such as as

elemental function default_integer(def,opt) result(ii)
! return opt if it is present, otherwise def (integer arguments and
result)
integer, intent(in) :: def
integer, intent(in), optional :: opt
integer :: ii
if (present(opt)) then
ii = opt
else
ii = def
end if
end function default_integer

(similar functions have been written for other types). Using this
technique makes the procedures with optional arguments shorter and
easier to read IMO. It uses the feature of Fortran that allows non-
present optional arguments to be passed to procedures.

.