! demo2.zpl
!
input "Enter pupil increment:", step
if ((step <= 0) | (step >= 1.0))
	PRINT "Error: invalid step size"
	PRINT "Should be fraction, such as .1"
	GOTO 1
endif

nw = nwav()
if (nw == 1)
	Print "There is only one wavelength defined!"
	goto 1
else
	minwav = 1
	maxwav = 1
	for i = 2, nw, 1
		if (wavl(minwav) > wavl(i)) THEN minwav = i
		if (wavl(maxwav) < wavl(i)) THEN maxwav = i
	next
endif
! minwavnum and maxwavnum contain the min and max wavelength values

print "Minimum wavelength = ", wavl(minwav), " microns"
print "Maximum wavelength = ", wavl(maxwav), " microns"

if (unit() == 0) THEN print "Units are mm"
if (unit() == 1) THEN print "Units are cm"
if (unit() == 2) THEN print "Units are in"
if (unit() == 3) THEN print "Units are meters"

numsteps = 1/step

FOR i = 0, numsteps, 1
	py = i * step
	if (py > 1.0) then py = 1.0

	RAYTRACE 0, 0, 0, py, minwav
	IF (RAYE())
		Print "Ray error occured.."
		goto 1
	ENDIF
	yf = RAYY(NSUR())

	RAYTRACE 0, 0, 0, py, maxwav
	IF (RAYE())
		Print "Ray error occured.."
		goto 1
	ENDIF
	yc = RAYY(NSUR())

	Print "Pupil zone = ", py, " ZTCA = ", yf - yc
NEXT

label 1
