Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran Operators

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

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 corresponding errer 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)
like image 976
Zeus Avatar asked May 20 '26 14:05

Zeus


1 Answers

I believe that the standard rules out the use of arbitrary symbols, such as ^, when defining operators. In the draft of the 2008 standard I have to hand para 7.1.6.1.4 states

A binary defined operation is an operation that has the form x1 defined-binary-op x2 or x1 intrinsic-operator x2 and that is defined by a function and a generic interface.

A defined-binary-op is a sequence of letters between stops, for example .cross. or .times., and an intrinsic-operator is one of the operators defined in the language standard (+, <, *, etc).

Prodded by @francescalus, I should add that the sequence should be no longer than 63 letters and should not be the same as any of the intrinsic operators (e.g. .eq) or logical literals (e.g. .true.)

like image 63
High Performance Mark Avatar answered May 24 '26 01:05

High Performance Mark