ZEMAX Users' Knowledge Base - http://www.zemax.com/kb
How to Create Binary IMA and BIM Files
http://www.zemax.com/kb/articles/217/1/How-to-Create-Binary-IMA-and-BIM-Files/Page1.html
By Sanjay Gangadhara
Published on 14 February 2008
 
This article explains how to create binary IMA and BIM files, which are occasionally needed for use with the Image Analysis features in the sequential mode of ZEMAX.

Introduction
There are a number of analysis features in ZEMAX which use IMA and/or BIM files to provide a description of an extended source in sequential mode. Files have been provided which describe a variety of illumination patterns, such as a circle, a square, a grid, or the letter F. However, there may be cases where a user-defined illumination source is needed, requiring the user to create their own IMA or BIM file. In many of these cases, a simple ASCII IMA file is sufficient to describe the desired illumination source. Such a file can be created with any text editor, e.g. Notepad. For cases in which the illumination source is more complicated but can be represented with a .BMP or .JPG file, the Geometric Bitmap Image Analysis feature can be used to create an RGB image of the source. However, there may remain some cases in which a source is required which cannot be described with either an ASCII IMA file or a .BMP or .JPG file. For these special cases binary IMA or BIM files are required. This article describes how such binary files may be generated using a simple C code.

Writing the code which generate the files

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:

Specifying the names of the IMA and BIM files

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:

Writing header information to each of the files

Finally, illumination data are written to each file. The data alternate between minimum and maximum values, to produce a checkerboard pattern:

Filling the IMA and BIM files with a checkerboard pattern


Compiling the code

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:

Specifying the project as a Console Application

This application will be created as an Empty project:

Specifying the project as Empty

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.


Viewing the results

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:

Geometric Image Analysis showing checkerboard illumination pattern


Summary
A simple piece of C code can be used to generate binary IMA and BIM files. These types of files are only necessary for those rare occasions in which neither an ASCII IMA file or a .BMP or .JPG file can be used to describe the desired illumination of an extended source in the sequential mode of ZEMAX.