13.07.2015 Views

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

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.

<strong>Fortran</strong> <strong>90</strong>/<strong>95</strong> <strong>Programming</strong> <strong>Manual</strong>External proceduresAn example of a program that contains two functions:program angv1v2implicit nonereal, dimension (3) :: v1, v2real :: ang! define two vectors v1 and v2v1(1) = 1.0v1(2) = 0.0v1(3) = 2.0v2(1) = 1.5v2(2) = 3.7v2(3) = 2.0print * , "angle = ", ang (v1, v2)end program angv1v2! ang computes the angle between 2 vectors vect1 and vect2function ang (vect1, vect2 )implicit none! function resultreal :: ang! dummy argumentsreal, dimension (3), intent (in) :: vect1, vect2! local variablesreal :: cosang, normcosang = vect1(1) * vect2(1) + vect1(2) * vect2(2) + vect1(3) * vect2(3)cosang = cosang / (norm(vect1) * norm(vect2))ang = acos (cosang)end function ang! norm returns the norm of the vector vfunction norm (v)implicit nonereal :: norm! dummy argumentsreal, dimension (3) :: vnorm = sqrt ( v(1) ** 2 + v(2) ** 2 + v(3) ** 2)end function norm27

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

Saved successfully!

Ooh no, something went wrong!