在将Fortran77文件与感叹号注释接口时,f2py引发“断言错误”

时间:2019-08-13 13:25:17

标签: fortran fortran90 fortran77 f2py

我的任务是将Fortran 77代码包装到python3中。我试图用以下命令将其包装

inside

f2py出现以下错误

f2py -c mum1_6.f -m mum

代码的相应部分:

running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "mum" sources
f2py options: []
f2py:> /tmp/tmp79t4vbg0/src.linux-x86_64-3.5/mummodule.c
creating /tmp/tmp79t4vbg0/src.linux-x86_64-3.5
Reading fortran codes...
    Reading file 'mum1_6.f' (format:fix,strict)
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
rmbadname1: Replacing "len" with "len_bn".
Post-processing...
    Block: mum
            Block: init_mu
            Block: prinfo
            Block: med_cons
            Block: spl1
            Block: dspl1
            Block: spl2
Traceback (most recent call last):
  File "/home/veniamin/.local/bin/f2py", line 11, in <module>
    sys.exit(main())
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/f2py2e.py", line 683, in main
    run_compile()
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/f2py2e.py", line 650, in run_compile
    setup(ext_modules=[ext])
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/distutils/core.py", line 171, in setup
    return old_setup(**new_attr)
  File "/usr/lib/python3.5/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.5/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/distutils/command/build.py", line 47, in run
    old_build.run(self)
  File "/usr/lib/python3.5/distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/usr/lib/python3.5/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/distutils/command/build_src.py", line 148, in run
    self.build_sources()
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/distutils/command/build_src.py", line 165, in build_sources
    self.build_extension_sources(ext)
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/distutils/command/build_src.py", line 325, in build_extension_sources
    sources = self.f2py_sources(sources, ext)
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/distutils/command/build_src.py", line 562, in f2py_sources
    ['-m', ext_name]+f_sources)
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/f2py2e.py", line 425, in run_main
    postlist = callcrackfortran(files, options)
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/f2py2e.py", line 329, in callcrackfortran
    postlist = crackfortran.crackfortran(files)
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/crackfortran.py", line 3254, in crackfortran
    postlist = postcrack(grouplist[0])
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/crackfortran.py", line 1891, in postcrack
    g = postcrack(g, tab=tab + '\t')
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/crackfortran.py", line 1910, in postcrack
    block['body'] = analyzebody(block, args, tab=tab)
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/crackfortran.py", line 2072, in analyzebody
    b = postcrack(b, as_, tab=tab + '\t')
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/crackfortran.py", line 1910, in postcrack
    block['body'] = analyzebody(block, args, tab=tab)
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/crackfortran.py", line 2072, in analyzebody
    b = postcrack(b, as_, tab=tab + '\t')
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/crackfortran.py", line 1906, in postcrack
    block['vars'] = analyzevars(block)
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/crackfortran.py", line 2653, in analyzevars
    for d in rmbadname([x.strip() for x in markoutercomma(dim).split('@,@')]):
  File "/home/veniamin/.local/lib/python3.5/site-packages/numpy/f2py/crackfortran.py", line 833, in markoutercomma
    assert not f, repr((f, line, l))
AssertionError: (-1, '9) !---> array which contains dimensions for output ', '9) !---> array which contains dimensions for output ')

我不明白的是'!'是什么问题。注释?如果删除它们,不会引发错误。也有很多行带有相同的“!”在这部分代码之前的注释。实际上,我要包装的文件非常有趣,而且几乎在每一行上都有这样的注释。我不知道为什么f2py只有一部分问题。

我试图考虑所有这些问题,并得出结论,这些评论实际上不是Fortran 77标准的一部分,并且可能是这种情况。因此,我决定将扩展名更改为“ .f90”,然后再次运行f2py。这个问题似乎已经解决了。正如我在几个站点上所读到的那样,Fortran 77代码是Fortran 90的子集,因此我确定一切都很好。但是一段时间后,我尝试将一些Fortran 77代码(不是使用f2py而是直接使用编译器)编译为Fortran 90代码,但我发现这并不是那么简单。至少F90编译器不接受老式的'c'注释。

所以我有两个问题:

1)是否可以通过“!”解决这些问题?内联注释而不将文件编译为f90?

2)将我的.f文件作为.f90馈送到f2py甚至正确吗? f2py是否会在同一个文件中分隔不同的“代码标准”,并以正确的方式进行换行?

不幸的是,我正在谈论的代码非常庞大,可以将其附加在代码段中。

1 个答案:

答案 0 :(得分:0)

因此,我在将程序与f2py作为F77交互时没有任何运气。我尝试将其作为F90文件提供给f2py,它对我来说很好用,因为Fortran 90编译器了解固定格式表示法。