Fortran type mismatch error

2019-09-16 08:57发布

In this fortran program I've been given and told to debug, I'm getting the error:

"type mismatch in argument 'p1' at (1); passed REAL(4) to TYPE(point)"

and I can't seem to figure out where the error is occuring. I've tried defining different variables to pass to each function instead of p1 and p2 with the same error. Any ideas?

MODULE PointType

TYPE POINT
REAL:: x
REAL:: y
END TYPE

CONTAINS

FUNCTION arePointsEqual(p1, p2)
REAL:: arePointsEqual
TYPE(POINT), INTENT(IN):: p1
TYPE(POINT), INTENT(IN):: p2
LOGICAL :: isEqual
IF ( p1%x == p2%x .AND. p1%y == p2%y) THEN
isEqual = .TRUE.
ELSE
isEqual = .FALSE.
END IF
END FUNCTION

 FUNCTION arePointsNotEqual(p1,p2)
 REAL:: arePointsNotEqual
 TYPE(POINT), INTENT(IN):: p1
 TYPE(POINT), INTENT(IN):: p2
 LOGICAL :: isNotEqual

 IF ( p1%x == p2%x .AND. p1%y == p2%y) THEN
 isNotEqual = .FALSE.
 ELSE
 isNotEqual = .TRUE.
 END IF
 END FUNCTION

 FUNCTION distance(p1, p2)
 REAL:: distance
 TYPE(POINT), INTENT(IN):: p1
 TYPE(POINT), INTENT(IN):: p2
 distance = SQRT((p2%x - p1%x)**2 + (p2%y - p1%y)**2)
 END FUNCTION

 END MODULE

 !MAIN PROGRAM BELOW THIS LINE

 PROGRAM Project3

 USE PointType

 PRINT *, arePointsEqual(p1, p2)

 PRINT *, arePointsNotEqual(p1, p2)

 PRINT *, distance(p1, p2)

 END PROGRAM Project3

1条回答
The star\"
2楼-- · 2019-09-16 09:30

Hint: try "implicit none". Always a good idea.

查看更多
登录 后发表回答