! --- scalar and vector products of two vectors --- PROGRAM main IMPLICIT NONE REAL :: s TYPE vector REAL :: x, y, z END TYPE vector TYPE(vector) :: a, b, c PRINT '(1X, A)', 'Input 3 components of the first vector: ' READ *, a PRINT '(1X, A)', 'Input 3 components of the second vector: ' READ *, b s = a%x * b%x + a%y * b%y + a%z * b%z ! s = a * b とは書けない PRINT '("a.b = ", F6.3)', s c = vector_product(a,b) PRINT '("a^b = (", F6.3, ",", F6.3, ",", F6.3, ")")', c CONTAINS FUNCTION vector_product( u, v ) RESULT( w ) IMPLICIT NONE TYPE(vector), INTENT(IN) :: u, v TYPE(vector) :: w w%x = u%y * v%z - u%z * v%y w%y = u%z * v%x - u%x * v%z w%z = u%x * v%y - u%y * v%x END FUNCTION END PROGRAM main