【问题标题】:Error compiling subroutine which uses module defined in same fortran file编译使用在同一 fortran 文件中定义的模块的子例程时出错
【发布时间】:2015-04-08 11:10:28
【问题描述】:

我正在尝试编译一个fortran文件,timedel.f,文件

此文件创建模块 gettimedel

  module gettimedel

  parameter (maxpnt=10000)
  double precision :: q(maxpnt),qen(maxpnt)
  integer :: nrestofit

  end module gettimedel

其中定义了两个数组,q、qen 和整数 nrestofit。

在这个 fortran 文件 timedel.f 的后面,我有一个子程序,它使用这个模块来获取这些数组和整数

      subroutine fitlors(nresdum,npt,dum1,dum2,approx,reson,backgr,
 1     error,ifail)

  use gettimedel

  intent(in) nresdum,npt,dum1,dum2,approx
  intent(out) reson,backgr,error,ifail
  integer :: liw,ifail,i,lw,nresdum,npt
  parameter (liw=2000)
  double precision :: error,backgr,fvec(npt),
 1     work(14*(nresdum+1)+4*(nresdum+1)**2 +4*npt*(nresdum+1)
 2     + 3*npt + (nresdum+1)*(2*(nresdum+1)-1))
  double precision :: dum1(npt),dum2(npt),reson(nresdum*2)
  double precision :: x(nresdum*2+1),tol
  integer :: approx(nresdum),info,iw(liw)
  external fcn,lmdf1
  work=0.0D0
  x=0.0D0
  nrestofit=nresdum
  q(1:npt)=dum1
  qen(1:npt)=dum2
  do i=1,nrestofit
     x(2*i-1)=qen(approx(i))
     x(2*i)=q(approx(i))
  enddo
  tol=1.0D-03

          call lmdif1 (fcn,npt,nrestofit*2+1,x,fvec,tol,info,iw,
 *              work,lw)            
  reson=x(1:nrestofit*2)
  backgr=x((nrestofit*2)+1)
    print *,'Fitlors done.INFO=',info
  return
  end

这个子程序使用这个模块gettimedel来定义整数nrestofit以及模块中使用的数组q()和qen()。

但是,当我编译这个 fortran 文件时,我看到了错误消息

timedel.f(1): error #7001: Error in creating the compiled module file.   [GETTIMEDEL]
      module gettimedel
-------------^
timedel.f(388): error #7002: Error in opening the compiled module file.  Check INCLUDE paths.   [GETTIMEDEL]
      use gettimedel
----------^
timedel.f(407): error #6404: This name does not have a type, and must have an explicit type.   [NRESTOFIT]
      nrestofit=nresdum
------^
timedel.f(415): error #6404: This name does not have a type, and must have an explicit type.   [Q]
      q(1:npt)=dum1
------^
timedel.f(415): error #6514: A substring must be of type CHARACTER.   [Q]
      q(1:npt)=dum1
------^
timedel.f(415): error #6054: A CHARACTER data type is required in this context.   [DUM1]
      q(1:npt)=dum1
---------------^
timedel.f(415): error #6366: The shapes of the array expressions do not conform.   [Q]
      q(1:npt)=dum1
------^
timedel.f(416): error #6404: This name does not have a type, and must have an explicit type.   [QEN]
      qen(1:npt)=dum2
------^
timedel.f(416): error #6514: A substring must be of type CHARACTER.   [QEN]
      qen(1:npt)=dum2
------^
timedel.f(416): error #6054: A CHARACTER data type is required in this context.   [DUM2]
      qen(1:npt)=dum2
-----------------^
timedel.f(416): error #6366: The shapes of the array expressions do not conform.   [QEN]
      qen(1:npt)=dum2
------^
compilation aborted for timedel.f (code 1)
make: *** [timedel.o] Error 1

我可以解决这个问题,但在子例程 fitlors 中定义 q、qen 和 nrestofit 的类型,但是我想修复它,以便模块 gettimedel 正确定义这些类型。 (我认为我的代码应该这样做)。

我认为这不是 INCLUDE 路径的问题,因为模块 gettimedel 是在与子例程相同的文件中创建的。

我正在使用 ifort 编译器。

任何帮助将不胜感激,如果需要更多信息,请告诉我。

非常感谢

詹姆斯

(函数 lmdif1 是从 minpack 中调用的)

【问题讨论】:

  • 你的编译命令是什么样子的?

标签: compiler-errors fortran


【解决方案1】:

您可能想尝试解决此问题的一些建议(这种格式我无法发表评论):

1 将子程序 fitlors 放入一个新模型中(如果你愿意,可以在同一个文件中),然后在这个模型中使用 gettimedel

2 尝试将您的子程序放在主程序后面(可能您已经这样做了)

4 通常我将我的参数定义为(也许 maxpnt 是罪魁祸首?):

integer, parameter :: a=1

5 尝试添加隐式无,看看编译器输出是否改变

【讨论】:

  • 3.废话,乍一看它是一个固定格式的文件,stackoverflow 只是吃掉了行首的空格。
  • @vladimir F 是的。我刚注意到。我的错误 - 编辑更正。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多