SlideShare a Scribd company logo
1 of 25
OpticsTalk: Advanced
ZPL macro programming
Alexandra Culler and Julia Zhang
8/18/2020
OpticsTalk Overview
• Introductions
 Name, company, experience with ZPL or programming in general, and what you’re hoping
to get out of this talk
• What is ZPL?
• In-depth examples and discussion
About me: Alexandra Culler
• Optical Engineer with the Customer Success team at Zemax
 Responsible for providing technical support and creating
knowledgebase content to help users make the most of their
Zemax products
• Joined Zemax in January 2019
• M.Sc. in Applied Physics from University of Oregon
About me: Julia Zhang
• Optical Engineer at Zemax China
• Responsible for technical support and public training course
in APAC, help customers with problems of modeling and
analyzing optical systems in OpticStudio
• Joined Zemax in August 2017
• M.Sc. in Physics at Tongji University
Zemax Programming Language
• ZPL is a simple programming language written to mimic BASIC
• Not case-sensitive
• ZPL is an interpreted language: the code is read and executed line-by-line with no
pre-compiled guidance
• Includes loops, variables, arrays, and basic mathematic functions
 Also allows the ability to call a “function file” via CALLMACRO
ZPL-Specific operations
• ZPL operates through its own set of keywords and numeric functions
 Keywords make a change to the file
 Numeric and string functions extract information about the system
When to use the ZPL
• When you need a unique format for data
• To implement features or calculations not in the program, such as data retrieval,
export, or simple plotting
• To optimize when there is no appropriate operand (custom operand creation)
• To create custom/complex solves (custom solve creation)
• To automate repetitive keyboard activity
Discussion
• Any other purpose of using ZPL macro to accomplish a specific task? What is your
experience using ZPL?
• What macros have you written? How frequently do you use it? Should we add it to
OpticStudio or to the Knowledgebase?
• Some tricks to share? (SOSO, GOSUB, etc..)
• We have a new learning path on the ZPL. What other help or examples would you
like to see?
• Let’s go through some examples! Each will be posted to the OpticsTalk forum post.
To implement features or calculations
not in the program…
• Example: Calculate the angle of incidence (AOI) for all rays across the pupil at a
given surface
 Can be used to check for high AOI which would indicate a very sensitive optic (difficult to
manufacture at low cost)
• What we need:
 A method to calculate AOI
 A way to calculate the AOI for multiple rays
• The optimization operand RAID will calculate the Angle of Incidence for a
particular field and pupil coordinate, at a given surface, for a specific wavelength
AOI analysis: Procedure
1. Choose the surface, number of rays to trace in X and Y across the pupil, and
wavelength of interest.
2. To assess across all fields, declare an array to hold the field data.
3. Find the maximum field in the system for calculation of Hx and Hy.
4. Use a nested FOR loop to cycle through fields (1), X-direction (2), Y-direction (3).
5. Use optimization operand RAID to report the incident angle.
OpticStudio Output
Post-processing results
Can we clean this up?
• Instead of hard-coded inputs, ask the user for the surface, step number, and
wavenumber of interest.
• Instead of a nested FOR loop, use CALLMACRO
 CALLMACRO gives us the ability to call a second (child) macro from within the first (parent)
 CALLMACRO is analogous to calling an external function file. We typically save common
tasks to function files for use later.
• Data may be passed back and forth between the parent and child macros using
the keywords CALLSETDBL and CALLSETSTR and the functions CALD and
$CALLSTR
• More information:
 The Programming Tab > About the ZPL > Calling a Macro from within a Macro
 https://my.zemax.com/en-US/Knowledge-Base/kb-article/?ka=KA-01473
Update the macro
• Global variables (to be passed to the child macro):
 Surface number, wave number, number of rays (numSteps), hx, hy, and the operand of interest
