当前将 python 代码包装到 Fortran 子程序中的最佳方法

问题描述

目前我正在运行一个由 Fortran 90 编写的大气模型。在一些子程序中,我使用 python(主要是 tensorflow)做了一些创新。现在我需要将这个 python 代码实现到 Fortran 中,那么是否有任何包装器可以做到这一点?只是在 Fortran 子程序中调用 python?我知道 F2py 能够将 fortran 代码包装到 python 脚本中,即在 python 脚本中调用 fortran 子例程,但我想做相反的方式。我搜索了互联网,但找不到方法

这是我的想法的伪代码

SUbroUTINE demo(INPUTS,OUTPUTS)
! DeFinition of INPUTS
REAL,DIMENSION(:,:,:),INTENT(IN) :: PINPUTS
REAL,INTENT(IN) :: POUTPUTS

PINPUTS = INPUTS

! using some python wrappers
POUTPUTS = python_wrapper(PINPUTS)

OUTPUTS = POUTPUTS
END SUbroUTINE demo

在python脚本“python_wrapper.py”中,我需要做

import tensorflow as tf

# read saved model "model_saved";
# get the variables "OUTPUTS" passed from demo.f90;

prediction = model_saved.predict(OUTPUTS)

# then pass this variable "prediction" back to Fortran subroutine demo.f90;
# so that the "prediction" will be used for following calculation of the atmospheric model

请注意,不可能将大气模型(最初在 Fortran 90 代码中)重写为 python 代码,重新发明这将花费我很多时间。而且也不可能将所有部分(包括大气模型和python脚本的创新部分)都运行到一个python脚本中,因为demo.f90子程序只是整个Fortran 90大气模型的一个小分支。

那么有什么软件包可以做到这一点吗?非常感谢! 非常感谢!

解决方法

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

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

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