/* Java applet reflPW.java calculates the plane-wave optical reflectance of a multi-layer stack. Modified 01/03/2001 to properly handle thread stop signalling by M. I. Gallant Copyright 01/03/2001 */ import java.awt.*; public class reflPW extends java.applet.Applet implements Runnable { private volatile Thread runner; //to allow efficient interruption Image offIm; Graphics offGr; boolean initFinished = false; String modeType = "TE" ; int wApp, hApp, hPlot, dataHeight, pixGap; int nReg, nVary, pts; double lam, k0, deg, theta, tmin, tmax, tt, xOld, xPlot, yOld, yPlot, deltaThick; double plotYmin, plotYmax; // plot range. double[] thick; double scaleX, scaleY, reflectance; // scale factors for plotting. double[] RR; // reflectance array. Color appBgnd; cNum refl, r12, r23; cNum[] index, kx; Label[] lThick; TextField[] tIndexR, tIndexI, tThick; TextField tLam, tDeg, tReflect, tNvary; TextField tTmin, tTmax; TextField tYmin, tYmax; public void init() { /* set initial default parameters */ nReg = 5; pts = 201; // # of data points to compute/plot. RR = new double[pts] ; kx = new cNum[nReg] ; lam = 1.30 ; k0 = 2.0*Math.PI/lam ; deg = 5.0; nVary = 1; tmin = 0.0; // plot range in um. tmax = 0.25; plotYmin = 0.0; // reflectance plot range. plotYmax = 1.0; reflectance = 0.55; deltaThick = (tmax-tmin)/(pts-1) ; theta = (Math.PI)/180*deg; // angle in radians. dataHeight = 300; pixGap = 5; //pixel gap for grid plot. appBgnd = getBackground(); wApp = this.size().width; hApp = this.size().height; hPlot = hApp - dataHeight; offIm = createImage(wApp, hPlot); // create buffer for backgnd image. offGr = offIm.getGraphics(); setLayout(new GridLayout(nReg+4, 4, 2,2) ); guiSetup(); createGrid() ; validate(); } public Insets insets() { return new Insets(hPlot+2,2,2,10); } public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } public void stop() { runner = null ; } public void pause(int time) { try { Thread.sleep(time);} // wait for time milliseconds. catch (InterruptedException e) { } } /* ------------- Main Calculation Loop Thread------------------------ */ public void run() { //displayData(); Thread thisthread = Thread.currentThread() ; double ksint = k0*Math.sin(theta); cNum ni0 = new cNum(ksint*ksint*(index[0].re)*(index[0].re) , 0) ; cNum[] kxRat = new cNum[nReg-1] ; for (int i=0; i < nReg; i++) { cNum nik0; nik0 = cMath.rcMul(k0, index[i]); kx[i] = cMath.cSqrt(cMath.cSub(cMath.cMul(nik0,nik0) , ni0)) ; } for (int i=0; i 0; lay--) { //Rouard's method iteration. cNum cpart, denom, num, phase; cNum cUnit = new cNum(1.0, 0) ; if (modeType.equals("TE")) r12 = cMath.cDiv(cMath.cSub(kx[lay-1], kx[lay]), cMath.cAdd(kx[lay-1], kx[lay])); //s-pol else r12 = cMath.cDiv(cMath.cSub(kx[lay-1], kxRat[lay-1]), cMath.cAdd(kx[lay-1], kxRat[lay-1])); //p-pol phase = (cMath.cMul(cMath.rcMul(2*thick[lay],cMath.ima), kx[lay])).neg() ; cpart = cMath.cMul(r23, cMath.cExp(phase)) ; num = cMath.cAdd(r12, cpart) ; denom = cMath.cAdd(cUnit, cMath.cMul(r12, cpart)) ; refl = cMath.cDiv(num, denom); r23 = refl ; //iterate. } RR[j] = refl.magsq(); if (runner != thisthread) // check for signal to stop this thread. return ; } initFinished = true; repaint(); } /*--------------------------------------------------------------- */ public void update(Graphics g) { if (!initFinished) return ; g.clipRect(0,0,wApp, hPlot) ; scaleX = wApp/(tmax-tmin); scaleY = hPlot/(plotYmax-plotYmin); g.drawImage(offIm,0,0,this) ; // draw the grid. g.setColor(Color.black); for (int i=0; i < pts ; i++ ) { tt = tmin + i*deltaThick ; xPlot =scaleX*(tt-tmin); reflectance = RR[i]; yPlot =hPlot - scaleY*(reflectance-plotYmin) ; if(i==0) { xOld=xPlot; yOld=yPlot; } if(yPlot>0 && yPlot0; j-=pixGap) offGr.drawLine(x,j,x,j); // dot grid. } for (int y=0; y<=hPlot; y+=hPlot/10 ) { offGr.drawLine(0, y, 7, y); for (int j=8; j0 && i