• Child macro will now be used to walk across the pupil for any operand which has the same
properties as RAID:
Questions and discussion
• We could use this for optimization. If we want to avoid the TIR error message, we
can search for cases in which RAID is “0”. That may allow us to figure out what
operands we can eliminate to allow the optimization to continue.
• Can we output the data directly to Excel, instead of copying? Yes! Use OUTPUT to
print directly to a CSV vile, and use $TAB() as delimiter.
• Can we use this to find maximum AOI? Sure! We could store the RAID results to an
array for that purpose.
• What are your thoughts?
To optimize when there is no
appropriate operand…
• Example: Footprint diagram operand for returning the max Y landing coordinate
for a particular surface
 Right now, there is no operand which will report this value
• What we need:
 A way to access this value
• The value is provided in the Text tab of the Footprint Diagram. This means it is able
to be extracted with the keyword GETTEXTFILE
Custom operand: Procedure
1. Create a temporary file to save the Footprint Diagram text output. Create a
variable to hold the value of interest.
2. Open the file and cycle through the “header” data until we reach the line of
interest.
3. Save the line of interest and truncate so that only the numeric data is retained.
4. Convert the string to number.
5. Close the temporary file and delete it.
6. Report as the “Value” output for the operand.
Can we make this more generic?
• Use the LABEL and GOTO commands to create a Switch statement
 A switch statement allows the value of a variable or expression to change the control flow
of program execution via search and map.
 In other words, we will run the statement’s command until a particular variable value
“breaks” us out of that cycle
Lines 18 and 19 will continue to be
executed until the IF statement at line 20
or line 21 is TRUE.
If line 20 is TRUE, then we will “break” from
the loop and move to line 27
Now, we don’t need to know how many
lines to skip before we reach the line of
interest
Questions and discussion
• What is EOFF() doing? This is an end of file flag with a Boolean output. It will return
1 if the end of the file has been reached, otherwise, it will be 0. Only valid after the
execution of a READ or READSTRING keyword.
• Converting between string values and numeric values: SVAL(A$), $STR(expression)
 $STR() is coming up in our next example. It is useful for generating files which are named
based on the current iteration value of a FOR loop.
 When we convert from number to string, we can use FORMAT and INTE(). This will help us
avoid things like “1.000.txt” or “1.1.txt”.
• What are your thoughts?
To automate repetitive keyboard
activity…
• Example: Apply the Make Thermal tool to Monte Carlo files
 Without the ZPL, we would need to open every Monte Carlo file and run the tool by hand
 With the ZPL, we can automate opening each file and modifying the Multi-Configuration
Editor
• What we need:
 Open each MC file and apply Make Thermal
 Currently, there is no ZPL keyword to apply Make Thermal. We will need to manually apply
the operands to the Multi-Configuration Editor
• We can use the keywords LOADLENS to open the MC files. We can use the
keyword SETMCOPERAND to update Multi-Configuration operands
Apply Make Thermal: Procedure
1. Enter number of configs, min, and max temperature.
2. Set up the format of the MC files to be opened.
a. Discussed in more detail: https://my.zemax.com/en-US/Knowledge-Base/kb-
article/?ka=KA-01485
3. Open an MC file for editing.
4. Clear the Multi-Configuration Editor.
5. Insert new configurations based on the input configNUM
6. Apply each standard operand (Radius, Thickness, Clear Semi-Diameter, Chip
Zone, Mechanical Semi-Diameter).
7. Apply the Thermal Pickup solves.
8. Update lens, and save output.
Can we expand the functionality?
• The coefficients for Even Aspheres will have additional Multi-Configuration
operands than the standard ones already added. We can check for the surface
type with the BUFFER command.
• $BUFFER():
 Numeric Functions will return numeric values (marked as black in the ZPL)
 Occasionally, certain settings for some Numeric Functions will return a string value. In that
case, the string is placed in the “buffer”. To extract it, use the String Function $BUFFER()
Update the macro
• Add a Numeric Function which checks on surface properties. Use this Numeric Function to
pull the Surface Type. Use $BUFFER() to return the string.
• Add an IF statement to check for an Even Asphere. If one exists, add and edit more Multi-
Configuration operands
Additional Discussion Points
• Similar one is used for ZPL solve, SOSO(). The function returns the surface number
and/or object number of the macro currently being executed as a solve. The
function is very useful if we want to include parameter of the surface, but we have
no idea of the surface number in advance until we decide to add ZPL solve for the
certain surface.
• SURC(A$), SRCN(A$, n)- tag a specific surface if the surface comment matching A$
or if nth surface comment matching A$.
 SCOM(A$, B$), If the strings are equal, SCOM returns 0.
