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.

98 <strong>8.</strong>2. sub-programas<br />

Programa <strong>8.</strong>2: Exemplifica o uso de matrizes de forma assumida.<br />

program prog sub<br />

implicit none<br />

real , dimension ( 0 : 9 , 1 0 ) : : a<br />

real , dimension ( 5 , 5 ) : : c<br />

real : : valor max<br />

integer : : i<br />

INTERFACE<br />

subroutine sub ( ra , rb , rc , max a )<br />

real , dimension ( : , : ) , intent ( in ) : : ra , rb<br />

real , dimension ( : , : ) , intent ( out ) : : rc<br />

real , intent ( out ) : : max a<br />

end subroutine sub<br />

END INTERFACE<br />

!<br />

a= reshape ( source =(/( cos ( real ( i ) ) , i= 1 , 1 0 0 ) / ) , shape= ( / 1 0 , 1 0 / ) )<br />

c a l l sub ( a , a ( 0 : 4 , : 5 ) , c , valor max )<br />

print , ”A matriz a : ”<br />

do i= 0 , 9<br />

print , a ( i , : )<br />

end do<br />

print , ””<br />

print , ”O maior v a l o r em a : ” , valor max<br />

print , ””<br />

print , ”A matriz c : ”<br />

do i= 1 , 5<br />

print , c ( i , : )<br />

end do<br />

end program prog sub<br />

SUBROUTINE EXEMPLO(PALAVRA1)<br />

IMPLICIT NONE<br />

CHARACTER(LEN= *) :: PALAVRA1<br />

CHARACTER(LEN= LEN(PALAVRA1)) :: PALAVRA2<br />

...<br />

como um exemplo. Se este objeto consiste em uma função de caractere de tamanho variável, a interface deve<br />

ser explícita, como no programa-exemplo loren abaixo.<br />

A definição dos limites das dimensões de um objeto automático pode ser realizada também de argumentos<br />

mudos ou de variáveis definidas por associação por uso ou por associação ao hospedeiro. Associação por uso<br />

program l o r e n<br />

implicit none<br />

character ( len= ) , parameter : : a= ”Só um pequeno exemplo . ”<br />

print , dobro ( a )<br />

CONTAINS<br />

function dobro ( a )<br />

character ( len= ) , intent ( in ) : : a<br />

character ( len= 2 len ( a)+2) : : dobro<br />

dobro= a // ” ” // a<br />

return<br />

end function dobro<br />

end program l o r e n<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!