! centroid.zpl
!
! Written by Kenneth Moore 9/1/92
! Added TIMER function 4/18/96
!
TIMER
!
! The delta controls how many rays will be traced. A
! delta of .025 will trace a 80 x 80 grid in the pupil.
!
delta = .025
!
print "This program computes the chief ray coordinates,"
print "centroid coordinates, and middle coordinates for" 
print "the primary wave spot at each field position."
maxfield = maxf()
if maxfield == 0 then maxfield = 1
n = nsur()
f = 1
label 1
hx = fldx(f)/maxfield
hy = fldy(f)/maxfield
raytrace hx,hy,0,0
format 10.4
print
print "  X Field    = ", fldx(f),
print "  Y Field    = ", fldy(f)
print "  X Chief    = ",rayx(n),
print "  Y Chief    = ",rayy(n)
xraymax = -9e9
yraymax = -9e9
xraymin =  9e9
yraymin =  9e9
xraytot = 0
yraytot = 0
numray = 0
numrayattempt = 0
px = -1 - delta
label 2
px = px + delta
py = -1 - delta
label 3
py = py + delta
rad = px*px + py*py
if rad <= 0.9999999
        raytrace hx, hy, px, py
        numrayattempt = numrayattempt+1
        if !rayv(n)
                numray = numray + 1
                x = rayx(n)
                y = rayy(n)
                if (x < xraymin) then xraymin = x
                if (x > xraymax) then xraymax = x
                if (y < yraymin) then yraymin = y
                if (y > yraymax) then yraymax = y
                xraytot = xraytot + x
                yraytot = yraytot + y
        endif
endif
if py < 1.0 then goto 3
if px < 1.0 then goto 2
if numray
        format 14.8
        print "  X Centroid = ",xraytot/numray,
        print "  Y Centroid = ",yraytot/numray
        print "  X Middle   = ",(xraymax+xraymin)/2,
        print "  Y Middle   = ",(yraymax+yraymin)/2
        format .0
        print "  ",numray, " out of ", numrayattempt," rays made it through."
else
        print "  No rays made it through!"
endif
f=f+1
if f<= nfld() then goto 1
print
print "All field positions done!"
FORMAT 0.1
print "Elapsed time ", ETIM(), " seconds."
