next up previous
Next: Description of the functions Up: The C code Previous: The C code

The IDL function CALL_EXTERNAL

The IDL function CALL_EXTERNAL seems to be the fastest way for passing parameters from IDL to a precompiled C function and the result back to IDL. In the IDL functions described above, CALL_EXTERNAL is used like this:
result=CALL_EXTERNAL('library_file','function_name',p1,double(p2),long(p3)..., /d_value)
library_file is the name of the library file containing the desired function, including the path of the library file.
function_name is the name of the desired function as it is given in the C source code.
p1, p2, p3 are parameters. The keyword /d_value is used to tell IDL that the called function returns something of the type double precision floating point. The user of CALL_EXTERNAL has to make sure that the passed arguments are of the same type as the C routine expects them to be. For this reason, in the function magmax the arguments are converted to double precision, long int, etc. before passing them to the C routine to make sure that the data types are correct . The number of parameters passed is up to the user of CALL_EXTERNAL. So he also has to make sure that the right number of arguments is passed! For this reason, the IDL function magmax was written, so that the IDL user need not deal with these things.
The arguments are passed from CALL_EXTERNAL to a C function in the same way command line parameters are passed to a program run from the command line. The general prototype of the C function in magnitude.so is:
double function(int argc, void** argv)
However the first argument in the pointer array argv is not the function name, but the first parameter passed by CALL_EXTERNAL. So the arguments are copied to normal variables like this (taken from the source code of magnitude.so, includes some here not further used variables):

double magnitude (int argc, void** argv)
{

.....
double *x,*y,*xspec,*yspec,*xspec0,*yspec0,*result,*z,*dm;
int error,max,maxspec,maxspec0,spec,i,j;
long int zmax,fil;

z=(double*)argv[0];
dm=(double*)argv[1];
zmax=*((long int*)argv[2]);
fil=*((long int*)argv[3]);
mb=*((double*)argv[4]);
result=(double*)argv[5];

.....
}

Note that dm, z and result are arrays and zmax and fil are scalar.


next up previous
Next: Description of the functions Up: The C code Previous: The C code
Peter E. Nugent Jr.
1998-10-01