Capítulo 8. Funções e Subrotinas - UFMG
Capítulo 8. Funções e Subrotinas - UFMG
Capítulo 8. Funções e Subrotinas - UFMG
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Capítulo</strong> <strong>8.</strong> Sub-Programas e Módulos 101<br />
! Usa s u b r o t i n a p l o t a e chama a função externa Meu F .<br />
!<br />
program t e s p l o t a<br />
implicit none<br />
integer : : pts , j<br />
real : : yi , yf<br />
real , dimension ( : , : ) , allocatable : : xy<br />
INTERFACE<br />
subroutine p l o t a ( f , xi , xf , npt , p l o t )<br />
integer , intent ( in ) : : npt<br />
real , intent ( in ) : : xi , xf<br />
real , dimension ( 2 , npt ) , intent ( out ) : : p l o t<br />
INTERFACE<br />
function f ( x )<br />
real : : f<br />
real , intent ( in ) : : x<br />
end function f<br />
END INTERFACE<br />
end subroutine p l o t a<br />
!<br />
function Meu F( y )<br />
real : : Meu F<br />
real , intent ( in ) : : y<br />
end function Meu F<br />
END INTERFACE<br />
!<br />
print , ”Entre com o número de pontos : ”<br />
read , pts<br />
print , ”Entre com os l i m i t e s i n f e r i o r e s u p e r i o r : ”<br />
read , yi , yf<br />
allocate ( xy ( 2 , pts ) )<br />
!<br />
c a l l p l o t a (Meu F , yi , yf , pts , xy )<br />
!<br />
do j= 1 , pts<br />
print , xy ( : , j )<br />
end do<br />
end program t e s p l o t a<br />
! Função sen ( exp ( x ) ) .<br />
function Meu F( x )<br />
real : : Meu F<br />
real , intent ( in ) : : x<br />
!<br />
Meu F= s i n ( exp ( x ) )<br />
return<br />
end function Meu F<br />
Autor: Rudi Gaelzer – IFM/UFPel Impresso: 23 de abril de 2008