fortran complications passing arrays in function

Posted by user1514188 on Stack Overflow See other posts from Stack Overflow or by user1514188
Published on 2012-11-20T15:57:35Z Indexed on 2012/11/20 17:00 UTC
Read the original article Hit count: 297

Filed under:
|
|
|
|

I'm trying to write a program to calculate a cross product of two vectors (input is of "real" type, so for example [1.3 3.4 1,5]). But I keep getting numerous errors:

    program Q3CW
    implicit none
   REAL :: matA(3), matB(3)
   REAL :: A11, A12, A13
   REAL :: B11, B12, B13
   real :: productc(3), answer(3)
   read*,A11, A12, A13
   read*,B11, B12, B13

   matA = (/A11, A12, A13/)
   matB = (/B11, B12, B13/)
   answer = productc(matA, matB)

   print*,'Answer = ', answer(1), answer(2), answer(3)
   end program

   real function productc(matIn1, matIn2)
   real, dimension(3) :: matIn1, matIn2

   productc(1)=(/matIn1(2)*matIn2(3)-matIn1(3)*matIn2(2)/)
   productc(2)=(/matIn1(3)*matIn2(1)-matIn1(1)*matIn2(3)/)
   productc(3)=(/matIn1(1)*matIn2(2)-matIn1(2)*matIn2(1)/)
   end function

This is the error I get:

   Error: Q33333.f95(20) : Statement function definition for pre-existing procedure PRODUCTC; detected at )@=
   Error: Q33333.f95(21) : Statement function definition for pre-existing procedure PRODUCTC; detected at )@=
   Error: Q33333.f95(22) : Statement function definition for pre-existing procedure PRODUCTC; detected at )@=
   Warning: Q33333.f95(23) : Function PRODUCTC has not been assigned a value; detected at FUNCTION@<end-of-statement>
   Build Result Error(3) Warning(1) Extension(0)

Any idea what the problem could be ?

© Stack Overflow or respective owner

Related posts about function

Related posts about integer