Ben Hocking
Ben Hocking

Reputation: 8082

How do I suppress an unused dummy argument warning for a single function in Fortran?

I have the following FORTRAN code:

FUNCTION inverse_deterministic_cdf(dist, p) RESULT(value)
    !=========== result ============
    REAL(C_DOUBLE) :: value

    !====== input parameters =======
    TYPE(deterministic), INTENT(IN) :: dist
    REAL(C_DOUBLE), INTENT(IN) :: p

    !======= subroutine body =======
    value = p ! This is only here to suppress unused dummy argument warning
    value = dist%value
END FUNCTION inverse_deterministic_cdf

In this case, inverse_deterministic_cdf is an implementation of an inverse_cdf interface, which is why there's the unused p here. As you can see, I have a method of suppressing the unused dummy argument, but it feels inelegant to me. Does anyone have any best practices for how they handle this? (I also want this to be compiler agnostic.) I know how to suppress the warnings universally, but I want to be warned when I have an unused dummy argument and I'm not anticipating it.

Edit to add (upon request):

The inverse_cdf interface is defined thusly:

INTERFACE inverse_cdf
    MODULE PROCEDURE inverse_distribution_cdf, inverse_normal_cdf, inverse_lognormal_cdf, inverse_deterministic_cdf
END INTERFACE

Upvotes: 2

Views: 1879

Answers (2)

janneb
janneb

Reputation: 37208

Since you have your procedure in a module (and thus, the procedure has an explicit interface), why not use an optional argument? E.g. something like


FUNCTION inverse_cdf(dist, p) RESULT(value)
    !=========== result ============
    REAL(C_DOUBLE) :: value

    !====== input parameters =======
    TYPE(deterministic), INTENT(IN) :: dist
    REAL(C_DOUBLE), INTENT(IN), OPTIONAL :: p

    !======= subroutine body =======
    IF (PRESENT(p)) THEN
        value = dist%value * p ! Some expression using p
    ELSE
        value = dist%value
    END IF
END FUNCTION inverse_cdf

Upvotes: 0

Wildcat
Wildcat

Reputation: 8870

My guess would be that you need to define a generic interface.

stuff.f90

MODULE stuff

  IMPLICIT NONE

  INTERFACE stuff_foo
    MODULE PROCEDURE foo1
    MODULE PROCEDURE foo2
  END INTERFACE stuff_foo

  CONTAINS

    FUNCTION foo1(a) RESULT(f)
    REAL :: a
    REAL :: f

      f = a

    END FUNCTION foo1

    FUNCTION foo2(a, b) RESULT(f)
    REAL :: a
    REAL :: b
    REAL :: f

      f = a + b

    END FUNCTION foo2

END MODULE stuff

main.f90

PROGRAM main

  USE stuff

  IMPLICIT NONE

  PRINT *, stuff_foo(1.0)
  PRINT *, stuff_foo(1.0, 2.0)

END PROGRAM main

Upvotes: 3

Related Questions