2

Fortran subroutines can take another subroutine as argument.

subroutine mst(yht)
 ..
 ..
 call yht(..)

But how about an array of objects from python? How can I send say

arr=[yht,yht,yht]

to Fortran. I tried it but failed.Is there any way to do this?

1 Answer 1

1

This is perhaps an extended comment rather than an answer ...

As I understand it f2py will translate Fortran procedure (ie functions and subroutines) signatures into Python. I don't think that f2py will translate Fortran derived-type definitions into Python object definitions. I've not used f2py for several years so I may be wrong on this. The obvious route, of identifying Python objects with instances of Fortran derived types, may be difficult to implement.

You might have more success if you can persuade your Python code to create things which a Fortran compiler recognises as C structs and use the interoperability-with-C features of Fortran to read and write them. Metcalf, Reid and Cohen state (p246)

These restrictions allow the type to interoperate with a C struct type that has the same number of components. The components correspond by position in their definitions. Each Fortran component must be interoperable with the corresponding C component.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.