Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29252 Discussions

Using An Optional Dummy Arguments in a Function

stutzbach
Beginner
476 Views
hello,

i have a problem using optional parameters in a function. i allways get the error #7836 (if the actual element is scalar, the corresponding dummy argument shall be scalar....)

the function's code is a follows:

FUNCTION get_wgprop_fn(this, wgcf, wgct, t)

IMPLICIT NONE

CLASS(tprop) :: this

REAL, DIMENSION(5) :: get_wgprop_fn

REAL, DIMENSION(4), INTENT(IN), OPTIONAL :: wgcf

REAL,DIMENSION(3), INTENT(IN), OPTIONAL :: wgct

REAL, INTENT(IN), OPTIONAL :: t

IF (PRESENT(wgcf)) THEN
get_wgprop_fn = 1
END IF

IF (PRESENT(wgct)) THEN
get_wgprop_fn = 2
END IF

IF (PRESENT(t)) THEN
wgprop_fn = wgprop_fn * 2
END IF

END FUNCTION get_wgprop_fn

calling the function from extern like

test = get_wgprop(ac) with ac as a real dimension(4) array results in no error.

but

t = get_wgprop(ac, t) with ac as defined above and t as real result in the error described a the top of this topic.

perhaps somebody sees the mistake in my code? i think, the optional-keyword says that a dummy-argments
must no be present? in the second case (get_wgprop(ac, t) the compiler searches for a dimension(3)-array what in my understanding cant be because of the optional argument???

greetings moritz

0 Kudos
1 Reply
Steven_L_Intel1
Employee
476 Views
If you just say get_whprop(ac, t), the actual argument t is associated with the dummy argument wgcf, which is not what you want. If you want to "skip" optional arguments, you must use keyword specifiers. For example:

t = get_wgprop(ac,T=t)
0 Kudos
Reply