Coder Social home page Coder Social logo

dlr-sc / f2x Goto Github PK

View Code? Open in Web Editor NEW
38.0 4.0 5.0 1.83 MB

A versatile, template-based FORTRAN wrapper written in Python.

License: Apache License 2.0

GAP 19.83% Python 58.04% Fortran 11.84% Makefile 0.41% Perl 8.97% C 0.52% Raku 0.38%
fortran python wrapper fortran-wrappers hybrid-programming hpc

f2x's Introduction

F2x

A versatile, template-based Fortran wrapper written in Python.

F2x is a Python tool that allows you to take your Fortran code and make it accessible from other languages (mainly Python). Compared to the popular tool f2py it comes with two important differences:

Quickstart

Documentation Status

To install the latest version of F2x, you can use the following commands:

  1. git clone https://github.com/DLR-SC/F2x.git
  2. cd F2x
  3. python setup.py install --user (Note the --user flag to allow installation without admin rights.)
  4. F2x --help (Confirms installation of F2x.)

Please refer to the documentation to find more infomation about getting started.

Requirements and acknowledgements

F2x reuses a lot of stuff from other Open Source projects. Namely the following parts were really helpful:

  • It is developed in Python 3 and does currently not support Python 2 out of the box.
  • The PLY project is used as parser generator. PlyPlus does the heavy lifiting of converting ANTLR-like grammars to PLY.
  • The Fortran grammar that comes bundled with F2x originates from the OpenFortranProject.
  • Templates are based on Jinja2.

Legal stuff

Copyright 2018 German Aerospace Center (DLR)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

f2x's People

Contributors

led02 avatar melven avatar pankfr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

f2x's Issues

Prepare for publication

  • Review documentation
    • Adapt Readme for getting started
    • Review other documenation, at least add a note where it is superceeded
  • Add copyright to all files
  • Add citation hint
  • Tag version "1.0"

No support for Fortran Interfaces

Currently, there is no support for the interface construct.
Also the parser accepts those constructs, they are not handled by the templates and AST transformers.

The 'F2x==0.1.dev0' distribution was not found

After installing F2x on a SLED12 using our module system, I obtain the following error:

F2x --help
Traceback (most recent call last):
File "/tools/modulesystem/tools/F2x/F2x-git/install/sled12.x86_64.gcc-4.8.5.release/bin/F2x", line 5, in
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2912, in
@_call_aside
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2898, in _call_aside
f(_args, *_kwargs)
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 2925, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 642, in _build_master
ws.require(requires)
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 943, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python2.7/site-packages/pkg_resources/init.py", line 830, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'F2x==0.1.dev0' distribution was not found and is required by the application

There might just be some missing paths or so...any idea?

Here the output of the install script: f2x_install_sled12.zip

Syntax errors for valid Fortran

The Fortran grammar specification has several issues:

  1. Kind-specifiers for constants are not supported, e.g. 1.0_8 or 1.0_myKindParameter
  2. kind is not only a keyword inside a declaration, but also an intrinsic function, e.g. i = kind(1.)
  3. Fortran explicitly allows reusing keywords of the language. Keywords are not reserved, you can for example name a variable value or kind. The compiler only fails if the usage is ambigious.

Here is a valid Fortran file:

module test
  implicit none
  public

  integer, parameter :: rk = kind(1.0)
  real(kind=rk), parameter :: eps = epsilon(1._rk)
  integer, parameter :: value = 10

end module test

And the respective errors I obtain:

> F2x -t @_bindc.f90.t -t @_ctypes.py.t test.f90
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home_local/zoel_ml/F2x/src/F2x/main.py", line 165, in main
    src.parse()
  File "/home_local/zoel_ml/F2x/src/F2x/source.py", line 180, in parse
    self.tree = grammar.parse(self.source)
  File "/home_local/zoel_ml/F2x/src/plyplus/plyplus.py", line 575, in parse
    return self._grammar.parse(text)
  File "/home_local/zoel_ml/F2x/src/plyplus/plyplus.py", line 716, in parse
    raise ParseError('\n'.join(self.errors))
plyplus.plyplus.ParseError: Syntax error in input at 'kind' (type T_KIND) line 5 col 30
Syntax error in input at '_' (type T_UNDERSCORE) line 6 col 47
Syntax error in input at 'value' (type T_VALUE) line 7 col 25
Could not create parse tree!

Error when running `mylib` example since d40f96d

When running the example according to https://f2x.readthedocs.io/en/latest/content/introduction/getting_started.html the following error occurs in master and the previous commit d40f96d:

$~/code/F2x/draft$ F2x -W lib -m mylib.* mylib/test.f90
INFO  F2x Version 0.2
Traceback (most recent call last):
  File "/usr/local/bin/F2x", line 11, in <module>
    load_entry_point('F2x', 'console_scripts', 'F2x')()
  File "/home/calbert/code/F2x/src/F2x/runtime/main.py", line 157, in main
    for template_package in args.register_template:
TypeError: 'NoneType' object is not iterable

With earlier versions this is working fine.

Automatically ignore execution part

The execution part contains irrelevant information for wrapper generation but makes the grammar more complex. Hence, it is a good idea to ignore it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.