Upload
others
View
11
Download
1
Embed Size (px)
Citation preview
Macro in CODE V
2012. 5
WikiOptics
YIM BOOBIN
Contents
(1st Day)
Lecturer
References
Section 1 Command
Section 2 Basic macro
Section 3 Buffer management
Section 4 User graphics
Section 5 Programming
2/192
Contents
(2nd Day)
Section 6 Functions
Section 7 Lens module
Section 8 Laser diode
Astigmatism
Coupling efficiency
Section 9 Zernike polynomials
3/192
Contents
(3rd Day)
Section 10 Image-height performance
Section 11 Interferogram
Section 12 Active aberration compensator
4/192
YIM, BOOBIN
Career
• WikiOptics (2012~ ) – Optics engineering ( Pico-projector etc. )
• LG Electronics (2004~2012)
– SMB(BD/HD DVD/DVD/CD) PU
– DVD Writer PU/BD-P PU
• SAMSUNG Electro-mechanics (2002~2004)
– DVD-ROM/P PU
– Lens for PU ( Diffractive lens )
• DAEWOO Electronics(1995~2002)
– Car CD/Audio CD/DVD-P PU
Education
• POSTECH, physics (Master, 1996) – A Study of Simultaneous Measurement of In-plane and Out-of-
plane Displacement Using Holographic Interferometry
• Chung-ang Univ. (CAU), physics (1994)
• Korea National Open Univ., Japanese study (2010)
• Korea National Open Univ., English literature(2002)
Concerns
• Laser pico-projector
• HUD/HMD
• Optical pickup lens
• Interferometer
• Education
5/192
WikiOptics
References
• CODE V Reference Manual
• CODE V Seminar Notes
– Introduction to CODE V, Spring 2001
– Advanced Topics in CODE V , Spring 2001
– Methods for Optical Design and Analysis, March 1999
– Materials on the ORA website
• Eugene Hecht, Optics (2nd Edition), Addison Wesley(1989)
• W. J. Smith, Modern Optical Engineering, McGraw-Hill(1990)
• J. C. Wyant and K. Creath, Chapter 1. Basic Wavefront Aberration Theory for Optical
Metrology, APPLIED OPTICS AND OPTICAL ENGINEERING, VOL. Xl, Academic Press, Inc.(1992)
• J. C Wyant, Zernike Polynomials for the Web, http://www.optics.arizona.edu/jcwyant/
6/192
1st day
7/192
Section 1
Command mode
8/192
The structure of CODE V
• The Lens Data Manager(LDM) is where you manage the lens database - You can use both GUI and Command mode - In this lecture, I’ll use mainly the Command mode
• CODE V’s options are sophisticated, special purpose “report generators”
9/192
The structure of CODE V
10/192
Command window
Lens data manager
Navigation bar
Error log
Status bar
Command mode
• Command mode is CODE V’s native language.
• Experts and frequent users of CODE V often use command mode
– Command mode is fast, powerful, and flexible
– Allows stacking of commands on a single line (separated by ;)
– Allows use of expressions in place of numbers
• Command mode requires more memorization
– Must know frequently used commands
– Proper syntax must be used
11/192
Command mode
• CODE V>
– This prompt indicates you are in the LDM
• XYZ>
– This prompt indicates you are in the XYZ option
• In options
– GO command executes the option
– CAN(CEL) commands you out of the option and back to the LDM
• Syntax Help
– The proper syntax for a command can be seen by preceding the command with a backslash \
– CODE V> \ sur (or sur\)
Syntax: SUR Sk|Si..j [F] [Zk]
– HEL [command [ INDX]]
12/192
Command structure
• Command Qualifiers Data Items
1 to 3 chars none or more none or more
– In general, qualifiers can be entered in any order(especially index qualifiers)
– Data items usually have an order associated with them
– Parts of commands are separated by white space(one or more blanks)
• Commands are case insensitive(except text strings)
13/192
Index Qualifiers
• Used to limit the command to a specific surface, field, wavelength, zoom position, etc.
• Are indicated by an appropriate letter(S, F, W, Z, etc.) followed by the surface number, field number, etc.
– S7, W3, Z2, etc.
• Index qualifiers can include a range, indicated by ..
– S4..7, F1..3
• Some special letters can be used in place of the numbers
– O = object, S = stop, I=image
– L can be used for last
– A can be used for all(SA=S0..I, FA=F1..L)
• Addition and subtraction of index numbers can be used
– SI-1, SS+2, FL-2, etc.
14/192
Data items
• Data items usually have an order associated with them
• For specification data, the data often both define and number the items – WL 656 587 486
specifies 3 wavelengths, identified as W1,W2,W3
– YAN 0 10 20 40
specifies 4 fields, identified as F1, F2, F3, F4
• Sometimes, the data item is Yes or No – These can be entered as Yes or No or as Y or N
– If the data is Yes, the Yes can be omitted(Y is assumed)
– PIM Y, RDM N, RDM (same as RDM Y)
• Data items which are strings must be enclosed in quotes ( single or double) – TIT “Double Gauss F/2”
– HEA ‘WikiOptics’
15/192
Index qualifiers and data
• Qualifiers or data separated by | means OR(only enter one) – RDM Yes|No
• Items in square brackets [ ] are optional – SUR Sk|Si..j [F] [Zk]
• Items followed by [....z] can take different values for different zoom positions
– Assume there are zoom positions and RDY S3 is zoomed • RDY Sk radius[....z] syntax
• RDY S3 10 20 30 example
• RDY S3 Z2 25 example with Z qualifires
– Also applies to ....f and ....w
16/192
A note on Numbers
• Exponential input may be used – 0.1E2 = 1.0E1 = 10
• Object stop, and image surfaces can be called O, S, and I, respectively – SI image surface (can only be referenced by I)
– SO object surface (can be zero or oh)
– SS stop surface
– SI-1 surface before the image surface
• 1013(=1E13) is the default for INFINITY for object distance
17/192
Useful commands
• EVA macro_expression
– EVA (EFL) ! Evaluate the effective focal length of the lens
– EVA (EPD) ! Evaluate the entrance pupil diameter
– EVA (Y F1 R2 SI) ! Evaluate the Y value at the image surface(SI) of
! the upper marginal ray(R2) for field 1(F1)
• WRI [U^unit_number] [Qformat_picture] [expression_list]
– Allows you to output data to the screen display or to an opened file
– Immediate command
• TOW;commands – Generates output in a tabbed output window
– TOW;VIE;GO
18/192
CODE V> RES MYLENS CODE V> ^x == 5 CODE V> WRI "The curvature of surface" ^x "is" (CUY S^x) The curvature of surface 5 is 4.62243
Section 2
Basic macro
19/192
A typical simple macro
! Macro to list individual element focal lengths, clear aperture
! diameters, and ET's at max of the two semi-diameters.
^format == "'3d' '3d' '9d.4d' '8c' '4d.4d' '7d.4d'"
wri "Surfaces Focal Length Glass C.A. Diam. Edge Thickness"
for ^s 1 (num s)-1
if (gla s^s) <> ""
^s2 == ^s+1
^c1 == (cuy s^s) ; ^c2 == (cuy s^s2)
if ^c1=0 and ^c2=0
^FL == 0
else
^n == (ind s^s) ; ^t == (thi s^s)
^FL == 1/(^n-1)/(^c1-^c2+^t*(^n-1)*^c1*^c2/^n)
end if
^sd == maxf((sd s^s),(sd s^s2))
^et == (thi s^s) - sagf(^s,1,0,^sd) + sagf(^s2,1,0,^sd)
wri q^format ^s ^s2 ^FL (gla s^s) 2*^sd ^et
end if
end for
20/192
Formatted output
Loop
Variables Access to lens data
Functions
What is Macro-PLUS?
• Macro-PLUS is a programming language built into CODE V
• It allows you to customize CODE V to your needs
• It adds flexibility and power to CODE V
• Historically, macros started as simple sequences of commands
– That is why macros are saved as .SEQ files
– In version 7.20 (about 1988), Macro-PLUS was added to CODE V
– The terms “sequence” and “macro” are roughly synonymous
• Some use the name "sequence" for simple sequences of commands (such as the commands for an AUTO run) and the name "macro" for more complex calculations
• However, they are both stored in .SEQ files and are executed the same way (with the IN command)
21/192
Macro-PLUS’s feature
• Macro-PLUS is a versatile programming language built into CODE V
– It is used to extend and automate the capabilities of CODE V, as shown in ORA supplied macros
– It is available anywhere within CODE V
– Direct access to lens database and ray trace quantities
– Allows interaction with external text files
– Allows the use of an expression wherever CODE V expects a number
22/192
What can I do with macros?
• Level 1: Nothing – You can ignore macros if you want to - they are not required to run
CODE V
• Level 2: Use pre-written macros – ORA supplies over 200 macros with CODE V – no programming needed
– Many of these are integrated into the CODE V GUI without you realizing it!
• Level 3: Use macro expressions in place of numbers – Use CODE V as a calculator, using expressions in place of numbers
• Level 4: Command sequences – These are text files of CODE V commands, such as optimization or
tolerancing input.
• Level 5: Complex macros – These are macros which may include loops and branching and compute
user-desired quantities or output.
23/192
Sample macros supplied with CODE V
• Over 200 macros are supplied with CODE V
• These sample macros have three purposes :
– Demonstrate the type of things that can be done with macros
– Extend the capabilities of CODE V in many areas
– Provide examples to users who wish to modify the samples or write their own macros
• You do not have to program to use these sample macros
24/192
Using supplied macros
• CODE V includes a large number of supplied macros that expand the basic capabilities
– Macros are written in command-based Macro-PLUS
• Macros are used through a dialog box launched from the Tools>Macro Manager… menu
– Also available from the command line (IN command)
25/192
Integrated macros
• Some macros have been integrated into the user interface as standard features
• These include macros for user-defined tolerancing, inserting various prisms, and distortion grid plotting
• Removing or changing certain macros in the CV_MACRO: directory may disable some program features, so please don’t change them!
– Copy any macros that you wish to change to another folder before editing
26/192
Macro sequences
• Macro sequences are simply text files containing a sequence of CODE V commands you wish to run
– These are often called sequence files(.SEQ files), although all macros are actually text files with the file extender .SEQ
– These text files are created and modified with the CODE V Editor or with any other text editor or word processor (ASCII text only)
• For example : MYMTF.SEQ
MTF
MFR 100
IFR 10
PLO FRE
GO
• Execute the macro with the IN command or from Tools>Macro Manager…
– CODE V> IN MYMTF
27/192
Parameter substitution
• When you run a macro with IN, you can pass parameters to the macro – This requires the use of parameter inputs in the macro
– RFD command (replacement field default) can specify parameter defaults
• Example : MYMTF.SEQ
RFD 100 10 YES
MTF
MFR #1
IFR #2
PLO FRE #3
GO
• Execute with or without parameter substitution – IN MYMTF 200 20 N ! Uses input values
– IN MYMTF 200 ! Defaults for #2 and #3
– IN MYMTF ! Defaults for all parameters
28/192
Macro input dialog boxes
• When you launch a macro from the macro dialog box, it will display its own input dialog box if one is defined for it
– The dialog box is defined in specially formatted comments in the macro source code
– These comments are interpreted at run time to build the dialog box
– The dialog is not created if you run a macro from the command line with the IN command
29/192
Dialog box commands
• The dialog box commands have the form ARGn, where n is an integer from 0 to 9 ( you can use 9 arguments because the ARG0 is used for a description of the macro)
! ARG0 “description” ! Description of the macro’s function
! ARGn NAME “argument name”
! ARGn TYPE NUM|INT|STR|LITERAL
NUM – Floating point number
INT – Integer number
STR – String variable. It must be enclosed in quotes
LITERAL – Character string (no blanks) passed without quotes (e.g., Yes or No)
! ARGn CHOICE value1 value2….
Creates a choice button in the parameter value box, up to 32 choices
! ARGn DEFAULT default_value
! ARGn HELP “help_string” ! Gives a line help message
30/192
Workshop
• Making “default.seq” file
– Every time CODE V is started, it runs the default.seq file specified in the Startup Parameters window : CODE V setup
– Useful for
• Specifying default parameters (units, radius mode, plot settings, glass catalog search order)
• Setting paths
• Defining global variables (^pi, ^deg2rad)
• Calling macro function definitions
31/192
Default parameters
• Default parameters allow you to establish settings for all lenses
• Examples
– RDM NO ! Use curvature mode, not radius mode
– DDM M ! Set default dimensions to mm
– DIN ‘ORA’ ! Designer initials
– CSO OHARA SCHOTT SPECIAL ! Change order for searching glass
– VER ALL NO ! Don’t echo macro or sequence commands
32/192
Setting paths
• CODE V first checks in your current directory for any lenses, macros, .mul or .int files that you reference
• If the file isn’t found there, it searches the directories specified by the current path (PTH) command for that type of file
– PTH LEN CV_LENS: E:\CVUSER\EDU
– CV_LENS: and CV_MACRO: are aliases that point to the “lens” and “macros” directories of the version of CODE V currently running. They allow your defaults.seq file to be independent of CODE V version
• Up to 10 directories can be specified for each
– PTH LEN ! .len and .mul files
– PTH SEQ ! .seq files
– PTH INT ! .int files
33/192
Useful entries
• Global variables
– Constants
GBL NUM ^pi ^deg2rad
^pi == 4*atanf(1)
^deg2rad == ^pi/180.0
– Very useful since CODE V’s trigonometric functions use radians, but tilts and ray trace output use degrees
• Define any commonly used functions
– IN CV_MACRO:FIFTHDEF ! Defined @FIFTH, for 5th order
! aberration calculations
34/192
mydefault.seq
GBL NUM ^pi ^deg2rad
^pi == 4*atanf(1)
^deg2rad == ^pi/180.0
DIN “YIM”
DDM M
PTH LEN CV_LENS:
PTH SEQ CV_MACRO:
EVA (CD) ! Current directory : CD
35/192
run "E:\CVUSER\mydefault.seq" CODE V> DIN "YIM" CODE V> DDM M CODE V> PTH LEN CV_LENS: CODE V> PTH SEQ CV_MACRO: CODE V> EVA (CD) (CD) = "E:\CODEV104" ?ddm DDM = MM ?din DIN = YIM eva (^pi) (^PI) = 3.14159265358979 eva (^deg2rad) (^DEG2RAD) = 0.017453292250994
Section 3
Buffer management
36/192
Worksheet buffer
• CODE V’s worksheet buffer facility is a set of RAM buffers which can hold data in a spreadsheet form
– Data (numeric or string) are stored in cells, and are accessed by row and column number
• The lowest numbered buffer, B0, is a special buffer used only to collect CODE V text output
– The CODE V output is then available to Macro-PLUS through database items
• You can use additional buffers, B1, B2, … for other purposes
– Creating your own tables of analysis data
– Collecting formatted data from options that have a WBF capability
• There are commands to search buffers, copy buffers, sort them, plot from them, etc.
37/192
Data collection buffer B0
• The B0 buffer is used to collect CODE V text output – It is collected independently of the state of the OUT flag
• The command BUF YES starts collection, and BUF NO stops collection
• Buffer B0 is 10,000 lines long – Adding more data will cause the top lines to scroll off the top
– The length can be changed with the BUF LEN command
– User buffers (B1..n) are unlimited in size
• Some buffer commands – BUF LIS list a buffer
– BUF DEL delete a buffer ( clear contents of buffer)
– BUF COP copy a buffer
– BUF FND search a buffer for a number or text
– BUF PUT put data into a buffer
– BUF ? query the status of all buffers
38/192
Some buffer commands
• BUF Yes|No – Turns the collecting of CODE V output into worksheet B0 on or off
• BUF ? – Reports status of CODE V worksheet
• BUF DEL Bk|Bi..j – Deletes a specified worksheet buffer or range of buffers
• BUF EXP [Bn] [Ii..j] [Jk..l] [SEP] [filename] – Exports all or a portion of specified buffer to a file ( default extender
.DAT)
– Output file is tab delimited unless SEP qualifier is used
buf exp file1 ! Export using tab as separator
Buf exp sep file2 ! Export using user-defined separator
39/192
Some buffer commands
• BUF FND [Bn] “expression”|word|num – Finds the first and successive matches of the given expressions,
words, or numbers in Bn
– To determine success or failure of a match use the (BUF.FND) item
• BUF LEN maximum_B0_lines Def:10000 – Sets the maximum number of lines to be stored in worksheet B0
• BUF LIS [Bn] [Ik] [Jk] [“expression”|word|num…] – List specified worksheet.
• BUF PUT [Bn] [Ik] [Jm] “string”|num… – Allows one or more values to be stored in a given range of cells BUF PUT B1 I1..2 J1..2 “Hello?” “Everyone”
BUF LIS B1
1: Hello? Everyone
2: Hello? Everyone
40/192
Example of data collection
CODE V> res doublet
File CV_LENS:doublet.len has been restored
Lens title: "Doublet"
CODE V> buf yes ! Start collection
CODE V> sur sa
RDY THI RMD GLA
> OBJ: INFINITY INFINITY
STO: 61.07222 10.345634 BSM24_OHARA
2: -42.17543 2.351280 SF1_SCHOTT
3: -316.13853 92.451433
IMG: INFINITY 0.000000
CODE V> buf no ! Stop collection
CODE V> buf lis b0
1: CODE V> sur sa
2: RDY THI RMD GLA
3: > OBJ: INFINITY INFINITY
4: STO: 61.07222 10.345634 BSM24_OHARA
5: 2: -42.17543 2.351280 SF1_SCHOTT
6: 3: -316.13853 92.451433
7: IMG: INFINITY 0.000000
8: CODE V> buf no
CODE V> wri (buf.num b0 i6 j3)
92.4514
41/192
Accessing data in a buffer
• Data are stored and accessed by row and column number
– I is always used for row number
– J is always used for column number
• Letters can be used in place of numbers with I and J
– IL, JL last row or column
– IC, JC current row or column
– IA, JA used for I1..L and J1..L
• Data are accessed through database items
– (BUF.NUM Bk Im Jn) number in buffer Bk at row m column n
– (BUF.STR Bk Im Jn) string in buffer Bk at row m column n
– Defaults are current buffer, current row, and current column
42/192
Default parsing
• As CODE V output is captured in worksheet B0, each incoming line is separated into cells – Initial leading white space is ignored
– Text is automatically split into cells whenever two or more spaces or a single tab are found
– After automatic cell boundaries have been applied, individual words may be broken into cells further
– A word is defined as a set of text with a single space on either side
• If a word looks like a number, it is made a distinct cell. Otherwise words are strung together to form a single cell of type STR
43/192
Default parsing example
BUF
WRI “The diameter is 25.4 centimeters”
WRI “The diameter is 25.4, centimeters”
BUF NO
BUF LIS B0
EVA (BUF.COL I2) ! Number of columns in row I2
(BUF.COL I2) = 3 ! Cell 1 = “The diameter is” (STR)
! Cell 2 = 25.4 (NUM)
! Cell 3 = “centimeters” (STR)
EVA (BUF.COL I4) ! Number of columns in row I4
(BUF. COL I4) = 1 ! Cell 1 = “The diameter is 25.4, centimeters” (STR)
• Notice that the word ‘25.4,’ in row I4 cannot be converted into a number due the trailing comma.
44/192
1: CODE V> WRI "The diameter is 25.4 centimeters"
2: The diameter is 25.4 centimeters
3: CODE V> WRI "The diameter is 25.4, centimeters"
4: The diameter is 25.4, centimeters
5: CODE V> buf no
Matching expressions
• Matching expressions provide a powerful way to find data items in a worksheet. Matching expression apply to both the BUF FND and BUF LIS commands. Matching is NEVER case sensitive
After BUF FND “THI” : ic=2, jc=1
Command Rows listed Match condition
BUF LIS i1..2 “2” i1 and i2 All cells with substring ”2”
BUF LIS i1..2 2 i2 All Num cells with value 2
45/192
j1 j2
i1 “CUY = “ 3.4
i2 “THI = “ 1.9
j1 j2
i1 “DLY 2.00v “ 3.65
i2 “DLX 3.65v“ 2
Some special characters
• ? – This is used match any single character. Use it when you do not care
what character appears in the particular string position
– “a?c” will match all the following : “abc”, “aac”, “a4c”, “a+c”
• [ ] – Defines a character class
– [abc] means that if the match is to be successful, the next character must be either a, b, or c
– [0-9] means the next character must be a number
Expression Matches But not
“th[ia][st]” “this” “th”
“that” “thi”
“thas” “thia”
“thit”
• ?* - to match everything
46/192
Buffer database items
• BUF.B returns number of current buffer
• BUF.COL [Bn] [Ik] returns number of cells in row k
• BUF.EMP [Bn] queries if buffer n is empty (1 or 0)
• BUF.FND queries success of last search (1 or 0)
• BUF.I [Bn] returns number of current row
• BUF.J [Bn] returns number of current column
• BUF.LST [Bn] returns row number of last row
• BUF.MXJ [Bn] returns largest column for all rows
• BUF.NUM [Bn] [Ik] [Jm] returns the number in specified cell
• BUF.STR [Bn] [Ik] [Jm] returns the string in specified cell
• BUF.ON status of B0 buffer collection (1 or 0)
• Like any other database item, enclose in parentheses
– ^x == (buf.num b0 i^i j4)
47/192
Extracting specific output from the buffer
• Task : extract a particular datum from the collection buffer B0
• In general, you do not know the exact location of the datum in buffer B0
• One way to find it is as follows
– Do a search for some known output pattern or keyword
– Know that the desired output datum is x columns and y rows away from the known pattern/keyword
– This typically requires you to run the option interactively beforehand (with BUF Y) to determine
• What the output pattern/keyword is
• What the row and column numbers or offsets are
– If column number is ambiguous, use BUF SEP to define a non-blank column separator (e.g., BUF SEP “|”), then use BUF LIS to list the ambiguous lines. BUF SEP with no separator shows default spacing
48/192
Workshop
• Restore Cooke1.len • Write the radial and tangential MTF for a frequency of 30 cycles/mm at the field
whose filed angle is 14°
RES COOKE1 BUF TOW; MTF; MFR 30; IFR 10; GO BUF NO BUF FND ‘14?*DEG’ ! ?* means any number, any characters ^mtfr==(buf.num ic+13 jL-1);^mtft==(buf.num ic+13 jL) EVA (^mtfr); EVA (^mtft)
49/192
63: Cooke Triplet f/4.5
64: WAVELENGTH WEIGHT NO. OF RAYS
65: FIELD (X,Y)=( 0.00, 0.69)MAX, ( 0.00, 14.00)DEG 656.3 NM 1 776
66: RELATIVE ILLUMINATION = 87.1 PER CENT 546.1 NM 2 1134
67: ILLUMINATION (UNIT BRIGHTNESS) = 0.033685 486.1 NM 1 1426
68: DISTORTION = 0.49 PER CENT
69:
70:
71: DIFFRACTION LIMIT FOCUS POSITION
72: Formula Actual 0.00000
73: L/MM f/4.500 RAD TAN RAD TAN
74: ---- ---------------- ---------
75: 0 .999 .999 .999 .999 .999
76: 10 .968 .968 .964 .794 .573
77: 20 .936 .936 .927 .397 .423
78: 30 .904 .904 .892 .087 .370
Find this pattern to locate the field at 14°
Desired data are 13 rows down in last 2 columns
BUF SEP [separator_string]
• buf sep '|'; buf lis i71..78
• buf sep ‘$’; buf lis i71..78
50/192
71: DIFFRACTION LIMIT|FOCUS POSITION
72: Formula|Actual|0.00000
73: L/MM f/4.500 RAD|TAN|RAD|TAN
74: ---- ----------------|---------
75: 0|.999|.999|.999|.999|.999
76: 10|.968|.968|.964|.794|.573
77: 20|.936|.936|.927|.397|.423
78: 30|.904|.904|.892|.087|.370
71: DIFFRACTION LIMIT$$FOCUS POSITION
72: Formula$$Actual$$0.00000
73: L/MM f/4.500 RAD$$TAN$$RAD$$TAN
74: ---- ----------------$$---------
75: 0$$.999$$.999$$.999$$.999$$.999
76: 10$$.968$$.968$$.964$$.794$$.573
77: 20$$.936$$.936$$.927$$.397$$.423
78: 30$$.904$$.904$$.892$$.087$$.370
Section 4
User graphics
51/192
Using the UGR option
• There are three different types of plots
– Plots of X,Y data. Up to 20 different X,Y data sets can be graphed on the same plot
– Plots of two-dimensional data (called scalar field plots). 2D data can be plotted in contour form, oblique projection form, or as color raster contour plots.
– Plots of two- or three-dimensional vector data(called visualization plots). Vector data are plotted at specified X,Y locations using visualization icons
52/192
X,Y data plot (DPO)
53/192
17:20:15
YIM 29-Feb-12
Example
X-AXIS
Y-AXIS
0. 2. 4. 6. 8. 10.
0.
2.
4.
6.
8.
10.
Mountain
UGR
TIT 'Example'
DPO 'Mountain'
0 0
1 2
2 3
3 2
4 0
5 4
6 7
7 10
8 7
9 4
10 0
END
GO
UGR
TIT 'Example'
DPO 'Mountain1'
0 0;1 2;2 3;3 2;4 0;5 4
6 7;7 10;8 7;9 4;10 0
END
DPO 'Mountain2'
0 10;1 8;2 5;3 4;4 5;5 8;6 5;7 2;8 0
END
DPO 'Mountain3'
0 2;1 3;2 4;3 4;4 5;5 7;8 1;9 0;10 2
END
GO
17:29:09
YIM 29-Feb-12
Example
X-AXIS
Y-AXIS
0. 2. 4. 6. 8. 10.
0.
2.
4.
6.
8.
10.
Mountain1
Mountain2
Mountain3
Axis control and numeric labeling
• Axis and range definition
• Numeric axis labeling – XFO F 3 ! 1000.000 F Floating point format
– XFO E 3 ! 1.000E+03 E Exponential 1.000E+03
– XFO D 2 ! 1.00D+03 D Exponential 1.000D+03
– XFO G 3 ! 1000 will appear 1.000E+03, while 500 will appear as 50
! G “general” format switches automatically form F to E format when necessary to preserve precision for large numbers
– In CODE V E and D are identical (double precision)
54/192
Plot method/line color/line style
• LIN [PNT] [line_style]
• LIN [PNT] [line_style line_color]
– Connect data points with straight line segments in the ordered entered
• SPL [PNT] [line_style]
• SPL [PNT] [line_style line_color]
– Connect data points with spline curve after sorting in X ascending order
• PNT [NOT] [point_color]
– Only draw symbols at entered points. The NOT qualifier indicates that the points will be annotated
55/192
Color/dot/line lists
• CLS [color….25]
– Selects the color list used for generic data sets such as in the UGR
– Default
Red, Green, Blue, Magenta, Yellow, Cyan, White, Gray, Charcoal, Pink, Rust, Chiffon Green, Forest Green, Baby Blue, Royal Blue
• DTL dot_symbol….25
– Default 1-17
• STL Yes|No|line_style….25
– Default No(uses solid line #1)
56/192
Using UGR with Macro-PLUS
UGR
TIT 'SIN & COS graph'
STL 1 2
XAX 0
XDE 10
XMI -360
XMA 360
YAX 0
YDE 0.5
YMA 1.5
YMI -1.5
DPO 'SIN'
SPL PNT
FOR ^i -360 360 10
^i sinf(^i*^deg2rad)
END FOR
END
DPO 'COS'
SPL PNT
FOR ^i -360 360 10
^i cosf(^i*^deg2rad)
END FOR
END
GO
57/192
11:11:17
YIM 08-Mar-12
SIN & COS graph
X-AXIS
Y-AXIS
-360. -310. -260. -210. -160. -110. -60. -10. 40. 90. 140. 190. 240. 290. 340.
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
SIN
COS
Plotting from the worksheet buffer
• DTB command (data table form buffer)
– DTB [Bn] Ij..k Jn..m [ROW|COL] [PNT|LIN|SPL] ‘label’…(20)
– Use to plot a contiguous set of data
• First row or column is x data
• Remaining (contiguous) rows or columns are y data
• Up to 20 data sets can be plotted
• BIM command (buffer import)
– BIM [Bn] [CC|CR|RC|RR] x_row x_col y_row y_col num_pts
– Use to add data to the current data set
• The x data and y data can be located separately in the buffer and can be in different directions
• SFP (scalar field plot) – use for plotting 2D data
– SFP [Bn] Ij..k Jn..m PLO|CON|DIS
58/192
Buffer data
RES cooke1 ; buf y; fie go; buf no; buf lis b0
14: RELATIVE ANGLE X-FOCUS Y-FOCUS X-FOCUS Y-FOCUS DISTORTION 15: FIELD HEIGHT (DEG) AT THE IMAGE SURFACE (DISPLACED BY 0.000000) (PER CENT)
16:
17: 0.00 0.00 -0.028933 -0.028933 -0.028933 -0.028933 0.00000
18: 0.10 2.08 -0.037182 -0.028489 -0.037182 -0.028489 0.00914
19: 0.20 4.16 -0.061446 -0.027324 -0.061446 -0.027324 0.03691
20: 0.30 6.23 -0.100283 -0.026215 -0.100283 -0.026215 0.08432
21: 0.40 8.28 -0.151292 -0.026980 -0.151292 -0.026980 0.15316
22: 0.50 10.31 -0.211126 -0.033353 -0.211126 -0.033353 0.24604
23: 0.60 12.32 -0.275480 -0.052407 -0.275480 -0.052407 0.36657
24: 0.70 14.29 -0.339068 -0.096802 -0.339068 -0.096802 0.51958
25: 0.80 16.23 -0.395560 -0.188305 -0.395560 -0.188305 0.71152
26: 0.90 18.14 -0.437445 -0.363345 -0.437445 -0.363345 0.95098
27: 1.00 20.00 -0.455803 -0.681918 -0.455803 -0.681918 1.24963
59/192
rows 17..27
x data (col 2)
y data (col 3..4)
Plotting with DTB
UGR
TIT 'Cooke Triplet f/4.5'
DTB B0 I17..27 J2..4 SPL 'X-FOCUS' 'Y-FOCUS'
GO
60/192
11:50:49
YIM 08-Mar-12
Cooke Triplet f/4.5
X-AXIS
Y-AXIS
0. 4. 8. 12. 16. 20.
-0.7
-0.6
-0.5
-0.4
-0.3
-0.2
-0.1
0.0
X-FOCUS
Y-FOCUS
Plotting with BIM
UGR
TIT 'Cooke Triplet f/4.5'
XDE GRD
YDE GRD
DPO 'X-FOCUS'
BIM B0 CC 17 2 17 3 11
END
DPO 'Y-FOCUS'
BIM B0 CC 17 2 17 4 11
END
GO
61/192
11:55:58
YIM 08-Mar-12
Cooke Triplet f/4.5
X-AXIS
Y-AXIS
0. 4. 8. 12. 16. 20.
-0.7
-0.6
-0.5
-0.4
-0.3
-0.2
-0.1
0.0
X-FOCUS
Y-FOCUS
Plotting with SFP
• The SFP (scalar field plot) command in UGR is for plotting 2D data
• Data can be plotted as contours, 3D oblique plots, or as color raster plots
• Example : 10X10 array of random numbers
BUF MOV B1
FOR ^i 1 10
FOR ^j 1 10
BUF PUT B1 i^i j^j RANDF
END FOR
END FOR
UGR
SFP B1 i1..10 j1..10 DIS
GO
62/192
.01340
0.9953
0.5043
Section 5
Programming
63/192
Major features
• Global and local variables
• Numeric and string variables
• One- and two-dimensional arrays
• Access to the lens database (surface data, raytrace data)
• Many built-in functions (math, string, optical, etc.)
• User-defined macro functions
• Control structures and branching (WHILE, UNTIL, IF, etc.)
• Subprograms (macros can call macros)
• Interaction (read, write) with text files
• Format control of input and output
• Unlimited program size
64/192
Programming in Macro-PLUS
• You need to be familiar with CODE V command mode
– LDM commands
– Option commands
• You need to know Macro-PLUS commands
– Defining and assigning variables
– Expressions
– Branching and looping
– Input and output
• You need to be familiar with basic programming concepts
– If you ever learned Basic, C, Fortran, Pascal, etc., you’ll do fine!
• CVEdit is a text editor supplied with CODE V
– Supports file versioning
– Open from CODE V command line : CODE V> edi test.seq
65/192
Macro variables
• Macro-PLUS has both numeric and string variables
• The names of variables all start with ^ (caret or "hat"):
^x ^bigval ^string3
– This is to avoid conflict with CODE V commands
• Variable names can contain letters, numbers, and underscores ( _ ), e.g., ^the_original_value
– The name must start with a letter.
• Once a variable is declared as numeric or string type, its type cannot be changed.
– Trying to assign the wrong data type to a variable will result in an error.
– Variables can be dropped (DROP command) and redeclared.
66/192
Declaring variables
• Macro-PLUS must know what type a variable is (numeric or string)
• This declaration can be done implicitly or explicitly.
• Implicit declaration is done by simply assigning data to a new variable:
^x == 3 - implicitly declared as numeric type
^y == "hello" - implicitly declared as string type
• Explicit declaration is done with the NUM or STR command:
num ^a ^b ^num - explicitly declared as numeric types
str ^m ^n ^text - explicitly declared as string types
• In macros, variable declarations must be made before any other executable statements
• The command CHK Y forces all variables to be explicitly declared before use. This is useful for debugging
• There is no integer variable type
67/192
Local and global variables
• Local variables are only known in their current context – If a local variable is defined interactively (at the CODE V> prompt), it is
not known in any macro
– If a local variable is defined in any macro, it is not known in other macros or at the interactive level
– Declare with LCL command (e.g., lcl num ^x)
• Global variables are known throughout CODE V – Global variables defined in any macro or interactively are always known
– Declare with GBL command (e.g., gbl str ^text)
• If LCL or GBL is not given in a declaration, LCL is assumed
• Global and local variable conflicts are possible. – An implicitly declared variable will use the global definition, if it exists.
– Local variables explicitly declared in a macro will override any global variables previously defined with the same name.
• It is always good practice to explicitly declare local variables in macros to avoid possible conflicts with global variables.
68/192
Array variables
• One- and two-dimensional arrays can be defined – Can be numeric or string
• Array variables must be explicitly declared before use
• One-dimensional array (vector) num ^field(5) ^field(2) == (yan f2) • Two-dimensional array (matrix) num ^x(10,10) ^x(5,5) == 25 • The array subscript can start at numbers other than 1 num ^x(11) ^y(-5..5) ^z(20..31) str ^a(11,11) ^b(-5..5,10..21)
• Array sizes are unlimited (limited only by memory)
69/192
Database access
• Most of the data in the lens database is available to Macro-PLUS – Lens data (radii, thickness, EPD, fields, aspheric coefficients, etc.)
– Calculated values (EFL, ray trace data, etc.)
• Database items usually have the same name as the corresponding lens data
• The database names are always enclosed in parentheses. – This identifies them as database items.
• Examples:
(rdy s3)
(epd)
(y r1 f3 w2 z2 s7)
• Database items can return numeric data or string data
eva (rdy s3)
(rdy s3) = 57.1234
eva (gla s1)
(gla s1) = "BK7"
70/192
Use of database items
• Database items can be used for variable assignment (note that the assignment operator in Macro-PLUS is the double == )
^rdy_s1 == (rdy s1)
^y3 == (y s3)
• They can be used in expressions
^x == (rdy s3)*2 + (thi s4)/(thi s5)
^y == sinf((ade s2)/57.29578)
• They can be used in CODE V commands
rdy s1 -(rdy s1)
epd (epd)
aut;efl = (efl);go
• They can be used in data queries (with EVA command)
eva (rdy s2)
eva (efl)
71/192
Macro expressions
• Expressions are mixtures of variables, database items, functions, and operators
• Expressions have many uses – Variable assignment
^pupilarea == ^pi/4*(epd)**2
– Can be used in place of numbers in CODE V commands
thi s3 90-(thi s2)
• Note that this does not create a relationship (database items are just numbers or strings)
• To form a relationship, use a pickup
pik thi s3 thi s2 -1 90
• Always remember to enclose database items in parentheses!
72/192
Rules for expressions
• Expressions consist of operators, parentheses, and operands – Operators
• Unary + or –
• Arithmetic (+, -, *, /, **)
• Relational (<, <=, =, >=, >, <>)
• Logical (NOT, AND, OR)
– Parentheses are used for database items, function arguments, and to change the order of evaluation of operators
– Operands are variables, functions, constants, database items
• In variable assignments, expressions can include spaces for readability
^x == (^a1 + ^a2) / (^b1 + ^b2) + ^c
• In CODE V commands, expressions should not include spaces unless enclosed in parentheses
yan 0 10 10 + 10 - gives an error
yan 0 10 (10 + 10) - OK
73/192
Expression examples
• Evaluation EVA (EFL)
EVA TANF((ADE S3)/57.2958)
• Lens data definition THI S5 -(THI S3)/2
• AUTO constraints EFL = (EFL)
• Miscellaneous ^i == 8
^tau == (thi s^i) / (ind s^i) ! t/n
^nmn == (ind s^i+1) - (ind s^i) ! n' - n
^radial_dist_3 == sqrtf((x s3)**2 + (y s3)**2))
^metric == (dim)='M' or (dim)='C' ! TRUE = 1
^normal == (yan f1) > (yan fL) ! FALSE = 0
74/192
Loops
• Macro-PLUS has three methods for looping through program steps
• FOR loop – Loops through steps a fixed number of times, based on starting value,
final value, and increment (they do not need to be integers)
FOR ^I 1 20 2
• WHILE loop – Continues to loop through steps while some condition is true
– Test is at the top of the loop, so execution occurs 0 or more times
WHILE ^x=3
• UNTIL loop – Loops through steps until some condition is true
– Test is at bottom of loop, so execution occurs at least once
UNTIL
. . .
END UNTIL ^x=5
75/192
Loop examples
• Macro to list radius, thickness, and glass for all surfaces – With FOR loop
for ^i 0 (num s) ! (num s) number of surfaces
wri ^i (rdy s^i) (thi s^i) (gla s^i)
end for
– With WHILE loop
^i == 0
while ^i <= (num s)
wri ^i (rdy s^i) (thi s^i) (gla s^i)
^i == ^i + 1
end while
– With UNTIL loop
^i == 0
until
wri ^i (rdy s^i) (thi s^i) (gla s^i)
^i == ^i + 1
end until ^i > (num s)
76/192
Tips, bug of for-loop
• Fractional increment
for ^i 0 0.5 0.1; wri ^i ;end for
We expect
0
0.1
0.2
0.3
0.4
0.5
But the result will be
0
0.1
0.2
0.3
0.4
77/192
Recommend for ^i 0 5 1 wri ^i/10 end for
IF tests
• IF tests allow conditional execution of a section of code – The basic idea is “If TRUE, do this, if FALSE, skip it”
• The IF test allows multiple additional tests (ELSE IF), plus allows a final choice (ELSE)
• The basic structure is IF test . . . ELSE IF test . . . ELSE . . . END IF • Note that unlike FORTRAN, END IF is two words (otherwise, Macro-
PLUS does not know what you are ending, since it only reads the first 3 letters)
78/192
optional
IF example
• Test to check on lens units, and set a scale factor of mm per lens unit
if (dim) = “I”
wri “Dimensions are inches”
^scale == 25.4
else if (dim) = “C”
wri “Dimensions are centimeters”
^scale == 10.0
else
wri “Dimensions are millimeters”
^scale == 1.0
end if
79/192
GOTO command
• The GOTO command transfers execution unconditionally to a corresponding LBL statement (label)
GOTO NEXT
. . .
LBL NEXT
• The LBL statement can be after, or before the GOTO command
– There can be only one LBL statement with a given label
• Note that there is no space between GO and TO
– GOTO NEXT, not GO TO NEXT
• Excessive use of GOTOs can make programs hard to understand
– Programming purists think they’re inelegant
– However, they are useful in many situations
80/192
Macros calling macros
• Complex macros can often be broken into smaller macros where some macros call others (like subroutines in other programming languages)
• Macros can call other macros, which in turn can call other macros, etc.
– The calling depth is unlimited
– When a macro terminates, it returns execution to wherever it was called from
– A macro terminates when it reaches its end or when it encounters an RTN command (return)
• Note that when any macro encounters an error, even if it's in a subroutine call, execution stops and you are returned to the interactive level.
81/192
Debugging your macros
• There are several tools in Macro-PLUS to help you debug your macros
• VERIFY command
– VER allows you to specify the types of commands and output which is sent to the terminal during macro execution
• VER [COM|CTL|FCT|IO|MAC|SEQ|ALL] YES|NO
– The default is VER N; VER SEQ Y, which will echo CDOE V commands
– To debug a macro, it is often helpful to use VER ALL Y
– When running macros, it is usually best to use VER ALL N
• LVR command (list variables)
– LVR allows you to list all the variables, their current values, and user-defined functions
– You can limit the list (e.g., LVR LCL, LVR GBL, LVR FCT)
82/192
Debugging your macros (cont’d)
• CHK command (check variables)
– CHK YES forces all variables to be explicitly declared before use
– Useful for checking long macros, especially where a variable name may be mistyped somewhere
– The default is CHK NO, which allows implicit variables declaration
• BND command (boundary checking)
– BND YES forces checking of limits on array subscripts
• This is the default
• Provides an error message if an array subscript exceeds its limits
– BND NO does not check for subscripts out of range
• Allows macro to run faster
• Only use on error-free macros!
83/192
Reading data
• Macro-PLUS can read data during execution – From the Command Window input line (interactively)
– From a file
• Reading is done with the REA command
• When reading data interactively, the macro stops and prompts for data:
REA ^X
READ > 35 (^x is given the value 35)
• The read prompt can be set with RPR (read prompt)
RPR "INPUT A NUMBER, PLEASE:“
REA ^X
INPUT A NUMBER, PLEASE: 35 – Giving the RPR command with no string following it resets the prompt
to the default.
84/192
Reading data (cont.)
• More than one datum can be read at a time:
REA ^X ^Y ^Z – Separate multiple inputs by spaces:
INPUT > 10 20 30
– If not enough values are entered, the variables are given values of 0
• When reading text strings, text strings are separated by spaces (unless formatted reads are used)
STR ^A ^B
REA ^A
INPUT > CODE V ! A = "CODE"
REA ^A
INPUT > "CODE V" ! A = ""CODE"
REA ^A ^B
INPUT > CODE V ! A = "CODE", B = "V" – If no input is given, the variable is made a null string ("")
85/192
Writing data
• The WRI command writes data
– To the Command Window, or
– To a file
• Example: WRI ^X
• Multiple data items can be written with one WRI command
WRI "The values of x and y are" ^X "and" ^Y
• Numeric values are written with a default format which
– Resembles Fortran G format, and
– Provides about 6 significant figures
• Each WRI command starts writing on a new line
– A standalone WRI command writes a blank line.
86/192
Formatted READ and WRITE
• By default, reading and writing is done unformatted
– Which means it uses a default format
• You can specify your own format with a template string called a Q format
– It uses the qualifier Q followed by a text string defining the format
• The template contains characters representing different types of data:
– D for numeric digit in fixed format
– E for numeric digit in exponential format
– G for numeric digit in general format (switches between fixed and exponential format depending on magnitude)
– A period ( . ) for a decimal point location
– C for a text character
– The format can also contain other text and spaces as desired
87/192
Formatted READ and WRITE (cont.)
• The Q format is a text string which must be enclosed in double quotes – This is the only place in CODE V where it matters whether you use single
quotes or double quotes
• For each datum, the individual format string is enclosed in single quotes:
'ddd.ddd' '3d.4d' 'dd' '3g.5g' 'cccccccc' '10c‘
• Examples
WRI Q"The value of x is 'ddd.ddd'" ^x
WRI Q" 'dd' 'ddd.dddd' 'cccccccc'" ^x ^y ^text
WRI Q" '2d' '3d.4d' '8c'" ^x ^y ^text
• The format string can be stored in a string variable
^format == " 'ddd.ddd' 'dd.dddd' 'cccccccc'“
wri q^format 1.23 4.56 "text“ – This is useful if you want to re-use the format in several WRI commands
88/192
Formatted READ and WRITE
• If numbers do not fill the format, leading spaces are added WRI Q"'dddd.ddd'" 1
1.000
• If a number is too large to fit in a fixed format, the format is automatically expanded as needed
WRI Q"'dddd.ddd'" 1000000
1000000.000
• If text does not fill a character format, the text is left justified in the format and trailing spaces are added
WRI Q"'cccccccc' = 'ddd.ddd'" "radius" 10
radius = 10.000
• If text is larger than a character format, the text is truncated WRI Q"'ccc' = 'ddd.ddd'" "radius" 10
rad = 10.000
89/192
File input/output
• Macro-PLUS can read from and write to text (ASCII) files
– Macro-PLUS can interact with several files at the same time
– Files must be opened and closed as with other computer languages (see next slide)
• Use the REA and WRI commands read and write to/from files just as you would for REA and WRI to/from the Command Window.
– Except there’s no RPR prompt available for REA from a file.
• You can use Q formats
• Note that BUF IMP can import an entire file at once into a buffer, while BUF EXP can export an entire file at once
– This is much faster than repeated REA or WRI commands
90/192
Opening and closing files
• Files are referred to by a U qualifier and a unit number – Unit number is a global variable
– Actual value of the unit number is assigned by Macro-PLUS
• Files are accessed with the OPEN command and are opened in three ways: – NEW create a new file to write to
– OLD to read from an existing file
– APPEND to write data at the end of an existing file
• Examples
OPE NEW U^file1 TEXT1.DAT (create new file text1.dat)
OPE OLD U^file2 TEXT2.DAT (open existing file text2.dat)
• Files are closed with the CLOSE command
CLO U^file1
91/192
2nd day
92/192
Section 6
Functions
93/192
Built-in functions
• Math functions – SINF, COSF, TANF, ASINF, ACOSF, ATANF, ABSF, EXPF, LOGF, LOG10F, MAXF, MINF,
MODF, RANDF, ROUNDF, SQRTF, SIGNF, ZFRFIT, ZRNFIT, GAUSSWTS, functions pertaining to FFTs
• Array functions
– STDEV, SUMF, ARR_TO_BUF, BUF_TO_ARR, + many more
• Optical functions – RAYRSI, RAYSIN, RAYTRA, SAGF, SASF, TRANSFORM, ZFRCOEF, INDEX, BESTSPH,
SURFSAGD, ZERNIKE, EVALZERN, NORMRADIUS, FITERROR, POLGRID, RAYPOL
• Functions that emulate CODE V options – GAUSSBEAM, TRA_1FLD, MTF_1FLD, RMSWFE, RMS_1FLD, ZERNIKEGQ , RMSSPOT,
SPOTDATA
• String Functions – CONCAT, LENSTR, LOCSTR, LOWCASE, SUBSTR, NUM_TO_STR, RFSTR, STR_TO_NUM,
TRUNC, UPCASE
• Others
– EOFILE, CVERROR, Image simulation (IMS) functions
94/192
Using built-in functions
• Functions can take none, one, or several arguments
– Multiple arguments are separated by commas
• All functions requiring arguments have their arguments enclosed in parentheses
– Database arguments require their own parentheses in addition
RANDF, SQRTF(10), MAXF(^X,^Y), SINF((ADE S3)/57.2958)
• Math functions, array functions, and optical functions all return a single numeric value
– Some functions load array variables with values
• String functions return a single nemeric or string value
95/192
User-defined functions
• You can write a macro to define your own user-defined function(UDF) – Once defined, it acts like and is used like a built-in function
• A UDF always returns a single numeric value – It also can store values in global variables which are then available
outside the function call
• The name of a UDF always start with @(e.g., @my_function)
• A UDF must be defined before it can be used – Function definition is in a .SEQ file
• Function definition starts with FCT @NAME
• Function definition ends with END FCT expression
– Function is complied by running the defining macro once
(IN MACRO_NAME)
– Function can then be used like any other macro function
– More than one function can be defined in a single .SEQ file
96/192
Example UDF
• User-defined macro function to compute x**y
• First, write the definition macro (here called POWERDEF.SEQ)
fct @power(num ^x, num ^y)
lcl num ^answer
if ^x <= 0
^answer == 0
else
^answer == expf(^y * logf(^x))
end if
end fct ^answer
• Second, compile the function (only needed once per CODE V session)
IN POWERDEF
• Third, use @POWER as any other macro function
^x == 3 * @power(2,3.5)
97/192
Programming UDFs
• User-defined functions can not contain CODE V commands – They cannot modify the database
– They cannot run CODE V options
• They can only contain Macro-PLUS commands – This includes database references
– If more than one value needs to be returned by the function, the macro function can put data into a global array
• A UDF can only be defined once per CODE V session – The existence of a UDF can be tested in two ways:
• With the ISFCT command
if isfct(“power”) ! TRUE if it exists
• With the LVR FCT command, which lists user-defined functions
– A UDF can be dropped with the DROP command and then be re-defined
dro fct power !@power no longer exists
98/192
String manipulation
• Macro-PLUS has many functions for string manipulation: – Concatenate concat("CODE ","V") (= "CODE V")
– Substring substr("abcde",3,2) (= "cd")
– String length lenstr("abcdefg") (= 7)
– Location locstr("abcdef","e") (= 5)
– Convert str to num str_to_num("ab35cd") (= 35)
– Convert num to str num_to_str(25) (= "25")
– Upper case upcase("abcd“) (= "ABCD")
– Lower case lowcase("ABCD") (= "abcd")
– Truncate blanks trunc("abcd ") (= "abcd")
99/192
The $ prefix for string variables
• Use of a $ instead of ^ will strip outer quotes form a string
^file == “dbgauss”
res ^file ! res “dbgauss” - not OK
res $file ! Res dbgauss - OK
• This technique can be used to make “shortcuts” for CODE V commands
– Define a global string variable which contains a CODE V command
– Execute the command by using $
– For example :
CODE V> gbl str ^dst
CODE V> ^dst == “in cv_macro:dist”
CODE V> $dst 30
100/192
Section 7
Lens module
101/192
Lens module capability
• “Blackbox” lens module can be used in a general optical design
– Completely general model based on the optical eikonal(image)
– Models thick and thin lenses
– Includes third order aberrations
– Simulates chromatic effects
• Lens module applications
– Entry of a perfect lens anywhere in the optical system
• AFO/AFI surface must be the last surface before the image
– Aberration generator
– Model lenses with unknown prescriptions from measureable quantities
– Optimization of first order properties prior to detailed design
– Feasibility studies using ideal lenses
102/192
Entering a lens module
• A lens module is different from other special surface types in that it takes two surfaces to create a lens module – The module properties are associated with the first of the two surfaces
– Both surfaces must be spherical
• Both surfaces must have the same material on both sides – The first surface can have tilts/decenters associated with it but the
second surface cannot
• If the second surface does not yet exist, a warning message is issued
• The module surfaces can have curvatures – This might be to model the outer surfaces of a real lens
– The surface curvatures have no effect on the ray trace
• Note that the ray trace within a module (between the two surfaces) is meaningless – Only the ray trace entering and exiting the module has meaning
103/192
First order characteristics of a lens module
H = Object height
DE = Entrance pupil diameter
dE = Entrance pupil distance
f = focal length
fF = Front focal length
fB = Back focal length
104/192
Lens module commands
MOD Sk [CHR|ACH] ! Change Sk and Sk+1 to lens module
MFL Sk module_focal_length [....z]
MRD Sk module_reduction_ratio [....z]
MFF Sk front_focal_distance [....z]
MBF Sk back_focal_distance [....z]
MEN Sk entrance_pupil_distance [....z]
MFD Sk [OBJ|IMG] max_field_spec [....z]
MED Sk entrance_pupil_diameter [....z]
MWL Sk 1st_wl_nm 2nd_wl_nm 3rd_wl_nm
MCO Sk Cj coefficient[....z]
105/192
Thin lens
Aberrations
Thick lens
Calculation of ray direction
106/192
Workshop 1
• Task : Set up the system of NA 0.6, MFL 3.05mm using lens module ( wavelength 650nm)
lens new
epd 2*0.6*3.05
wl 650
ins s2..3
mod s2;mfl 3.05
pim
tow;vie;fan;go
107/192
? Discontinuity occurs
Sine condition
• Abbe sine condition
– Let u and U designate the paraxial and finite slope angle of an aperture ray, respectively, for all rays in the axial aperture pencil
– With magnification m (and finite conjugates) the sine condition takes the form
– For an object at infinity with the incoming marginal ray height h (where h is used for both, the paraxial and the finite marginal ray) and focal length f becomes
108/192
'
'sinsin
u
U
u
U
'sin'
sin
'' Un
Un
un
num
'sin''
U
h
u
hf )'tan(
''sinNA U
f
hU
Workshop 2
• Task : Set up the system of magnification 1, using lens modules.
Each lens module has NA 0.1 and MFL 25mm
109/192
12:10:07
New lens from CVMACRO:cvnewlens.seq Scale: 3.60 YIM 07-Mar-12
6.94 MM
mod mfl 25 mrd 1E10
mod mfl 25 mrd 1E-10
Section 8
Laser diode Astigmatism
Coupling efficiency
110/192
Laser diode
• Laser diode(LD) has special features as follows
– Astigmatic focus shift makes source astigmatism
• The figure shows negative shift
– Asymmetrical light distribution (pupil apodization)
• Large divergence angle perpendicular to the active layer
111/192
Astigmatic shift
Active layer
Astigmatic shift
• ASF delta_f_microns [….z]
– Astigmatic focus shift in microns. Shift of sagittal source (line object in the X-Z plane) from the tangential source (line object in Y-Z plane)
• ASO orientation_angle_degr [….z]
– Orientation of astigmatic focus shift
112/192
Astigmatism
• Astigmatic shift(d) versus astigmatism
• For example
– Wavelength : 660nm(0.660um)
– NA : 0.1
113/192
n
NAd 2
64
1ASrms
d(um) z5 z6 AS angle ASrms(λ) Note
1 -0.0038 0 90° 0.0015 High power
-1 0.0038 0 0° 0.0015
20 -0.0757 0 90° 0.0309 Low power
-20 0.0757 0 0° 0.0309
d -20um d 20um
PMA with Zernike fitting
• ASF 1
• ASF -20
114/192
PMA;ADW FOC; ZFR 36;GO
Pupil apodization
• Guassian distribution with FWHMx=θ∥, FWHMy=θ⊥
115/192
}]PUYPUX
[lnPUI{exp
)]NAO(tan[sin 0.5,PUI
)]NAO(tan[sin
2tan
PUX ,)]NAO(tan[sin
2tan
PUX
}]
2tan
1
2tan
1{2ln[exp
2
0
2
0
1
0
11
2
2
2
2
r
y
r
xI(x,y)
fr
θθ
f
y
θf
x
θI(x,y)
||
||
Coupling efficiency
• Coupling efficiency is as follows
A is the area at the entrance pupil plane
116/192
2ln2
tan2
tan
),(
||
2
f
dxdyyxIA
PMA option
• NA 0.1, FWHMx 7.5deg., FWHMy 24.5 deg.
PUI 0.5, PUX 0.652, PUY 2.16
• PMA
117/192
Workshop
• Task : make macro for calculating the coupling efficiency
118/192
Dialog box NAO, FWHMx, FWHMy
Define variables ^NAO, ^PI, ^RAD, ^PUX, ^PUY
Lens module MFL 1mm
PMA & buffer treatment PMA, buf fnd “APODIZED”
Write the result PUX, PUY, coupling efficiency
Dialog box & variables
!****************************************************************
! Calculation the coupling efficiency
!****************************************************************
!****************************************************************
! arg0 "Macro to calculate the coupling efficiency "
! arg1 name "System NAO"
! arg1 type num
! arg1 default 0.1
! arg1 help "Input the NAO!"
! arg2 name "Parallel"
! arg2 type num
! arg2 default 9
! arg2 help "X-direction"
! arg3 name "Perpendicular"
! arg3 type num
! arg3 default 23
! arg3 help "Y-direction"
!****************************************************************
RFD 0.1 9 23
^NAO==#1
^PI == 4*ATANF(1)
^RAD == 180/^PI
^PUX==tanf(#2/2/^RAD)/tanf(asinf(^NAO))
^PUY==tanf(#3/2/^RAD)/tanf(asinf(^NAO))
119/192
Lens module
LENS NEW
DIM M
NAO 0.1
TIT 'Coupling efficiency'
XOB 0.0
YOB 0.0
SO 0.0 0.0
S 0.0 1.0
S -1.0 1.0
MOD
MFL 1.0
MRD 1E13
S 0.0 0.0
S 0.0 0.0
STO
S 0.0 2.0
S 0.0 1.0
MOD
MFL 1.0
S 1.0 0.0
S 0.0 1.0
PIM
SI 0.0 0.0
GO
120/192
15:06:01
Coupling efficiency Scale: 32.00 YIM 07-Mar-12
0.78 MM
If you set new NAO, the aperture stop size will be changed to fit it
15:41:02
Coupling efficiency Scale: 32.00 YIM 07-Mar-12
0.78 MM
NAO 0.1
NAO 0.6 V10.XX bug
PMA and buffer treatment
NAO ^NAO ! New NAO
PUI 0.5 ! Apodization
PUX (^PUX)
PUY (^PUY)
BUF DEL B0
BUF YES
PMA; PIN YES; TGR 128; LIS NO; PLO NO; DIS NO; GO
BUF NO
BUF FND "APODIZED” !ic=42, jc=1
^p == (buf.num ic+5 jc+3)
121/192
Write the result and etc.
WRI "PUX" ^PUX
WRI "PUY" ^PUY
WRI "Coupling Efficiency"^p"%“
• Tip1
– OUT NO/OUT YES insert before and after lens module for simplicity
• Tip2
– To secure the current working lens
• SAV “temp.seq” ! Save current lens as temp.seq
• RES “temp.seq” ! Restore current lens
122/192
3rd day
123/192
Section 9
Zernike polynomials
124/192
About Zernike polynomials
• Zernike polynomial comprise a polynomial sequence that has been found to be extremely useful in representing optical surfaces and wavefronts
– Continuous and orthogonal over a unit circle
• Mathematically independent
– Be composed of terms that have the same form as the types of aberrations routinely observed in optical tests, making them particularly applicable to quantitatively describing optical aberrations
• Zernike polynomials are defined in radial coordinates ( radial distance R and azimuth θ), where X=R*cos θ and Y=R*sin θ
125/192
Alternate formulations
• Standard Zernike Polynomials are originally formulated by Frits Zernike in 1934. An alternative ordering of the terms (Extended Fringe Zernike Polynomials) was formulated in the 1970s, which permits better fitting of the type of zonal errors that are commonly encountered when fabricating large aspheric optical components. Both of these sets can have any number of terms
• In the 1970s, John Loomis at the Optical Sciences Center of the University of Arizona used a subset of the re-ordered (Extended Fringe) Zernike polynomials in his FRINGE interferometric data analysis software program. This abbreviated set contains the first 36 terms of the Extended set, and appends the 49th term of the Extended set as its 37th term. This set is popularly known as the Fringe Zernike polynomials, and is the most commonly used form
126/192
Fringe Zernike polynomials
No Polynomial Name
1 1 Piston
2 R cosθ Tilt X
3 R sinθ Tilt Y
4 -1 + 2R2 Power
5 R2 cos2θ Astig X
6 R2 sin2θ Astig Y
7 R(-2+3R2) cosθ Coma X
8 R(-2+3R2) sinθ Coma Y
9 1-6R2+6R4 Spherical
10 R3 cos3θ
11 R3 sin3θ
12 R2(-3+4R2) cos2θ 5th Astig X
13 R2(-3+4R2) sin2θ 5th Astig Y
No Polynomial Name
14 R(3-12R2+10R4) cosθ 5th Coma X
15 R(3-12R2+10R4) sinθ 5th coma Y
16 -1+12R2-30R4+20R6 5th Spherical
17 R4 cos4θ
18 R4 sin4θ
19 R3(-4+5R2) cos3θ
20 R3(-4+5R2) sin3θ
21 R2(6-20R2+15R4) cos2θ 7th Astig X
22 R2(6-20R2+15R4) sin2θ 7th Astig Y
23 R(-4+30R2-60R4+35R6 ) cosθ 7th Coma X
24 R(-4+30R2-60R4+35R6 ) sinθ 7th coma Y
25 1-20R2 +90R4-140R6+70R8 7th Spherical
127/192
3rd order aberrations (Seidel)
• James C Wyant
128/192
Description Magnitude Angle Zygo
Tilt
Focus
Sign chosen to minimize absolute value of magnitude
Astigmatism
Sign opposite that chosen in focus term
Coma
Spherical
72
831
2ZZ
2ZZtan
2
83
2
72 )2Z(Z)2Z(Z
2
6
2
594 ZZ6Z2Z
2
6
2
5 ZZ2
2
8
2
7 ZZ3
96Z
5
61
Z
Ztan
2
1
7
81
Z
Ztan
2
6
2
5 ZZ2
94 6Z2Z
RMS aberration
129/192
Description RMS aberration
Astigmatism
Coma
Spherical
2
6
2
5 ZZ6
1
2
8
2
7 ZZ22
1
9Z5
1
Example
• DVD optical pickup wavefront error by SAXTANT interferometer
130/192
Workshop
• Calculate Seidel and its rms aberration using previous Zernike polynomials
131/192
No Value
Z1 0.4171
Z2 -1.1823
Z3 0.0398
Z4 0.0139
Z5 -0.0511
Z6 0.0183
Z7 0.0189
Z8 -0.0077
Z9 -0.0007
PV RMS Angle
AS
Coma
SA
Hint : atan2
Visit websites
• http://www.optics.arizona.edu/jcwyant/
• http://wyant.optics.arizona.edu/zernikes/zernikes.htm
132/192
Note. James starts Zernike polynomials from Z0 not Z1
Aberration definition by HOYA(PENTAX)
133/192
2. Wavefront error : SA
Section 10
Image-height performance
134/192
Image-Height performance
• Explains almost everything about the diffraction-free lens
• DVD objective lens (NA 0.6)
135/192
YIM or YRI
Dialog box
136/192
!******************************************************************* ! ARG0 "Macro to calculate aberration." ! ! ARG1 NAME "Image height(XMA)" ! ARG1 TYPE NUM ! ARG1 DEFAULT 0.1 ! ARG1 HELP "Image height limit" ! ! ARG2 NAME "Max Y axis(YMA)" ! ARG2 TYPE NUM ! ARG2 DEFAULT 0.2 ! ! ARG3 NAME "X interval(XDE)" ! ARG3 TYPE NUM ! ARG3 DEFAULT 0.01 ! ! ARG4 NAME "Pupil type" ! ARG4 TYPE STR ! ARG4 DEFAULT "EXS" ! ARG4 CHOICE "EXS" "EXP" "ENP" ! ARG4 HELP "Generally use [EXP], but exactly use [EXS]" ! !******************************************************************* RFD 0.1 0.2 0.01 "EXS"
YMA
XMA
XDE
Variables
lcl num ^i ^j ^max ^yri ^xde ^num_fld ^yma
lcl str ^type_fld ^type_pupil ^title
ver no ! echo no
BUF LEN 10000
buf del b1
^num_fld == (num f)
^type_fld == (typ fld)
^max == #1
^yri == ^max/20.000
^yma == #2
^xde == #3
^type_pupil==#4
^title==concat('Image Height VS Aberration : ', ^type_pupil)
SAV "temp.seq“
137/192
ZFRCOEF
• ZFRCOEF(wave_num, field_num, zoom_pos, coef_num, nrd, num_terms, ‘pupil type’) – wavelength_num – Number of wavelength to use (not the value of
the wavelength). Range: 1 to (NUM W)
– field_num – Number of the field point to use (not the value of the field). Range: 1 to (NUM F)
– zoom_pos – Zoom position to use. Range: 1 to (NUM Z)
– coef_num – Fringe Zernike coefficient to compute. Range: 1 to 37
– nrd – Number of rays across the pupil diameter (0 uses a default value of 21)
– num_terms – Number of Fringe Zernike terms to use in computing the coefficient (0 uses a default value of 37 - the full Fringe Zernike set). Range: 1 to 37
– 'pupil _type' – A string expression specifying the type of pupil coordinate system to use • 'ENP' – Entrance pupil plane. This is the default; if the entry does not
match one of the three allowed choices, 'ENP' is used.
• 'EXP' – Exit pupil plane
• 'EXS' – Exit pupil sphere
138/192
Main routine
^j==0 For ^i 0 ^max ^yri ; ^j == ^j+1 out no ; yri ^i ; set vig; buf del b0;buf yes; wav;go; BUF NO BUF FND "FRACT“ ; ^opd == (BUF.NUM IC+3 J6) !RMS wavefront error ^ZFR_Z5 == ZFRCOEF(1,1,1,5,30,37,^type_pupil) !Astigx ^ZFR_Z6 == ZFRCOEF(1,1,1,6,30,37,^type_pupil) !Astigy ^ZFR_Z7 == ZFRCOEF(1,1,1,7,30,37,^type_pupil) !Comax ^ZFR_Z8 == ZFRCOEF(1,1,1,8,30,37,^type_pupil) !Comay ^ZFR_Z9 == ZFRCOEF(1,1,1,9,30,37,^type_pupil) !SA3 ^SA_3 == (^ZFR_Z9)/SQRTF(5) !Spherical aberration ^CM_3 == SQRTF(^ZFR_Z7**2+^ZFR_Z8**2)/SQRTF(8) !Coma ^AS_3 == SQRTF(^ZFR_Z5**2+^ZFR_Z6**2)/SQRTF(6) !Astigmatism BUF PUT B1 I^j J1 ^SA_3 ; BUF PUT B1 I^j J2 ^CM_3 BUF PUT B1 I^j J3 ^AS_3 ; BUF PUT B1 I^j J4 ^opd ^form == "'dd.ddd' 'dd.ddddd' 'dd.ddddd' 'dd.ddddd' 'dd.ddddd'" OUT T; WRI Q^form ^I ^SA_3 ^CM_3 ^AS_3 ^opd END FOR RES "temp.seq”
139/192
Assign listed output stream
• OUT [T] [*|filespec] or OUT Yes|No
– T Screen display
and/or
– * Last used OUT filespec (default : lensname.LIS)
– filespec Designed file (default extender : .LIS)
– No Turn off screen display listings and .LIS output
– Yes Restores output to prior OUT T and/or filespec
140/192
OUT image_height
^j==0
FOR ^i 0 ^max ^yri
^j == ^j+1
wri Q^form ^i (BUF.NUM B1 I^j J1) (BUF.NUM B1 I^j J2) &
(BUF.NUM B1 I^j J3) (BUF.NUM B1 I^j J4)
END FOR
OUT no
Assign vector graphics output stream
• GRA [T] [*|filespec] or GRA Yes|No
– T Screen display
and/or
– * Last used GRA filespec (default : filename.PLT)
– filespec Designated file (default extender : .PLT)
– Yes Restores vector graphics to previously defined output
stream
– No Turns off vector graphics
141/192
Plot
GRA T image_height
UGR
tit ^title ; XLA 'Image height (mm)‘; YLA 'Aberration‘ ; XAX -0.02; YAX 0; XMI 0; XMA ^max; YMI -0.02; YMA ^yma
XDE GRD ^xde ; YDE GRD 0.01 ; XFO F 2 ; YFO F 2
DPO 'SA'
LIN 1 RED
^j==0
FOR ^i 0 ^max ^yri
^j==^j+1 ; ^i (BUF.NUM B1 I^j J1)
END FOR
END
DPO 'COMA'
LIN 1 GRE
^j==0
FOR ^i 0 ^max ^yri
^j==^j+1 ; ^i (BUF.NUM B1 I^j J2)
END FOR
END
DPO 'AS'
LIN 1 BLU
^j==0
FOR ^i 0 ^max ^yri
^j==^j+1; ^i (BUF.NUM B1 I^j J3)
END FOR
END
DPO 'WFErms'
LIN 1 BLA
^j==0
FOR ^i 0 ^max ^yri
^j==^j+1; ^i (BUF.NUM B1 I^j J4)
END FOR
END
GO ; OUT yes ; GRA T;out T
142/192
16:12:26
YIM 10-Mar-12
Image Height VS Aberration : EXS
Image height (mm)
Aberration
0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10
-0.02
-0.01
0.00
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.10
0.11
0.12
0.13
0.14
0.15
0.16
0.17
0.18
0.19
0.20
SA
COMA
AS
WFErms
Workshop
• Task : Modeling DVD objective lens
• Specification
– Purpose : Objective lens for DVD Player
– Wavelength : 650nm
– Focal length : 3.05mm
– Numerical aperture : 0.6
– Magnification : 0
– Working distance : 1.67mm
– Lens thickness : 1.78mm
– Cover glass : 0.6mm (Polycarbonate)
– Material : APEL (5514ML)
– Surface Type
- 1st Surface : Aspheric surface
- 2nd Surface : Aspheric surface
– Design temperature : 25C
– Image height : 0.1mm
143/192
Layout for design
• Use EPD instead of NA(or NAO)
– EPD(Entrance pupil diameter)=2 X f X NA =3.66
LEN NEW
EPD 3.66
WL 650
YIM 0 0.07 0.1
144/192
18:09:21
New lens from CVMACRO:cvnewlens.seq Scale: 33.00 YIM 26-Feb-12
0.76 MM
Cover glass t0.6(Polycarbonate)
EPD 3.66
Lens t1.78(APEL)
Material data
• IN CV_MACRO:PLASTICPRV
– Polycarbonate
– APEL
145/192
Surface data
• Now surface pointer is at the stop surface
INS S2..6 ! Insert surfaces s2..6
CIR S1 (3.66/2) ! User defined aperture
S2 2 1.78 'A5514_25‘ ! RDY 2 for initial value
S3 -7 0.02 ! RDY -7 for initial value
! Distance from lens vertex to flange
S4 0 1.67
S5 0 0.6 'P-CARBO' ! Cover glass
PIM ! Solver for first order layout
TOW;VIE;GO ! Drawing lens
146/192
First order data
CODE V> FIR
INFINITE CONJUGATES
EFL 4.1373 Target : 3.05mm
BFL 1.2053
FFL -3.7677
FNO 1.1304
CODE V> IND
REFRACTIVE INDICES
GLASS CODE 650.00
'A5514_25' 1.541433
'P-CARBO' 1.580296
147/192
EFL optimization
ASP S2; ASP S3 ! Make S1 and S2 aspheric
S2 ! Move surface pointer to S2
CCY 0; KC 0; AC 0; BC 0; CC 0; DC 0 ! Make variables
S3 ! Move surface pointer to S3
CCY 0; KC 0; AC 0; BC 0; CC 0; DC 0 ! Make variables
SUR S2..3 F
AUT; EFL=3.05;imd=0; GO
148/192
0
0
1st result
• WAV;GO
– The RMS wavefront is good in general, but its image-height performance isn’t fit for optical storage
149/192
18:09:21
New lens from CVMACRO:cvnewlens.seq Scale: 33.00 YIM 26-Feb-12
0.76 MM
16:39:22
YIM 10-Mar-12
Image Height VS Aberration : EXS
Image height (mm)
Aberration
0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10
-0.02
-0.01
0.00
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.10
0.11
0.12
0.13
0.14
0.15
0.16
0.17
0.18
0.19
0.20
SA
COMA
AS
WFErms
Image-height performance
150/192
COMA is too large (green line)
SA is too large (red line)
2nd optimization
• WTF 20 2 1
• AUT; EFL=3.05; IMD=0; IMP 0.00001; MXC 500; GO
• WAV; GO
• SUR S2..3
151/192
16:33:17
YIM 10-Mar-12
Image Height VS Aberration : EXS
Image height (mm)
Aberration
0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10
-0.02
-0.01
0.00
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.10
0.11
0.12
0.13
0.14
0.15
0.16
0.17
0.18
0.19
0.20
SA
COMA
AS
WFErms
Image-height performance
152/192
COMA isn’t large (green line)
SA is 0 (red line)
Section 11
Interferogram
153/192
Definition
• An interferogram is the interference pattern formed by the combination of two coherent optical beams
– They are usually created in an instrument called an interferometer
• Interferograms are widely used in optical testing
– They can be a measure of the surface figure of an individual surface
– They can be a measure of the wavefront quality of a complete optical system
154/192
Schematic of an interferometer
155/192
Interferograms and aberrations
• Wavefront interferograms of a system can provide aberration information
• Individual aberrations (as well as tilt and defocus) have characteristic patterns
– Real interferograms include mixes of aberrations, tilt, focus, etc.
• Examples of some classical aberrations (contour and isometirc plots)
156/192
Interferograms in CODE V
• An interferogram in CODE V is a representation of a wavefront, a surface deformation, or an apodization profile – These representations can be of actual measured data (e.g., from an
interferometer) or of calculated or simulated data
• Interferograms are stored as .INT files in a special file format – Interferogram data must be in a text file with the extender .INT
– The data are defined as a set of (x,y) grid points, radial grid points, Zernike polynomial coefficients, or computed via a user-defined function
– The files are attached to surfaces or pupils to model various effects • Pupil interferograms can be defined for individual fields
• Multiple .INT files are allowed on any surface or pupil – If more than one, they must each have labels to distinguish them
– Effect of deformation is additive
– Effect of apodization (filters) is multiplicative
157/192
Interferograms in CODE V
• In addition to modeling interferograms, the .INT file format is also used to input or output many other types of 2D data in various options, such as:
– Source spatial and angular distribution in LUM option
– Source distribution in PAR and BPR options
– Modeling non-uniform stress birefringence (BIR/CAO)
– Modeling coating thickness variations (THV)
– Output from PSF option, etc.
– Simulating apertures
– The above uses utilize the .INT file format, even though the data are not really interferograms
• Up to 50 .INT files allowed per system
158/192
Effect of interferometric data
• Does not affect first-order (paraxial) ray tracing
• Does affect calculations and options which use real ray tracing
– OPD : Adds OPD directly to ray based on the INT data value at intersection point
– Ray slope : Changes the ray angle in proportion to the local slope of the interferogram at the intersection point
159/192
Types of interferograms in CODE V
• There are three main types of interferogram files used in CODE V, each with a specific application
• SUR (surface deformation) – Can only be attached to a real refracting or reflecting surface
– Used to model a deformed surface; deviations are measured along surface normal
– In ray trace, alters OPD and ray direction
– Example of use: Predicting performance of “as-built” systems
• WFR (wavefront interferogram) – Adds OPD error in the ray trace
– Can be attached to a real or dummy surface, or to a pupil
– In ray trace, alters OPD and ray direction
– Example of use: Computer-aided alignment of optical systems (ALI)
• FIL (transmission filter) – Used to introduce apodization (non-uniform intensity) over the pupil
– Can be attached to a real or dummy surface or to a pupil
– Does not alter ray directions
– Affects ray intensities only
– Example of use: Introduction of user-defined or non-Gaussian apodization
160/192
Where do .INT files come from?
• .INT data can be obtained from various sources :
– Data export from various commercial interferometers
– Output from CODE V options
• PMA, PSF, LUM
– Manually generated patterns created with a text editor or math software
• ASCII text format allows user to generate arbitrary simulation data
• Good for “user-created” interferogram patterns
161/192
.INT file format
• Begin file with any number (zero is OK) of comment lines starting with !
• First line is a title line of up to 80 characters (can’t be blank)
• Second line has several codes to define the form and function of the interferogram and scale the data – Type of .INT file data and grid size or number of terms (no default)
• GRD n m ! rectangular grid of n columns and m rows • GRD n R ! rotational grid of n radial data points • ZRN n ! standard (Born & Wolf) Zernike of n terms • ZFR n ! FRINGE Zernike of n terms • UDI n ! user-defined function with n parameters
– Type of .INT file (no default): WFR, SUR, FIL, THV, BIR/CAO • WVL value ! wavelength in microns (WFR or SUR) (no default) • SSZ value ! scale size (no default) • NDA value ! code number indicating missing data (default 32767) • XSC value ! x scale factor (default 1.0) • NNB ! use nearest neighbor interpolation if GRD format (default: linear interpolation)
• Subsequent lines in the file contain the data in free format
162/192
Grid type .INT files
• Total number of data items in the file must equal (or be greater than) the product of the GRD values (any extra values are ignored)
• Values are entered in integers in the range -32768 to +32767
– For WFR interferograms, each value corresponds to an amount of OPD in waves equal to value/SSZ at the WVL wavelength
• For different wavelengths, the OPD is scaled by the wavelength ratio
– For SUR interferograms, each value corresponds to a surface deformation equal to (value/SSZ)*WVL in microns
• Note that positive data are always outward bumps, regardless of which side of the lens the interferogram is attached to
– For FIL interferograms, each value corresponds to a transmission equal to value/SSZ
– To get more resolution in the .INT file data, increase the SSZ
163/192
Grid .INT file example
164/192
Rectangular grid size 11 by 11
Comment
Title
Measurement wavelength(microns) Scale 1000=1wave deformation
“No data” -32767 blocks rays
Data Deformation at individual grid points
Header
Surface deformation
Grid type .INT files (cont.)
• Grid data are read in from –x to +x (left to right) starting at +y(top)
• Rectangular grid interferograms are assumed to cover a square area – IF the number of rows and columns are unequal, then this
corresponds to unequal sampling across the square
GRD 6 3
– To force coverage of a rectangle, the XSC value in the INT file header must be set to be non-unity
GRD 6 3 XSC 2.5
• Rotational grid data start at the center and go out to the edge
• A grid point with the NDA value blocks rays at that point
165/192
Zernike type .INT files
• In CODE V, the coefficient associated with each Zernike polynomial term is stored in the .INT file in the appropriate order
• The number of data items in the file must equal or exceed the number of terms specified with ZRN or ZFR (any extra terms are ignored)
• The coefficients are entered in floating point or exponential form (decimal points are optional)
• The SSZ value is required, but is usually set to 1.0
• For ZRN data, it is usually best to have the number of terms complete a full order
– For example, 1, 3, 6, 10, 15, 21, 28, etc.
166/192
Zernike .INT file example
167/192
Measurement data
ZFR 9 SSZ 1.0 WFR WVL 0.650
0.4171 ! Z1 piston
-1.1823 ! Z2 tilt x
-0.0398 ! Z3 tilt y
0.0139 ! Z4 power
-0.0511 ! Z5 astigmatism x
0.0183 ! Z6 astigmatism y
0.0189 ! Z7 coma x
-0.0077 ! Z8 coma y
-0.0007 ! Z9 spherical
Title
Fringe Zernike With 9 terms
Unity scaling for coefficients Wavefront
aberration
Measurement wavelength (microns)
User-defined type .INT files
• You first must write and compile a subroutine called USERINT
• The USERINT subroutine computes the value and derivatives of the interferogram at a point x,y [i.e., defined as f(x,y)]
– The value can also be a function of the direction cosines l,m,n and/or the cosine of the angle of incidence(cos_I) of the last ray traced [e.g.,f(x,y,l,m,n,cos_I)]
• You can pass as many parameters as you wish between the interferogram file and the USERINT function
– The number of parameters is the number n used in the .INT file definition
• You can also pass the name of the user-defined subroutine(allows for multiple USERINT routines in the same lens) and an external data file that can be passed to the subroutine
168/192
User-defined .INT file example
• Default USERINT : Gaussian with one parameter, the standard deviation σ
f(x,y)=expf[(x2+y2)/2σ2]
Sample .INT file for σ=1.25
Sample UDI file
UDI 1 FIL SSZ 1.0
1.25 ! Data
169/192
Title
Fringe Zernike With 9 terms
Filter(apodization) data
Unity scaling
Displaying .INT files
• INT data can be displayed using Display>View Interferogram
– Only one plot is displayed per run
170/192
FAB ; DIS filename|Si|ENP|EXP; (RAN COL RGB [r_val g_val b_val]); GO
FAB ; CON filename|Si|ENP|EXP; GO
Saved .INT file displayed
.INT file applied to surface or pupil displayed, including operation specifications
Attaching interferograms to a surface or pupil
• Lens > Surface Properties, select Interferogram to attach to a surface
• Lens > System Data, select Pupil Apodization for pupils
171/192
Interferogram controls
• Scaling (ISF) provides a convenient scale factor separate from the SSZ specified in the interferogram file – Scale 0.5 for wavefront data measured in a double-pass test
– Scale -1 to flip the deformation from “bump” to “dent” or vice versa
• Mirror allows reorientation of data, moving data from the +x coordinate to the –x coordinate (or from +y to –y coordinate)
(IMI XC|YC)
• Rotation angle allows the INT data to be rotated about the center of the grid (IRO)
• X decenter and Y decenter specify the X and Y coordinates where the center of the INT data with this label is placed (in lens units) (INX, INY)
172/192
CODE V commands for .INT files
INT Sk [L”abc”] file ! attach interferogram to a surface INT ENP | EXP [Fk] file ! attach interferogram to a pupil INR ! specify y dimension of interferogram (default is maximum aperture) ISF ! interferogram scale factor (default 1.0) INX, INY ! center of interferogram relative to surface (default 0) IRO ! rotation of interferogram relative to surface (default 0) IMI XC | YC ! mirror image around x or y axis (default not done) DEL INT Sk ! delete interferogram from surface DEL INT ENP | EXP [Fk] ! delete interferogram from pupil
• Examples (assumes .INT file extenders) int s2 test3 int s5 L”in1” test5 int enp f2 test2
173/192
Interferogram radius
• The size of the interferogram is specified by the radius value(INR)
– The default interferogram radius values is the maximum aperture value returned by the macro database item (MAP Sk)
– MAP (blue arrow) has these values for the indicated aperture shapes:
174/192
Shape MAP = default INR
Circle Radius (CIR)
Rectangle Semi-diagonal = sqrt(REX**2+REY**2)
Ellipse Maximum radius = max(ELX, ELY)
Sizing the interferogram radius
• To size the interferogram differently, specify the desired radius – The radius value corresponds to the Y semi-dimension of the
interferogram
– The X semi-dimension is INR*XSC
• If you want a rectangular grid interferogram to cover a rectangular aperture, you must have
REX=XSC*INR
REY=INR
• For a rectangular grid interferogram to cover an elliptical aperture, need
ELX=XSC*INR
ELY=INR
• For Zernike interferograms, the radius value corresponds to the normalizing radius (the unit circle)
175/192
Generating interferograms with PMA
• The pupil map option (PMA) generates OPD maps of the optical system
– These OPD maps can be displayed as interferograms using controls on Color Display page
– Commands :
DIS INT
RAN COL RGB [r_value g_value b_value]
176/192
Adjusting wavefront in PMA interferograms
• Use Wavefront Adjustment on Computation page to simulate adding tilt or focus in an interferometer to make the fringes more visible
– Command is ADW (add wavefront)
177/192
Saving OPD maps as .INT files
• You can write OPD maps as .INT files using the Output Controls and Zernike Coefficients tabs
– A separate version of the file is saved for each field, wavelength and zoom position (WIN filename)
– Format options :
• No fit : square grid of size (FFT grid size -1 = TGR-1) is written
• Standard or Fringe Zernikes can be specified with number of terms and normalization radius
– Default : fit is done at entrance pupil plane; can specify exit pupil plane(EXP) or exit pupil sphere (EXS) instead
ZRN [EXP|EXS] num_terms [norm_radius]
ZFR [EXP|EXS} num_terms [norm_radius]
178/192
Example outputs from PMA
179/192
10:24:57 YIM 10-Mar-12
POSITION 1
WAVE ABERRATION
Cooke Triplet f/4.5 WAVELENGTH: 546.10 NM
FLD( 0.00, 1.00)MAX, ( 0.0,20.0)DEG
DEFOCUSING: 0.000000 MM
CONTOUR INTERVAL: 0.25 WAVES
MIN/MAX: 0.00 / 2.81
25
5075
100
125
150175
200
225
250
275
10:24:58
Cooke Triplet f/4.5
POSITION 1
YIM 10-Mar-12
5 Waves
WAVE ABERRATION
FIELD ANGLE - Y: 20.00 DEGREES X: 0.00 DEGREES
DEFOCUSING: 0.000000 MM
WAVELENGTH: 486.10 NM
HORIZONTAL WIDTH REPRESENTS GRID SIZE 128 X 128
Section 12
Active aberration compensator
180/192
Active compensator using liquid crystal
181/192
Optical Application of Liquid Crystals, Series in Optics and Optoelectronics, IOP publishing, 2003
Layout
• Liquid crystal can make phase difference with proper patterns to compensate system aberrations, Spherical aberration, Coma and Astigmatism
182/192
Liquid crystal device 17:50:53
New lens from CVMACRO:cvnewlens.seq Scale: 33.00 YIM 10-Mar-12
0.76 MM
Objective lens
Disc
Attach .INT file
Coma pattern
• When the disc alpha tilt is 1 deg., the z8 is -0.2803
183/192
Waves
-0.303
0.2630
-.0202
WAVEFRONT ABERRATION
New lens from CVMACRO:cvnewlens.seq
Field = ( 0.000, 0.000) DegreesWavelength = 650.0 nmDefocusing = 0.000000 mm
20:18:07 YIM 10-Mar-12
POSITION 1
WAVE ABERRATION
New lens from CVMACR
O:cvnewlens.seq
WAVELENGTH: 650.00 NM
FLD( 0.00, 0.00)MAX, ( 0.0, 0.0)DEG
DEFOCUSING: 0.000000 MM
CONTOUR INTERVAL: 0.05 WAVES
MIN/MAX: -0.30 / 0.26
-25
-20
-15
-10
-5
0
5
10
15
20
25
LC pattern for Coma-Y
• If LC electrode is limited by 3(level 3), we can make 3 different phase areas
• How to define the area is not clear, but practically R ~ 0.26 is best
184/192
-1.5
-1
-0.5
0
0.5
1
1.5
-1.5 -1 -0.5 0 0.5 1 1.5
3R3-2R @θ=90°
Dialog box
!**************************************************************************
! arg0 "Macro to make the compensation pattern for coma"
!
! arg1 name "Level 1"
! arg1 type num
! arg1 default 0.26
! arg1 help "Interval"
!
! arg2 name " File Name"
! arg2 type str
! arg2 default "ComaPattern"
! arg2 help "Make *.int and *.dat file"
!
!**************************************************************************
185/192
Variables
gbl num ^OPD(1000,1000)
buf len 100000
buf del b4
^real_XY == 3.66 !EPD
^size_array == 256
^dxy == ^real_xy/^size_array ! Increment in x,y
^center==^size_array/2
^int == concat(#2,".int") ! INT file name for CODEV
^dat== concat(#2,".dat") ! Data file name for EXCEL
186/192
Making coma pattern
out no
for ^i 1 ^size_array
^y==-^dxy*(^i-1-^center)
for ^j 1 ^size_array
^x==^dxy*(^j-1-^center)
^q==3*^y**3+3*^y*^x**2-2*^y ! Coma Y
if (^q < -#1) ! Area -1
^OPD(^i,^j)== -1
els if (^q >=#1) ! Area 1
^OPD(^i,^j)== 1
els ! Area 0
^OPD(^i,^j)== 0
end if
buf put b4 i^i+2 j^j ^OPD(^i,^j)
end for
end for
187/192
Making .INT and .DAT files
out t
buf put b4 i1 j1 "COMA PATTERN" ! INT Header
buf put b4 i2 j1 "GRD" ! INT Header
buf put b4 i2 j2 ^size_array ! INT Header
buf put b4 i2 j3 ^size_array ! INT Header
buf put b4 i2 j4 "WFR WVL 0.650 SSZ 1" ! INT Header
buf exp b4 sep ^int ! Make INT File
buf exp b4 sep ^dat ! Make Data File
188/192
3 pole coma pattern
189/192
Waves
-1.000
1.0000
0.0000
WAVEFRONT DEFORMATION
COMA PATTERN
Wavelength = 650.0 nm
Attach ComaPattern.int
RDY THI RMD GLA
OBJ: INFINITY INFINITY
1: INFINITY 0.300000 BK7_SCHOTT
> 2: INFINITY 0.300000 BK7_SCHOTT
INT:E:\CVUSER\ComaPattern.int
COMA PATTERN
RMS = 0.738 P-V = 2.00 COVERAGE: 1.00
ISF: 1.000000 IMI: NO
INR: 1.830000
3: INFINITY 1.000000
STO: INFINITY 0.000000
5: 1.94523 1.780000 'A5514_25'
ASP:
K : -0.669978
CUF: 0.000000
A :0.527600E-02 B :-.404795E-03 C :0.191057E-03 D :-.373578E-04
6: -7.41796 0.020000
ASP:
K : -84.089204
CUF: 0.000000
A :0.375431E-02 B :-.103522E-02 C :0.238059E-04 D :0.114952E-04
7: INFINITY 1.670000
8: INFINITY 0.000000
9: INFINITY 0.600000 'P-CARBO'
XDE: 0.000000 YDE: 0.000000 ZDE: 0.000000
ADE: 1.000000 BDE: 0.000000 CDE: 0.000000
10: INFINITY 0.000000
11: INFINITY 0.000000
RET S8
12: INFINITY 0.600000
IMG: INFINITY 0.000000
190/192
Adjust ISF to make the aberration minimum
Coma compensation
• At ISF = 0.15, RMS aberration is minimized from 0.1 to 0.043
191/192
20:34:06 YIM 10-Mar-12
POSITION 1
WAVE ABERRATION
New lens from CVMACR
O:cvnewlens.seq
WAVELENGTH: 650.00 NM
FLD( 0.00, 0.00)MAX, ( 0.0, 0.0)DEG
DEFOCUSING: 0.000000 MM
CONTOUR INTERVAL: 0.02 WAVES
MIN/MAX: -0.13 / 0.11
-11
-9
-6
-4
-2
0
2
4
7
9
20:36:07 YIM 10-Mar-12
POSITION 1
WAVE ABERRATION
New lens from CVMACR
O:cvnewlens.seq
WAVELENGTH: 650.00 NM
FLD( 0.00, 0.00)MAX, ( 0.0, 0.0)DEG
DEFOCUSING: 0.000000 MM
CONTOUR INTERVAL: 0.05 WAVES
MIN/MAX: -0.30 / 0.26
-25
-20
-15
-10
-5
0
5
10
15
20
25
MIN/MAX : -0.30/0.26 MIN/MAX : -0.13/0.11
LC patterns
192/192
Waves
-2.000
2.0000
0.0000
WAVEFRONT ABERRATION
COMA PATTERN
Wavelength = 408.0 nm
Waves
-1.000
1.0000
0.0000
WAVEFRONT ABERRATION
COMA PATTERN
Wavelength = 408.0 nm
Waves
-3.000
3.0000
.00001
WAVEFRONT ABERRATION
COMA PATTERN
Wavelength = 408.0 nm
3 Pole 5 Pole 7 Pole