Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Foreign function calls
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Siegfried Gonzi <siegfried.gonzi@k...>
Subject: [Caml-list] Foreign function calls

I studied the manuals but didn't grasp it: how can I use the following 
subprogram (the get_mie() function) from OCaml:

#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <math.h>
#include "/home/gonzi/Wissenschaft/mie/complex.h"
#include "/home/gonzi/Wissenschaft/mie/nrutil.h"
#include "/home/gonzi/Wissenschaft/mie/bhmie.h"
#define mxnang 1000
#define nmxx 3000
#define CXONE Complex(1.0, 0.0)

void get_mie(float re_part, float im_part,float x, unsigned long 
nang,float* erg_s1_re,float* erg_s1_im,float* erg_s2_re,float* 
erg_s2_im, float* erg)
fcomplex cxref;
fcomplex cxs1[mxnang], cxs2[mxnang];
float pqext,pqsca,pqback,pgsca;
unsigned long i;


/* function call */
bhmie(x, cxref, nang, cxs1, cxs2, &pqext, &pqsca, &pqback, &pgsca);

/* return values; the passed array pointers become updated*/
for (i=1; i<=(2*nang-1); i++)
   erg_s1_re[i] = cxs1[i].r;
   erg_s1_im[i] = cxs1[i].i;
   erg_s2_re[i] = cxs2[i].r;
   erg_s2_im[i] = cxs2[i].i;
erg[0] = pqext;
erg[1] = pqsca;
erg[2] = pqback;
erg[3] = pgsca;

In Python I did it with SWIG (I took me as an absolute beginner in 
foreign function calls only an afternoon).

S. Gonzi
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: