Skip to main content
Solved

How to read absorption data from material via ZOS-API


ReneFromJena

I just want to read all data from the material behind a surface in a given lens system which I need to construct the wavelength dependent complex refractive index for that material.
I already managed to read the real valued refrative index (dispersion) via ZOSAPI.Tools.IMaterialsCatalog.

But I cannot find a way to read the wavelength dependent absorption data from the same material.

Does anybody have an advice or hint for me?

Looking forward to your answers. Thank you.

Best answer by MichaelH

Hi Rene,

Unfortunately, the only “button” hooked up from the bottom section of the Materials Catalog is the Save Catalog As.  No other buttons including the transmission section is hooked up.

Luckily, the AGF file is a text-based file so you can write a simple parser to open the AGF file, loop through until you find the NM line which matches your desired glass, then continue to read lines until you get to the IT line; once you get to the next NM line, you have finished parsing all the data for the desired glass.

Below is C# pseudo code from a similar task I had to accomplish:

string orgagf = Path.Combine(TheApplication.GlassDir, @"SCHOTT.AGF")

string desiredGlass = "N-BK7";

using (StreamReader file = new StreamReader(orgagf))

{

    string ln;

    string[] parts;

    bool foundGlass = false;

    

    // data to save

    List<double[]> transmissionData = new List<double[]>();

    while ((ln = file.ReadLine()) != null)

    {

        ln = ln.Trim();

        parts = ln.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

        if (parts.Length > 1 && parts[0].ToUpper() == "NM")

        {

            // we have already found the desired glass and now we have hit the next glass in the catalog

            if (!foundGlass)

            { break;}

        

            // we found the desired glass...now we can extract the data

            if (parts[1].ToUpper() == desiredGlass)

            { foundGlass = true;}

        }

        

        if (foundGlass)

        {

            // let's get the transmission data

            if (parts.Length > 3 && parts[0].ToUpper() == "IT")

            {

                transmissionData.Add(new double[] { Convert.ToDouble(parts[1]), Convert.ToDouble(parts[2]), Convert.ToDouble(parts[3]) });

            }    

        }

    }

}

View original
Did this topic help you find an answer to your question?

4 replies

MichaelH
Ansys Staff
Forum|alt.badge.img+2
  • Ansys Staff
  • 358 replies
  • Answer
  • June 3, 2022

Hi Rene,

Unfortunately, the only “button” hooked up from the bottom section of the Materials Catalog is the Save Catalog As.  No other buttons including the transmission section is hooked up.

Luckily, the AGF file is a text-based file so you can write a simple parser to open the AGF file, loop through until you find the NM line which matches your desired glass, then continue to read lines until you get to the IT line; once you get to the next NM line, you have finished parsing all the data for the desired glass.

Below is C# pseudo code from a similar task I had to accomplish:

string orgagf = Path.Combine(TheApplication.GlassDir, @"SCHOTT.AGF")

string desiredGlass = "N-BK7";

using (StreamReader file = new StreamReader(orgagf))

{

    string ln;

    string[] parts;

    bool foundGlass = false;

    

    // data to save

    List<double[]> transmissionData = new List<double[]>();

    while ((ln = file.ReadLine()) != null)

    {

        ln = ln.Trim();

        parts = ln.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

        if (parts.Length > 1 && parts[0].ToUpper() == "NM")

        {

            // we have already found the desired glass and now we have hit the next glass in the catalog

            if (!foundGlass)

            { break;}

        

            // we found the desired glass...now we can extract the data

            if (parts[1].ToUpper() == desiredGlass)

            { foundGlass = true;}

        }

        

        if (foundGlass)

        {

            // let's get the transmission data

            if (parts.Length > 3 && parts[0].ToUpper() == "IT")

            {

                transmissionData.Add(new double[] { Convert.ToDouble(parts[1]), Convert.ToDouble(parts[2]), Convert.ToDouble(parts[3]) });

            }    

        }

    }

}


ReneFromJena
  • Author
  • Single Emitter
  • 4 replies
  • June 7, 2022

Hi Michael,

thanks a lot for your answer and the code!

Admittedly, I am already aware of the possibility of parsing the AGF file. The background of my question is the possibility that the text-based material data will be replaced by binaries eventually (just like the ZMX format is being replaced by the ZOS format).

I just want to be prepared for the case that reading the text-based files isn’t possible anymore. And since reading the dispersion data can be done via ZOSAPI.Tools.IMaterialsCatalog, I was hoping for a similar possibility for the absorption data…

Cheers, René


Jeff.Wilde
Luminary
Forum|alt.badge.img+3
  • Luminary
  • 505 replies
  • June 7, 2022

Hi Rene,

Your concern about text-based Zemax files being replaced by binary versions may be mitigated somewhat by this change at Zemax as recently posted by Alissa (see:Save .ZMX files by default ):

 

Regards,

Jeff

 


ReneFromJena
  • Author
  • Single Emitter
  • 4 replies
  • June 8, 2022

Hi Jeff,

thank you, that is good to know.

Best regards,

René


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings