chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Help with foreign-lambda


From: Jim Miller
Subject: [Chicken-users] Help with foreign-lambda
Date: Mon, 15 May 2006 23:59:09 -0400

I'm trying to least expensive way to wrap a C function into scheme.  The following is the C interface to the function I need:

typedef long int integer;
typedef float real;

int gtd6_(integer *iyd, real *sec, real *alt, real *glat, real *glong, real *stl, real *f107a, real *f107, real *ap, integer *mass, real *d__, real *t);

(Its actually a fortran function so the pointers to the function are not my choice)

The first 10 arguments (iyd - mass) are actually pointers to single values.  The final two must be pointers to arrays.  d must be capable of holding 8 elements while t must be capable of 2.

Here is my scheme:

(require 'srfi-4)

(foreign-declare "typedef long int integer;")

(foreign-declare "typedef float real;")

(foreign-declare/parse
 "int gtd6_(integer *iyd, real *sec, real *alt, real *glat,
 real *glong, real *stl, real *f107a, real *f107,
 real *ap, integer *mass, real *d__, real *t);")


(let ([iyd   138]
      [sec   345.0]
      [lat    50.0]
      [alt   100.0]
      [lon    50.0]
      [stl   100.0]
      [f107a 150.0]
      [f107  150.0]
      [ap      8.0 ]
      [mass   48]
      [d      (make-f32vector 8)]
      [t      (make-f32vector 2)])
  (gtd6 iyd sec alt lat lon stl f107a f107 ap mass d t))


I compile the program using the command line (msislib.o is the f77 compiled file containing the gtd6_ function)

csc -L/opt/local/lib chapman.scm ../Science/msisr/msislib.o -lg2c

when I run the program I get the error:

Error: bad argument type - not a pointer: 138

So my questions are

a) If I have to pass a pointer to an allocated array of memory in the C function am I doing this correctly when I use the make-f32vector function?  I'm not sure if this is where the error is occurring but it seems like its the only place that it could?

b) What ways do I have to debug or more tightly trace this to track down these types of errors?

c) Is there an easier way to do this?

d) Being new to scheme (but not new to programming) I'd appreciate gentle comments on the style

Thanks

reply via email to

[Prev in Thread] Current Thread [Next in Thread]