ZEMAX is an optical simulation code (http://www.zemax.com/). One of its features, Physical Optics Propagation, calculates the electric fields as they travel through the simulated optical system. The results can be saved in the ZEMAX Beam File (ZBF) format. It is useful to be able to read the ZBF file into Matlab so the electric field amplitudes and phases can be plotted in Matlab for display. Multiple simulation results can be easily compared in this way.
Since this code uses mex, the user will first need to compile part of the code. I only tested this on Windows, and I believe the code will only compile using gcc. Please install MinGW (http://www.mingw.org/) and GNUMex (http://gnumex.sourceforge.net/). Then, go to Matlab and type:
This will compile the mex part of the code. To run the code, type
[ x y Ex Ey ] = read_zbf( filename )
and replace filename with a string containing the filename of the ZBF file to be read. To plot the results, issue commands like:
pcolor(x,y,real(Ex)); shading flat
to plot just the real part of the x-component of the E-field amplitude in the ZBF file.
I am grateful to Bill Jones for sending me his make_zbf C-code which I modified to make this code. I believe both of our codes are based on an example file included in ZEMAX.