Difference: CallingCfromIDL (r2 vs. r1)

Calling C Code from IDL Modules

David Fanning has some excellent advice and useful info about calling C from IDL.

Tips

(From David Fanning):

  • All arrays which need to be passed between IDL and C must be allocated in IDL. This includes both arrays being passed from IDL to C and from C back to IDL. Sometimes this requires an initial call to the C code to return the array sizes which IDL will allocate, if the array sizes are not known to IDL beforehand.
  • Don't deallocate any arrays which were passed from IDL.
  • Don't pass strings, rather pass byte arrays. It is much simpler. Convert strings to byte arrays in IDL before or after the Call_External call.
  • Convert all output variables to the data type which C is expecting in the Call_External call.

Links

Examples

See the attached files mandelbrot.c and mandelbrot.pro for examples of a C file called by an IDL routine.

First, compile the mandelbrot C routine as a shared library:

  • % gcc -fPIC -o mandelbrot.o -c mandelbrot.c
  • % ld -shared -o mandelbrot.dll mandelbrot.o

Second, run the mandelbrot routine from IDL:

  • % idl
  • IDL> result = mandelbrot(2.2,3.4,6.3,5.5,4,2.2,2.1)

The result can be printed as an array of mandelbrot values.

-- ElizabethAuden - 11 May 2005

IAttachmentHistoryActionSizeDateWhoComment
C source code filecmandelbrot.c r1 manage 0.9 K 2005-05-14 - 22:12ElizabethAuden Mandelbrot C program
Unknown file formatpromandelbrot.pro r1 manage 0.8 K 2005-05-14 - 22:11ElizabethAuden Mandelbrot IDL program

View topic | View difference side by side | History: r3 < r2 < r1 | More topic actions
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback