Fortran Operators

I am implementing a cross product of two vectors using ^, however I am getting an error. Not sure how the problem can be solved.

Here is the code

Interface Operator (^)
    Module Procedure vector_cross_product
End Interface Operator (^)

Contains

Function vector_cross_product (u, v) Result (w)

    !!$ Input
    Type (Vector), Intent(in) :: u, v

    !!$ Output
    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 vector_cross_product

      

This is the relevant error code I am getting using gfortran

Interface Operator (^)
                    1
Error: Syntax error in generic specification at (1)
lib/vectors.f:110.18:

  Module Procedure vector_cross_product
                  1
Error: MODULE PROCEDURE at (1) must be in a generic module interface
lib/vectors.f:111.3:

End Interface Operator (^)
   1
Error: Expecting END MODULE statement at (1)

      

+3


source to share


1 answer


I believe that the standard excludes the use of arbitrary characters, such as ^

when defining operators. In the 2008 draft standard, I must specify clauses 7.1.6.1.4.

A binary specified operation is an operation that is of the form x1 define-binary-op x2 or x1-inner x2 and which is defined by a function and a common interface.



Specific-binary-op - a sequence of letters between stops, for example .cross.

, or .times.

, as an internal operator - one of the operators defined in the standard language ( +

, <

, *

etc.).

Subroutine @francescalus, I should add that the sequence should be no more than 63 characters and should not coincide with any internal operators (for example .eq

) or logical literals (for example .true.

)

+5


source







All Articles