• CALLMACRO can be used to call child macro in current executed parent macro. If a
subroutine is used several times within one macro, we can use SUB to define the
subroutine, and use GOSUB to direct the program flow to the defined subroutine.
OpticsTalk Feedback
• Thank you for attending! Please continue the discussion, post questions, or give
advice about your experience with the ZPL at the corresponding forum post.
• Some additional examples (and anything we didn’t get to) will be posted in the
forum as well!
• Look out for a survey about this talk. We greatly appreciate your feedback!

More Related Content

Similar to advancedzplmacroprogramming_081820.pptx

Scalding: Twitter's New DSL for Hadoop
Scalding: Twitter's New DSL for HadoopScalding: Twitter's New DSL for Hadoop
Scalding: Twitter's New DSL for HadoopDataWorks Summit
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascadingjohnynek
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.Jason Hearne-McGuiness
 
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...Jose Quesada (hiring)
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programmingDhaval Dalal
 
1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docxhoney725342
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perlmegakott
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introductionBirol Efe
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller ColumnsJonathan Fine
 
distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...
distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...
distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...7mind
 
Choosing the Right Transformer for Your Data Challenge
Choosing the Right Transformer for Your Data ChallengeChoosing the Right Transformer for Your Data Challenge
Choosing the Right Transformer for Your Data ChallengeSafe Software
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principlesdeonpmeyer
 
introduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and Pigintroduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and PigRicardo Varela
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
Javascripts hidden treasures BY - https://geekyants.com/
Javascripts hidden treasures            BY  -  https://geekyants.com/Javascripts hidden treasures            BY  -  https://geekyants.com/
Javascripts hidden treasures BY - https://geekyants.com/Geekyants
 

Similar to advancedzplmacroprogramming_081820.pptx (20)

Scalding: Twitter's New DSL for Hadoop
Scalding: Twitter's New DSL for HadoopScalding: Twitter's New DSL for Hadoop
Scalding: Twitter's New DSL for Hadoop
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascading
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.
 
Concurrency and parallel in .net
Concurrency and parallel in .netConcurrency and parallel in .net
Concurrency and parallel in .net
 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
 
Javascript
JavascriptJavascript
Javascript
 
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
 
1 Project 2 Introduction - the SeaPort Project seri.docx
1  Project 2 Introduction - the SeaPort Project seri.docx1  Project 2 Introduction - the SeaPort Project seri.docx
1 Project 2 Introduction - the SeaPort Project seri.docx
 
Stack and heap
Stack and heapStack and heap
Stack and heap
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perl
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introduction
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...
distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...
distage: Purely Functional Staged Dependency Injection; bonus: Faking Kind Po...
 
Choosing the Right Transformer for Your Data Challenge
Choosing the Right Transformer for Your Data ChallengeChoosing the Right Transformer for Your Data Challenge
Choosing the Right Transformer for Your Data Challenge
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
 
introduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and Pigintroduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and Pig
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Javascripts hidden treasures BY - https://geekyants.com/
Javascripts hidden treasures            BY  -  https://geekyants.com/Javascripts hidden treasures            BY  -  https://geekyants.com/
Javascripts hidden treasures BY - https://geekyants.com/
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

