Menu

#2 C (gcc) compiler option

closed-accepted
None
5
2002-03-20
2002-03-18
No

I have modified fortran_compiler.py to add gcc as a
compiler. This enables pyfort to be used for C code
instead of Fortran code only. To use this option, call
pyfort with the -cgcc option to specify gcc as the
compiler. In order to switch off the default TRANSPOSE
and MIRROR options, some small modifications were
needed in generator.py also.

Before writing this addition to pyfort, I tried to use
swig to generate the wrapper for my C code. However,
pyfort was easier to use in my case because it is
integrated with numpy. I wasn't able to get swig use
numpy arrays. In addition, I am writing extension code
both in fortran and C, so it is easier having to use
only one tool (pyfort) for both.

In a sense, it is easier to extend python with C than
with fortran because you don't have to worry about
transposing the array. I tried to be minimally
instrusive on the existing pyfort code to switch off
transposing arrays; there may be prettier ways to do
this than what I have done. With this modification, I
was able to pass one- and two-dimensional numpy arrays
from Python to C and back without problems, as well as
scalar variables with intent(in) and intent(out). I
have also used the modified Pyfort on some Fortran
routines to make sure I didn't break something in the
fortran part of Pyfort.

I haven't done an extensive test of this addition, but
I haven't found any problems with it so far. I hope
this patch will be useful to other people trying to
extend Python/numpy with C routines.

Michiel de Hoon
Human Genome Center
University of Tokyo
mdehoon@ims.u-tokyo.ac.jp

Discussion

  • Michiel de Hoon

    Michiel de Hoon - 2002-03-18

    Patches for generator.py and fortran_compiler.py (TAR file)

     
  • Paul F. Dubois

    Paul F. Dubois - 2002-03-19

    Logged In: YES
    user_id=5550

    Terrific. Actually, I started to do this myself and got
    distracted. I'll take a look at this right away.

     
  • Paul F. Dubois

    Paul F. Dubois - 2002-03-20
    • assigned_to: nobody --> dubois
    • status: open --> closed-accepted
     
  • Paul F. Dubois

    Paul F. Dubois - 2002-03-20

    Logged In: YES
    user_id=5550

    I changed it a little, but this is in the next release
    (7.0). Thank you so much.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.