//SmithPanel.java
/** 
 * @author - Singh T. Jr, and U. Ravaioli
 * Maestro Series, Amanogawa, 1997
 */
/* Usage: SmithPanel sp = new SmithPanel(); sp.setBounds(5,5,310,469); */

import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.net.*;
import java.awt.event.*;



public class SmithPanel2 extends Panel implements MouseListener, MouseMotionListener, ItemListener{
	public SmithCanvas2 sc;
	public SmithMan2 sm; 
	private SmithProbe2 sp;
	public SmithControls2 scon;
	private static final Color bgcolor = Color.white;
	//public Checkbox large;
        public Button large;
         public Button colore;
        public boolean colore_dark;
        
        protected static final Font buttonfont = new Font("SanSerif",Font.PLAIN,11);
        
public SmithPanel2(){
	setLayout(null);
	
	large = new Button("Reduce");
	add(large);
	large.setBackground(Color.white);
	large.setBounds(7,7,50,20);
        large.setFont(buttonfont);
        
        colore = new Button("Color");
	add(colore);
	colore.setBackground(Color.white);
	colore.setBounds(514,7,50,20);
        colore.setFont(buttonfont);
        
        colore_dark = false;
	
	setBackground(bgcolor);
	sc = new SmithCanvas2();
	add(sc);
	sc.setBounds(5,5,561,561);

	sm = new SmithMan2(250,83);
	add(sm);
	sm.setBounds(6,571,250,85);

	sp = new SmithProbe2(298,37);
	add(sp);
	sp.setBounds(261,571,303,37);

	scon = new SmithControls2();
	add(scon);
	scon.setBounds(268,615,296,40);
	
	sc.addMouseListener(this);
	sc.addMouseMotionListener(this);
	scon.imp.addItemListener(this);
	scon.adm.addItemListener(this);
	scon.swr.addItemListener(this);
	scon.swrline.addItemListener(this);
	
	Panel pgraph1 = new Panel();
	    pgraph1.setBackground(Color.black);
	    add(pgraph1);
	    pgraph1.setBounds(5,570,252,87);
	    
	Panel pgraph2 = new Panel();
	    pgraph2.setBackground(Color.black);
	    add(pgraph2);
	    pgraph2.setBounds(260,570,306,40);
	
	Panel pgraph4a = new Panel();
	    pgraph4a.setBackground(new Color(236,236,221));
	    add(pgraph4a);
	    pgraph4a.setBounds(261,615,303,40);
	
	Panel pgraph4b = new Panel();
	    pgraph4b.setBackground(Color.black);
	    add(pgraph4b);
	    pgraph4b.setBounds(260,614,306,43);
	
	
}
public void paint(Graphics g){
	g.setColor(bgcolor.darker());
	g.fillRect(0,getSize().height-2,getSize().width,2);
	g.fillRect(getSize().width-2,0,2,getSize().height);
	g.setColor(bgcolor.brighter());
	g.fillRect(0,0,2,getSize().height-1);
	g.fillRect(0,0,getSize().width-2,2);
}

public  synchronized void setZin(Complex Zin){
	sc.setZin(Zin);
	sm.setZin(Zin);
}

public synchronized void setYin(Complex Yin){
	sc.setYin(Yin);
	sm.setYin(Yin);
}

public synchronized void setZin(Complex Zin, double Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public synchronized void setYin(Complex Yin, double Z0){
	setYin(Complex.Multiply(Yin,Z0));
}

public synchronized void setZin(Complex Zin, Complex Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public synchronized void setYin(Complex Yin, Complex Z0){
	setYin(Complex.Multiply(Yin,Z0));
}

public synchronized void setZL(Complex ZL){
	sc.setZL(ZL);
	sm.setZL(ZL);
}
public synchronized void setalpha(double alpha){
	sc.setalpha(alpha);
}

public synchronized void setGammaFlag(boolean IsLargerThanOne){
	sc.setGammaFlag(IsLargerThanOne);
}


public synchronized void setZL(Complex ZL, double Z0){
	setZL(Complex.Divide(ZL,Z0));
}

public synchronized void setZL(Complex ZL, Complex Z0){
	setZL(Complex.Divide(ZL,Z0));
}

public synchronized void setYL(Complex YL){
	sc.setYL(YL);
	sm.setYL(YL);
}

public synchronized void setYL(Complex YL, double Z0){
	setYL(Complex.Multiply(YL,Z0));
}

public synchronized void setYL(Complex YL, Complex Z0){
	setYL(Complex.Multiply(YL,Z0));
}

public synchronized void setColoreDark(boolean colore_dark){
        sc.setColoreDark(colore_dark);
}

public synchronized void set_swr_circle(boolean arg){
	sc.set_swr_circle(arg);
}

public synchronized void set_swr_line(boolean arg){
	sc.set_swr_line(arg);
}

public synchronized void set_impedance(boolean arg){
	sc.set_impedance(arg);
}

public synchronized void set_admittance(boolean arg){
	sc.set_admittance(arg);
}

public synchronized void setZL(boolean arg){
	sc.setZL(arg);
}

public synchronized void setZin(boolean arg){
	sc.setZin(arg);	
}

public synchronized void setYin(boolean arg){
	sc.setYin(arg);
}

public synchronized void setxpos(double xpos){
	sc.setxpos(xpos);
	sp.setxpos(xpos);
	sp.setmode(1);
}

public void mouseDragged(MouseEvent evt){cricket_1();}
public void mouseMoved(MouseEvent evt){;}
public void mouseClicked(MouseEvent evt){cricket_1();}
public void mouseEntered(MouseEvent evt){;}
public void mouseExited(MouseEvent evt){;}
public void mousePressed(MouseEvent evt){cricket_1();}
public void mouseReleased(MouseEvent evt){cricket_1();}
public void itemStateChanged(ItemEvent evt){cricket_2(evt);}

private void cricket_1(){
    String str1, str2;
    
	if(Complex.Imaginary(sc.getZProbe()) > 1.0E200){str1="z =  \u221e     "+"       y = 0.0 + j 0.0";}
	else if(Complex.Imaginary(sc.getYProbe()) > 1.0E200){str1="z =  0.0 + j 0.0         y =  \u221e     ";}
	else{
	    str1="z = "+sc.getZProbe().toString(Complex.CARTESIAN,5)+
		"       y = "+Complex.Divide(1.0,sc.getZProbe()).toString(Complex.CARTESIAN,5);
	}
	str2="\u0393 = "+sc.getGammaProbe().toString(Complex.POLAR_DEGREE,5);
	sp.setmode(2);
	sp.set(str1,str2);
	 
}

private void cricket_2(ItemEvent evt){
    if(evt.getSource()==scon.imp){
			sc.set_impedance(scon.imp.getState());
			sm.setMode(1);
			sm.setZL(sc.getZL());
			sm.setZin(sc.getZin());
    }
    else if(evt.getSource()==scon.adm){
			sc.set_admittance(scon.adm.getState());
			sm.setMode(2);
			sm.setZL(sc.getZL());
			sm.setYin(sc.getYin());
    }
    else if(evt.getSource()==scon.swr){
			sc.set_swr_circle(scon.swr.getState());
    }
    else if(evt.getSource()==scon.swrline){
			sc.set_swr_line(scon.swrline.getState());
    }
    sc.repaint();
    sm.repaint();
}

}//End of SmithPanel


/****************************************************************************************/

class SmithCanvas2 extends Canvas implements MouseListener, MouseMotionListener{
//private final Color bgcolor = new Color(216,216,191);
private final Color bgcolor = new Color(236,236,236);

private int xCenter, yCenter, yCenter2, yCenter3;
private int Radius1, Diam1, Radius2, Diam2, Radius3, Diam3, Radius4;
private int width, height;
public boolean draw_impedance_chart;
public boolean draw_admittance_chart;
public boolean draw_swr_circle;
public boolean draw_swr_line;
private boolean draw_arcs;
private boolean draw_vline;
private boolean draw_ZL, draw_Zin, draw_Yin;
private Complex Zin, Yin, ZL, YL;
private Complex GammaZin, GammaYin, GammaZL;
private double xpos, Z0, alpha;
private Complex GammaProbe, ZProbe, YProbe; 
private int xProbe, yProbe;
private static final Cursor cursorA = new Cursor(Cursor.DEFAULT_CURSOR);
private static final Cursor cursorB = new Cursor(Cursor.CROSSHAIR_CURSOR);
private Image im;
private Graphics buf;
private boolean IsLargerThanOne;
private boolean colore_dark;

public SmithCanvas2(){
	super();
	setBackground(Color.white); 
	draw_impedance_chart=true;
	draw_admittance_chart=false;
	draw_swr_circle=true;
	draw_swr_line=true;
	draw_ZL=true;
	draw_Zin=true;
	draw_Yin=true;
	draw_arcs=true;
	draw_vline=true;
	xpos = 0.0;
	Z0 = 1.0;
	alpha = 0.0;
	ZL = new Complex(1.0,1.0);
	//ZL = state.ZL;
	YL = EMF.Inv(ZL);
	GammaZL = EMF.computeGamma(ZL);
	Zin = new Complex(0.0,0.0);
	GammaZin = EMF.computeGamma(Zin);
	Yin = EMF.Inv(Zin);
	GammaYin = EMF.computeGamma(Yin);
	ZProbe = new Complex();
	YProbe = new Complex();
	GammaProbe = new Complex();
	xProbe=0;
	yProbe=0;
	
	IsLargerThanOne = false;
        colore_dark = false;
	
	this.addMouseListener(this);
	this.addMouseMotionListener(this);
}

public void paint(Graphics g){
	

	//drawSmith(g);
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawSmith(buf);
	    }
	    else{
		drawSmith(buf);
	    }
	    g.drawImage(im,0,0,null);
}


//Addition to reduce flicker new routine
public void update(Graphics g){		// added to avoid clearing
	paint(g);
}


public void clear(){
	this.getGraphics().clearRect(0,0,getSize().width,getSize().height);
	repaint();
}

public void drawSmith(Graphics g){
    Graphics2D g2d = (Graphics2D)g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);


	Font labfont1 = new Font("SanSerif",Font.BOLD,11);

	int i, Ncurves1, Ncurves2;
	double rl[], xl[];
	
	if(IsLargerThanOne){
	    Ncurves1 = 14;
	    Ncurves2 = 9;
	    rl= new double[Ncurves1];
	    xl= new double[Ncurves2];
	    
	    rl[0]=-4.0; rl[1]=-2.0; rl[2]=-1.5; rl[3]=-0.999; rl[4]=-0.8; rl[5]=-0.6; rl[6]=-0.4;
	    rl[7]=-0.2; rl[8]=0.0; rl[9]=0.2; rl[10]=0.5; rl[11]=1.0; rl[12]=2.0; rl[13]=4.0;
	    
	    xl[0]=0.0; xl[1]=0.2; xl[2]=0.4; xl[3]=0.6; xl[4]=0.8; xl[5]=1.0; xl[6]=1.5; xl[7]=2.0; xl[8]=4.0;
	}
	else{
	    Ncurves1 = 17;
	    Ncurves2 = 17;
	    rl= new double[Ncurves1];
	    xl= new double[Ncurves2];
	    
	    rl[0]= 0.0; rl[1]= 0.2; rl[2]= 0.4; rl[3]= 0.6; rl[4]= 0.8; rl[5]= 1.0; rl[6]= 1.2; rl[7]= 1.4; rl[8]= 1.6; rl[9]= 1.8; rl[10]= 2.0;
	    rl[11]= 3.0; rl[12]= 4.0; rl[13]= 5.0; rl[14]= 10.0; rl[15]= 20.0; rl[16]= 50.0;
	    xl[0]= 0.0; xl[1]= 0.2; xl[2]= 0.4; xl[3]= 0.6; xl[4]= 0.8; xl[5]= 1.0; xl[6]= 1.2; xl[7]= 1.4; xl[8]= 1.6; xl[9]= 1.8; xl[10]= 2.0;
	    xl[11]= 3.0; xl[12]= 4.0; xl[13]= 5.0; xl[14]= 10.0; xl[15]= 20.0; xl[16]= 50.0;
	    
	}
	
	width=getSize().width;
	height=getSize().height;

	xCenter = width/2;
	yCenter = height/2;
	yCenter2 = yCenter - (int)(width/2/(1+Math.sqrt(2)))*85/100;
	yCenter3 = yCenter + (int)(width/2/(1+Math.sqrt(2)))*85/100;
	
	if(IsLargerThanOne){
	    Radius1 = (int)(width/2/(1+Math.sqrt(2)))*85/100+1;
	    Radius2 = (width/2)*95/100;
	    Radius3 = (width/2)*85/100;
	    Radius4 = (int)((double)(Radius1)*Math.sqrt(2))+1;
	    yCenter2 = yCenter - (int)(width/2/(1+Math.sqrt(2)))*85/100;
	    yCenter3 = yCenter + (int)(width/2/(1+Math.sqrt(2)))*85/100;
	}
	else{
	    Radius1 = (width/2)*85/100;
	    Radius2 = (width/2)*95/100;
	    Radius3 = Radius1;
	    Radius4 = Radius1;
	    yCenter2 = yCenter;
	    yCenter3 = yCenter;
	}
	
	Diam1 = 2*Radius1;
	Diam2 = 2*Radius2;
	Diam3 = 2*Radius3;
	
	
	//Draw the background circle
	if(IsLargerThanOne){
	    g.setColor(new Color(252,252,245));
	
	    fillCircle(g,xCenter,yCenter2,Radius4);
	    fillCircle(g,xCenter,yCenter3,Radius4);
	}
	
	if(colore_dark){
            g.setColor(bgcolor.darker());
        }
        else{
            g.setColor(bgcolor);
        }
        
	fillCircle(g,xCenter,yCenter,Radius1);
        
	//Draw a horizontal line
	g.setColor(Color.lightGray);
	g.drawLine(xCenter-Radius1,yCenter,xCenter+Radius1,yCenter);
	
	//Draw a vertical line
	if(draw_vline){g.drawLine(xCenter,yCenter-Radius1,xCenter,yCenter+Radius1);}
	
        Color plotchart = Color.lightGray;

	if(draw_impedance_chart){
	//Draw resistance and reactance circles
		for(i=0;i<Ncurves1;i++){
			draw_resistance(rl[i],g,plotchart);
		}
		for(i=0;i<Ncurves2;i++){
			draw_reactance(xl[i],g,plotchart);
		}
	}
	if(draw_admittance_chart){
	//Draw conductance and susceptance circles
		for(i=0;i<Ncurves1;i++){
			draw_conductance(rl[i],g,plotchart);
		}
		for(i=0;i<Ncurves2;i++){
			draw_supseptance(xl[i],g,plotchart);
		}
	}
        
        //draw background with circular hole for chart
        Color outer;
        
        if(colore_dark){
            outer = new Color(236,236,236);
        }
        else{
            //outer = new Color(205,195,180);
            outer = Color.lightGray;
        }

        
        drawStencil(g, width, height, Radius3, xCenter, yCenter, outer);
	
        //draw black frame
        g.setColor(Color.black);
	g.drawRect(0,0,width-1,height-1);
	

	//Draw tick-marks in the periphery
	draw_tick_marks(g);
        
        //Draw external and internal circles
	g.setColor(Color.black);
	drawCircle(g,xCenter,yCenter,Radius1);
	drawCircle(g,xCenter,yCenter,Radius2);
	
        
	//Draw rl=1 circle in blue
        Color r_one_color;
        
            if(colore_dark){
                r_one_color = Color.white;
            }
            else{
                r_one_color = Color.gray;
            }
       
	if(draw_impedance_chart){
		draw_resistance(1.0,g,r_one_color);
	}
	else{
		draw_conductance(1.0,g,r_one_color);
	}

	//Draw a small blue circle at the center
	g.setColor(Color.blue);
	drawCircle(g,xCenter,yCenter,(int)(Radius1*0.04));
	
        //draw_arcs()
	if(draw_arcs){draw_arcs(g);}
	
	//draw swr_circle
	if(draw_swr_circle){draw_swr_circle(g);}

	//draw swr_line
	if(draw_swr_line){draw_swr_line(g);}

	drawPoints(g);

	
	if(IsLargerThanOne){
	    g.setFont(labfont1);
	    g.setColor(Color.white);
	    g.drawString("Extended",8,getSize().height-23);
	    g.drawString("Smith Chart",8,getSize().height-10);
	    
	    g.setColor(bgcolor.darker());
	    g.fillRect(getSize().width-65,getSize().height-28,10,10);
	    
	    g.setColor(new Color(252,252,245));
	    g.fillRect(getSize().width-65,getSize().height-13,10,10);
	    g.drawString("|    | < 1.0",getSize().width-50,getSize().height-20);
	    g.drawString("|    | > 1.0",getSize().width-50,getSize().height-5);
	    
	    Font symbolfont=new Font("Symbol",Font.PLAIN,12);
	
	    g.setFont(symbolfont);
	    
	    String GammaSymb="\u0393";   
	    g.drawString(""+GammaSymb,getSize().width-45,getSize().height-20);
	    g.drawString(""+GammaSymb,getSize().width-45,getSize().height-5);
	}
}

private void drawStencil(Graphics g, int width, int height, int radius, int xcenter, int ycenter, Color stencilcolor){
	int rule; float alpha;
        rule = AlphaComposite.SRC_OVER;
        alpha = 1.0f;
        
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(stencilcolor);      
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setComposite(AlphaComposite.getInstance(rule, alpha));
        
        Area a1, a2, a3;
        
	Rectangle2D newrect = new Rectangle2D.Double(0.0,0.0,(double)width,(double)height);
        a1 = new Area(newrect);
        Ellipse2D newellipse = new Ellipse2D.Double((double)(xcenter-radius),(double)(ycenter-radius),(double)(radius*2),(double)(radius*2));
        a2 = new Area(newellipse);
        a3 = new Area();
        a3.add(a1);
        a3.subtract(a2);
        g2d.fill(a3);
        
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
}


private void drawCircle(Graphics g, int xCenter, int yCenter, int Radius){
	g.drawOval(xCenter-Radius,yCenter-Radius,2*Radius,2*Radius);
}

private void fillCircle(Graphics g, int xCenter, int yCenter, int Radius){
	g.fillOval(xCenter-Radius,yCenter-Radius,2*Radius,2*Radius);
}

private void draw_resistance(double rl, Graphics g, Color color){
	double xcen, ycen, raio;
	//Microwave Engineering, David M. Pozar, Equation 3.56a, Page 86.
	
	ycen = 0.0;
	
	if(rl<-1.0){
	    raio = 1.0/(1.0+(-2.0-rl));
	    //xcen = -(rl+1)*raio;
	    g.setColor(color);
	    drawCircle(g,xCenter+Radius1+(int)(raio*Radius1),yCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
	else{
	    raio = 1.0/(1.0+rl);
	    xcen = (rl)/(1.0+rl);
	    g.setColor(color);
	    drawCircle(g,xCenter+(int)(xcen*Radius1),yCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
}

private void draw_conductance(double rl, Graphics g, Color color){
	double xcen, ycen, raio;
	//Microwave Engineering, David M. Pozar, Equation 3.56a, Page 86.
	
	ycen = 0.0;
	
	if(rl<-1.0){
	    raio = 1.0/(1.0+(-2.0-rl));
	    g.setColor(color);
	    drawCircle(g,xCenter-Radius1-(int)(raio*Radius1),yCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
	else{
	    raio = 1.0/(1.0+rl);
	    xcen = -(rl)/(1.0+rl);
	    g.setColor(color);
	    drawCircle(g,xCenter+(int)(xcen*Radius1),yCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
	}
}

private void draw_reactance(double xl, Graphics g, Color color){
	double xcen, ycen, raio;
	//Microwave Engineering, David M. Pozar, Equation 3.56b, Page 86.
	xcen = 1.0;
	ycen = 1.0/xl;
	raio = 1.0/xl;

	g.setColor(color);
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));

	ycen = -1.0/xl;
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
}

private void draw_supseptance(double xl, Graphics g, Color color){
	double xcen, ycen, raio;
	//Microwave Engineering, David M. Pozar, Equation 3.56b, Page 86.
	xcen = -1.0;
	ycen = 1.0/xl;
	raio = 1.0/xl;

	g.setColor(color);
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));

	ycen = -1.0/xl;
	drawCircle(g,xCenter+(int)(xcen*Radius1),xCenter+(int)(ycen*Radius1),(int)(raio*Radius1));
}

private void draw_tick_marks(Graphics g){
	int Nmarks=360;
	int i;
	int tmpx1, tmpy1;
	int tmpx2, tmpy2;
	double beta = 2.0*Math.PI;
	int r1, r2,r3,r4;
	
	r4=(int)(Radius3+(Radius2-Radius3)*0.3);
        r3=(int)(Radius3+(Radius2-Radius3)*0.5);
        r1=(int)(Radius3+(Radius2-Radius3)*0.7);
	r2=(int)(Radius2*0.98);

	//g.setColor(bgcolor);
	
	for(i=0;i<Nmarks;i++){
                g.setColor(Color.gray);
                
		tmpx1=(int)(xCenter+r1*Math.cos(beta*i/(Nmarks)));
		tmpy1=(int)(yCenter+r1*Math.sin(beta*i/(Nmarks)));
		if(i%5==0){
			tmpx1=(int)(xCenter+r3*Math.cos(beta*i/(Nmarks)));
			tmpy1=(int)(yCenter+r3*Math.sin(beta*i/(Nmarks)));
                        //g.setColor(Color.black);
		}
                if(i%10==0){
			tmpx1=(int)(xCenter+r4*Math.cos(beta*i/(Nmarks)));
			tmpy1=(int)(yCenter+r4*Math.sin(beta*i/(Nmarks)));
                        //g.setColor(Color.blue);
                }
		tmpx2=(int)(xCenter+r2*Math.cos(beta*i/(Nmarks)));
		tmpy2=(int)(yCenter+r2*Math.sin(beta*i/(Nmarks)));
                if(i == 270){tmpx1 = tmpx1+1; tmpx2=tmpx1;}
                {
		g.drawLine(tmpx1,tmpy1,tmpx2,tmpy2);}
	}	
}


public void drawPoints(Graphics g){
	
	int radius, tmpx, tmpy;
	
	if(IsLargerThanOne){
	    radius = 3;
	}
	else{
	    radius=4;
	}
        
        //-------------------------------------
                draw_Zin = true;
                draw_Yin = true;
            /*
	    if(xpos == 0.0){
		if(draw_impedance_chart){

                    draw_Zin = false;
                    draw_Yin = true;
                }
                if(draw_admittance_chart){
                    draw_Yin = false;
                    draw_Zin = true;
                }
	    }
	    else{
		draw_Zin = true;
                draw_Yin = true;
	    }
            */
        //---------------------------------------
	if(xpos<0.1){
            if(draw_Zin){
		//Zin
		if(draw_impedance_chart){
		    tmpx=xCenter+(int)(GammaZin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaZin.Imaginary()*Radius1);
		    g.setColor(Color.green);
		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		    tmpx=xCenter+(int)(GammaYin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaYin.Imaginary()*Radius1);
		    g.setColor(Color.green);
		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
            }	
            if(draw_Yin){
		//Yin
		if(draw_impedance_chart){
		    tmpx=xCenter+(int)(GammaYin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaYin.Imaginary()*Radius1);
		    //g.setColor(Color.blue);
                    g.setColor(new Color(0,150,255));

		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		    tmpx=xCenter+(int)(GammaZin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaZin.Imaginary()*Radius1);
		    //g.setColor(Color.blue);
                    g.setColor(new Color(0,150,255));

		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}		
            }
            if(draw_ZL){
		//ZL
		if(draw_impedance_chart){
		tmpx=xCenter+(int)(GammaZL.Real()*Radius1);
		tmpy=yCenter+(int)(-GammaZL.Imaginary()*Radius1);
		g.setColor(Color.red);
		fillCircle(g,tmpx,tmpy,radius);
		g.setColor(Color.black);
		drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		tmpx=xCenter+(int)(GammaZL.Real()*Radius1);
		tmpy=yCenter+(int)(-GammaZL.Imaginary()*Radius1);
		g.setColor(Color.yellow);
		fillCircle(g,tmpx,tmpy,radius);
		g.setColor(Color.black);
		drawCircle(g,tmpx,tmpy,radius);
		}
            }
        }
        else{
            if(draw_ZL){
		//ZL
		if(draw_impedance_chart){
		tmpx=xCenter+(int)(GammaZL.Real()*Radius1);
		tmpy=yCenter+(int)(-GammaZL.Imaginary()*Radius1);
		g.setColor(Color.red);
		fillCircle(g,tmpx,tmpy,radius);
		g.setColor(Color.black);
		drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		tmpx=xCenter+(int)(GammaZL.Real()*Radius1);
		tmpy=yCenter+(int)(-GammaZL.Imaginary()*Radius1);
		g.setColor(Color.yellow);
		fillCircle(g,tmpx,tmpy,radius);
		g.setColor(Color.black);
		drawCircle(g,tmpx,tmpy,radius);
		}
            }
            if(draw_Zin){
		//Zin
		if(draw_impedance_chart){
		    tmpx=xCenter+(int)(GammaZin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaZin.Imaginary()*Radius1);
		    g.setColor(Color.green);
		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		    tmpx=xCenter+(int)(GammaYin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaYin.Imaginary()*Radius1);
		    g.setColor(Color.green);
		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
            }	
            if(draw_Yin){
		//Yin
		if(draw_impedance_chart){
		    tmpx=xCenter+(int)(GammaYin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaYin.Imaginary()*Radius1);
		    //g.setColor(Color.blue);
                    g.setColor(new Color(0,150,255));

		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}
		if(draw_admittance_chart){
		    tmpx=xCenter+(int)(GammaZin.Real()*Radius1);
		    tmpy=yCenter+(int)(-GammaZin.Imaginary()*Radius1);
		    //g.setColor(Color.blue);
                    g.setColor(new Color(0,150,255));

		    fillCircle(g,tmpx,tmpy,radius);
		    g.setColor(Color.black);
		    drawCircle(g,tmpx,tmpy,radius);
		}		
            }
        }
}


public void draw_swr_circle(Graphics g){
	
        if(colore_dark){
            g.setColor(Color.cyan);
        }
        else{
            g.setColor(Color.magenta);
        }

	drawCircle(g,xCenter,yCenter,(int)(Radius1*GammaZL.Magnitude()));
}


public void draw_swr_line(Graphics g){
	int xcor, ycor, xxcor, yycor;
	double theta;
        
        draw_Zin = true;
        draw_Yin = true;
            
        /*
	    if(xpos == 0.0){
                draw_Zin = false;
                draw_Yin = true;
	    }
	    else{
		draw_Zin = true;
                draw_Yin = true;
	    }
	*/
        
        if(xpos<0.1){
            if(draw_Zin){
		//For Zin
		theta=-GammaZin.Arg2();
		//g.setColor(new Color(204,50,50));
		if(draw_impedance_chart){
		g.setColor(Color.green.darker());
		}
		if(draw_admittance_chart){
		g.setColor(Color.blue);
		}
		
		xcor=(int)(GammaZin.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaZin.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		
		g.drawLine(xcor,ycor,xxcor,yycor);
            }
            if(draw_Yin){
		//For Yin
		theta=-GammaYin.Arg2();
		//g.setColor(new Color(204,50,50));
		if(draw_impedance_chart){
		g.setColor(Color.blue);
		}
		if(draw_admittance_chart){
		g.setColor(Color.green.darker());
		}
		xcor=(int)(GammaYin.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaYin.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		
		g.drawLine(xcor,ycor,xxcor,yycor);
            }
            if(draw_ZL){
		//For  ZL ...
		theta=-GammaZL.Arg2();
		g.setColor(new Color(204,50,50));
		xcor=(int)(GammaZL.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaZL.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		if(draw_impedance_chart){
		    g.setColor(Color.red);
		}
		if(draw_admittance_chart){
		    g.setColor(Color.yellow);
		}
		g.drawLine(xcor,ycor,xxcor,yycor);
            }
        }
        else{
            if(draw_ZL){
		//For  ZL ...
		theta=-GammaZL.Arg2();
		g.setColor(new Color(204,50,50));
		xcor=(int)(GammaZL.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaZL.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		if(draw_impedance_chart){
		    g.setColor(Color.red);
		}
		if(draw_admittance_chart){
		    g.setColor(Color.yellow);
		}
		g.drawLine(xcor,ycor,xxcor,yycor);
            }
            if(draw_Zin){
		//For Zin
		theta=-GammaZin.Arg2();
		//g.setColor(new Color(204,50,50));
		if(draw_impedance_chart){
		g.setColor(Color.green.darker());
		}
		if(draw_admittance_chart){
		g.setColor(Color.blue);
		}
		
		xcor=(int)(GammaZin.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaZin.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		
		g.drawLine(xcor,ycor,xxcor,yycor);
            }
            if(draw_Yin){
		//For Yin
		theta=-GammaYin.Arg2();
		//g.setColor(new Color(204,50,50));
		if(draw_impedance_chart){
		g.setColor(Color.blue);
		}
		if(draw_admittance_chart){
		g.setColor(Color.green.darker());
		}
		xcor=(int)(GammaYin.Real()*Radius1)+xCenter;
		ycor=(int)(-GammaYin.Imaginary()*Radius1)+yCenter;
		g.drawLine(xCenter,yCenter,xcor,ycor);
		xxcor=(int)(Math.cos(theta)*Radius2)+xCenter;
		yycor=(int)(Math.sin(theta)*Radius2)+yCenter;
		
		g.drawLine(xcor,ycor,xxcor,yycor);
            }
        }
}



public final synchronized void setZin(Complex Zin){
	this.Zin = Zin;
	GammaZin = EMF.computeGamma(Zin);
	this.Yin = EMF.Inv(Zin);
	GammaYin = EMF.computeGamma(Yin);
	repaint();
}

public final synchronized void setZin(Complex Zin, double Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public final synchronized void setZin(Complex Zin, Complex Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public final synchronized void setYin(Complex Yin){
	this.Yin = Yin;
	this.Zin = EMF.Inv(Yin);
	GammaZin = EMF.computeGamma(Zin);
	GammaYin = EMF.computeGamma(Yin);
	repaint();
}

public final synchronized void setYin(Complex Yin, double Z0){
	setZin(Complex.Divide(Yin,Z0));
}

public final synchronized void setYin(Complex Yin, Complex Z0){
	setZin(Complex.Divide(Zin,Z0));
}

public final synchronized void setZL(Complex ZL){
	this.ZL = ZL;
	GammaZL = EMF.computeGamma(this.ZL);
	this.YL = EMF.Inv(ZL);
	repaint();
}

public final synchronized void setZL(Complex ZL, double Z0){
	setZL(Complex.Divide(ZL,Z0));
}

public final synchronized void setZL(Complex ZL, Complex Z0){
	setZL(Complex.Divide(ZL,Z0));
}

public final synchronized void setYL(Complex YL){
	this.YL = YL;
	GammaZL = EMF.computeGamma(this.YL,false);
	this.ZL = EMF.Inv(YL);
	repaint();
}

public final synchronized void setYL(Complex YL, double Z0){
	setYL(Complex.Multiply(YL,Z0));
}

public final synchronized void setYL(Complex YL, Complex Z0){
	setYL(Complex.Multiply(YL,Z0));
}


public synchronized void set_swr_circle(boolean arg){
	draw_swr_circle=arg;
	repaint();
}

public synchronized void set_swr_line(boolean arg){
	draw_swr_line=arg;
	repaint();
}

public synchronized void set_impedance(boolean arg){
	draw_impedance_chart=arg;
	draw_admittance_chart=!arg;
	repaint();
}

public synchronized void set_admittance(boolean arg){
	draw_admittance_chart=arg;
	draw_impedance_chart=!arg;
	repaint();
}

public synchronized void setZL(boolean arg){
	draw_ZL = arg;
	repaint();
}

public synchronized void setZin(boolean arg){
	draw_Zin = arg;	
	repaint();
}

public synchronized void setYin(boolean arg){
	draw_Yin = arg;
	repaint();
}

public synchronized void setxpos(double xpos){
	this.xpos=xpos;
	repaint();
}
public synchronized void setalpha(double alpha){
	this.alpha=alpha;
	repaint();
}

public synchronized void setGammaFlag(boolean IsLargerThanOne){
	this.IsLargerThanOne = IsLargerThanOne;
	repaint();
}

private  void cricket_1(MouseEvent evt){
	int tx1, ty1, tx2, ty2, tx3, ty3, newRadius;
	int x, y, forbid1, forbid2;
	x=evt.getX();
	y=evt.getY();
	Graphics g = this.getGraphics();
	forbid1 = 15*getSize().width/100;
	forbid2 = 80*getSize().width/100;
	
	if(!IsLargerThanOne){
	    tx1=x-xCenter;
	    ty1=y-yCenter;	
	
	    //System.out.println(tx1+"   "+ty1+"    "+Radius3);
	    if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius3,2.0)){
		//Graphics g = this.getGraphics();
		g.clipRect(xProbe-10,yProbe-10,20,20);
		paint(g);
		g.clipRect(0,0,getSize().width,getSize().height);
		SmithCanvas.plot_red_cross(g,x,y);
		g.dispose();
		xProbe=x;
		yProbe=y;
		if(IsLargerThanOne){
		    GammaProbe=new Complex(2.4140*tx1/Radius3,-2.4140*ty1/Radius3);
		}
		else{
		    GammaProbe=new Complex(1.0*tx1/Radius3,-1.0*ty1/Radius3);
		}
		if(Complex.Real(GammaProbe) == 1.0 && Complex.Imaginary(GammaProbe) == 0.0){
		    ZProbe = new Complex(0.0, 1.0E230);
		    YProbe = new Complex(0.0, 0.0);
		}
		else if(Complex.Real(GammaProbe) == -1.0 && Complex.Imaginary(GammaProbe) == 0.0){
		    YProbe = new Complex(0.0, 1.0E230);
		    ZProbe = new Complex(0.0, 0.0);
		}
		else{
		    ZProbe=EMF.computeZ(GammaProbe);
		    YProbe=Complex.Divide(new Complex(1.0,0.0),ZProbe);
		}
	    }
	}
	else{
	
	    if(y <= yCenter){
		tx1=x-xCenter;
		ty1=y-yCenter;	
	    
		newRadius = 1+(int)((Radius3/(1+Math.sqrt(2.0))*Math.sqrt(2)));
		tx2=x-xCenter;
		ty2=y-(int)(newRadius)-(getSize().height/2-Radius3);	
		
			g.setColor(Color.black);
			g.drawString("Forbidden",forbid2,getSize().height/2);
			g.drawString("Region",forbid2,getSize().height/2+12);
			g.drawString("Forbidden",forbid1,getSize().height/2);
			g.drawString("Region",forbid1,getSize().height/2+12);
			//redraw the SWR circle, etc, or it would get partially overwritten by the black above
			draw_swr_circle(g);
			draw_swr_line(g);
			drawPoints(g);
		
		if(Math.pow(tx2,2.0)+Math.pow(ty2,2.0)<=Math.pow(newRadius,2.0)){
		    
		    g.clipRect(xProbe-10,yProbe-10,20,20);
		    paint(g);
		    g.clipRect(0,0,getSize().width,getSize().height);
		    SmithCanvas.plot_red_cross(g,x,y);
		    g.dispose();
		    
		    xProbe=x;
		    yProbe=y;
		    if(IsLargerThanOne){
			GammaProbe=new Complex(2.4140*tx1/Radius3,-2.4140*ty1/Radius3);
		    }
		    else{
			GammaProbe=new Complex(1.0*tx1/Radius3,-1.0*ty1/Radius3);
		    }
		    if(Complex.Real(GammaProbe) == 1.0 && Complex.Imaginary(GammaProbe) == 0.0){
			ZProbe = new Complex(0.0, 1.0E230);
			YProbe = new Complex(0.0, 0.0);
		    }
		    else if(Complex.Real(GammaProbe) == -1.0 && Complex.Imaginary(GammaProbe) == 0.0){
			YProbe = new Complex(0.0, 1.0E230);
			ZProbe = new Complex(0.0, 0.0);
		    }
		    else{
			ZProbe=EMF.computeZ(GammaProbe);
			YProbe=Complex.Divide(new Complex(1.0,0.0),ZProbe);
		    }
		    
		    		
		}
		else if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius3,2.0)
			&& Math.pow(tx2,2.0)+Math.pow(ty2,2.0)>Math.pow(newRadius,2.0)){
		    
		    if(x < xCenter){
			g.setColor(Color.black);
			g.drawString("Forbidden",forbid2,getSize().height/2);
			g.drawString("Region",forbid2,getSize().height/2+12);
			//redraw the SWR circle, or it would get partially overwritten by the black above
			draw_swr_circle(g);
			draw_swr_line(g);
			drawPoints(g);
			
			g.setColor(Color.white);
			g.drawString("Forbidden",forbid1,getSize().height/2);
			g.drawString("Region",forbid1,getSize().height/2+12);
		    }
		    if(x > xCenter){
			g.setColor(Color.black);
			g.drawString("Forbidden",forbid1,getSize().height/2);
			g.drawString("Region",forbid1,getSize().height/2+12);
			//redraw the SWR circle, or it would get partially overwritten by the black above
			draw_swr_circle(g);
			draw_swr_line(g);
			drawPoints(g);
			
			g.setColor(Color.white);
			g.drawString("Forbidden",forbid2,getSize().height/2);
			g.drawString("Region",forbid2,getSize().height/2+12);
		    }
		}
	    }
	    
	    else if(y > yCenter){
		tx1=x-xCenter;
		ty1=y-yCenter;	
		
		newRadius = 1+(int)((Radius3/(1+Math.sqrt(2.0))*Math.sqrt(2)));
		tx3=x-xCenter;
				
		ty3=y-(yCenter+Radius3-newRadius);	
			
			g.setColor(Color.black);
			g.drawString("Forbidden",forbid2,getSize().height/2);
			g.drawString("Region",forbid2,getSize().height/2+12);
			g.drawString("Forbidden",forbid1,getSize().height/2);
			g.drawString("Region",forbid1,getSize().height/2+12);
			//redraw the SWR circle, or it would get partially overwritten by the black above
			draw_swr_circle(g);
			draw_swr_line(g);
			drawPoints(g);
	
	       if(Math.pow(tx3,2.0)+Math.pow(ty3,2.0)<=Math.pow(newRadius,2.0)){
		    //Graphics g = this.getGraphics();
		    g.clipRect(xProbe-10,yProbe-10,20,20);
		    paint(g);
		    g.clipRect(0,0,getSize().width,getSize().height);
		    SmithCanvas.plot_red_cross(g,x,y);
		    					    
		    g.dispose();
		    xProbe=x;
		    yProbe=y;
		    if(IsLargerThanOne){
			GammaProbe=new Complex(2.4140*tx1/Radius3,-2.4140*ty1/Radius3);
		    }
		    else{
			GammaProbe=new Complex(1.0*tx1/Radius3,-1.0*ty1/Radius3);
		    }
		    if(Complex.Real(GammaProbe) == 1.0 && Complex.Imaginary(GammaProbe) == 0.0){
			ZProbe = new Complex(0.0, 1.0E230);
			YProbe = new Complex(0.0, 0.0);
		    }
		    else if(Complex.Real(GammaProbe) == -1.0 && Complex.Imaginary(GammaProbe) == 0.0){
			YProbe = new Complex(0.0, 1.0E230);
			ZProbe = new Complex(0.0, 0.0);
		    }
		    else{
			ZProbe=EMF.computeZ(GammaProbe);
			YProbe=Complex.Divide(new Complex(1.0,0.0),ZProbe);
		    }		    
		}
		else if(Math.pow(tx1,2.0)+Math.pow(ty1,2.0)<=Math.pow(Radius3,2.0)
			&& Math.pow(tx3,2.0)+Math.pow(ty3,2.0)>Math.pow(newRadius,2.0)){
		    
		    if(x < xCenter){
			g.setColor(Color.black);
			g.drawString("Forbidden",forbid2,getSize().height/2);
			g.drawString("Region",forbid2,getSize().height/2+12);
			//redraw the SWR circle, or it would get partially overwritten by the black above
			draw_swr_circle(g);
			draw_swr_line(g);
			drawPoints(g);
			
			g.setColor(Color.white);
			g.drawString("Forbidden",forbid1,getSize().height/2);
			g.drawString("Region",forbid1,getSize().height/2+12);
		    }
		    if(x > xCenter){
			g.setColor(Color.black);
			g.drawString("Forbidden",forbid1,getSize().height/2);
			g.drawString("Region",forbid1,getSize().height/2+12);
			//redraw the SWR circle, or it would get partially overwritten by the black above
			draw_swr_circle(g);
			draw_swr_line(g);
			drawPoints(g);
			
			g.setColor(Color.white);
			g.drawString("Forbidden",forbid2,getSize().height/2);
			g.drawString("Region",forbid2,getSize().height/2+12);
		    }
		}
		
	    }
	}
}
public void mouseDragged(MouseEvent evt){cricket_1(evt);}
public void mouseMoved(MouseEvent evt){;}
public void mouseClicked(MouseEvent evt){cricket_1(evt);}
public void mouseEntered(MouseEvent evt){setCursor(cursorB);}
public void mouseExited(MouseEvent evt){setCursor(cursorA);}
public void mousePressed(MouseEvent evt){cricket_1(evt);}
public void mouseReleased(MouseEvent evt){cricket_1(evt);}


public void draw_arcs(Graphics g){

	double beginAngle, beginAngle2, Angle, Angle2;
	double raio, del;
	double txpos=xpos;
	while(txpos>0.5){txpos-=0.5;}
	raio = (double)(2.03*Radius3);	

	beginAngle=GammaZL.Arg2(Complex.POLAR_DEGREE);
	Angle=-720.0*xpos;
        while(Math.abs(beginAngle)>360){beginAngle = beginAngle+360.0;}
        while(Math.abs(Angle)>360){Angle = Angle+360.0;}
        
        //drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),raio,beginAngle,Angle,3,Color.red);
                
	beginAngle2 = GammaZL.Arg2(Complex.POLAR_DEGREE) + Angle;
	Angle2=-(0.5-txpos)*720.0;
        if(Math.abs(beginAngle2)>360){beginAngle2 = beginAngle2+360.0;}
        if(Math.abs(Angle2)>360){Angle2 = Angle2+360.0;}
        
        drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),raio+1.0,beginAngle2,Angle2,3,Color.green);
        drawArcThick(g,(double)(xCenter-raio/2),(double)(yCenter-raio/2),raio+1.0,beginAngle,Angle,3,Color.red);
}

private void drawArcThick(Graphics g, double xCenter, double yCenter, double Radius, double startangle, double endangle, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick));
        
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
     
        Arc2D.Double arc_one = new Arc2D.Double(xCenter,yCenter,Radius,Radius,startangle,endangle,0);
        g2d.draw(arc_one);
  
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
}


public final Complex getZProbe(){
	return ZProbe;
}

public final Complex getYProbe(){
	return YProbe;
}

public final Complex getGammaProbe(){
	return GammaProbe;
}

public static void plot_red_cross(Graphics g, int x, int y){
	g.setColor(Color.white);
			g.fillRect(x-5, y-1,11,3);
			g.fillRect(x-1,y-5,3,11);
		g.setColor(Color.red);
			g.drawLine(x-4,y,x+4,y);
			g.drawLine(x,y-4,x,y+4);
}

public Complex getZL(){
	return (Complex)ZL.clone();
}

public Complex getZin(){
	return (Complex)Zin.clone();
}

public Complex getYin(){
	return (Complex)Yin.clone();
}

public synchronized void setColoreDark(boolean colore_dark){
	this.colore_dark = colore_dark;
	repaint();
}


}//End SmithCanvas

/*******************************************************************************************/
class SmithMan2 extends Panel{
private Label[] vlab, lab;
//private static final Color bgcolor = new Color(216,216,191);
private static final Color bgcolor = new Color(236,236,236);
int mode;//mode=1 Impedance, mode=2 Admittance Chart

boolean IsLoadOpen, IsLoadShort, IsLoadImaginary, IsLoadRegular, Gamma_plusone, Gamma_minusone;

public Complex ZL, YL, GammaL, Zin, Yin, GammaIn;
	
      SmithMan2(int width, int height){
		super();
		setLayout(null);
		mode=1;
		setBackground(bgcolor);
		Font labelfont=new Font("SanSerif",Font.PLAIN,11);
                int ystart = 6;
                int ystep = 16; 
                int yhigh = 12;
                
                IsLoadOpen = false;
                IsLoadShort = false;
                IsLoadImaginary = false;
                IsLoadRegular = true;
                ZL = new Complex(1.0,1.0);
                YL = new Complex(0.5,-0.5);
                Zin = new Complex(1.0,1.0);
                Yin = new Complex(0.5,-0.5);
                
                if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)==0.0){
                    IsLoadShort = true;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if(Complex.Real(YL)==0.0 && Complex.Imaginary(YL)==0.0){
                    IsLoadOpen = true;
                    IsLoadShort = false;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)!=0.0){
                    IsLoadImaginary = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadRegular = false;
                }
                else if((Complex.Real(ZL)!=0.0 && Complex.Imaginary(ZL)!=0.0) ||
                    (Complex.Real(ZL)!=0.0 && Complex.Imaginary(ZL)==0.0))
                {
                    IsLoadRegular = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                }
                
                lab = new Label[5];
		vlab = new Label[5];
		lab[0] = new Label("z",Label.LEFT);
		lab[1] = new Label("",Label.LEFT);
		lab[2] = new Label("z(d)",Label.LEFT);
		lab[3] = new Label("(d)",Label.LEFT);
		lab[4] = new Label("y(d)",Label.LEFT);
                
                lab[0].setBounds(30,ystart-1,10,yhigh);
                lab[1].setBounds(30,ystart+ystep-1,0,yhigh);
                lab[2].setBounds(30,ystart+2*ystep,30,yhigh);
                lab[3].setBounds(40,ystart+3*ystep,20,yhigh);
                lab[4].setBounds(30,ystart+4*ystep,30,yhigh);
                
		for(int i = 0; i<lab.length; i++){
			vlab[i] = new Label("",Label.LEFT);
			vlab[i].setFont(labelfont);
			lab[i].setFont(labelfont);
                        vlab[i].setBounds(65,ystart+(i)*ystep,180,yhigh);
                        //add(lab[i]);
			//add(vlab[i]);
		}
		/*
		//Panel p = new Panel();
		//p.setLayout(new GridLayout(5,2));
		lab = new Label[5];
		vlab = new Label[5];
		lab[0] = new Label("Load Impedance = ",Label.LEFT);
		lab[1] = new Label("Load Refl. Coef. = ",Label.LEFT);
		lab[2] = new Label("Cursor Impedance = ",Label.LEFT);
		lab[3] = new Label("Cursor Refl. Coef. = ",Label.LEFT);
		lab[4] = new Label("Cursor Admittance = ",Label.LEFT);
		for(int i = 0; i<lab.length; i++){
			vlab[i] = new Label("",Label.LEFT);
			vlab[i].setFont(labelfont);
			lab[i].setFont(labelfont);
			//p.add(lab[i]);
			//p.add(vlab[i]);
		}
		//add(p);
		//p.setBounds(20,2,width-22,height-2);
		
		//input for ourwidth the number used for the smith man panel
		int ourwidth = 250;
		//80 is 5 pixels smaller than the width of the panel (85)
		int vstep = 80/5;
		
		int vstepinit = 0;
		int xinit = 15; 
		int xinit2 = 48*ourwidth/100;
		
		lab[0].setBounds(xinit,vstepinit,100,vstep+2);
		add(lab[0]);
		lab[1].setBounds(xinit,vstepinit+vstep,100,vstep+2);
		add(lab[1]);
		lab[2].setBounds(xinit,vstepinit+2*vstep,100,vstep+2);
		add(lab[2]);
		lab[3].setBounds(xinit,vstepinit+3*vstep,100,vstep+2);
		add(lab[3]);
		lab[4].setBounds(xinit,vstepinit+4*vstep,100,vstep+2);
		add(lab[4]);
		
		vlab[0].setBounds(xinit2,vstepinit,125,vstep+2);
		add(vlab[0]);
		vlab[1].setBounds(xinit2,vstepinit+vstep,125,vstep+2);
		add(vlab[1]);
		vlab[2].setBounds(xinit2,vstepinit+2*vstep,125,vstep+2);
		add(vlab[2]);
		vlab[3].setBounds(xinit2,vstepinit+3*vstep,125,vstep+2);
		add(vlab[3]);
		vlab[4].setBounds(xinit2,vstepinit+4*vstep,125,vstep+2);
		add(vlab[4]);
		*/
	}
	public void paint(Graphics g){
                Font symbolfont=new Font("Symbol",Font.PLAIN,12);
                FontMetrics fm;
		
                g.setFont(new Font("Serif",Font.PLAIN,12));
		
		//-----------------------------------------------------
                String alpha, Ohm, lambda, infinity, Gamma, plusj, minusj, sign;
		g.setFont(symbolfont);
		alpha="\u03b1";
		lambda="\u03bb";
		Ohm="\u03a9";
		infinity="\u221e";
		Gamma="\u0393";
                int vstep = 85/5;
		int vstepinit = 12;
		int xinit = 35;
		int xinit2 = xinit+30;
		int xinit3 = xinit2+70;

            //---------------------------------------------------------------------------------------    
            g.setColor(Color.white);
            g.drawLine(0,0,0,getSize().height-1);
            g.drawLine(0,0,getSize().width-1,0);
            g.setColor(Color.black);
            g.drawLine(getSize().width-1,0,getSize().width-1,getSize().height-1);
            g.drawLine(0,getSize().height-1,getSize().width-1,getSize().height-1);
                
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        	
	    if(mode==1){
		g.setColor(Color.red);
		g.fillOval(8,3,8,8);
		g.setColor(Color.green);
		g.fillOval(8,37,8,8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(8,70,8,8);	
    	    }
	    if(mode==2){
		g.setColor(Color.yellow);
		g.fillOval(8,3,8,8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(8,37,8,8);
		g.setColor(Color.green);
		g.fillOval(8,70,8,8);
	    }
            g.setColor(Color.black);
            g.drawOval(8,3,8,8);
            g.drawOval(8,37,8,8);
            g.drawOval(8,70,8,8);
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
            //-------------------------------------------------------------------------------------------
		g.setFont(new Font("SanSerif",Font.PLAIN,11));
		plusj =" + j ";
		minusj=" - j ";
                
                fm = g.getFontMetrics();
             //-----------------------------------------------------------------------
             double tempR = 1.0, tempX = 2.0;
             int stepx = 0;
             
            if(mode==1){
                 if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)==0.0){
                    IsLoadShort = true;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                 else if((Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)<-1.0E130)||Complex.Magnitude(ZL)>1.0E130){
                    IsLoadOpen = true;
                    IsLoadShort = false;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                 else if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)!=0.0){
                    IsLoadImaginary = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadRegular = false;
                }
                 else if((Complex.Real(ZL)!=0.0 && Complex.Imaginary(ZL)!=0.0) ||
                    (Complex.Real(ZL)!=0.0 && Complex.Imaginary(ZL)==0.0))
                {
                    IsLoadRegular = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                }
    
                //-----------------------------------------------------------------------------
                    g.setColor(Color.black);
                    MaestroG.subscripter(" z","L","",g,11,xinit,vstepinit);
		
		if(IsLoadOpen){
		    MaestroG.subscripterInfinityOne("=    ","","","",g,11,xinit2,vstepinit);
		}
		else if(IsLoadShort){
		    MaestroG.subscripter("=    0.0 + j 0.0","","",g,11,xinit2,vstepinit);
		}
		else{
		    if(Complex.Imaginary(ZL) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = ZL.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=    0.0","","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=    0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=  "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(ZL.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,11,xinit3,vstepinit);
		    }
                }

                MaestroG.subscripterSS3(" "+Gamma,"L","",g,11,xinit+1,vstepinit + vstep);
		
                //write the angle with italic L for angle symbol - modify the toString process
                double dtmp1, dtmp2;
                dtmp1=MaestroA.rounder(GammaL.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GammaL.Arg2()*180/Math.PI,6);}
                MaestroG.SansPLAIN("=   "+dtmp1,"  \u2220 ",""+dtmp2+" \u00ba",g,11,xinit2,vstepinit + vstep);
	

                MaestroG.subscripterSS3(""+Gamma,"","(d)",g,11,xinit+1,vstepinit + 3*vstep);
		//MaestroG.superscripter("= "+Ginput.toString(Complex.POLAR_DEGREE,4),"","",g,11,xinit2,vstepinit + 3*vstep);
		
                //write the angle with italic L for angle symbol - modify the toString process
                dtmp1=MaestroA.rounder(GammaIn.Magnitude(),8);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GammaIn.Arg2()*180/Math.PI,6);}
                MaestroG.SansPLAIN("=   "+dtmp1,"  \u2220 ",""+dtmp2+" \u00ba",g,11,xinit2,vstepinit + 3*vstep-1);
                
		if(Complex.Real(GammaIn) > 0.999999 && Math.abs(Complex.Imaginary(GammaIn)) < 0.000001){
		    Gamma_plusone = true;
		    Gamma_minusone = false;
		}
		else if(Complex.Real(GammaIn) < -0.999999 && Math.abs(Complex.Imaginary(GammaIn)) < 0.000001){
		    Gamma_plusone = false;
		    Gamma_minusone = true;
		}
		else{
		    Gamma_plusone = false;
		    Gamma_minusone = false;
		}
		
		MaestroG.subscripter("z","","(d)",g,11,xinit,vstepinit + 2*vstep);
   
                MaestroG.subscripter("z","","(d)",g,11,xinit,vstepinit + 2*vstep);
                
                if((IsLoadOpen || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=    ","","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadOpen || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("=    0.0 + j 0.0","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=    ","","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("=    0.0 + j 0.0","","",g,11,xinit2,vstepinit + 2*vstep);
		}

    
		else{
                   
		    if(Complex.Imaginary(Zin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }

		    else if(IsLoadRegular){
			tempR = Zin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=    0.0","","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=    0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=  "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(Zin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,vstepinit + 2*vstep);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		}
                
                vstepinit-=1;
                MaestroG.subscripter("y","","(d)",g,11,xinit+2,vstepinit + 4*vstep);
		
		if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.0E130){
		    MaestroG.subscripterInfinityOne("=    ","","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		else if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)==0.0){
		    MaestroG.subscripter("=    0.0 + j 0.0","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		else{
		    if(Complex.Imaginary(Yin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Yin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			if(Math.abs(Yin.Imaginary())<1.0e6){
                            MaestroG.superscripter("=    0.0","","",g,11,xinit2,vstepinit+ 4*vstep);
                        }
			stepx = fm.stringWidth("=    0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			if(Math.abs(Yin.Imaginary())<1.0e6){
                            MaestroG.superscripter("=   0.0","","",g,11,xinit2,vstepinit+ 4*vstep);
                            stepx = fm.stringWidth("=   0.0");
                        }
		    }
		    
		    tempX = Math.abs(Yin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,vstepinit + 4*vstep);
		    }
		    else if(tempX <= 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                    // alternate
                    else if(tempX > 1.0E6){
			MaestroG.subscripterInfinityOne("=    ","","","",g,11,xinit2,vstepinit + 4*vstep);
		    }
		    /*
                    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                     */
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-9 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    /*
                    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                     */
		}               
            }
             else if(mode == 2){
                
                if(Complex.Real(YL)==0.0 && Complex.Imaginary(YL)==0.0){
                    IsLoadShort = false;
                    IsLoadOpen = true;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if((Complex.Real(YL)==0.0 && Complex.Imaginary(YL)<-1.0E130)||Complex.Magnitude(YL)>1.0E100 ||
                    Complex.Magnitude(ZL)==0.0){
                    IsLoadOpen = false;
                    IsLoadShort = true;
                    IsLoadImaginary = false;
                    IsLoadRegular = false;
                }
                else if(Complex.Real(YL)==0.0 && Complex.Imaginary(YL)!=0.0){
                    IsLoadImaginary = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadRegular = false;
                }
                else if((Complex.Real(YL)!=0.0 && Complex.Imaginary(YL)!=0.0) ||
                    (Complex.Real(YL)!=0.0 && Complex.Imaginary(YL)==0.0))
                {
                    IsLoadRegular = true;
                    IsLoadShort = false;
                    IsLoadOpen = false;
                    IsLoadImaginary = false;
                }

                //--------------------------------------------------------------------------------------------- 
                 
                g.setColor(Color.black);
		MaestroG.subscripter(" y","L","",g,11,xinit,vstepinit);
		
		if(IsLoadShort){
		    MaestroG.subscripterInfinityOne("=  ","","","",g,11,xinit2,vstepinit);
		}
		else if(IsLoadOpen){
		    MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit);
		}
		else{
		    if(Complex.Imaginary(YL) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = YL.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=   0.0","","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("= "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,11,xinit2,vstepinit);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(YL.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,11,xinit3,vstepinit);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,11,xinit3,vstepinit);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,11,xinit3,vstepinit);
		    }
		}

                 MaestroG.subscripterSS3(" "+Gamma,"L","",g,11,xinit+1,vstepinit + vstep);
		
		MaestroG.subscripterSS3(""+Gamma,"","(d)",g,11,xinit+1,vstepinit + 3*vstep);
		//-----------------------------------------------------------------------------------------------                
                //write the angle with italic L for angle symbol - modify the toString process
                double dtmp1, dtmp2;
                dtmp1=MaestroA.rounder(GammaL.Magnitude(),4);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GammaL.Arg2()*180/Math.PI,4);}
                MaestroG.SansPLAIN("= "+dtmp1,"  \u2220 ",""+dtmp2+" \u00ba",g,11,xinit2,vstepinit + vstep);
                
                dtmp1=MaestroA.rounder(GammaIn.Magnitude(),4);
                    if(dtmp1 == 0.0){dtmp2 = 0.0;}
                    else{dtmp2=MaestroA.rounder(GammaIn.Arg2()*180/Math.PI,4);}
                MaestroG.SansPLAIN("= "+dtmp1,"  \u2220 ",""+dtmp2+" \u00ba",g,11,xinit2,vstepinit + 3*vstep);
                //---------------------------------------------------------------------------------------------- 
                 
                 
                 if(Complex.Real(GammaIn) > 0.999999 && Math.abs(Complex.Imaginary(GammaIn)) < 0.000001){
		    Gamma_plusone = true;
		    Gamma_minusone = false;
		}
		else if(Complex.Real(GammaIn) < -0.999999 && Math.abs(Complex.Imaginary(GammaIn)) < 0.000001){
		    Gamma_plusone = false;
		    Gamma_minusone = true;
		}
		else{
		    Gamma_plusone = false;
		    Gamma_minusone = false;
		}
		
		MaestroG.subscripter("y","","(d)",g,11,xinit+2,vstepinit + 2*vstep);
		
		if((IsLoadOpen || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripterInfinityOne("=   ","","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadOpen || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("=   0.0 + j 0.0","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripterInfinityOne("=   ","","","",g,11,xinit2,vstepinit + 2*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripter("=   0.0 + j 0.0","","",g,11,xinit2,vstepinit + 2*vstep);
		}

				
		//if(Complex.Real(Yinput)==0.0&&Complex.Imaginary(Yinput)<-1.0E130){
		  //  MaestroG.subscripter("=  "+infinity,"","",g,11,xinit2,vstepinit + 2*vstep);
		//}
		//else if(Complex.Real(Yinput)==0.0&&Complex.Imaginary(Yinput)==0.0){
		  //  MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit + 2*vstep);
		//}
		else{
		    if(Complex.Imaginary(Yin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Yin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=   0.0","","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,11,xinit2,vstepinit+ 2*vstep);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(Yin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,vstepinit + 2*vstep);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,11,xinit3,vstepinit+ 2*vstep);
		    }
		}
		
		
		MaestroG.subscripter("z","","(d)",g,11,xinit,vstepinit + 4*vstep);
		
		if((IsLoadOpen || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=   ","","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		else if((IsLoadOpen || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("=   0.0 + j 0.0","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_plusone){
		    MaestroG.subscripterInfinityOne("=   ","","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		else if((IsLoadShort || IsLoadImaginary) && Gamma_minusone){
		    MaestroG.subscripter("=   0.0 + j 0.0","","",g,11,xinit2,vstepinit + 4*vstep);
		}
		
		//if(Complex.Real(Zinput)==0.0&&Complex.Imaginary(Zinput)<-1.0E130){
		  //  MaestroG.subscripter("=  "+infinity,"","",g,11,xinit2,vstepinit + 4*vstep);
		//}
		//else if(Complex.Real(Zinput)==0.0&&Complex.Imaginary(Zinput) == 0.0){
		  //  MaestroG.subscripter("=  0.0 + j 0.0","","",g,11,xinit2,vstepinit + 4*vstep);
		//}
		else{
		    if(Complex.Imaginary(Zin) >= 0.0){sign = plusj;}
		    else{sign = minusj;}
		    
		    if(IsLoadImaginary || IsLoadOpen || IsLoadShort){
			tempR = 0.0;
		    }
		    else if(IsLoadRegular){
			tempR = Zin.Real();
		    }
		    
		    if(tempR < 1.0E3 && tempR >= 1.0E-3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR,6),"","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR,6));
		    }
		    else if(tempR == 0.0){
			MaestroG.superscripter("=   0.0","","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   0.0 ");
		    }
		    else if(tempR < 1.0E6 && tempR >= 1.0E3){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-3,2)+" x 10","3","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-3,2)+"x 10 3");
		    }
		    else if(tempR < 1.0E9 && tempR >= 1.0E6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-6,2)+" x 10","6","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-6,2)+"x 10 6");
		    }
		    else if(tempR < 1.0E12 && tempR >= 1.0E9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-9,2)+" x 10","9","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-9,2)+"x 10 9");
		    }
		    else if(tempR < 1.0E15 && tempR >= 1.0E12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-12,2)+" x 10","12","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-12,2)+"x 10 12");
		    }
		    else if(tempR < 1.0E18 && tempR >= 1.0E15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-15,2)+" x 10","15","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-15,2)+"x 10 15");
		    }
		    else if(tempR < 1.0E21 && tempR >= 1.0E18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-18,2)+" x 10","18","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-18,2)+"x 10 18");
		    }
		    else if(tempR < 1.0E24 && tempR >= 1.0E21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-21,2)+" x 10","21","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-21,2)+"x 10 21");
		    }
		    else if(tempR < 1.0E27 && tempR >= 1.0E24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-24,2)+" x 10","24","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-24,2)+"x 10 24");
		    }
		    else if(tempR < 1.0E30 && tempR >= 1.0E27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-27,2)+" x 10","27","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-27,2)+"x 10 27");
		    }
		    else if(tempR >= 1.0E30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E-30,2)+" x 10","30","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E-30,2)+"x 10 30");
		    }
		    else if(tempR < 1.0E-3 && tempR >= 1.0E-6){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E6,2)+" x 10","-6","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E6,2)+"x 10 -6");
		    }
		    else if(tempR < 1.0E-6 && tempR >= 1.0E-9){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E9,2)+" x 10","-9","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E9,2)+"x 10 -9");
		    }
		    else if(tempR < 1.0E-9 && tempR >= 1.0E-12){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E12,2)+" x 10","-12","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E12,2)+"x 10 -12");
		    }
		    else if(tempR < 1.0E-12 && tempR >= 1.0E-15){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E15,2)+" x 10","-15","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E15,2)+"x 10 -15");
		    }
		    else if(tempR < 1.0E-15 && tempR >= 1.0E-18){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E18,2)+" x 10","-18","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E18,2)+"x 10 -18");
		    }
		    else if(tempR < 1.0E-18 && tempR >= 1.0E-21){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E21,2)+" x 10","-21","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E21,2)+"x 10 -21");
		    }
		    else if(tempR < 1.0E-21 && tempR >= 1.0E-24){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E24,2)+" x 10","-24","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E24,2)+"x 10 -24");
		    }
                    else if(tempR < 1.0E-24 && tempR >= 1.0E-27){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E27,2)+" x 10","-27","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E27,2)+"x 10 -27");
		    }
                    else if(tempR < 1.0E-27 && tempR >= 1.0E-30){
			MaestroG.superscripter("=   "+MaestroA.rounder(tempR*1.0E30,2)+" x 10","-30","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   "+MaestroA.rounder(tempR*1.0E30,2)+"x 10 -30");
		    }
                    else if(tempR < 1.0E-30 && tempR != 0.0){
			MaestroG.superscripter("=   0.0","","",g,11,xinit2,vstepinit+ 4*vstep);
			stepx = fm.stringWidth("=   0.0");
		    }
		    
		    tempX = Math.abs(Zin.Imaginary());
		    xinit3 = xinit2+stepx;
		    
		    if(tempX < 1.0E3 && tempX >= 1.0E-3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX,6),"","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX == 0.0){
			MaestroG.superscripter(" + j 0.0","","",g,11,xinit3,vstepinit + 4*vstep);
		    }
		    else if(tempX < 1.0E6 && tempX >= 1.0E3){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-3,2)+" x 10","3","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E9 && tempX >= 1.0E6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-6,2)+" x 10","6","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E12 && tempX >= 1.0E9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-9,2)+" x 10","9","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E15 && tempX >= 1.0E12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-12,2)+" x 10","12","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E18 && tempX >= 1.0E15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-15,2)+" x 10","15","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E21 && tempX >= 1.0E18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-18,2)+" x 10","18","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E24 && tempX >= 1.0E21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-21,2)+" x 10","21","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E27 && tempX >= 1.0E24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-24,2)+" x 10","24","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E30 && tempX >= 1.0E27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-27,2)+" x 10","27","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX >= 1.0E30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E-30,2)+" x 10","30","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-3 && tempX >= 1.0E-6){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E6,2)+" x 10","-6","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-6 && tempX >= 1.0E-9){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E9,2)+" x 10","-9","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-9 && tempX >= 1.0E-12){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E12,2)+" x 10","-12","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-12 && tempX >= 1.0E-15){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E15,2)+" x 10","-15","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-15 && tempX >= 1.0E-18){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E18,2)+" x 10","-18","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-18 && tempX >= 1.0E-21){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E21,2)+" x 10","-21","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		    else if(tempX < 1.0E-21 && tempX >= 1.0E-24){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E24,2)+" x 10","-24","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-24 && tempX >= 1.0E-27){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E27,2)+" x 10","-27","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-27 && tempX >= 1.0E-30){
			MaestroG.superscripter(sign+""+MaestroA.rounder(tempX*1.0E30,2)+" x 10","-30","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
                    else if(tempX < 1.0E-30 && tempX != 0.0){
			MaestroG.superscripter(sign+" 0.0","","",g,11,xinit3,vstepinit+ 4*vstep);
		    }
		}
             }
                
            
                
                //-----------------------------------------------------
                
              /*
                //String alpha, Ohm, lambda, infinity, Gamma, plusj, minusj, sign;
		//g.setFont(symbolfont);
		//alpha="\u03b1";
		//lambda="\u03bb";
		//Ohm="\u03a9";
		//infinity="\u221e";
		//Gamma="\u0393";
		//g.setFont(new Font("SanSerif",Font.PLAIN,11));
		//plusj =" + j ";
		//minusj=" - j ";
                
                fm = g.getFontMetrics();
                
                MaestroG.subscripter("","L","",g,11,40,12);
                MaestroG.subscripterSS(""+Gamma,"L","",g,11,32,29);
                MaestroG.subscripterSS(""+Gamma,"","",g,11,32,61);
            
		g.setColor(Color.white);
		g.drawLine(0,0,0,getSize().height-1);
		g.drawLine(0,0,getSize().width-1,0);
		g.setColor(Color.black);
		g.drawLine(getSize().width-1,0,getSize().width-1,getSize().height-1);
		g.drawLine(0,getSize().height-1,getSize().width-1,getSize().height-1);
		
	    //Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        	
	    if(mode==1){
		g.setColor(Color.red);
		g.fillOval(8,5,8,8);
		g.setColor(Color.green);
		g.fillOval(8,44*getSize().height/100,8,8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(8,82*getSize().height/100,8,8);	
    	    }
	    if(mode==2){
		g.setColor(Color.yellow);
		g.fillOval(8,5,8,8);
		//g.setColor(Color.blue);
                g.setColor(new Color(0,150,255));
		g.fillOval(8,44*getSize().height/100,8,8);
		g.setColor(Color.green);
		g.fillOval(8,82*getSize().height/100,8,8);
	    }
		
            g.setColor(Color.black);
            g.drawOval(8,5,8,8);
            g.drawOval(8,44*getSize().height/100,8,8);
            g.drawOval(8,82*getSize().height/100,8,8);
                
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
		*/
               
	}
	public void setZL(Complex ZL){
		//Complex GammaL;
		this.ZL = ZL;
                if(mode==1){
		lab[0].setText("z");
		
		if(Complex.Real(ZL)==0.0&&Complex.Imaginary(ZL)<-1.0e130){
		    vlab[0].setText("=   \u221e ");}
		else{
		    vlab[0].setText("=   "+ZL.toString(Complex.CARTESIAN,5));}
		}
		
		else{
		lab[0].setText("y");
		
		if(Complex.Real(ZL)==0.0 && Complex.Imaginary(ZL)==0.0){
		    vlab[0].setText("=   \u221e ");}
		else{
		vlab[0].setText("=   "+EMF.Inv(ZL).toString(Complex.CARTESIAN,5));}
		}
		GammaL=EMF.computeGamma(ZL);
		vlab[1].setText("=   "+GammaL.toString(Complex.POLAR_DEGREE,5));
                repaint();
	}
	public void setZL(Complex ZL, double Z0){
		setZL(Complex.Divide(ZL,Z0));
	}
	public void setZL(Complex ZL, Complex Z0){
		setZL(Complex.Divide(ZL,Z0));
	}
	
	public void setYL(Complex YL){
		//Complex GammaL;
                this.YL = YL;
		if(mode==1){
		lab[0].setText("z");
		
		if(Complex.Real(YL)==0.0&&Complex.Imaginary(YL)==0.0){
		    vlab[0].setText("=   \u221e ");}
		else{
		vlab[0].setText("=   "+EMF.Inv(YL).toString(Complex.CARTESIAN,5));}
		
		}
		else{
		lab[0].setText("y");
		
		if(Complex.Real(YL)==0.0&&Complex.Imaginary(YL)<-1.0e130){
		    vlab[0].setText("=   \u221e ");}
		else{
		vlab[0].setText("=   "+YL.toString(Complex.CARTESIAN,5));}
		}
		GammaL=EMF.computeGamma(YL,false);
		vlab[1].setText("=   "+GammaL.toString(Complex.POLAR_DEGREE,5));
                repaint();
	}
	
	public void setYL(Complex YL, double Z0){
		setYL(Complex.Multiply(YL,Z0));
	}
	
	public void setYL(Complex YL, Complex Z0){
		setYL(Complex.Divide(YL,Z0));
	}
	
	public void setZin(Complex Zin){
		//Complex GammaIn, Yin;
                this.Zin = Zin;
		if(mode==1){
		    lab[4].setText("y (d)");
		    lab[2].setText("z (d)");
		    if((Complex.Real(Zin)==0.0||Complex.Real(Zin)<-1.E130)&&Complex.Imaginary(Zin)<-1.E130)
			    {vlab[2].setText("=   \u221e");}
		    else{vlab[2].setText("=   "+Zin.toString(Complex.CARTESIAN,5));}
		
		    Yin = EMF.Inv(Zin);
		    GammaIn = EMF.computeGamma(Zin);
		    vlab[3].setText("=   "+GammaIn.toString(Complex.POLAR_DEGREE,5));
		
			if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.E130)
			{vlab[4].setText("=   \u221e");}
		    else{
		    vlab[4].setText("=   "+Yin.toString(Complex.CARTESIAN,5));
		    }
		}
		else{
		    lab[2].setText("y (d)");
		    lab[4].setText("z (d)");
		    if((Complex.Real(Zin)==0.0||Complex.Real(Zin)<1.0E-130)&&Complex.Imaginary(Zin)<-1.E130)
			    {vlab[4].setText("=   \u221e");}
		    else{vlab[4].setText("=   "+Zin.toString(Complex.CARTESIAN,5));}
		
		    Yin = EMF.Inv(Zin);
		    GammaIn = EMF.computeGamma(Zin);
		    vlab[3].setText("=   "+GammaIn.toString(Complex.POLAR_DEGREE,5));
		
		    if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.E130)
			{vlab[2].setText("=   \u221e");}
		    else{
			vlab[2].setText("=   "+Yin.toString(Complex.CARTESIAN,5));
		    }
		}
                repaint();
	}
	
	public void setZin(Complex Zin, double Z0){
		setZin(Complex.Divide(Zin,Z0));
	}
	public void setZin(Complex Zin, Complex Z0){
		setZin(Complex.Divide(Zin,Z0));
	}
	public void setYin(Complex Yin){
		//Complex GammaIn, Zin;
                this.Yin = Yin;
		if(mode==1){
		    lab[4].setText("y (d)");
		    lab[2].setText("z (d)");
		
		    if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.E130)
			    {vlab[4].setText("=   \u221e");}
		    else{vlab[4].setText("=   "+Yin.toString(Complex.CARTESIAN,5));}
		
		    Zin = EMF.Inv(Yin);
		    GammaIn = EMF.computeGamma(Zin);
		    vlab[3].setText("=   "+GammaIn.toString(Complex.POLAR_DEGREE,5));
		    if((Complex.Real(Zin)==0.0||Complex.Real(Zin)<-1.0E130)&&Complex.Imaginary(Zin)<-1.E130)
			{vlab[2].setText("=   \u221e");}
		    else{vlab[2].setText("=   "+Zin.toString(Complex.CARTESIAN,5));}
		}
		else{
		    lab[2].setText("y (d)");
		    lab[4].setText("z (d)");
		
		    if(Complex.Real(Yin)==0.0&&Complex.Imaginary(Yin)<-1.E130)
			    {vlab[2].setText("=   \u221e");}
		    else{vlab[2].setText("=   "+Yin.toString(Complex.CARTESIAN,5));}
		
		    Zin = EMF.Inv(Yin);
		    GammaIn = EMF.computeGamma(Zin);
		    vlab[3].setText("=   "+GammaIn.toString(Complex.POLAR_DEGREE,5));
		    if((Complex.Real(Zin)==0.0||Complex.Real(Zin)<-1.0E130)&&Complex.Imaginary(Zin)<-1.E130)
			{vlab[4].setText("=   \u221e");}
		    else{vlab[4].setText("=   "+Zin.toString(Complex.CARTESIAN,5));}
		}
                repaint();
	}
	
	public void setYin(Complex Yin, double Z0){
		setYin(Complex.Divide(Yin,Z0));
	}
	
	public void setYin(Complex Yin, Complex Z0){
		setYin(Complex.Divide(Yin,Z0));
	}
	public synchronized void setMode(int mode){
		this.mode=mode;
	}
}//End of SmithMan	


/**********************************************************************************/
class SmithProbe2  extends Panel{
Label[] lab;
private int mode;
//private final Color bcolor = new Color(216,216,191);
private final Color bcolor = new Color(236,236,236);
SmithProbe2(int width, int height){
	super();
	setLayout(null);
	setBackground(bcolor);
	Font labfont = new Font("SanSerif",Font.PLAIN,11);
	Panel p = new Panel();
	p.setLayout(new GridLayout(2,1));
	lab = new Label[2];
	lab[0] = new Label(" ",Label.LEFT);
	lab[1] = new Label(" ",Label.LEFT);
	lab[0].setFont(labfont);
	lab[1].setFont(labfont);
	p.add(lab[0]);
	p.add(lab[1]);
	add(p);
	p.setBounds(20,1,width-17,height-1);	
	mode=2;
}

public void paint(Graphics g){
	int width=getSize().width;
	int height=getSize().height;
	
	g.setColor(bcolor);
	g.fillRect(1,1,width-2,height-2);
	draw_icon(g);
}

public void update(Graphics g){
	draw_icon(g);
}

public void setxpos(double xpos){
	double txpos=xpos;
	if(xpos<=0.5){
	    lab[0].setText("d = "+MaestroA.rounder(txpos,4)+"\u03bb  \u00a6  2\u03b2 d = "+MaestroA.rounder(txpos*4*Math.PI,4)+" rad = "+MaestroA.rounder(txpos*4*180,4)+"\u00ba");
	    lab[1].setText("0.5\u03bb-d = "+MaestroA.rounder((0.5-txpos),4)+"\u03bb \u00a6  2\u03b2 (0.5\u03bb-d) = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,4)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,4)+"\u00ba");
	    repaint();
	}
	else{
	    while(txpos>0.5) {txpos-=0.5;}
	    lab[0].setText("d' = "+MaestroA.rounder(txpos,4)+"\u03bb  \u00a6  2\u03b2 d' = "+MaestroA.rounder(txpos*4*Math.PI,4)+" rad = "+MaestroA.rounder(txpos*4*180,4)+"\u00ba");
	    lab[1].setText("0.5\u03bb-d' = "+MaestroA.rounder((0.5-txpos),4)+"\u03bb \u00a6 2\u03b2 (0.5\u03bb-d') = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,4)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,4)+"\u00ba");
	    repaint();
	}
		
	/*
	while(txpos>0.5) {txpos-=0.5;}
	lab[0].setText("d = "+MaestroA.rounder(txpos,5)+" \u03bb  \u00a6  2\u03b2d = "+MaestroA.rounder(txpos*4*Math.PI,3)+" rad = "+MaestroA.rounder(txpos*4*180,3)+"\u00ba");
	lab[1].setText("0.5\u03bb-d = "+MaestroA.rounder((0.5-txpos),5)+" \u03bb  \u00a6  2\u03b2(0.5\u03bb-d) = "+MaestroA.rounder((0.5-txpos)*4*Math.PI,3)+" rad = "+MaestroA.rounder((0.5-txpos)*4*180,3)+"\u00ba");
	repaint();
	*/
}


public void set(String str1, String str2){
	lab[0].setText(str1);
	lab[1].setText(str2);
}

private void draw_icon(Graphics g){
	g.clipRect(2,2,getSize().width/4,getSize().height-2);
	if(mode==1){
		g.setColor(bcolor);
		g.fillRect(1,5,20,25);
		FontMetrics fm = g.getFontMetrics();
		                
                double sep, sep2, height;
                
                sep = 5.0; height = 12.0;
                Color newred = new Color(250,0,0);
                MaestroG.drawArcThick(g,5.0,sep,height,40.0,180.0,3,newred);

		sep = 22.0; height = 12.0;
                Color newgreen = new Color(0,220,0);
                MaestroG.drawArcThick(g,5.0,sep,height,40.0,180.0,3,newgreen);

	}
	else if(mode==2){
		int x= 10;
		int y=10;
		//int x=15, y=getSize().height/2;
		g.setColor(bcolor);
		g.fillRect(1,1,20,40);
		SmithCanvas.plot_red_cross(g,x,y);
	}
	else{
		g.setColor(bcolor);
		g.fillRect(1,1,20,40);
	}
	g.dispose();
}

public synchronized void setmode(int mode){
	this.mode=mode;
	repaint();
}
		
}//End of SmithProbe

/******************************************************************************************/

class SmithControls2 extends Panel{
public Checkbox imp, adm;
public CheckboxGroup cgrid;
public Checkbox swr, swrline;

private static final Color bgcolor = new Color(236,236,236);
SmithControls2(){
	setLayout(new GridLayout(2,2));
	cgrid = new CheckboxGroup();

	imp = new Checkbox("Impedance Grid",cgrid,true);
	adm = new Checkbox("Admittance Grid",cgrid,false);
	
	swr = new Checkbox("SWR Circle",null,true);
	swrline = new Checkbox("Cursor Line",null,true);
		
	add(imp);
	add(adm);
	
	add(swr);
	add(swrline);
	
	imp.setBackground(bgcolor);
	adm.setBackground(bgcolor);
	swr.setBackground(bgcolor);
	swrline.setBackground(bgcolor);
}
public void paint(Graphics g){
		
}

}//End of SmithControls;
