【发布时间】:2021-08-18 21:30:56
【问题描述】:
我的问题
我意识到需要在我的项目中实现从 Fortran 到 Python 的正式连接(上下文如下),我的场景对于 f2py 或 forpy 来说似乎是完美的场景。我选择了 forpy,因为它似乎更适合从 Fortran 调用 Python,而这在 f2py 中似乎更困难。
我克隆了 git repo 并浏览了 Getting Started 部分,但在编译 forpy_mod.F90 时遇到了一个奇怪的错误(粘贴在下面)。有谁知道这个错误的原因/解决方法?
- 在 linux 机器上使用 python 3.8.8 运行 miniconda
- [编辑:] 使用 GNU Fortran (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
可能是不必要的上下文:
我正在使用一个基于 Fortran 的大型轨道软件,该软件由数千个 Fortran 子例程组成。我的任务是在其中一个子例程中调用 Python 代码,然后调用 Python API,该 API 已简化为将单个值返回给 Fortran 程序。这一序列将在一次轨道运行中发生数万到数十万次。
我已经使用 Fortran 的 EXECUTE_COMMAND_LINE() 函数成功地在这两个程序之间建立了连接,但是 Python 代码本身有很大的开销,当从命令行调用时,它会重新导入包(其中有很多) 每次调用该函数时。这会导致运行时间非常长(使用默认值只需要大约 6 分钟)。我已经尽我所能减少了 Python API 的开销。
尝试编译 forpy 时出错
$ gfortran -c forpy_mod.F90
forpy_mod.F90:1924.54:
character(kind=C_CHAR, len=:), pointer :: doc_string
1
Error: Deferred-length character component 'doc_string' at (1) is not yet supported
forpy_mod.F90:1961.54:
character(kind=C_CHAR, len=:), pointer :: doc_string
1
Error: Deferred-length character component 'doc_string' at (1) is not yet supported
forpy_mod.F90:1961.54:
character(kind=C_CHAR, len=:), pointer :: doc_string
1
Error: Deferred-length character component 'doc_string' at (1) is not yet supported
forpy_mod.F90:11788.12:
m = c_loc(self%methods)
1
Error: Argument 'self' to 'c_loc' at (1) must be an associated scalar POINTER
forpy_mod.F90:9581.41:
flag = strcmp(buffer_format, c_loc(format_code))
1
Error: CHARACTER argument 'format_code' to 'c_loc' at (1) must have a length of 1
forpy_mod.F90:9586.43:
flag = strcmp(buffer_format, c_loc(format_code))
1
Error: CHARACTER argument 'format_code' to 'c_loc' at (1) must have a length of 1
forpy_mod.F90:9595.41:
flag = strcmp(buffer_format, c_loc(format_code))
1
Error: CHARACTER argument 'format_code' to 'c_loc' at (1) must have a length of 1
forpy_mod.F90:9600.43:
flag = strcmp(buffer_format, c_loc(format_code))
1
Error: CHARACTER argument 'format_code' to 'c_loc' at (1) must have a length of 1
forpy_mod.F90:9606.43:
flag = strcmp(buffer_format, c_loc(format_code))
1
Error: CHARACTER argument 'format_code' to 'c_loc' at (1) must have a length of 1
forpy_mod.F90:9613.37:
flag = strcmp(buffer_format, c_loc(format_c_string))
1
Error: CHARACTER argument 'format_c_string' to 'c_loc' at (1) must have a length of 1
forpy_mod.F90:9292.24:
buffer%format = c_loc(format_c_string)
1
Error: CHARACTER argument 'format_c_string' to 'c_loc' at (1) must have a length of 1
forpy_mod.F90:9186.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:9102.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:9018.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8934.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8850.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8766.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8682.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8598.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8514.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8430.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8346.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8262.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8178.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
forpy_mod.F90:8094.51:
ierror = ndarray_create_nocopy_helper(res, c_loc(array), shape(array, kind=PY
1
Error: Assumed-shape array 'array' at (1) cannot be an argument to the procedure 'c_loc' because it is not C interoperable
Fatal Error: Error count reached limit of 25.
【问题讨论】:
-
4.8.5,虽然是许多基于 RH 的发行版的默认版本,但太旧了,无法让编程和使用 Fortran 成为一种愉快的体验。
-
感谢所有这些有用的信息和捕捉我的编辑哈哈
标签: python compiler-errors fortran gfortran