healpix: calling f90 from C

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Greg Hennessy
Posts: 3
Joined: October 27 2006
Affiliation: USNO

healpix: calling f90 from C

Post by Greg Hennessy » October 27 2006

I'm not very familiar with F90 (much more experiance with F77) but I wanted to know if were possible to call the healpix f90 modules from C code? If it is possible, is there documentation available anywhere, or does anyone have an example test program?
I have Healpix 2.01 and Fedora Core 5 on a 64 bit Opteron in case that makes a difference.


Thanks.

Martin Reinecke
Posts: 13
Joined: July 26 2006
Affiliation: Max-Planck-Institute for Astrophysics

healpix: calling f90 from C

Post by Martin Reinecke » October 28 2006

Hi Greg,

calling Fortran90 routines from C is, at the very least, very nonportable. There are different problems:
  • The routine names you have to call can be very different from the names appearing in the Fortran sources. They may be all caps, have one or two underscores at the end, maybe have the module name encoded somewhere etc. This strongly depends on the compiler manufacturer.
    The Fortran routines may take some hidden parameters, like string lengths, array shapes etc. You would have to "fake" these additional parameters in your calls.
With Fortran77 things are somewhat less complex, but still not trivial.

These problems will become solvable in Fortran 2003, but compilers for that are still rare.

If you need Healpix functionality, I expect it would be much easier to use chealpix or the C++ port, unless of course you need some routines that are only available in the Fortran version.

Cheers,
Martin

Greg Hennessy
Posts: 3
Joined: October 27 2006
Affiliation: USNO

Re: healpix: calling f90 from C

Post by Greg Hennessy » October 30 2006

I note that the routine I'm interested in (query_disk) is available in the java version. I calling java from C easier than calling F90?

Martin Reinecke
Posts: 13
Joined: July 26 2006
Affiliation: Max-Planck-Institute for Astrophysics

healpix: calling f90 from C

Post by Martin Reinecke » October 31 2006

I note that the routine I'm interested in (query_disk) is available in the java version. I calling java from C easier than calling F90?
Not really, although it is at least standardized.
I think your best bet is to write a C-compatible wrapper function around Healpix_Base::query_disc() and call this from your code. Unless your application is absolutely time-critical, this should work nicely.

Greg Hennessy
Posts: 3
Joined: October 27 2006
Affiliation: USNO

Re: healpix: calling f90 from C

Post by Greg Hennessy » October 31 2006

Martin Reinecke wrote:I
I think your best bet is to write a C-compatible wrapper function around Healpix_Base::query_disc() and call this from your code. Unless your application is absolutely time-critical, this should work nicely.
I'll give that a try. Thanks.

Post Reply