advancedzplmacroprogramming_081820.pptx

  • 1. OpticsTalk: Advanced ZPL macro programming Alexandra Culler and Julia Zhang 8/18/2020
  • 2. OpticsTalk Overview • Introductions  Name, company, experience with ZPL or programming in general, and what you’re hoping to get out of this talk • What is ZPL? • In-depth examples and discussion
  • 3. About me: Alexandra Culler • Optical Engineer with the Customer Success team at Zemax  Responsible for providing technical support and creating knowledgebase content to help users make the most of their Zemax products • Joined Zemax in January 2019 • M.Sc. in Applied Physics from University of Oregon
  • 4. About me: Julia Zhang • Optical Engineer at Zemax China • Responsible for technical support and public training course in APAC, help customers with problems of modeling and analyzing optical systems in OpticStudio • Joined Zemax in August 2017 • M.Sc. in Physics at Tongji University
  • 5. Zemax Programming Language • ZPL is a simple programming language written to mimic BASIC • Not case-sensitive • ZPL is an interpreted language: the code is read and executed line-by-line with no pre-compiled guidance • Includes loops, variables, arrays, and basic mathematic functions  Also allows the ability to call a “function file” via CALLMACRO
  • 6. ZPL-Specific operations • ZPL operates through its own set of keywords and numeric functions  Keywords make a change to the file  Numeric and string functions extract information about the system
  • 7. When to use the ZPL • When you need a unique format for data • To implement features or calculations not in the program, such as data retrieval, export, or simple plotting • To optimize when there is no appropriate operand (custom operand creation) • To create custom/complex solves (custom solve creation) • To automate repetitive keyboard activity
  • 8. Discussion • Any other purpose of using ZPL macro to accomplish a specific task? What is your experience using ZPL? • What macros have you written? How frequently do you use it? Should we add it to OpticStudio or to the Knowledgebase? • Some tricks to share? (SOSO, GOSUB, etc..) • We have a new learning path on the ZPL. What other help or examples would you like to see? • Let’s go through some examples! Each will be posted to the OpticsTalk forum post.
  • 9. To implement features or calculations not in the program… • Example: Calculate the angle of incidence (AOI) for all rays across the pupil at a given surface  Can be used to check for high AOI which would indicate a very sensitive optic (difficult to manufacture at low cost) • What we need:  A method to calculate AOI  A way to calculate the AOI for multiple rays • The optimization operand RAID will calculate the Angle of Incidence for a particular field and pupil coordinate, at a given surface, for a specific wavelength
  • 10. AOI analysis: Procedure 1. Choose the surface, number of rays to trace in X and Y across the pupil, and wavelength of interest. 2. To assess across all fields, declare an array to hold the field data. 3. Find the maximum field in the system for calculation of Hx and Hy. 4. Use a nested FOR loop to cycle through fields (1), X-direction (2), Y-direction (3). 5. Use optimization operand RAID to report the incident angle.
  • 12. Can we clean this up? • Instead of hard-coded inputs, ask the user for the surface, step number, and wavenumber of interest. • Instead of a nested FOR loop, use CALLMACRO  CALLMACRO gives us the ability to call a second (child) macro from within the first (parent)  CALLMACRO is analogous to calling an external function file. We typically save common tasks to function files for use later. • Data may be passed back and forth between the parent and child macros using the keywords CALLSETDBL and CALLSETSTR and the functions CALD and $CALLSTR • More information:  The Programming Tab > About the ZPL > Calling a Macro from within a Macro  https://my.zemax.com/en-US/Knowledge-Base/kb-article/?ka=KA-01473
  • 13. Update the macro • Global variables (to be passed to the child macro):  Surface number, wave number, number of rays (numSteps), hx, hy, and the operand of interest • Child macro will now be used to walk across the pupil for any operand which has the same properties as RAID:
  • 14. Questions and discussion • We could use this for optimization. If we want to avoid the TIR error message, we can search for cases in which RAID is “0”. That may allow us to figure out what operands we can eliminate to allow the optimization to continue. • Can we output the data directly to Excel, instead of copying? Yes! Use OUTPUT to print directly to a CSV vile, and use $TAB() as delimiter. • Can we use this to find maximum AOI? Sure! We could store the RAID results to an array for that purpose. • What are your thoughts?
  • 15. To optimize when there is no appropriate operand… • Example: Footprint diagram operand for returning the max Y landing coordinate for a particular surface  Right now, there is no operand which will report this value • What we need:  A way to access this value • The value is provided in the Text tab of the Footprint Diagram. This means it is able to be extracted with the keyword GETTEXTFILE
  • 16.
  • 17. Custom operand: Procedure 1. Create a temporary file to save the Footprint Diagram text output. Create a variable to hold the value of interest. 2. Open the file and cycle through the “header” data until we reach the line of interest. 3. Save the line of interest and truncate so that only the numeric data is retained. 4. Convert the string to number. 5. Close the temporary file and delete it. 6. Report as the “Value” output for the operand.
  • 18. Can we make this more generic? • Use the LABEL and GOTO commands to create a Switch statement  A switch statement allows the value of a variable or expression to change the control flow of program execution via search and map.  In other words, we will run the statement’s command until a particular variable value “breaks” us out of that cycle Lines 18 and 19 will continue to be executed until the IF statement at line 20 or line 21 is TRUE. If line 20 is TRUE, then we will “break” from the loop and move to line 27 Now, we don’t need to know how many lines to skip before we reach the line of interest
  • 19. Questions and discussion • What is EOFF() doing? This is an end of file flag with a Boolean output. It will return 1 if the end of the file has been reached, otherwise, it will be 0. Only valid after the execution of a READ or READSTRING keyword. • Converting between string values and numeric values: SVAL(A$), $STR(expression)  $STR() is coming up in our next example. It is useful for generating files which are named based on the current iteration value of a FOR loop.  When we convert from number to string, we can use FORMAT and INTE(). This will help us avoid things like “1.000.txt” or “1.1.txt”. • What are your thoughts?
  • 20. To automate repetitive keyboard activity… • Example: Apply the Make Thermal tool to Monte Carlo files  Without the ZPL, we would need to open every Monte Carlo file and run the tool by hand  With the ZPL, we can automate opening each file and modifying the Multi-Configuration Editor • What we need:  Open each MC file and apply Make Thermal  Currently, there is no ZPL keyword to apply Make Thermal. We will need to manually apply the operands to the Multi-Configuration Editor • We can use the keywords LOADLENS to open the MC files. We can use the keyword SETMCOPERAND to update Multi-Configuration operands
  • 21. Apply Make Thermal: Procedure 1. Enter number of configs, min, and max temperature. 2. Set up the format of the MC files to be opened. a. Discussed in more detail: https://my.zemax.com/en-US/Knowledge-Base/kb- article/?ka=KA-01485 3. Open an MC file for editing. 4. Clear the Multi-Configuration Editor. 5. Insert new configurations based on the input configNUM 6. Apply each standard operand (Radius, Thickness, Clear Semi-Diameter, Chip Zone, Mechanical Semi-Diameter). 7. Apply the Thermal Pickup solves. 8. Update lens, and save output.
  • 22. Can we expand the functionality? • The coefficients for Even Aspheres will have additional Multi-Configuration operands than the standard ones already added. We can check for the surface type with the BUFFER command. • $BUFFER():  Numeric Functions will return numeric values (marked as black in the ZPL)  Occasionally, certain settings for some Numeric Functions will return a string value. In that case, the string is placed in the “buffer”. To extract it, use the String Function $BUFFER()
  • 23. Update the macro • Add a Numeric Function which checks on surface properties. Use this Numeric Function to pull the Surface Type. Use $BUFFER() to return the string. • Add an IF statement to check for an Even Asphere. If one exists, add and edit more Multi- Configuration operands
  • 24. Additional Discussion Points • Similar one is used for ZPL solve, SOSO(). The function returns the surface number and/or object number of the macro currently being executed as a solve. The function is very useful if we want to include parameter of the surface, but we have no idea of the surface number in advance until we decide to add ZPL solve for the certain surface. • SURC(A$), SRCN(A$, n)- tag a specific surface if the surface comment matching A$ or if nth surface comment matching A$.  SCOM(A$, B$), If the strings are equal, SCOM returns 0. • CALLMACRO can be used to call child macro in current executed parent macro. If a subroutine is used several times within one macro, we can use SUB to define the subroutine, and use GOSUB to direct the program flow to the defined subroutine.
  • 25. OpticsTalk Feedback • Thank you for attending! Please continue the discussion, post questions, or give advice about your experience with the ZPL at the corresponding forum post. • Some additional examples (and anything we didn’t get to) will be posted in the forum as well! • Look out for a survey about this talk. We greatly appreciate your feedback!