Re: calling C function from Python via f2py

From: Gary Bates <gary.bates_at_nyahnyahspammersnyahnyah>
Date: Fri May 21 2010 - 13:21:36 MDT

Matt, Dave,

I don't know about C but I recently used f2py on a fortran code to do
exactly what you're describing.

The f2py syntax I used was:
f2py -c -m build_mrf_logr build_mrf_logr.f lsq.o logistic.o

where lsq and logistic were previously compiled (but not linked) fortran
subroutines that are called by build_mrf_logr.f

This produced build_mrf_logr.so that I was able to import into a
Python2.5 script just fine.

Gary

On 5/21/10 12:46 PM, David Brown wrote:
>
> Yes, I'm just saying that you might get more help from the NumPy list
> for this question. But if someone can help that is fine with me.
> -dave
>
> On May 21, 2010, at 12:33 PM, Matt Fearon wrote:
>
>> Hi Dave,
>>
>> My ultimate goal is to import Ngl and Nio into this Python script and
>> read and process grib data- this part I have figured out. However, I
>> need to pass some of my data to a prewritten C function. Surely,
>> calling C or Fortran from Python is related and would be helpful to
>> folks amongst or using this list?
>>
>> Matt
>>
>>
>> On Fri, May 21, 2010 at 2:26 PM, David Brown<dbrown@ucar.edu> wrote:
>>> Hi Matt,
>>>
>>> This question is really off-topic for this mailing list. This is for
>>> discussion of the PyNGL and PyNIO Python modules specifically.
>>> Since f2py is
>>> part of the NumPy package, I would suggest asking your question on
>>> numpy-discussion@scipy.org.
>>> (http://mail.scipy.org/mailman/listinfo/numpy-discussion to sign up).
>>> -dave
>>>
>>>
>>> On May 21, 2010, at 11:58 AM, Matt Fearon wrote:
>>>
>>>> Hello,
>>>>
>>>> New to PyNGL. I am trying to use f2py to generate a wrapped C
>>>> function
>>>> that I can call from Python (passing arguments to and from). I have
>>>> this almost working, but I receive trouble with "exp and pow"
>>>> related
>>>> to C and some "pos (2) error" with one of my passed variables. My
>>>> f2py
>>>> syntax is:
>>>>
>>>> f2py -c -lm FFMCcalc.pyf FFMCcalc.c
>>>>
>>>> Also, my 3 scripts are short and attached.
>>>>
>>>> 1. FFMCcalc.c, C function
>>>> 2. FFMCcalc.pyf, wrapper file
>>>> 3. test.py, short python code that calls C function
>>>>
>>>> Any advice would greatly appreciated to get this working.
>>>> thanks,
>>>> Matt
>>>>
>>>> <
>>>> FFMCcalc
>>>> .c
>>>>>
>>>> <
>>>> FFMCcalc
>>>> .pyf><test.py>_______________________________________________
>>>> pyngl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
>>>
>>>
>>
>>
>>
>> --
>
> _______________________________________________
> pyngl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Fri May 21 13:21:47 2010

This archive was generated by hypermail 2.1.8 : Fri Jul 02 2010 - 10:10:53 MDT