Giter Site home page Giter Site logo

py2f's Introduction

py2f

Allows embedding python code inside fortran.

Installation

make

Using

All functions return an int error code, check against the SUCCESS constant.

Startup

   res=setup()
   if(res/=SUCCESS) THEN
      write(*,*) "Init failed"
      stop
   end if

Initializes the code and must be called before any other py2f function

End

res=finish()

Shutdown python at the end, not much to do if it fails

Set a variable

res=set(str object, str name, int|double|str value)

Creates a parameter called name with value value. If you want to create the variable in the top level python name space ie if you typed

x=1

in the python interpreter, then object=MAIN_MOD,

res=set(MAIN_MOD,"x",1)

otherwise pass the name of the python object as a string.

Can also pass an array of upto 5d of ints or doubles to the set function, note we pass a pointer tp the array, thus if the array ceases to exists (delalocate, exits functions etc) you can't then use it in python.

Get a variable

res=get(str object, str name, int|double|str value)

Gets a parameter called name with value value. If the variable is in the top level python name space, then object=MAIN_MOD, otherwise pass the name of the python object as a string.

You can also pass a 1d allocatable array or a 1d pointer to get (of type int or double). The array version returns a copy while the pointer version is a pointer.

Run command

res=run_cmd(str cmd)

Where cmd is the command to run, for instance

res=run_cmd("x=1")

Import module

res=run_cmd("import numpy as np")

Multiline blocks

res=run_cmd("x=1;y=1")

Use a semi-colon to split commands in one string

res=run_cmd("if x: print x")

Use colon (as normal python), though you can't nest another statement that needs a colon (say nested if statements). For more complicated code, like a function, then put that it in a file and import it.

Accessing sub-objects

Sometimes accessing objects thats are part of other objects wont work using the get command. Instead use:

res=run_cmd("temp=x.a.b")
res=get(MAIN_MOD,"temp",x)

i.e. create a local varaible in the top level namespace and access that

and similairly setting a nested object

res=set(MAIN_MOD,"temp",x)
res=run_cmd("x.a.b=temp")

py2f's People

Stargazers

Mathieu Renzo avatar  avatar Bater.Makhabel avatar Robert Farmer avatar Adil Sbai  avatar Stefano Zaghi avatar  avatar Izaak "Zaak" Beekman avatar Jacob Williams avatar

Watchers

James Cloos avatar Stefano Zaghi avatar Robert Farmer avatar  avatar

Forkers

macicco

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.