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.18 Visibilità 305<br />

• <strong>Il</strong> nome di una procedura interna si estende a tutta l’unità di programma ospite. Inoltre,<br />

tutte le procedure interne ad una stessa unità di programma devono avere nomi differenti.<br />

<strong>Il</strong> seguente frammento fornisce un esempio dei diversi livelli delle unità di visibilità:<br />

MODULE scope1 ! scope 1<br />

... ! scope 1<br />

CONTAINS ! scope 1<br />

SUBROUTINE scope2() ! scope 2<br />

TYPE scope3 ! scope 3<br />

... ! scope 3<br />

END TYPE scope3 ! scope 3<br />

INTERFACE ! scope 3<br />

... ! scope 4<br />

END INTERFACE ! scope 3<br />

REAL :: a, b ! scope 3<br />

10 ... ! scope 3<br />

CONTAINS ! scope 2<br />

FUNCTION scope5() ! scope 5<br />

REAL :: b ! scope 5<br />

b = a+1 ! scope 5<br />

... ! scope 5<br />

END FUNCTION ! scope 5<br />

END SUBROUTINE ! scope 2<br />

END MODULE ! scope 1<br />

A titolo di esempio si riporta il seguente programma che illustra la caratteristica di visibilita’<br />

di una struttura in una procedura interna:<br />

PROGRAM convert<br />

! Questo tipo e’ visibile "anche" dalle procedure interne<br />

TYPE :: polar<br />

REAL :: r, theta<br />

END TYPE polar<br />

!<br />

WRITE(*,*) complex_to_polar(CMPLX(-SQRT(2.0),-SQRT(2.0)))<br />

STOP<br />

CONTAINS<br />

FUNCTION complex_to_polar(z) RESULT(s)<br />

! Queste variabili sono visibili "solo" dalla procedura interna<br />

COMPLEX, INTENT(IN) :: z<br />

TYPE(polar) :: s<br />

s%r = ABS(z)<br />

s%theta = ATAN2(AIMAG(z),REAL(z))<br />

RETURN

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

Saved successfully!

Ooh no, something went wrong!