An example of a C code (Image files.c) used to generate a checkerboard illumination pattern is provided in the .ZIP file located at the end of this article. This code generates three types of files which are used by ZEMAX: an ASCII IMA file, a Binary IMA file, and a Binary BIM file. More information about these file types may be found in Chapter 7 of the ZEMAX manual, under the description for the Geometric Image Analysis feature. In this case, the illumination pattern generated in each file is a 5x5 checkerboard, where the intensity values alternate between 0 and 1 (or 255 for the case of the binary IMA file, which is the equivalent maximum value). ASCII IMA files may also be generated and edited with a text editor, of course. This code generates all types of IMA and BIM files that are supported by ZEMAX for completeness.
The code itself is straightforward. The initial part of the program is dedicated to specifying names for the three files, and then opening those files so that they may be written to:
After declaring variables that will be used later in the code and defining the size of the illumination array in x and y, the necessary header information necessary is written to each file:
Finally, illumination data are written to each file. The data alternate between minimum and maximum values, to produce a checkerboard pattern:
This code can be compiled using Microsoft Visual Studio 2005 (or your favorite C compiler). The procedure for this compilation is very similar to that described in the Knowledge Base article “How to Compile a User-Defined Surface”. In this case, rather than specifying the project as a Win32 Project or a Win32 Dynamic-Link Library, you should specify it as a Win32 Console Application:
This application will be created as an Empty project:
When the code is compiled, it will generate an application file with the name provided by the user during setup. The IMA and BIM files are generated by running this application (i.e. by double-clicking on the application icon). As indicated in the code, the files will be written to the \ZEMAX\IMAFiles directory.
A simple ZEMAX design (IMA files.zmx) which illustrates the use of each of these files (Checkers_ASC.IMA, Checkers_BIN.IMA, and Checkers_BIN.BIM) within the Geometric Image Analysis feature is also provided in the .ZIP file located at the end of this article. The checkerboard pattern is clearly visible for each case: