24.07.2013 Views

Capítulo 8. Funções e Subrotinas - UFMG

Capítulo 8. Funções e Subrotinas - UFMG

Capítulo 8. Funções e Subrotinas - UFMG

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

118 <strong>8.</strong>3. Módulos<br />

! Define nome g e n é r i c o para t r o c a de duas v a r i á v e i s q u a i s q u e r .<br />

MODULE gentroca<br />

implicit none<br />

type : : ponto<br />

real : : x , y<br />

end type ponto<br />

!<br />

INTERFACE t r o c a<br />

MODULE PROCEDURE troca ponto , t r o c a r e a l , t r o c a i n t , t r o c a l o g<br />

END INTERFACE t r o c a<br />

!<br />

CONTAINS<br />

elemental subroutine troca ponto ( a , b )<br />

type ( ponto ) , intent ( inout ) : : a , b<br />

type ( ponto ) : : temp<br />

temp= a<br />

a= b<br />

b= temp<br />

end subroutine troca ponto<br />

!<br />

elemental subroutine t r o c a r e a l ( a , b )<br />

real , intent ( inout ) : : a , b<br />

real : : temp<br />

temp= a<br />

a= b<br />

b= temp<br />

end subroutine t r o c a r e a l<br />

!<br />

elemental subroutine t r o c a i n t ( a , b )<br />

integer , intent ( inout ) : : a , b<br />

integer : : temp<br />

temp= a<br />

a= b<br />

b= temp<br />

end subroutine t r o c a i n t<br />

!<br />

elemental subroutine t r o c a l o g ( a , b )<br />

logical , intent ( inout ) : : a , b<br />

l o g i c a l : : temp<br />

temp= a<br />

a= b<br />

b= temp<br />

end subroutine t r o c a l o g<br />

END MODULE gentroca<br />

Autor: Rudi Gaelzer – IFM/UFPel Impresso: 23 de abril de 2008

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

Saved successfully!

Ooh no, something went wrong!