【问题标题】:Error(1147): This module has already been defined错误(1147):该模块已被定义
【发布时间】:2021-02-26 04:12:11
【问题描述】:

我编写的代码使用了另一个代码中的模块(不是我写的)。当我将此模块与主程序一起使用时,它运行良好并且没有显示错误。当我将此模块与子程序一起使用时,它显示:

这个模块已经被定义了

试图正确地总结代码。 这是可重现的代码:

subroutine polygoneclipping(n,vtable0,vcoord0,BOUNDARYPOINTS0,NEWvcoord0,Unumber)

use SutherlandHodgmanUtil
 only : polygon,sutherlandHodgman,edgeClipping

type(polygon) :: p1, p2, res
integer :: c, n 
double precision, dimension(2) :: y1, y2
integer(kind =3) :: i, Unumber
integer(kind =3), dimension(40,1) :: vtable0
real(kind =3), dimension(40,2) :: VCOORD0
real(kind =3), dimension(4,2) :: BOUNDARYPOINTS0
real(kind =3), dimension(40,2) :: NEWvcoord0

!MAIN SUB PART

end subroutine

module SutherlandHodgmanUtil

type polygon
!type for polygons
! when you define a polygon, the first and the last vertices have to be the same
integer :: n
double precision, dimension(:,:), allocatable :: vertex
end type polygon

contains 

subroutine sutherlandHodgman( ref, clip, outputPolygon )

type(polygon) :: ref, clip, outputPolygon

type(polygon) :: workPolygon               ! polygon clipped step by step 
double precision, dimension(2) :: y1,y2    ! vertices of edge to clip workPolygon
integer :: i  

!MAIN SUB PART

end subroutine sutherlandHodgman

subroutine edgeClipping( poly, y1, y2, outputPoly )

type(polygon) :: poly, outputPoly
double precision, dimension(2) :: y1, y2, x1, x2, intersecPoint
integer ::  i, c

!MAIN SUB PART

end subroutine edgeClipping

function intersection( x1, x2, y1, y2)
double precision, dimension(2) :: x1, x2, &  ! points of the segment
                        y1, y2     ! points of the line

double precision, dimension(2) :: intersection, vx, vy, x1y1 
double precision :: a

!MAIN FUNC PART

end function intersection

function inside( p, y1, y2)
double precision, dimension(2) :: p, y1, y2, v1, v2
logical :: inside

!MAIN FUNC PART

end function inside

end module SutherlandHodgmanUtil

这是什么错误,为什么会出现?

我会很高兴得到任何帮助并原谅我的长代码。

【问题讨论】:

  • 你如何使用subroutine polygoneclipping?请提供program 并说明您是如何拆分文件的。
  • @jack 编译上述子程序时出现此错误。
  • 请告诉我们更多信息。究竟是什么在哪个文件中?您正在运行哪些确切的命令?正如杰克的回答所示,如果你只是运行上面显示的代码,你会得到一个不同的错误。

标签: fortran


【解决方案1】:

如果我运行您的代码,我会收到以下错误消息

a.f90:3:7:

    3 |   use SutherlandHodgmanUtil
      |       1
Fatal Error: Cannot open module file ‘sutherlandhodgmanutil.mod’ for reading at (1): No such file or directory

对此的解释:在 Fortran 中没有自动的forward declarations。 这意味着尝试包含sutherlandhodgmanutil 的子例程失败,因为尚未定义模块。

解决方案:

  1. 在模块之后定义子程序。
  2. 首选方式:为模块创建一个单独的文件,然后先编译模块。

您的错误信息

这个模块已经被定义了

可能是因为您已经事先编译了模块SutherlandHodgmanUtil? 来自不同的文件或不同的测试运行? 但这只是一个疯狂的猜测..


顺便说一句,我不得不更改您的代码,因为 integer(kind=3) 在我的机器上不可用。 一般来说,最好使用与机器无关的种类定义,例如查看use iso_fortran_env, only: int32, real32

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 2020-07-10
    • 1970-01-01
    • 2014-12-20
    相关资源
    最近更新 更多