从外部文件使用Fortran模块

问题描述

我想调用模块中包含的子例程。该模块将保存在文件名为 my_mod.f95 的单独文件中。

module calc_mean
! this module contains two subroutines
implicit none
public :: calc_sum
public :: mean

contains
subroutine calc_sum(x,n,s)
! this subroutine calculates sum of elements of a vector
! x the vector
! n size of the vector
! s sum of elements of x

integer,intent(in):: n
real,intent(in):: x(n)
integer :: i
real,intent(out):: s
s=0
do i=1,n
s=s+x(i)
end do
end subroutine calc_sum
!
!
!
subroutine mean(x,xav)
! this subroutine calculates the mean of a vector
! x the vector
! n size of the vector
! xav mean of x

integer,intent(in):: x(n)
real,intent(out):: xav
real :: s
!
!
call calc_sum(x,s)
xav=s/n
end subroutine mean
end module calc_mean
 

我用'my_program.f95'

将主程序保存在另一个文件
program find_mean
! this program calculates mean of a vector
use calc_mean
implicit none

! read the vector from a file
integer,parameter ::n=200
integer :: un,ierror
character (len=25):: filename
real :: x(n),xav
un=30
filename='randn.txt'
! 
OPEN (UNIT=un,FILE=filename,STATUS='OLD',ACTION='READ',IOSTAT=ierror)
read(un,*) x ! 
!
call mean(x,xav)

write (*,100) xav
100 format ('mean of x is',f15.8)
end program find_mean

当我用 geany 编译主程序时,出现以下错误消息。请帮帮我!

**
/ usr / bin / ld:/tmp/cctnlPMO.o:在函数MAIN__': my_program.f08:(.text+0x1e1): undefined reference to __ calc_mean_MOD_mean'中 collect2:错误:ld返回1退出状态

**

当我将主程序和模块都保存到同一文件并运行它时,一切都很好。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...