在Fortran 90中从文件中读取函数 [英] Reading function from a file in Fortran 90

查看:248
本文介绍了在Fortran 90中从文件中读取函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Fortran 90中有一个优化求解器。所以,如果我想改变目标函数
,我必须修改主文件并用这种方式编写目标函数:

子程序fobj(n,x,f)
隐式无
整数:: n
实数(8):: f
real(8):: x(n)
intent(in):: n,x
intent(out):: f
!目标函数
f = x(1)** 2-x(2)+ 2 * x(3)
结束子程序fobj

我有一个很大的目标函数,所以我想从一个外部文件或者至少从这个行调用f = x(1)** 2-x(2)+ 2 * x(3) subrutine。



这可能吗? (我是Fortran中的新成员。)



我知道我可以用Python修改文件,但我想在其他文件中完成它。 b
$ b

非常感谢!

解决方案

当然。使用:

  include'file.inc'

包含来自外部文件的源代码。


I have an optimization solver in Fortran 90. So, if I want to change the objective function I have to modified the main file and write the objective function in this way:

  subroutine fobj(n,x,f)
    implicit none
    integer :: n
    real(8) :: f
    real(8) :: x(n)
    intent(in ) :: n,x
    intent(out) :: f
    !OBJECTIVE FUNCTION
    f = x(1)**2-x(2)+2*x(3)
   end subroutine fobj

I have a big objective function, so I want to call this line "f = x(1)**2-x(2)+2*x(3)" from an external file or at least the subrutine.

Is that possible? (I'm new in Fortran.)

I know that I can modified the file with Python, but I want to do it in other file.

Thanks a lot!

解决方案

Sure. Use:

include 'file.inc'

to include source code from an external file.

这篇关于在Fortran 90中从文件中读取函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