Fortran type mismatch error

断了今生、忘了曾经 提交于 2019-12-13 20:15:05

问题


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:


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



来源:https://stackoverflow.com/questions/13486909/fortran-type-mismatch-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!