This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: guile and Fortran?


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).

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]