- Home
- Programming ZEMAX
- ZPL
- How to Use the PLOT2D keyword in ZPL
How to Use the PLOT2D keyword in ZPL
- By Sanjay Gangadhara
- Published 24 June 2008
- ZPL
- Unrated
A simple example
An example macro (PLOT2D_TEST.ZPL) illustrating use of the PLOT2D keyword is provided as a part of the ZEMAX installation (i.e. the macro is located in the directory \ZEMAX\Macros\). This macro can be run with any ZEMAX file, as it does not use any data from the lens file.
The macro begins by defining a two-dimension data array (xy_data), and then specifying values for the array according to a radially symmetric distribution:
! Set up an array to hold 2D data
nx = 100 # Number of X points
ny = 100 # Number of Y points
DECLARE xy_data, DOUBLE, 2, nx, ny # 2D array of XY
data points
! Fill the 2D array with a radially symmetric distribution
maxval = 5000.0 # Maximum value for
the array
FOR i, 1, nx, 1
FOR j, 1, ny, 1
radsqr = (i - 0.5*nx)*(i - 0.5*nx) +
(j - 0.5*ny)*(j - 0.5*ny)
xy_data(i,j) = maxval - radsqr
NEXT j
NEXT i
Settings for the various PLOT2D arguments are then provided:
! Define settings for data plot
title$ = "Plot of XY data" # Plot title
comment1$ = "This is a simple test" # Plot comment
line #1
comment2$ = "to determine if the" # Plot comment
line #2
comment3$ = "PLOT2D keyword is" # Plot comment
line #3
comment4$ = "working correctly" # Plot comment
line #4
comment5$ = "for all inputs." # Plot comment
line #5
rmin = 0.0 # Minimum plot value
rmax = maxval # Maximum plot value
ratio = 1.0 # Plot aspect ratio
winrat = 0 # Window aspect ratio
actlft = -10.0 # Active cursor
left value
actbot = -10.0 # Active cursor
bottom value
actrgt = 10.0 # Active cursor
right value
acttop = 10.0 # Active cursor
top value
distyp = 5 # Display type
cnval$ = "900.0 2700.0 3400.0" # Contour format
sscale = 0.75 # Surface scaling
factor
lgpeak = 4 # Log plot peak value
lgdecd = 4 # Log plot decade
value
lgtype = 0 # Log plot flag
addshow = 1 # Flag for whether
to show address
in plot
conshow = 0 # Flag for whether
to show config
number in plot
Settings have been provided for the plot title (title$), plot range (rmin, rmax), etc. A number of PLOT2D commands are then issued to plot the results in a graphical display window, with the corresponding title, plot range, etc.:
! Plot the data
PLOT2D NEW
PLOT2D TITLE, ti$
PLOT2D COMM1, cm1$
PLOT2D COMM2, cm2$
PLOT2D COMM3, cm3$
PLOT2D COMM4, cm4$
PLOT2D COMM5, cm5$
PLOT2D RANGE, rmin, rmax
PLOT2D ASPECT, ratio
PLOT2D WINASPECT, winrat
PLOT2D ACTIVECURSOR, actlft, actrgt, actbot, acttop
PLOT2D DISPLAYTYPE, distyp
IF (distyp == 1) THEN PLOT2D SURFACESCALE, sscale
IF (distyp == 2) THEN PLOT2D CONTOURINTERVAL, cnval$
IF (lgtype == 1)
FOR i, 1, nx, 1
FOR j, 1, ny, 1
xy_data(i,j) = LOGT(xy_data(i,j))
NEXT j
NEXT i
PLOT2D LOGPLOT, lgpeak, lgdecd
ENDIF
PLOT2D HIDEADDRESS, addshow
PLOT2D CONFIG, conshow
PLOT2D DATA, xy_data
PLOT2D GO
Comments are provided in the macro for each of the PLOT2D commands (those comments have been omitted from this article for display purposes), and a full description of each of these commands may be found in the chapter of the ZEMAX manual entitled “ZEMAX Programming Language”. For the settings provided above, the resulting graphical output is:
As you can see, the PLOT2D keyword provides the user with a simple method for generating graphical displays of 2D numeric data.