Reputation: 891
In a calling function I have this:
call ESMF_TimeGet( date, yy=year, mm=month, dd=day, s=sec, rc=rc)
The signature for ESMF_TimeSet
is:
! ESMF_TimeGet - Get value in user-specified units
subroutine ESMF_TimeGet(time, YY, YRl, MM, DD, D, Dl, H, M, S, Sl, MS, &
US, NS, d_, h_, m_, s_, ms_, us_, ns_, Sn, Sd, &
dayOfYear, dayOfYear_r8, dayOfYear_intvl, &
timeString, rc)
type(ESMF_Time), intent(in) :: time
integer, intent(out), optional :: YY
integer(ESMF_KIND_I8), intent(out), optional :: YRl
integer, intent(out), optional :: MM
integer, intent(out), optional :: DD
integer, intent(out), optional :: D
integer(ESMF_KIND_I8), intent(out), optional :: Dl
integer, intent(out), optional :: H
integer, intent(out), optional :: M
integer, intent(out), optional :: S
integer(ESMF_KIND_I8), intent(out), optional :: Sl
integer, intent(out), optional :: MS
integer, intent(out), optional :: US
integer, intent(out), optional :: NS
double precision, intent(out), optional :: d_
double precision, intent(out), optional :: h_
double precision, intent(out), optional :: m_
double precision, intent(out), optional :: s_
double precision, intent(out), optional :: ms_
double precision, intent(out), optional :: us_
double precision, intent(out), optional :: ns_
integer, intent(out), optional :: Sn
integer, intent(out), optional :: Sd
integer, intent(out), optional :: dayOfYear
real(ESMF_KIND_R8), intent(out), optional :: dayOfYear_r8
character (len=*), intent(out), optional :: timeString
type(ESMF_TimeInterval), intent(out), optional :: dayOfYear_intvl
integer, intent(out), optional :: rc
type(ESMF_TimeInterval) :: day_step
integer :: ierr
When I'm calling ESMF_TimeSet
how is the subroutine able to convert the yy=yr
argument into a yy
variable inside the subroutine (and similarly for mm
and dd
)? Also, does FORTRAN care about case-sensitivity of variables?
Upvotes: 1
Views: 7086
Reputation: 8870
how is the subroutine able to convert the "yy=yr" argument into a yy variable inside the subroutine?
There is no yy
variable in your procedure. Only yy
dummy argument. When you call this procedure you use so-called named arguments. This feature is not specific to Fortran. But what's your problem with optional arguments?
And the same for mm and dd. Does FORTRAN care about case-sensitivity of variables?
Fortran is case-insensitive language. So no, it doesn't care.
Okay. I'll try to explain some basics because I have some difficulties with understanding your comments. :)
When it comes to procedures the Fortran terminology differs from the "common" one in some respects:
When procedure is called (is referenced in terms of Fortran standard)
the actual argument list identies the correspondence between the actual arguments and the dummy arguments of the procedure.
So basically the correspondence is by position. Some languages (including Fortran) also have the ability to establish correspondence by keyword. The long story short:
The keywords are the dummy argument names and there must be no further positional arguments after the first keyword argument.
(c) Michael Metcalf, John Reid, Malcolm Cohen. Modern Fortran Explained.
For details see Fortran Standard (you can grab the copy the final draft of the Fortran 2008 standard by the link provided here), 12.5.2 Actual arguments, dummy arguments, and argument association.
So keyword arguments is a feature known as named arguments or named parameters in other languages.
But this feature is not the only one which can help programmer to write concise and readable code for calling procedures without overloading. Some languages also have default arguments. Fortran has similar feature: so-called optional arguments. It looks a bit different but the aim is the same.
Keyword arguments are often used in conjunction with optional arguments. For example, you should use keyword arguments when you leave out optional arguments in the middle of the argument list.
So what's your question is?
Upvotes: 7