Solved

writing ZRD2MAT files

  • 6 February 2023
  • 2 replies
  • 123 views

Hey everyone. I have a NSC model that contains two sets of CPC’s and a Mersenne relay. My source is an array of conical wavefronts to mimic Cerenkov radiation. I need to trace a lot of rays through the system to the detector to look at the temporal dispersion of rays vs. time (or more correctly, Power vs. Time). So I’m writing my ray trace to a ZDR file. But when I convert it to text, I can’t get all the rays because the file is too large.

So I want to try using the ZRD2MAT function that writes the ZRD data to a Matlab.m file.

I have no idea how to do this. 

Currently, I’ve been creating a lot of text files with the ZRD info in them and reading and summing all the Optical Path data to get the total OP from source to detector. then, catching the last Intensity value for that ray and storing the info in a 2D array in Mathematica. It’s a PITA! I’d rather do it in Matlab.

What path do I use if Matlab is in one folder and the lens is in another folder?

anyone who can help me will get 100 Atta-Boys.

Thanks,

Paul Manhart

icon

Best answer by Jeff.Wilde 8 February 2023, 07:40

View original

2 replies

Userlevel 7
Badge +3

Hi Paul,

I typically use ZOS-API to parse ZRD files into Matlab.  There is a sample file that shows how this can be done:

 

However, if you prefer to use the ZPL keyword ZRD2MAT, it is certainly much simpler, but you have somewhat less control over what ray data is parsed and in what format it takes within Matlab.  Here’s an example using the NSC sample “Even Asphere” model. 

 

After running a ray trace, we can take a look at the ZRD file contents using the Ray Database Viewer:

 

To get the data into Matlab, here’s a very simple ZPL script that parses all segments of the first 10 rays (the ZRD and MAT files can reside in different folders, just provide the corresponding complete path info):

 

Important Note:  The file extensions must be capitalized or you’ll get an error.  Loading the *.MAT file into Matlab shows the results:

 

Data for any given segment (from any ray) is available.  For example, here are the coordinates for segment 1 of ray 1:

 

Hope this helps…

Regards,

Jeff

Userlevel 6
Badge +2

Hi Paul,

I had written a user extension for a LIDAR case that adds the paths and reads the intensity at the detector. It is written in C# but maybe that can help: https://support.zemax.com/hc/en-us/articles/1500005577762-How-to-create-a-Time-Of-Flight-User-Analysis-using-ZOS-API

 

 

Reply