Read ZEMAX Beam File (ZBF)
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:
mex read_zbf_mex.c
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.
Cite As
Sean Bryan (2025). Read ZEMAX Beam File (ZBF) (https://www.mathworks.com/matlabcentral/fileexchange/32099-read-zemax-beam-file-zbf), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Data Import and Analysis > Data Import and Export > Standard File Formats > Other Formats >
Tags
Acknowledgements
Inspired: Read a binary ZEMAX beam file (ZBF)
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.