在这个fortran程序中,我已被给予并告知调试,我收到了错误:
“参数'p1'中的类型不匹配(1);将REAL(4)传递给TYPE(点)”
我似乎无法弄清楚错误发生的位置。 我已经尝试定义不同的变量传递给每个函数而不是p1和p2具有相同的错误。有什么想法吗?
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
答案 0 :(得分:4)
提示:尝试“隐式无”。总是一个好主意。