-2

I get the error

"Fortran expected a right parenthesis in expression at (1)"

when specifying a component of a declared type in a subroutine. The (1) appears underneath the second % in the assignment from a, b, c in the subroutine. What am I doing wrong? Thanks in advance.

program prototipo

implicit none

!DECLARACIÓN DE TIPOS
type triangulo
    integer :: vertices(3)          !VECTOR DE VÉRTICES DE CADA TRIÁNGULO EN NUBE DE VÉRTICES
    real (kind = 8) :: X(3)         !VECTOR DE COORDENADAS X DE LOS TRES VÉRTICES DEL TRIÁNGULO
    real (kind = 8) :: Y(3)         !VECTOR DE COORDENADAS Y DE LOS TRES VÉRTICES DEL TRIÁNGULO
    real (kind = 8) :: area_triang  !ÁREA DEL TRIÁNGULO
end type triangulo

!irrelevant code removed

contains

subroutine Area (V)

  implicit none 
  type(triangulo), intent(inout) :: V       !VECTOR DE TRIÁNGULOS

    integer :: i                            !ÍNDICE
    real (kind = 8) :: a, b, c              !LONGITUDES DEL LADO DE CADA TRIANGULO
    real (kind = 8) :: t                    !TÉRMINO PARA CALCULAR LA ALTURA
    real (kind = 8) :: h                    !ALTURA

    do i = 1, 8042  
        a = sqrt(((V(i)%X(2) - V(i)%X(1))**2) + ((V(i)%Y(2) - V(i)%Y(1))**2))
        b = sqrt(((V(i)%X(3) - V(i)%X(1))**2) + ((V(i)%Y(3) - V(i)%Y(1))**2))
        c = sqrt(((V(i)%X(3) - V(i)%X(2))**2) + ((V(i)%Y(3) - V(i)%Y(2))**2))
        t = (sqrt((a + b - c)*(a - b + c)*(-a + b + c)*(a + b + c))) / 2.D0
        h = t / b
        V(i)%area_triang = (b*h) / 2.D0
    end do

end subroutine Area

end program
Steve
  • 109
  • 4
  • I forgot to mention, but the parentheses are checked and ok. It is an error concerning something else, hence something I am unable to spot. I am new to Fortran so it is likely a newbie mistake. – Steve Apr 16 '15 at 01:13

1 Answers1

1

You have incorrectly declared V to be a single triangle in subroutine Area rather than an array of triangles. Change your declaration to

type(triangulo), intent(inout) :: V(:)     !VECTOR DE TRIÁNGULOS

and it compiles.

RussF
  • 711
  • 3
  • 4