! 例題 9-3 スカラ積とベクトル積 [構造型変数名での出力 ] PROGRAM ex9_3 IMPLICIT NONE REAL :: s TYPE vector REAL :: x, y, z END TYPE vector TYPE ( vector ) :: a, b, c PRINT *, 'Input 3 components of the first vector: ' READ *, a PRINT *, 'Input 3 components of the second vector: ' READ *, b ! s = a * b とは書けない s = a%x * b%x + a%y * b%y + a%z * b%z PRINT '( 1P, "a.b = ", E9.2 )', s c = vector_product( a, b ) PRINT '( 1P, "a^b = (", E9.2, ",", E9.2, ",", E9.2, ")" )', c CONTAINS FUNCTION vector_product( u, v ) RESULT ( w ) IMPLICIT NONE TYPE ( vector ) :: u, v, 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 vector_product END PROGRAM ex9_3