25.06.2013 Views

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.16 Procedure generiche 285<br />

Tutte le procedure specificate nel blocco interface devono poter essere invocate in maniera<br />

non ambigua e di conseguenza ogni generic interface block può contenere solo funzioni o solo<br />

subroutine. A titolo di esempio, si supponga di volere scrivere una subroutine che permetta<br />

di ”invertire” due numeri che possono essere, a seconda dei casi, entrambi reali o entrambi<br />

complessi oppure entrambi interi. Ciò può essere fatto scrivendo le tre subroutine seguenti:<br />

SUBROUTINE swapint<br />

IMPLICIT NONE<br />

INTEGER, INTENT(INOUT) :: a, b<br />

INTEGER :: temp<br />

temp = a<br />

a = b<br />

b = temp<br />

END SUBROUTINE swapint<br />

SUBROUTINE swapreal<br />

IMPLICIT NONE<br />

REAL, INTENT(INOUT) :: a, b<br />

REAL :: temp<br />

temp = a<br />

a = b<br />

b = temp<br />

END SUBROUTINE swapreal<br />

SUBROUTINE swapcomplex<br />

IMPLICIT NONE<br />

COMPLEX, INTENT(INOUT) :: a, b<br />

COMPLEX :: temp<br />

temp = a<br />

a = b<br />

b = temp<br />

END SUBROUTINE swapcomplex<br />

Dato, allora, il seguente interface block:<br />

INTERFACE swap<br />

SUBROUTINE swapint(a,b)<br />

INTEGER, INTENT(INOUT) :: a, b<br />

END SUBROUTINE swapint<br />

SUBROUTINE swapreal(a,b)<br />

REAL, INTENT(INOUT) :: a, b<br />

END SUBROUTINE swapreal

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!