Skills Required to Combine External Code with IDL
There is a large difference between the level at which a typical user sees IDL compared to that of the internals programmer. To the user, IDL is an easy-to-use, array-oriented language that combines numerical and graphical abilities, and runs on many platforms. Internally, IDL is a large C language program that includes a compiler, an interpreter, graphics, mathematical computation, user interface, and a large amount of operating system-dependent code.
The amount of knowledge required to effectively write internals code for IDL can come as a surprise to the user who is only familiar with IDL's external face. To be successful, the programmer must have experience and proficiency in many of the following areas:
Microsoft COM
To incorporate a COM object into your IDL program, you should be familiar with COM interfaces in general and the interface of the object you are using in particular.
Microsoft ActiveX
To incorporate an ActiveX control into your IDL widget application, you should be familiar with COM interfaces in general and the interface of the control you are using in particular.
Sun Java
To incorporate a Java object into your IDL program, you should be familiar with Java object classes in general and the methods and data members of the object you are using in particular.
UNIX RPC
To use IDL as an RPC server, a knowledge of Sun RPC (Also known as ONC RPC) is required. Sun RPC is the fundamental enabling technology that underlies the popular NFS (Network File System) software available on all UNIX systems, and as such, is universally available on UNIX. The system documentation on this subject should be sufficient.
ANSI C
IDL is written in ANSI C. To understand the data structures and routines described in this document, you must have a complete understanding of this language.
System C Compiler, Linker, and Libraries
In order to successfully integrate IDL with your code, you must fully understand the compilation tools being used as well as those used to build IDL and how they might interact. IDL is built with the standard C compiler used (and usually supplied) by the vendor of each platform to ensure full compatibility with all system components.
Inter-language Calling Conventions (C++, Fortran, ...)
It is possible to link IDL directly with code written in compiled languages other than C although the details differ depending on the machine, language, and compiler used. It is the programmer's responsibility to understand the inter-language calling conventions and rules for the target environment—there are too many possibilities for ITT Visual Information Solutions to actively document them all. ANSI C is a standard system programming language on all systems supported by IDL, so it is usually straightforward to combine it with code written in other compiled languages. You need to understand:
- The conventions used to pass parameters to functions in both languages. For example, C uses call-by-value while Fortran uses call-by-reference. It is easy to compensate for such conventions, but they must be taken into account.
- Any systematic name changes applied by the compilers. For example, some compilers add underscores at the beginning or end of names of functions and global data.
- Any run-time initialization that must be performed. On many systems, the real initial entry point for the program is not main(), but a different function that performs some initialization work and then calls your main() function. Usually these issues have been addressed by the system vendor, who has a large interest in allowing such inter-language usage:
Alternatives to direct linking (Microsoft COM or Active X) exist on some systems that simplify the details of inter-language linking.
C++
We are often asked if IDL can call C++ code. Compatibility with C has always been a strong design goal for C++, and C++ is largely a superset of the C language. It certainly is possible to combine IDL with C++ code. Callable IDL is especially simple, as all you need to do is to include the idl_export.h header file in your C++ code and then call the necessary IDL functions directly. Calling C++ code from IDL (CALL_EXTERNAL, System Routines) is also possible, but there are some issues you should be aware of:
- As a C program, IDL is not able to directly call C++ methods, or use other object-oriented features of the C++ language. To use these C++ features, you must supply a function with C linkage (using an extern "C" specification) for IDL to call. That routine, which is written in C++ is then able to use the C++ features.
- IDL does not initialize any necessary C++ runtime code. Your system may require such code to be executed before your C++ code can run. Consult your system documentation for details. (Please be aware that this information can be difficult to find; locating it may require some detective work on your part.)
Fortran
Issues to be aware of when combining IDL with Fortran:
- The primary issue surrounding the calling of Fortran code from IDL is one of understanding the calling conventions of the two languages. C passes everything by value, and supplies an operator that lets you explicitly take the address of a memory object. Fortran passes everything by reference (by address). Difficulties in calling FORTRAN from C usually come down to handling this issue correctly. Some people find it helpful to write a C wrapper function to call their Fortran code, and then have IDL call the wrapper. This is generally not necessary, but may be convenient.
- IDL is a C program, and as such, does not initialize any necessary Fortran runtime code. Your system may require such code to be executed before your Fortran code can run. In particular, Fortran code that does its own input output often requires such startup code to be executed. Consult your system documentation for details. One common strategy that can minimize this sort of problem is to use IDL's I/O facilities to do I/O, and have your Fortran code limit itself to computation.
Operating System Features and Conventions
With the exception of purely numerical code, the programmer must usually fully understand the target operating system environment in which IDL is running in order to write code to link with it.
Microsoft Windows
You must be an experienced Windows programmer with an understanding of Windows APIs and DLLs.
UNIX
You should understand system calls, signals, processes, standard C libraries, and possibly even X Windows depending on the scope of the code being linked.