This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: guile and Fortran?
- To: Paul dot Emsley at chem dot gla dot ac dot uk
- Subject: Re: guile and Fortran?
- From: Mikael Djurfeldt <mdj at mdj dot nada dot kth dot se>
- Date: 31 May 2000 23:21:02 +0200
- Cc: guile at sourceware dot cygnus dot com
- Cc: djurfeldt at nada dot kth dot se
- References: <200005311710.SAA05471@eriskay.chem.gla.ac.uk>
Paul.Emsley@chem.gla.ac.uk writes:
> I have an old fortran library that I would like to extend with
> guile (i.e, I want to write scheme programs that use these
> functions).
>
> What is the best/quickest (hopefully the same) way of doing
> this?
You'd write glue code working as an interface between Guile and your
library.
Fortran uses "call by reference", so your fortran routines will expect
a pointer to the value you pass to them.
For example, if you have a fortran routine `foo' which takes an
integer as argument and returns an integer, you would do something
like:
SCM
glue_foo (SCM x)
{
int a1;
// Report an error if x isn't an integer represented as an "INUM".
SCM_ASSERT (SCM_INUMP (x), x, SCM_ARG1, "foo");
a1 = SCM_INUM (x);
return SCM_MAKINUM (foo (&a1));
}
You add glue_foo as a Guile primitive by passing it to one of the
gh_new_procedure functions (see the reference manual in guile-doc).