next up previous
Next: The subroutines used for 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',double(p1),double(p2),..., /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 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 functions calc_t, calc_dm, calc_vol and calc_scale the arguments are converted to double precision before passing them to the C routine to make sure that the data types are correct (the C routines in calc_lib.so expect the parameters to be of type double). 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 functions calc_t, calc_dm, calc_vol and calc_scale were 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 functions in calc_lib.so is:
double function(int argc, double** 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 (e.g. function time):

double time(int argc, double** argv)
{
double h0,z,omm,oml,w;

h0=*(argv[0]); /*parameter conversion to "normal" variables*/
z=*(argv[1]);
omm=*(argv[2]);
oml=*(argv[3]);
w=*(argv[4]);
....
}
Of ourse this is only possible for arguments of type double. In general, argv is of type void** so some kind of typecasting is necessary.


next up previous
Next: The subroutines used for Up: The C code Previous: The C code
Peter E. Nugent Jr.
1998-08-21