-
Notifications
You must be signed in to change notification settings - Fork 7
Taste
Stefano Zaghi edited this page Nov 6, 2015
·
2 revisions
VecFor allows a very simple, high-level implementation of vectorial calculus algebra.
use vecfor ! load vector type and all helperstype(vector) :: point1
type(vector) :: point2
type(vector) :: distancepoint1 = 1 * ex ! ex is the versor along x direction exposed by VecFor
point2 = 1 * ex + 2 * ey ! ey is the versor along y direction exposed by VecForNote that ex, ey and ez are the Cartesian versors exposed by VecFor.
distance = point2 - ponint1print "(A)", " Vectorial distance"
call distance%print
print "(A)", " Distance module"
print*, distance%normL2()
! expected output
! Vectorial distance
! Component x 0.000000000000000E+000
! Component y +0.200000000000000E+001
! Component z 0.000000000000000E+000
! Distance module
! +0.200000000000000E+001As you can see from the above example, defining and using a vector become very close to the mathematical formulation. Note that, using the dynamic dispatching resolved at compile time, there is no performance penalty on using a type(vector) variable instead of an hard-coded real, dimension(3) array variable (or even more verbose and less clear real :: x, y, z variables for each vector...).
Home | About | Getting Started Guide | Usage | Copyright © 2015 szaghi