//Trans_State.java
//Transmission line with three stubs.

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.applet.*;
import java.awt.font.*;
import java.net.URL;
import java.text.*;
import java.util.Map;
import java.util.Hashtable;
import java.util.jar.Attributes;


public class Trans_State{
    public double xpos;
    public double lineLength, xmesh;
    public double frequency;
    public double epsilon_r,mu_r;
    public double lineZ0, Vg, Rg, VScale, IScale, PScale, VScaleFlag, IScaleFlag, PScaleFlag;
    
    public Complex ZL, maximum1;
    public Complex YL, maximum2;
    public double Capacitance, Resistance, Conductance, xratio, T_c, RiseTime, FiftyPerCentDelay, Delay, Delay2;
    //public Generator generator;
    public double Pw[],ReflectionGenerator, TransmissionGenerator, T_period, velocity_phase, Vtplus,Itplus, DeltaT;
    public Stub stub[];
    public CircuitCanvas ccan;
    public boolean is_Load_Ztype, SwitchIsOpen, IsStepOn, Is_Millimeter, IsTransient1;
    //Plot Parameters
    Complex Voltage[], Current[], Impedance[], Admittance[];
    double GammaLoad, GammaInput, Vdivider, Idivider, Vold, Iold, Pold, Vnew, Inew, Vold2, Vnew2, Iold2, Inew2;
    public double Time_Voltage[], Time_Current[], Time_Power[], Vinfinity, Iinfinity, Pinfinity;
    double x[];
    double y1[];
    double y2[];
    double y2V[];
    double y2I[];
    double yclean[];
    public static final int NPoints=541;
    public int NTime, NTime2, ctime, reset, dtime, ilocation;
    Complex timeFactor; //jwt is the time factor.
    
    private static final Complex one = new Complex(1.0,0.0);
    private static final double epsilon0 = 8.8541878176E-12; // Units: F/m // exact value
    private static final double mu0 = 1.25663706144E-6; //      Units H/m
    //private static final double light_velocity = Math.sqrt(1.0/(epsilon0*mu0)); //  Units m/s
    private static final double light_velocity = 3.0E8; //  Units m/s - approximate value for textbook
    public static final double mil_factor = 0.0254; // 1 mil = 0.0254 mm
    
    public boolean LicenseExpired, OptionOne, OptionTwo, OptionThree, OptionFour;
    
    public int this_month, today_week, this_year, this_hour, this_minute, today_month, 
	       today_year,this_zone, saving_time;
	       
    GregorianCalendar Greg = new GregorianCalendar();
    
    public Font ttfFont, sanSerifFont, serifFont, symbolFont, italicFont;
    
    public Trans_State(){ //main constructor
	
	frequency=1.0;
	epsilon_r=1.0;
	mu_r=1.0;
	lineLength = 100.0;
	xmesh = lineLength* 1.0e-3 /(NPoints - 1);
	xpos = lineLength;
        
        lineZ0 = 50.0;
	YL = new Complex(0.01,00);
	ZL = new Complex(100,0.0);
	Capacitance = 1.0E-12; 
	Resistance = 100;
	Conductance = 0.01;
	Vg = 1.0;
	Rg = 200.0;
	
	is_Load_Ztype = true;
	SwitchIsOpen = true;
	IsStepOn = true;
	RiseTime = 0.5E-15;
	Is_Millimeter = true;
        IsTransient1 = true;
	
	VScaleFlag = 1.0;
	IScaleFlag = 1.0;
	PScaleFlag = 1.0;
	VScale = Vg;
	IScale = Vg/lineZ0;
	PScale = Vg*Vg/lineZ0;
	
	T_c = Capacitance * lineZ0;
	
    
	Voltage = new Complex[NPoints];
	Current = new Complex[NPoints];
	Impedance = new Complex[NPoints];
	Admittance = new Complex[NPoints];
	
	GammaLoad = (Resistance-lineZ0)/(Resistance+lineZ0);
	GammaInput = (Rg-lineZ0)/(Rg+lineZ0);
	Vdivider = Vg*lineZ0/(Rg+lineZ0);
	Idivider = Vg/(Rg+lineZ0);
	
	x = new double[NPoints];
	y1 = new double[NPoints];
	y2 = new double[NPoints];
        y2V = new double[NPoints];
	y2I = new double[NPoints];
	
	yclean = new double[NPoints];
	Time_Voltage = new double[NPoints];
	Time_Current = new double[NPoints];
	Time_Power = new double[NPoints];
	ilocation = NPoints-1;
	
	NTime=360;
        NTime2=2*NTime;
        
        OptionOne = true;
        OptionTwo = false;
        OptionThree = false;
        OptionFour = false;
        
	velocity_phase = light_velocity/Math.sqrt(epsilon_r);
	T_period = lineLength*1.0e-3/velocity_phase;
	
	FiftyPerCentDelay = T_period - T_c*Math.log(0.5);
	Delay = FiftyPerCentDelay/(3.0*T_period);
	
	xratio = xmesh/velocity_phase;
	ctime=0;
        reset = 0;
	DeltaT = T_period/NTime;
	dtime=10;
	
	timeFactor = new Complex(Math.cos(2.0*Math.PI*ctime/NTime),
				 Math.sin(2.0*Math.PI*ctime/NTime));
	
	for(int i = 0; i < NPoints; i++){
	    yclean[i] = 0;
	}
	Vnew = Vdivider;
	Inew = Idivider;
	Vold = 0.0;
	Iold = 0.0;
	Pold = 0.0;
	Vold2 = 0.0;
	Vnew2 = 0.0;
	Iold2 = 0.0;
	Inew2 = 0.0;
	
	Vinfinity = Vg*Resistance/(Rg + Resistance);
	Iinfinity = Vg/(Rg + Resistance);
	Pinfinity = Vinfinity*Iinfinity;
	
	this_month = Greg.get(Calendar.MONTH);
	//System.out.println("  This is the month = "+this_month);
	today_week = Greg.get(Calendar.DAY_OF_WEEK);
	//System.out.println("  This is the day_week = "+today_week);
	this_year = Greg.get(Calendar.YEAR);
	this_hour = Greg.get(Calendar.HOUR_OF_DAY);
	//System.out.println("  This is the year = "+this_year);
	this_minute = Greg.get(Calendar.MINUTE);
	//System.out.println("  This is the minute = "+this_minute);
	today_month = Greg.get(Calendar.DAY_OF_MONTH);
	//System.out.println("  This is the day_month = "+today_month);
	today_year = Greg.get(Calendar.DAY_OF_YEAR);
	//System.out.println("  This is the day_year = "+today_year);
	this_zone = Greg.get(Calendar.ZONE_OFFSET);
	//System.out.println("  This is the zone_offset = "+this_zone/3600000);
	saving_time = Greg.get(Calendar.DST_OFFSET);
	//System.out.println("  This is the dst_offset = "+saving_time/3600000);

	
	ignition();
    }
    
    public synchronized void ignition(){
	    double tolerance = 0.0001;
	    xmesh = lineLength* 1.0e-3 /(NPoints - 1);
	    velocity_phase = light_velocity/Math.sqrt(epsilon_r);
	    T_period = lineLength*1.0e-3/velocity_phase;
	    T_c = Capacitance * lineZ0;
	    xratio = xmesh/velocity_phase;
	    DeltaT = T_period/NTime;
	    //System.out.println("DeltaT = "+DeltaT+"   Tperiod = "+T_period);
	    GammaInput = (Rg-lineZ0)/(Rg+lineZ0);
	    Vdivider = Vg*lineZ0/(Rg+lineZ0);
	    Idivider = Vg/(Rg+lineZ0);
	    
	    
	    if(is_Load_Ztype){
		GammaLoad = (Resistance-lineZ0)/(Resistance+lineZ0);
		Vinfinity = Vg*Resistance/(Rg + Resistance);
		Iinfinity = Vg/(Rg + Resistance);
		Pinfinity = Vinfinity*Iinfinity;	
	    }
	    else{
		GammaLoad = (1.0 - (lineZ0 * Conductance))/(1.0 + (lineZ0 * Conductance));
		Vinfinity = Vg/(1.0+ Rg * Conductance);
		Iinfinity = Vg*Conductance/(1.0+ Rg * Conductance);
		Pinfinity = Vinfinity*Iinfinity;	
	    }
	    
	    if(Vdivider >  2.0 *Vinfinity){
		VScale = Vinfinity;
		VScaleFlag = 2.0;
	    }
	    else{
		VScale = Vinfinity;
		VScaleFlag = 1.0;
	    }
	    
	    if((Idivider) >  2.0 *Iinfinity){
		IScale = Iinfinity;
		IScaleFlag = 2.0;
	    }
	    else{
		IScale = Iinfinity;
		IScaleFlag = 1.0;
	    }
	    
	    if((Vdivider*Vdivider/lineZ0) >  2.0 *Pinfinity){
		PScale = Pinfinity;
		PScaleFlag = 2.0;
	    }
	    else{
		PScale = Vinfinity*Iinfinity;
		PScaleFlag = 1.0;
	    }
	    
	    
	if(is_Load_Ztype){
		ZL = new Complex(Resistance,0.0);
		Conductance = 1.0/Resistance;
		YL = new Complex(Conductance,0.0);
	}
	else{	
		YL = new Complex(Conductance,0.0);
		Resistance = 1.0/Conductance;
		ZL = new Complex(Resistance,0.0);
	}	
	
	    ilocation = (int)((lineLength - xpos)/lineLength*(NPoints-1));
	    //System.out.println("Vinf = "+Vinfinity+"    Iinf = "+Iinfinity+"    Pinf = "+Pinfinity);
    }
    
    public synchronized void increment(){
	ctime+=dtime;
        reset+=dtime;
        if(reset>720){reset -= 720;}
	//if(ctime>NTime){ ctime -= NTime; }
    }
    
    public synchronized void reset(){
	ctime = 0;
        reset = 0;
    }
    
    public synchronized void setRiseTime(double RiseTime){
	this.RiseTime = RiseTime;
    }
    
    public void ScanTimeVoltage(){
	
	double Total_Time, timeFactor1, timeFactor2, 
	       V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,
	       DV1,DV2,DV3,DV4,DV5,DV6,DV7,DV8,DV9,DV10,DV11,DV12,
	       T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
	       T1_P, T2_P, T3_P, T4_P, T5_P, T6_P, T7_P, T8_P, T9_P, T10_P, T11_P, T12_P,
	       Vplot1, Vplot2;
	int index1, index2;
	
	Vplot1 = 0.0;
	Vplot2 = 0.0;
	
	if(IsStepOn){
	
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * DeltaT;
	    } 
	    DV1 = 0.0;
	    DV2 = Vdivider * GammaLoad;
	    DV3 = DV2 * GammaInput;
	    DV4 = DV3 * GammaLoad;
	    DV5 = DV4 * GammaInput;
	    DV6 = DV5 * GammaLoad;
	    DV7 = DV6 * GammaInput;
	    DV8 = DV7 * GammaLoad;
	    DV9 = DV8 * GammaInput;
	    DV10 = DV9 * GammaLoad;
	    DV11 = DV10 * GammaInput;
	    DV12 = DV11 * GammaLoad;
	    
	    V1 = Vdivider + DV1;
	    V2 = V1 + DV2;
	    V3 = V2 + DV3;
	    V4 = V3 + DV4;
	    V5 = V4 + DV5;
	    V6 = V5 + DV6;
	    V7 = V6 + DV7;
	    V8 = V7 + DV8;
	    V9 = V8 + DV9;
	    V10 = V9 + DV10;
	    V11 = V10 + DV11;
	    V12 = V11 + DV12;
	    
	    for(int i = 0; i < NPoints; i++){
		index1 = NPoints - 0 - 1; //0 is position index
		index2 = ilocation;
	    
		Total_Time = i*8.0*DeltaT;
		
		//LOAD		
		T1 = T_period;
		T2 = 3.0*T_period;
		T3 = 5.0*T_period;
		T4 = 7.0*T_period;
		T5 = 9.0*T_period;
		T6 = 11.0*T_period;
		T7 = 13.0*T_period;
		
				
		if(Total_Time <= T_period){ 
		   Vplot1 = 0.0;
		}
		
		else if(Total_Time > T_period && Total_Time <= T2){
		    Vplot1 = V2;
		}
		else if(Total_Time > T2 && Total_Time <= T3){
		    Vplot1 = V4;
		}
		else if(Total_Time > T3 && Total_Time <= T4){
		    Vplot1 = V6;
		}
		else if(Total_Time > T4 && Total_Time <= T5){
		    Vplot1 = V8;
		}
		else if(Total_Time > T5 && Total_Time <= T6){
		    Vplot1 = V10;
		}
		else if(Total_Time > T6 && Total_Time <= T7){
		    Vplot1 = V12;
		}
		
		y1[NPoints - i-1] = Vplot1;
		
                //CURSOR
		if(index1 == index2){
                    y2[NPoints - i-1] = y1[NPoints - i-1]; 
                }
                else{
                    timeFactor1 = index2*xratio;
                    timeFactor2 = T_period - timeFactor1;

                    T1 = 2.0*timeFactor2;
                    T2 = timeFactor1 + T1;
                    T3 = T2 + 2.0*timeFactor1;
                    T4 = T3 + 2.0*timeFactor2;
                    T5 = T4 + 2.0*timeFactor1;
                    T6 = T5 + 2.0*timeFactor2;
                    T7 = T6 + 2.0*timeFactor1;
                    T8 = T7 + 2.0*timeFactor2;
                    T9 = T8 + 2.0*timeFactor1;
                    T10 = T9 + 2.0*timeFactor2;
                    T11 = T10 + 2.0*timeFactor1;
                    T12 = T11 + 2.0*timeFactor2;

                    if(Total_Time < timeFactor1){ 
                       Vplot1 = 0.0;
                    }
                    else if(Total_Time >= timeFactor1 && Total_Time < T2){
                        Vplot1 = V1;
                    }
                    else if(Total_Time >= T2 && Total_Time < T3){
                        Vplot1 = V2;
                    }
                    else if(Total_Time >= T3 && Total_Time < T4){
                        Vplot1 = V3;
                    }
                    else if(Total_Time >= T4 && Total_Time < T5){
                        Vplot1 = V4;
                    }
                    else if(Total_Time >= T5 && Total_Time < T6){
                        Vplot1 = V5;
                    }
                    else if(Total_Time >= T6 && Total_Time < T7){
                        Vplot1 = V6;
                    }
                    else if(Total_Time >= T7 && Total_Time < T8){
                        Vplot1 = V7;
                    }
                    else if(Total_Time >= T8 && Total_Time < T9){
                        Vplot1 = V8;
                    }
                    else if(Total_Time >= T9 && Total_Time < T10){
                        Vplot1 = V9;
                    }
                    else if(Total_Time >= T10 && Total_Time < T11){
                        Vplot1 = V10;
                    }
                    else if(Total_Time >= T11 && Total_Time < T12){
                        Vplot1 = V11;
                    }
                    else if(Total_Time >= T12){
                        Vplot1 = V12;
                    }

                    y2[NPoints - i-1] = Vplot1;
                    y2V[NPoints - i-1] = Vplot1;
                }
	    }
	}
	else{//input is a pulse
	
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * DeltaT;
	    } 
	    DV1 = 0.0;
	    DV2 = Vdivider * GammaLoad;
	    DV3 = DV2 * GammaInput;
	    DV4 = DV3 * GammaLoad;
	    DV5 = DV4 * GammaInput;
	    DV6 = DV5 * GammaLoad;
	    DV7 = DV6 * GammaInput;
	    DV8 = DV7 * GammaLoad;
	    DV9 = DV8 * GammaInput;
	    DV10 = DV9 * GammaLoad;
	    DV11 = DV10 * GammaInput;
	    DV12 = DV11 * GammaLoad;
	    
	    V1 = Vdivider + DV1;
	    V2 = V1 + DV2;
	    V3 = V2 + DV3;
	    V4 = V3 + DV4;
	    V5 = V4 + DV5;
	    V6 = V5 + DV6;
	    V7 = V6 + DV7;
	    V8 = V7 + DV8;
	    V9 = V8 + DV9;
	    V10 = V9 + DV10;
	    V11 = V10 + DV11;
	    V12 = V11 + DV12;
	    
	    for(int i = 0; i < NPoints; i++){
		index1 = NPoints - 0 - 1; //0 is position index
		index2 = ilocation;
	    
		Total_Time = i*8.0*DeltaT;
		
		//LOAD		
		T1 = T_period;
		T2 = 3.0*T_period;
		T3 = 5.0*T_period;
		T4 = 7.0*T_period;
		T5 = 9.0*T_period;
		T6 = 11.0*T_period;
		T7 = 13.0*T_period;
		
		T1_P = T_period+RiseTime;
		T2_P = 3.0*T_period+RiseTime;
		T3_P = 5.0*T_period+RiseTime;
		T4_P = 7.0*T_period+RiseTime;
		T5_P = 9.0*T_period+RiseTime;
		T6_P = 11.0*T_period+RiseTime;
		T7_P = 13.0*T_period+RiseTime;
		
				
		if(Total_Time <= T_period){ 
		   Vplot1 = 0.0;
		}
		
		else if(Total_Time > T_period && Total_Time <= T2){
		    Vplot1 = V2;
		}
		else if(Total_Time > T2 && Total_Time <= T3){
		    Vplot1 = V4;
		}
		else if(Total_Time > T3 && Total_Time <= T4){
		    Vplot1 = V6;
		}
		else if(Total_Time > T4 && Total_Time <= T5){
		    Vplot1 = V8;
		}
		else if(Total_Time > T5 && Total_Time <= T6){
		    Vplot1 = V10;
		}
		else if(Total_Time > T6 && Total_Time <= T7){
		    Vplot1 = V12;
		}
		
		if(Total_Time <= T1_P){ 
		   Vplot2 = 0.0;
		}
		
		else if(Total_Time > T1_P && Total_Time <= T2_P){
		    Vplot2 = -V2;
		}
		else if(Total_Time > T2_P && Total_Time <= T3_P){
		    Vplot2 = -V4;
		}
		else if(Total_Time > T3_P && Total_Time <= T4_P){
		    Vplot2 = -V6;
		}
		else if(Total_Time > T4_P && Total_Time <= T5_P){
		    Vplot2 = -V8;
		}
		else if(Total_Time > T5_P && Total_Time <= T6_P){
		    Vplot2 = -V10;
		}
		else if(Total_Time > T6_P && Total_Time <= T7_P){
		    Vplot2 = -V12;
		}
		
		y1[NPoints - i-1] = Vplot1 + Vplot2;
		
		//CURSOR
		if(index1 == index2){
                    y2[NPoints - i-1] = y1[NPoints - i-1]; 
                }
                else{
                    timeFactor1 = index2*xratio;
                    timeFactor2 = T_period - timeFactor1;

                    T1 = 2.0*timeFactor2;
                    T2 = timeFactor1 + T1;
                    T3 = T2 + 2.0*timeFactor1;
                    T4 = T3 + 2.0*timeFactor2;
                    T5 = T4 + 2.0*timeFactor1;
                    T6 = T5 + 2.0*timeFactor2;
                    T7 = T6 + 2.0*timeFactor1;
                    T8 = T7 + 2.0*timeFactor2;
                    T9 = T8 + 2.0*timeFactor1;
                    T10 = T9 + 2.0*timeFactor2;
                    T11 = T10 + 2.0*timeFactor1;
                    T12 = T11 + 2.0*timeFactor2;

                    T1_P = 2.0*timeFactor2 + RiseTime;
                    T2_P = timeFactor1 + T1 + RiseTime;
                    T3_P = T2 + 2.0*timeFactor1 + RiseTime;
                    T4_P = T3 + 2.0*timeFactor2 + RiseTime;
                    T5_P = T4 + 2.0*timeFactor1 + RiseTime;
                    T6_P = T5 + 2.0*timeFactor2 + RiseTime;
                    T7_P = T6 + 2.0*timeFactor1 + RiseTime;
                    T8_P = T7 + 2.0*timeFactor2 + RiseTime;
                    T9_P = T8 + 2.0*timeFactor1 + RiseTime;
                    T10_P = T9 + 2.0*timeFactor2 + RiseTime;
                    T11_P = T10 + 2.0*timeFactor1 + RiseTime;
                    T12_P = T11 + 2.0*timeFactor2 + RiseTime;

                    if(Total_Time < timeFactor1){ 
                       Vplot1 = 0.0;
                    }
                    else if(Total_Time >= timeFactor1 && Total_Time < T2){
                        Vplot1 = V1;
                    }
                    else if(Total_Time >= T2 && Total_Time < T3){
                        Vplot1 = V2;
                    }
                    else if(Total_Time >= T3 && Total_Time < T4){
                        Vplot1 = V3;
                    }
                    else if(Total_Time >= T4 && Total_Time < T5){
                        Vplot1 = V4;
                    }
                    else if(Total_Time >= T5 && Total_Time < T6){
                        Vplot1 = V5;
                    }
                    else if(Total_Time >= T6 && Total_Time < T7){
                        Vplot1 = V6;
                    }
                    else if(Total_Time >= T7 && Total_Time < T8){
                        Vplot1 = V7;
                    }
                    else if(Total_Time >= T8 && Total_Time < T9){
                        Vplot1 = V8;
                    }
                    else if(Total_Time >= T9 && Total_Time < T10){
                        Vplot1 = V9;
                    }
                    else if(Total_Time >= T10 && Total_Time < T11){
                        Vplot1 = V10;
                    }
                    else if(Total_Time >= T11 && Total_Time < T12){
                        Vplot1 = V11;
                    }
                    else if(Total_Time >= T12){
                        Vplot1 = V12;
                    }

                    if(Total_Time < timeFactor1+RiseTime){ 
                       Vplot2 = 0.0;
                    }
                    else if(Total_Time >= timeFactor1+RiseTime && Total_Time < T2_P){
                        Vplot2 = -V1;
                    }
                    else if(Total_Time >= T2_P && Total_Time < T3_P){
                        Vplot2 = -V2;
                    }
                    else if(Total_Time >= T3_P && Total_Time < T4_P){
                        Vplot2 = -V3;
                    }
                    else if(Total_Time >= T4_P && Total_Time < T5_P){
                        Vplot2 = -V4;
                    }
                    else if(Total_Time >= T5_P && Total_Time < T6_P){
                        Vplot2 = -V5;
                    }
                    else if(Total_Time >= T6_P && Total_Time < T7_P){
                        Vplot2 = -V6;
                    }
                    else if(Total_Time >= T7_P && Total_Time < T8_P){
                        Vplot2 = -V7;
                    }
                    else if(Total_Time >= T8_P && Total_Time < T9_P){
                        Vplot2 = -V8;
                    }
                    else if(Total_Time >= T9_P && Total_Time < T10_P){
                        Vplot2 = -V9;
                    }
                    else if(Total_Time >= T10_P && Total_Time < T11_P){
                        Vplot2 = -V10;
                    }
                    else if(Total_Time >= T11_P && Total_Time < T12_P){
                        Vplot2 = -V11;
                    }
                    else if(Total_Time >= T12){
                        Vplot2 = -V12;
                    }

                    y2[NPoints - i-1] = Vplot1 + Vplot2;
                    y2V[NPoints - i-1] = Vplot1 + Vplot2;
                }
	    }
	}
	    
    }
    
    public void ScanTimeCurrent(){ 
	
	double Total_Time, 
	       timeFactor1, timeFactor2, 
	       V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,
	       DV1,DV2,DV3,DV4,DV5,DV6,DV7,DV8,DV9,DV10,DV11,DV12,
	       T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
	       T1_P, T2_P, T3_P, T4_P, T5_P, T6_P, T7_P, T8_P, T9_P, T10_P, T11_P, T12_P,
	       Iplot1, Iplot2;
	int index1, index2;
	
	Iplot1 = 0.0;
	Iplot2 = 0.0;
	
	if(IsStepOn){
	
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * DeltaT;
	    } 
	    DV1 = 0.0;
	    DV2 = -Vdivider/lineZ0 * GammaLoad;
	    DV3 = -DV2 * GammaInput;
	    DV4 = -DV3 * GammaLoad;
	    DV5 = -DV4 * GammaInput;
	    DV6 = -DV5 * GammaLoad;
	    DV7 = -DV6 * GammaInput;
	    DV8 = -DV7 * GammaLoad;
	    DV9 = -DV8 * GammaInput;
	    DV10 = -DV9 * GammaLoad;
	    DV11 = -DV10 * GammaInput;
	    DV12 = -DV11 * GammaLoad;
	    
	    V1 = Vdivider/lineZ0 + DV1;
	    V2 = V1 + DV2;
	    V3 = V2 + DV3;
	    V4 = V3 + DV4;
	    V5 = V4 + DV5;
	    V6 = V5 + DV6;
	    V7 = V6 + DV7;
	    V8 = V7 + DV8;
	    V9 = V8 + DV9;
	    V10 = V9 + DV10;
	    V11 = V10 + DV11;
	    V12 = V11 + DV12;
	    
	    for(int i = 0; i < NPoints; i++){
		index1 = NPoints - 0 - 1; //0 is position index
		index2 = ilocation;
	    
		Total_Time = i*8.0*DeltaT;
		
		//LOAD		
		T1 = T_period;
		T2 = 3.0*T_period;
		T3 = 5.0*T_period;
		T4 = 7.0*T_period;
		T5 = 9.0*T_period;
		T6 = 11.0*T_period;
		T7 = 13.0*T_period;		
				
		if(Total_Time <= T_period){ 
		   Iplot1 = 0.0;
		}
		
		else if(Total_Time > T_period && Total_Time <= T2){
		    Iplot1 = V2;
		}
		else if(Total_Time > T2 && Total_Time <= T3){
		    Iplot1 = V4;
		}
		else if(Total_Time > T3 && Total_Time <= T4){
		    Iplot1 = V6;
		}
		else if(Total_Time > T4 && Total_Time <= T5){
		    Iplot1 = V8;
		}
		else if(Total_Time > T5 && Total_Time <= T6){
		    Iplot1 = V10;
		}
		else if(Total_Time > T6 && Total_Time <= T7){
		    Iplot1 = V12;
		}
		
		y1[NPoints - i-1] = Iplot1;
		
		//CURSOR
		if(index1 == index2){
                    y2[NPoints - i-1] = y1[NPoints - i-1]; 
                }
                else{
                    timeFactor1 = index2*xratio;
                    timeFactor2 = T_period - timeFactor1;

                    T1 = 2.0*timeFactor2;
                    T2 = timeFactor1 + T1;
                    T3 = T2 + 2.0*timeFactor1;
                    T4 = T3 + 2.0*timeFactor2;
                    T5 = T4 + 2.0*timeFactor1;
                    T6 = T5 + 2.0*timeFactor2;
                    T7 = T6 + 2.0*timeFactor1;
                    T8 = T7 + 2.0*timeFactor2;
                    T9 = T8 + 2.0*timeFactor1;
                    T10 = T9 + 2.0*timeFactor2;
                    T11 = T10 + 2.0*timeFactor1;
                    T12 = T11 + 2.0*timeFactor2;

                    if(Total_Time < timeFactor1){ 
                       Iplot1 = 0.0;
                    }
                    else if(Total_Time >= timeFactor1 && Total_Time < T2){
                        Iplot1 = V1;
                    }
                    else if(Total_Time >= T2 && Total_Time < T3){
                        Iplot1 = V2;
                    }
                    else if(Total_Time >= T3 && Total_Time < T4){
                        Iplot1 = V3;
                    }
                    else if(Total_Time >= T4 && Total_Time < T5){
                        Iplot1 = V4;
                    }
                    else if(Total_Time >= T5 && Total_Time < T6){
                        Iplot1 = V5;
                    }
                    else if(Total_Time >= T6 && Total_Time < T7){
                        Iplot1 = V6;
                    }
                    else if(Total_Time >= T7 && Total_Time < T8){
                        Iplot1 = V7;
                    }
                    else if(Total_Time >= T8 && Total_Time < T9){
                        Iplot1 = V8;
                    }
                    else if(Total_Time >= T9 && Total_Time < T10){
                        Iplot1 = V9;
                    }
                    else if(Total_Time >= T10 && Total_Time < T11){
                        Iplot1 = V10;
                    }
                    else if(Total_Time >= T11 && Total_Time < T12){
                        Iplot1 = V11;
                    }
                    else if(Total_Time >= T12){
                        Iplot1 = V12;
                    }

                    y2[NPoints - i-1] = Iplot1;
                    y2I[NPoints - i-1] = Iplot1;
                }
	    }
	}
	else{//input is a pulse
	
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * DeltaT;
	    } 
	    DV1 = 0.0;
	    DV2 = -Vdivider/lineZ0 * GammaLoad;
	    DV3 = -DV2 * GammaInput;
	    DV4 = -DV3 * GammaLoad;
	    DV5 = -DV4 * GammaInput;
	    DV6 = -DV5 * GammaLoad;
	    DV7 = -DV6 * GammaInput;
	    DV8 = -DV7 * GammaLoad;
	    DV9 = -DV8 * GammaInput;
	    DV10 = -DV9 * GammaLoad;
	    DV11 = -DV10 * GammaInput;
	    DV12 = -DV11 * GammaLoad;
	    
	    V1 = Vdivider/lineZ0 + DV1;
	    V2 = V1 + DV2;
	    V3 = V2 + DV3;
	    V4 = V3 + DV4;
	    V5 = V4 + DV5;
	    V6 = V5 + DV6;
	    V7 = V6 + DV7;
	    V8 = V7 + DV8;
	    V9 = V8 + DV9;
	    V10 = V9 + DV10;
	    V11 = V10 + DV11;
	    V12 = V11 + DV12;
	    
	    for(int i = 0; i < NPoints; i++){
		index1 = NPoints - 0 - 1; //0 is position index
		index2 = ilocation;
	    
		Total_Time = i*8.0*DeltaT;
		
		//LOAD		
		T1 = T_period;
		T2 = 3.0*T_period;
		T3 = 5.0*T_period;
		T4 = 7.0*T_period;
		T5 = 9.0*T_period;
		T6 = 11.0*T_period;
		T7 = 13.0*T_period;
		
		T1_P = T_period+RiseTime;
		T2_P = 3.0*T_period+RiseTime;
		T3_P = 5.0*T_period+RiseTime;
		T4_P = 7.0*T_period+RiseTime;
		T5_P = 9.0*T_period+RiseTime;
		T6_P = 11.0*T_period+RiseTime;
		T7_P = 13.0*T_period+RiseTime;
		

				
		if(Total_Time <= T_period){ 
		   Iplot1 = 0.0;
		}
		
		else if(Total_Time > T_period && Total_Time <= T2){
		    Iplot1 = V2;
		}
		else if(Total_Time > T2 && Total_Time <= T3){
		    Iplot1 = V4;
		}
		else if(Total_Time > T3 && Total_Time <= T4){
		    Iplot1 = V6;
		}
		else if(Total_Time > T4 && Total_Time <= T5){
		    Iplot1 = V8;
		}
		else if(Total_Time > T5 && Total_Time <= T6){
		    Iplot1 = V10;
		}
		else if(Total_Time > T6 && Total_Time <= T7){
		    Iplot1 = V12;
		}
		
		if(Total_Time <= T1_P){ 
		   Iplot2 = 0.0;
		}
		
		else if(Total_Time > T1_P && Total_Time <= T2_P){
		    Iplot2 = -V2;
		}
		else if(Total_Time > T2_P && Total_Time <= T3_P){
		    Iplot2 = -V4;
		}
		else if(Total_Time > T3_P && Total_Time <= T4_P){
		    Iplot2 = -V6;
		}
		else if(Total_Time > T4_P && Total_Time <= T5_P){
		    Iplot2 = -V8;
		}
		else if(Total_Time > T5_P && Total_Time <= T6_P){
		    Iplot2 = -V10;
		}
		else if(Total_Time > T6_P && Total_Time <= T7_P){
		    Iplot2 = -V12;
		}

		
		y1[NPoints - i-1] = Iplot1+Iplot2;
		
		//CURSOR
		if(index1 == index2){
                    y2[NPoints - i-1] = y1[NPoints - i-1]; 
                }
                else{
                    timeFactor1 = index2*xratio;
                    timeFactor2 = T_period - timeFactor1;

                    T1 = 2.0*timeFactor2;
                    T2 = timeFactor1 + T1;
                    T3 = T2 + 2.0*timeFactor1;
                    T4 = T3 + 2.0*timeFactor2;
                    T5 = T4 + 2.0*timeFactor1;
                    T6 = T5 + 2.0*timeFactor2;
                    T7 = T6 + 2.0*timeFactor1;
                    T8 = T7 + 2.0*timeFactor2;
                    T9 = T8 + 2.0*timeFactor1;
                    T10 = T9 + 2.0*timeFactor2;
                    T11 = T10 + 2.0*timeFactor1;
                    T12 = T11 + 2.0*timeFactor2;

                    T1_P = 2.0*timeFactor2 + RiseTime;
                    T2_P = timeFactor1 + T1 + RiseTime;
                    T3_P = T2 + 2.0*timeFactor1 + RiseTime;
                    T4_P = T3 + 2.0*timeFactor2 + RiseTime;
                    T5_P = T4 + 2.0*timeFactor1 + RiseTime;
                    T6_P = T5 + 2.0*timeFactor2 + RiseTime;
                    T7_P = T6 + 2.0*timeFactor1 + RiseTime;
                    T8_P = T7 + 2.0*timeFactor2 + RiseTime;
                    T9_P = T8 + 2.0*timeFactor1 + RiseTime;
                    T10_P = T9 + 2.0*timeFactor2 + RiseTime;
                    T11_P = T10 + 2.0*timeFactor1 + RiseTime;
                    T12_P = T11 + 2.0*timeFactor2 + RiseTime;


                    if(Total_Time < timeFactor1){ 
                       Iplot1 = 0.0;
                    }
                    else if(Total_Time >= timeFactor1 && Total_Time < T2){
                        Iplot1 = V1;
                    }
                    else if(Total_Time >= T2 && Total_Time < T3){
                        Iplot1 = V2;
                    }
                    else if(Total_Time >= T3 && Total_Time < T4){
                        Iplot1 = V3;
                    }
                    else if(Total_Time >= T4 && Total_Time < T5){
                        Iplot1 = V4;
                    }
                    else if(Total_Time >= T5 && Total_Time < T6){
                        Iplot1 = V5;
                    }
                    else if(Total_Time >= T6 && Total_Time < T7){
                        Iplot1 = V6;
                    }
                    else if(Total_Time >= T7 && Total_Time < T8){
                        Iplot1 = V7;
                    }
                    else if(Total_Time >= T8 && Total_Time < T9){
                        Iplot1 = V8;
                    }
                    else if(Total_Time >= T9 && Total_Time < T10){
                        Iplot1 = V9;
                    }
                    else if(Total_Time >= T10 && Total_Time < T11){
                        Iplot1 = V10;
                    }
                    else if(Total_Time >= T11 && Total_Time < T12){
                        Iplot1 = V11;
                    }
                    else if(Total_Time >= T12){
                        Iplot1 = V12;
                    }

                    if(Total_Time < timeFactor1+RiseTime){ 
                       Iplot2 = 0.0;
                    }
                    else if(Total_Time >= timeFactor1+RiseTime && Total_Time < T2_P){
                        Iplot2 = -V1;
                    }
                    else if(Total_Time >= T2_P && Total_Time < T3_P){
                        Iplot2 = -V2;
                    }
                    else if(Total_Time >= T3_P && Total_Time < T4_P){
                        Iplot2 = -V3;
                    }
                    else if(Total_Time >= T4_P && Total_Time < T5_P){
                        Iplot2 = -V4;
                    }
                    else if(Total_Time >= T5_P && Total_Time < T6_P){
                        Iplot2 = -V5;
                    }
                    else if(Total_Time >= T6_P && Total_Time < T7_P){
                        Iplot2 = -V6;
                    }
                    else if(Total_Time >= T7_P && Total_Time < T8_P){
                        Iplot2 = -V7;
                    }
                    else if(Total_Time >= T8_P && Total_Time < T9_P){
                        Iplot2 = -V8;
                    }
                    else if(Total_Time >= T9_P && Total_Time < T10_P){
                        Iplot2 = -V9;
                    }
                    else if(Total_Time >= T10_P && Total_Time < T11_P){
                        Iplot2 = -V10;
                    }
                    else if(Total_Time >= T11_P && Total_Time < T12_P){
                        Iplot2 = -V11;
                    }
                    else if(Total_Time >= T12){
                        Iplot2 = -V12;
                    }

                    y2[NPoints - i-1] = Iplot1+Iplot2;
                    y2V[NPoints - i-1] = Iplot1 + Iplot2;
                }
	    }  
	}	 

	  
    }
    
    public void ScanTimePower(){ 
	double Total_Time, 
	       timeFactor1, timeFactor2, 
	       V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,
	       I1,I2,I3,I4,I5,I6,I7,I8,I9,I10,I11,I12,
	       DV1,DV2,DV3,DV4,DV5,DV6,DV7,DV8,DV9,DV10,DV11,DV12,
	       DI1,DI2,DI3,DI4,DI5,DI6,DI7,DI8,DI9,DI10,DI11,DI12,
	       T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
	       T1_P, T2_P, T3_P, T4_P, T5_P, T6_P, T7_P, T8_P, T9_P, T10_P, T11_P, T12_P,
	       Pplot1, Pplot2, Pplot1b, Pplot2b;
	int index1, index2;
	
	Pplot1 = 0.0;
	Pplot2 = 0.0;
        Pplot1b = 0.0;
        Pplot2b = 0.0;
	
	if(IsStepOn){
	    
            ScanTimeVoltage();
            ScanTimeCurrent();
            
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * DeltaT;
	    } 
	    DV1 = 0.0;
	    DV2 = Vdivider * GammaLoad;
	    DV3 = DV2 * GammaInput;
	    DV4 = DV3 * GammaLoad;
	    DV5 = DV4 * GammaInput;
	    DV6 = DV5 * GammaLoad;
	    DV7 = DV6 * GammaInput;
	    DV8 = DV7 * GammaLoad;
	    DV9 = DV8 * GammaInput;
	    DV10 = DV9 * GammaLoad;
	    DV11 = DV10 * GammaInput;
	    DV12 = DV11 * GammaLoad;
	    
	    DI1 = 0.0;
	    DI2 = -Idivider * GammaLoad;
	    DI3 = -DI2 * GammaInput;
	    DI4 = -DI3 * GammaLoad;
	    DI5 = -DI4 * GammaInput;
	    DI6 = -DI5 * GammaLoad;
	    DI7 = -DI6 * GammaInput;
	    DI8 = -DI7 * GammaLoad;
	    DI9 = -DI8 * GammaInput;
	    DI10 = -DI9 * GammaLoad;
	    DI11 = -DI10 * GammaInput;
	    DI12 = -DI11 * GammaLoad;
	    
	    V1 = Vdivider + DV1;
	    V2 = V1 + DV2;
	    V3 = V2 + DV3;
	    V4 = V3 + DV4;
	    V5 = V4 + DV5;
	    V6 = V5 + DV6;
	    V7 = V6 + DV7;
	    V8 = V7 + DV8;
	    V9 = V8 + DV9;
	    V10 = V9 + DV10;
	    V11 = V10 + DV11;
	    V12 = V11 + DV12;
	    
	    I1 = Idivider + DI1;
	    I2 = I1 + DI2;
	    I3 = I2 + DI3;
	    I4 = I3 + DI4;
	    I5 = I4 + DI5;
	    I6 = I5 + DI6;
	    I7 = I6 + DI7;
	    I8 = I7 + DI8;
	    I9 = I8 + DI9;
	    I10 = I9 + DI10;
	    I11 = I10 + DI11;
	    I12 = I11 + DI12;
	   	    
	    for(int i = 0; i < NPoints; i++){
		index1 = NPoints - 0 - 1; //0 is position index
		index2 = ilocation;
	    
		Total_Time = i*8.0*DeltaT;
		
		//LOAD		
		T1 = T_period;
		T2 = 3.0*T_period;
		T3 = 5.0*T_period;
		T4 = 7.0*T_period;
		T5 = 9.0*T_period;
		T6 = 11.0*T_period;
		T7 = 13.0*T_period;
		
				
		if(Total_Time <= T_period){ 
		   Pplot1 = 0.0;
		}
		
		else if(Total_Time > T_period && Total_Time <= T2){
		    Pplot1 = V2;
                    Pplot1b = I2;
		}
		else if(Total_Time > T2 && Total_Time <= T3){
		    Pplot1 = V4;
                    Pplot1b = I4;
		}
		else if(Total_Time > T3 && Total_Time <= T4){
		    Pplot1 = V6;
                    Pplot1b = I6;
		}
		else if(Total_Time > T4 && Total_Time <= T5){
		    Pplot1 = V8;
                    Pplot1b = I8;
		}
		else if(Total_Time > T5 && Total_Time <= T6){
		    Pplot1 = V10;
                    Pplot1b = I10;
		}
		else if(Total_Time > T6 && Total_Time <= T7){
		    Pplot1 = V12;
                    Pplot1b = I12;
		}
		
		y1[NPoints - i-1] = Pplot1*Pplot1b;
		
		//CURSOR
		if(index1 == index2){
                    y2[NPoints - i-1] = y1[NPoints - i-1]; 
                }
                else{
                    timeFactor1 = index2*xratio;
                    timeFactor2 = T_period - timeFactor1;

                    T1 = 2.0*timeFactor2;
                    T2 = timeFactor1 + T1;
                    T3 = T2 + 2.0*timeFactor1;
                    T4 = T3 + 2.0*timeFactor2;
                    T5 = T4 + 2.0*timeFactor1;
                    T6 = T5 + 2.0*timeFactor2;
                    T7 = T6 + 2.0*timeFactor1;
                    T8 = T7 + 2.0*timeFactor2;
                    T9 = T8 + 2.0*timeFactor1;
                    T10 = T9 + 2.0*timeFactor2;
                    T11 = T10 + 2.0*timeFactor1;
                    T12 = T11 + 2.0*timeFactor2;


                    if(Total_Time < timeFactor1){ 
                       Pplot1 = 0.0;
                    }
                    else if(Total_Time >= timeFactor1 && Total_Time < T2){
                        Pplot1 = V1;
                        Pplot1b = I1;
                    }
                    else if(Total_Time >= T2 && Total_Time < T3){
                        Pplot1 = V2;
                        Pplot1b = I2;
                    }
                    else if(Total_Time >= T3 && Total_Time < T4){
                        Pplot1 = V3;
                        Pplot1b = I3;
                    }
                    else if(Total_Time >= T4 && Total_Time < T5){
                        Pplot1 = V4;
                        Pplot1b = I4;
                    }
                    else if(Total_Time >= T5 && Total_Time < T6){
                        Pplot1 = V5;
                        Pplot1b = I5;
                    }
                    else if(Total_Time >= T6 && Total_Time < T7){
                        Pplot1 = V6;
                        Pplot1b = I6;
                    }
                    else if(Total_Time >= T7 && Total_Time < T8){
                        Pplot1 = V7;
                        Pplot1b = I7;
                    }
                    else if(Total_Time >= T8 && Total_Time < T9){
                        Pplot1 = V8;
                        Pplot1b = I8;
                    }
                    else if(Total_Time >= T9 && Total_Time < T10){
                        Pplot1 = V9;
                        Pplot1b = I9;
                    }
                    else if(Total_Time >= T10 && Total_Time < T11){
                        Pplot1 = V10;
                        Pplot1b = I10;
                    }
                    else if(Total_Time >= T11 && Total_Time < T12){
                        Pplot1 = V11;
                        Pplot1b = I11;
                    }
                    else if(Total_Time >= T12){
                        Pplot1 = V12;
                        Pplot1b = I12;
                    }

                    y2[NPoints - i-1] = Pplot1*Pplot1b;
                    
                }
	    }
	}
	else{//Pulse
	   
	    ScanTimeVoltage();
            ScanTimeCurrent();
            
            for(int i = 0; i < NPoints; i++){
		x[i] = i * DeltaT;
	    } 
	    DV1 = 0.0;
	    DV2 = Vdivider * GammaLoad;
	    DV3 = DV2 * GammaInput;
	    DV4 = DV3 * GammaLoad;
	    DV5 = DV4 * GammaInput;
	    DV6 = DV5 * GammaLoad;
	    DV7 = DV6 * GammaInput;
	    DV8 = DV7 * GammaLoad;
	    DV9 = DV8 * GammaInput;
	    DV10 = DV9 * GammaLoad;
	    DV11 = DV10 * GammaInput;
	    DV12 = DV11 * GammaLoad;
	    
	    DI1 = 0.0;
	    DI2 = -Idivider * GammaLoad;
	    DI3 = -DI2 * GammaInput;
	    DI4 = -DI3 * GammaLoad;
	    DI5 = -DI4 * GammaInput;
	    DI6 = -DI5 * GammaLoad;
	    DI7 = -DI6 * GammaInput;
	    DI8 = -DI7 * GammaLoad;
	    DI9 = -DI8 * GammaInput;
	    DI10 = -DI9 * GammaLoad;
	    DI11 = -DI10 * GammaInput;
	    DI12 = -DI11 * GammaLoad;
	    
	    V1 = Vdivider + DV1;
	    V2 = V1 + DV2;
	    V3 = V2 + DV3;
	    V4 = V3 + DV4;
	    V5 = V4 + DV5;
	    V6 = V5 + DV6;
	    V7 = V6 + DV7;
	    V8 = V7 + DV8;
	    V9 = V8 + DV9;
	    V10 = V9 + DV10;
	    V11 = V10 + DV11;
	    V12 = V11 + DV12;
	    
	    I1 = Idivider + DI1;
	    I2 = I1 + DI2;
	    I3 = I2 + DI3;
	    I4 = I3 + DI4;
	    I5 = I4 + DI5;
	    I6 = I5 + DI6;
	    I7 = I6 + DI7;
	    I8 = I7 + DI8;
	    I9 = I8 + DI9;
	    I10 = I9 + DI10;
	    I11 = I10 + DI11;
	    I12 = I11 + DI12;
	    
	    
	    for(int i = 0; i < NPoints; i++){
		index1 = NPoints - 0 - 1; //0 is position index
		index2 = ilocation;
	    
		Total_Time = i*8.0*DeltaT;
		
		//LOAD		
		T1 = T_period;
		T2 = 3.0*T_period;
		T3 = 5.0*T_period;
		T4 = 7.0*T_period;
		T5 = 9.0*T_period;
		T6 = 11.0*T_period;
		T7 = 13.0*T_period;
		
		T1_P = T_period+RiseTime;
		T2_P = 3.0*T_period+RiseTime;
		T3_P = 5.0*T_period+RiseTime;
		T4_P = 7.0*T_period+RiseTime;
		T5_P = 9.0*T_period+RiseTime;
		T6_P = 11.0*T_period+RiseTime;
		T7_P = 13.0*T_period+RiseTime;
		
				
		if(Total_Time <= T_period){ 
		   Pplot1 = 0.0;
		}
		
		else if(Total_Time > T_period && Total_Time <= T2){
		    Pplot1 = V2;
                    Pplot1b = I2;
		}
		else if(Total_Time > T2 && Total_Time <= T3){
		    Pplot1 = V4;
                    Pplot1b = I4;
		}
		else if(Total_Time > T3 && Total_Time <= T4){
		    Pplot1 = V6;
                    Pplot1b = I6;
		}
		else if(Total_Time > T4 && Total_Time <= T5){
		    Pplot1 = V8;
                    Pplot1b = I8;
		}
		else if(Total_Time > T5 && Total_Time <= T6){
		    Pplot1 = V10;
                    Pplot1b = I10;
		}
		else if(Total_Time > T6 && Total_Time <= T7){
		    Pplot1 = V12;
                    Pplot1b = I12;
		}
		
		if(Total_Time <= T1_P){ 
		   Pplot2 = 0.0;
                   Pplot2b = 0.0;
		}
		
		else if(Total_Time > T1_P && Total_Time <= T2_P){
		    Pplot2 = -V2;
                    Pplot2b = -I2;
		}
		else if(Total_Time > T2_P && Total_Time <= T3_P){
		    Pplot2 = -V4;
                    Pplot2b = -I4;
		}
		else if(Total_Time > T3_P && Total_Time <= T4_P){
		    Pplot2 = -V6;
                    Pplot2b = -I6;
		}
		else if(Total_Time > T4_P && Total_Time <= T5_P){
		    Pplot2 = -V8;
                    Pplot2b = -I8;
		}
		else if(Total_Time > T5_P && Total_Time <= T6_P){
		    Pplot2 = -V10;
                    Pplot2b = -I10;
		}
		else if(Total_Time > T6_P && Total_Time <= T7_P){
		    Pplot2 = -V12;
                    Pplot2b = -I12;
		}
		
		y1[NPoints - i-1] = (Pplot1+Pplot2)*(Pplot1b+Pplot2b);
		
		//CURSOR
		if(index1 == index2){
                    y2[NPoints - i-1] = y1[NPoints - i-1]; 
                }
                else{
                    timeFactor1 = index2*xratio;
                    timeFactor2 = T_period - timeFactor1;

                    T1 = 2.0*timeFactor2;
                    T2 = timeFactor1 + T1;
                    T3 = T2 + 2.0*timeFactor1;
                    T4 = T3 + 2.0*timeFactor2;
                    T5 = T4 + 2.0*timeFactor1;
                    T6 = T5 + 2.0*timeFactor2;
                    T7 = T6 + 2.0*timeFactor1;
                    T8 = T7 + 2.0*timeFactor2;
                    T9 = T8 + 2.0*timeFactor1;
                    T10 = T9 + 2.0*timeFactor2;
                    T11 = T10 + 2.0*timeFactor1;
                    T12 = T11 + 2.0*timeFactor2;

                    T1_P = 2.0*timeFactor2 + RiseTime;
                    T2_P = timeFactor1 + T1 + RiseTime;
                    T3_P = T2 + 2.0*timeFactor1 + RiseTime;
                    T4_P = T3 + 2.0*timeFactor2 + RiseTime;
                    T5_P = T4 + 2.0*timeFactor1 + RiseTime;
                    T6_P = T5 + 2.0*timeFactor2 + RiseTime;
                    T7_P = T6 + 2.0*timeFactor1 + RiseTime;
                    T8_P = T7 + 2.0*timeFactor2 + RiseTime;
                    T9_P = T8 + 2.0*timeFactor1 + RiseTime;
                    T10_P = T9 + 2.0*timeFactor2 + RiseTime;
                    T11_P = T10 + 2.0*timeFactor1 + RiseTime;
                    T12_P = T11 + 2.0*timeFactor2 + RiseTime;

                    if(Total_Time < timeFactor1){ 
                       Pplot1 = 0.0;
                       Pplot1b = 0.0;
                    }
                    else if(Total_Time >= timeFactor1 && Total_Time < T2){
                        Pplot1 = V1;
                        Pplot1b = I1;
                    }
                    else if(Total_Time >= T2 && Total_Time < T3){
                        Pplot1 = V2;
                        Pplot1b = I2;
                    }
                    else if(Total_Time >= T3 && Total_Time < T4){
                        Pplot1 = V3;
                        Pplot1b = I3;
                    }
                    else if(Total_Time >= T4 && Total_Time < T5){
                        Pplot1 = V4;
                        Pplot1b = I4;
                    }
                    else if(Total_Time >= T5 && Total_Time < T6){
                        Pplot1 = V5;
                        Pplot1b = I5;
                    }
                    else if(Total_Time >= T6 && Total_Time < T7){
                        Pplot1 = V6;
                        Pplot1b = I6;
                    }
                    else if(Total_Time >= T7 && Total_Time < T8){
                        Pplot1 = V7;
                        Pplot1b = I7;
                    }
                    else if(Total_Time >= T8 && Total_Time < T9){
                        Pplot1 = V8;
                        Pplot1b = I8;
                    }
                    else if(Total_Time >= T9 && Total_Time < T10){
                        Pplot1 = V9;
                        Pplot1b = I9;
                    }
                    else if(Total_Time >= T10 && Total_Time < T11){
                        Pplot1 = V10;
                        Pplot1b = I10;
                    }
                    else if(Total_Time >= T11 && Total_Time < T12){
                        Pplot1 = V11;
                        Pplot1b = I11;
                    }
                    else if(Total_Time >= T12){
                        Pplot1 = V12;
                        Pplot1b = I12;
                    }

                    if(Total_Time < timeFactor1+RiseTime){ 
                        Pplot2 = 0.0;
                        Pplot2b = 0.0;
                    }
                    else if(Total_Time >= timeFactor1+RiseTime && Total_Time < T2_P){
                        Pplot2 = -V1;
                        Pplot2b = -I1;
                    }
                    else if(Total_Time >= T2_P && Total_Time < T3_P){
                        Pplot2 = -V2;
                        Pplot2b = -I2;
                    }
                    else if(Total_Time >= T3_P && Total_Time < T4_P){
                        Pplot2 = -V3;
                        Pplot2b = -I3;
                    }
                    else if(Total_Time >= T4_P && Total_Time < T5_P){
                        Pplot2 = -V4;
                        Pplot2b = -I4;
                    }
                    else if(Total_Time >= T5_P && Total_Time < T6_P){
                        Pplot2 = -V5;
                        Pplot2b = -I5;
                    }
                    else if(Total_Time >= T6_P && Total_Time < T7_P){
                        Pplot2 = -V6;
                        Pplot2b = -I6;
                    }
                    else if(Total_Time >= T7_P && Total_Time < T8_P){
                        Pplot2 = -V7;
                        Pplot2b = -I7;
                    }
                    else if(Total_Time >= T8_P && Total_Time < T9_P){
                        Pplot2 = -V8;
                        Pplot2b = -I8;
                    }
                    else if(Total_Time >= T9_P && Total_Time < T10_P){
                        Pplot2 = -V9;
                        Pplot2b = -I9;
                    }
                    else if(Total_Time >= T10_P && Total_Time < T11_P){
                        Pplot2 = -V10;
                        Pplot2b = -I10;
                    }
                    else if(Total_Time >= T11_P && Total_Time < T12_P){
                        Pplot2 = -V11;
                        Pplot2b = -I11;
                    }
                    else if(Total_Time >= T12){
                        Pplot2 = -V12;
                        Pplot2b = -I12;
                    }

                    y2[NPoints - i-1] = (Pplot1+Pplot2)*(Pplot1b+Pplot2b);
                }
	    }
	}	    
    }
    
    
    
    public void ScanRandom(){ // Routine for testing, not used for anything here
	for(int i = 0; i < NPoints; i++){
	    x[i] = i * lineLength/(NPoints-1);
	    y1[i] = -100.0 + 200.0*Math.random();
	    y2[i] = -100.0 + 200.0*Math.random();
	}
    }
    
    
    //
    //  TRANSIENTS
    //
    
    public void ScanTransientVoltage(){
	double Total_Time, Total_Time_Pulse, Total_Time_minus_2T, Total_Time_minus_2T_Pulse, 
	       Vtest1, Vtest2, Vtest3, Vtest4, Vstep1, Vstep2, Vstep3, Vstep4, 
	       timeFactor1, timeFactor2, timeFactor3, timeFactor4,
	       tsimple, tsimple2;
	int index, tindex, t2index, tindex2, t2index2;
	//---------------------------------------------------------------
	if(IsStepOn || (!IsStepOn && RiseTime == 0.0)){// Input is a step
	  //-------------------------------------- 
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * lineLength/(NPoints-1);
	    } 
	  //--------------------------------------
	    Total_Time = ctime*DeltaT;
	    tindex = (int)(Total_Time/T_period);
	    t2index = (int)(Total_Time/(2.0*T_period));
	    
	    if(reset == 720){ tsimple = 0.0;}
            else{tsimple =Total_Time - t2index*2.0*T_period;}
            
	    Total_Time_minus_2T = tsimple - 2.0*T_period;
            	    
	    Vtest1 = Vold;
	    Vtest2 = Vnew;
	    //System.out.println(ctime+"   "+reset+"   "+tsimple);
	    
            if(ctime < NTime2){
		Vold = 0.0;
		Vnew = Vdivider;
	    }
	    else{
		if(reset == 720){
		    Vold = Vtest1 + Vtest2 +Vtest2 * GammaLoad;
		    Vnew = Vtest2* GammaLoad*GammaInput;
		}
	    }
	    
	    for(int i = 0; i < NPoints; i++){
		index = NPoints - i - 1;
	    
		timeFactor1 = tsimple - index*xratio;//position index
		timeFactor2 = Total_Time_minus_2T + index*xratio;
		
		if(timeFactor1 < 0.0){ 
		    Vstep1 = Vold;
		}
		else{
		    Vstep1 = Vold + Vnew;
		}
	    
		if(timeFactor2 < 0.0){ 
		    Vstep2 = 0.0;
		}
		else{
		    Vstep2 = Vnew*GammaLoad;
		}
		
		
		y1[i] = Vstep1+Vstep2;
		y2[i] = 0.0;
	    
		if(ctime == 0){
		    y1[i]=0.0;
		}
	    }
	}
	else{// Input is a pulse
	for(int i = 0; i < NPoints; i++){
		x[i] = i * lineLength/(NPoints-1);
	    } 
	  
	    Total_Time = ctime*DeltaT;
	    Total_Time_Pulse = Total_Time-RiseTime;
	    
	  //--------------------------------------  
	    tindex = (int)(Total_Time/T_period);
	    t2index = (int)(Total_Time/(2.0*T_period));
	    
	    if(reset == 720){ tsimple = 0.0;}
            else{tsimple =Total_Time - t2index*2.0*T_period;}
            Total_Time_minus_2T = tsimple - 2.0*T_period;
	    
	    Vtest1 = Vold;
	    Vtest2 = Vnew;
	    
	    if(ctime < NTime2){
		Vold = 0.0;
		Vnew = Vdivider;
	    }
	    else{
		if(reset == NTime2){
		    Vold = Vtest1 + Vtest2 +Vtest2 * GammaLoad;
		    Vnew = Vtest2* GammaLoad*GammaInput;
		}
	    }
	    
	    //--------------------------------------------------------
	    tindex2 = (int)((Total_Time_Pulse)/T_period);
	    t2index2 = (int)(Total_Time_Pulse/(2.0*T_period));
	    
	    tsimple2 =Total_Time_Pulse - t2index2*2.0*T_period;
	    
	    Total_Time_minus_2T_Pulse = tsimple2 - 2.0*T_period;
	   
	    Vtest3 = Vold2;
	    Vtest4 = Vnew2;
	    
	    if(Total_Time_Pulse < 2.0*T_period){
		Vold2 = 0.0;
		Vnew2 = -Vdivider;
	    }
	    else{
		if((int)(tsimple2/DeltaT)<dtime){
		    Vold2 = Vtest3 + Vtest4 +Vtest4 * GammaLoad;
		    Vnew2 = Vtest4* GammaLoad*GammaInput;
		}
	    }
	    
	    
	    for(int i = 0; i < NPoints; i++){
		index = NPoints - i - 1;
	    
		timeFactor1 = tsimple - index*xratio;//position index
		timeFactor2 = Total_Time_minus_2T + index*xratio;
		
		timeFactor3 = tsimple2 - index*xratio;//position index
		timeFactor4 = Total_Time_minus_2T_Pulse + index*xratio;
		//--------------------------
		if(timeFactor1 < 0.0){ 
		    Vstep1 = Vold;
		}
		else{
		    Vstep1 = Vold + Vnew;
		}
		//---------------------------
		if(timeFactor2 < 0.0){ 
		    Vstep2 = 0.0;
		}
		else{
		    Vstep2 = Vnew*GammaLoad;
		}
		//---------------------------
		if(timeFactor3 < 0.0){ 
		    Vstep3 = Vold2;
		}
		else{
		    Vstep3 = Vold2 + Vnew2;
		}
		//---------------------------
		if(timeFactor4 < 0.0){ 
		    Vstep4 = 0.0;
		}
		else{
		    Vstep4 = Vnew2*GammaLoad;
		}
		//---------------------------
		
		y1[i] = Vstep1+Vstep2+Vstep3+Vstep4;
		y2[i] = 0.0;
	    
		if(ctime == 0){
		    y1[i]=0.0;
		}
	    }
	}	
    }
    
    public void ScanTransientCurrent(){
	
	double Total_Time, Total_Time_Pulse, Total_Time_minus_2T, Total_Time_minus_2T_Pulse, 
	       Itest1, Itest2, Itest3, Itest4, Istep1, Istep2, Istep3, Istep4, 
	       timeFactor1, timeFactor2, timeFactor3, timeFactor4,
	       tsimple, tsimple2;
	int index, tindex, t2index, tindex2, t2index2;
	
	//---------------------------------------------------------------
	if(IsStepOn || (!IsStepOn && RiseTime == 0.0)){// Input is a step
	  //--------------------------------------
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * lineLength/(NPoints-1);
	    } 
	  //--------------------------------------
	    Total_Time = ctime*DeltaT;
	    tindex = (int)(Total_Time/T_period);
	    t2index = (int)(Total_Time/(2.0*T_period));
	    
	    if(reset == 720){ tsimple = 0.0;}
            else{tsimple =Total_Time - t2index*2.0*T_period;}
            Total_Time_minus_2T = tsimple - 2.0*T_period;
	    
	    Itest1 = Iold;
	    Itest2 = Inew;
	    
	    if(ctime < NTime2){
		Iold = 0.0;
		Inew = Idivider;
                
	    }
	    else{
		if(reset == NTime2){
		    Iold = Itest1 + Itest2 -Itest2 * GammaLoad;
		    Inew = Itest2* GammaLoad*GammaInput;
                    
		}
	    }
	    
	    for(int i = 0; i < NPoints; i++){
		index = NPoints - i - 1;
	    
		timeFactor1 = tsimple - index*xratio;//position index
		timeFactor2 = Total_Time_minus_2T + index*xratio;
		
		if(timeFactor1 < 0.0){ 
		    Istep1 = Iold;
		}
		else{
		    Istep1 = Iold + Inew;
		}
	    
		if(timeFactor2 < 0.0){ 
		    Istep2 = 0.0;
		}
		else{
		    Istep2 = -Inew*GammaLoad;
		}
		
		
		y1[i] = Istep1+Istep2;
		y2[i] = 0.0;
	    
		if(ctime == 0){
		    y1[i]=0.0;
		}
	    }
	}
	else{// Input is a pulse
	    //--------------------------------------
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * lineLength/(NPoints-1);
	    } 
	  //--------------------------------------
	    Total_Time = ctime*DeltaT;
	    Total_Time_Pulse = Total_Time-RiseTime;
	   //-------------------------------------- 
	    tindex = (int)(Total_Time/T_period);
	    t2index = (int)(Total_Time/(2.0*T_period));
	    
	    if(reset == 720){ tsimple = 0.0;}
            else{tsimple =Total_Time - t2index*2.0*T_period;}
	    Total_Time_minus_2T = tsimple - 2.0*T_period;
	    
	    Itest1 = Iold;
	    Itest2 = Inew;
	    
	    if(ctime < NTime2){
		Iold = 0.0;
		Inew = Idivider;
	    }
	    else{
		if(reset == NTime2){
		    Iold = Itest1 + Itest2 -Itest2 * GammaLoad;
		    Inew = Itest2* GammaLoad*GammaInput;
		}
	    }
	    //--------------------------------------
	    tindex2 = (int)((Total_Time_Pulse)/T_period);
	    t2index2 = (int)(Total_Time_Pulse/(2.0*T_period));
	    
	    tsimple2 =Total_Time_Pulse - t2index2*2.0*T_period;
	    
	    Total_Time_minus_2T_Pulse = tsimple2 - 2.0*T_period;
	   
	    Itest3 = Iold2;
	    Itest4 = Inew2;
	    
	    if(Total_Time_Pulse < 2.0*T_period){
		Iold2 = 0.0;
		Inew2 = -Idivider;
	    }
	    else{
		if((int)(tsimple2/DeltaT)<dtime){
		    Iold2 = Itest3 + Itest4 -Itest4 * GammaLoad;
		    Inew2 = Itest4* GammaLoad*GammaInput;
		}
	    }
	    //----------------------------------------
		    
	    for(int i = 0; i < NPoints; i++){
		index = NPoints - i - 1;
	    
		timeFactor1 = tsimple - index*xratio;//position index
		timeFactor2 = Total_Time_minus_2T + index*xratio;
		
		timeFactor3 = tsimple2 - index*xratio;//position index
		timeFactor4 = Total_Time_minus_2T_Pulse + index*xratio;
		
		if(timeFactor1 < 0.0){ 
		    Istep1 = Iold;
		}
		else{
		    Istep1 = Iold + Inew;
		}
	    
		if(timeFactor2 < 0.0){ 
		    Istep2 = 0.0;
		}
		else{
		    Istep2 = -Inew*GammaLoad;
		}
		//---------------------------
		if(timeFactor3 < 0.0){ 
		    Istep3 = Iold2;
		}
		else{
		    Istep3 = Iold2 + Inew2;
		}
		//---------------------------
		if(timeFactor4 < 0.0){ 
		    Istep4 = 0.0;
		}
		else{
		    Istep4 = -Inew2*GammaLoad;
		}
		//---------------------------
		
		
		y1[i] = Istep1+Istep2+Istep3+Istep4;
		y2[i] = 0.0;
	    
		if(ctime == 0){
		    y1[i]=0.0;
		}
	    }
	}
    }
    
    public void ScanTransientPower(){
	double Total_Time, Total_Time_Pulse, Total_Time_minus_2T, Total_Time_minus_2T_Pulse,
	       Vtest1, Vtest2, Vtest3, Vtest4, Vstep1, Vstep2, Vstep3, Vstep4, 
	       Itest1, Itest2, Itest3, Itest4, Istep1, Istep2, Istep3, Istep4, 
	       timeFactor1, timeFactor2, timeFactor3, timeFactor4, 
	       tsimple, tsimple2;
	int index, tindex, t2index, tindex2, t2index2;
	
	
	//---------------------------------------------------------------
	if(IsStepOn || (!IsStepOn && RiseTime == 0.0)){// Input is a step
	  //--------------------------------------
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * lineLength/(NPoints-1);
	    } 
	  //--------------------------------------
	    Total_Time = ctime*DeltaT;
	    tindex = (int)(Total_Time/T_period);
	    t2index = (int)(Total_Time/(2.0*T_period));
	    
	    if(reset == 720){ tsimple = 0.0;}
            else{tsimple =Total_Time - t2index*2.0*T_period;}
	    Total_Time_minus_2T = tsimple - 2.0*T_period;
	    //------------------------------------------------------
	    Vtest1 = Vold;
	    Vtest2 = Vnew;
	    if(ctime < NTime2){
		Vold = 0.0;
		Vnew = Vdivider;
	    }
	    else{
		if(reset == NTime2){
		    Vold = Vtest1 + Vtest2 +Vtest2 * GammaLoad;
		    Vnew = Vtest2* GammaLoad*GammaInput;
		}
	    }
	    //------------------------------------------------------
	    Itest1 = Iold;
	    Itest2 = Inew;
	    
	    if(ctime < NTime2){
		Iold = 0.0;
		Inew = Idivider;
	    }
	    else{
		if(reset == NTime2){
		    Iold = Itest1 + Itest2 -Itest2 * GammaLoad;
		    Inew = Itest2* GammaLoad*GammaInput;
		}
	    }  
	    //------------------------------------------------------
	    for(int i = 0; i < NPoints; i++){
		index = NPoints - i - 1;
	    
		timeFactor1 = tsimple - index*xratio;//position index
		timeFactor2 = Total_Time_minus_2T + index*xratio;
		
		if(timeFactor1 < 0.0){ 
		    Vstep1 = Vold;
		    Istep1 = Iold;
		}
		else{
		    Vstep1 = Vold + Vnew;
		    Istep1 = Iold + Inew;
		}
	    
		if(timeFactor2 < 0.0){ 
		    Vstep2 = 0.0;
		    Istep2 = 0.0;
		}
		else{
		    Vstep2 = Vnew*GammaLoad;
		    Istep2 = -Inew*GammaLoad;
		}
		
		y1[i] = (Vstep1+Vstep2)*(Istep1+Istep2);
		y2[i] = 0.0;
		
		if(ctime == 0){
		    y1[i]=0.0;
		}
		
	    }
	}
		
	else{// Input is a pulse
	    //--------------------------------------
	    for(int i = 0; i < NPoints; i++){
		x[i] = i * lineLength/(NPoints-1);
	    } 
	  //--------------------------------------
	    Total_Time = ctime*DeltaT;
	    Total_Time_Pulse = Total_Time-RiseTime;
	    
	    tindex = (int)(Total_Time/T_period);
	    t2index = (int)(Total_Time/(2.0*T_period));
	    
	    if(reset == 720){ tsimple = 0.0;}
            else{tsimple =Total_Time - t2index*2.0*T_period;}
	    Total_Time_minus_2T = tsimple - 2.0*T_period;
	    //------------------------------------------------------
	    Vtest1 = Vold;
	    Vtest2 = Vnew;
            
	    if(ctime < NTime2){
		Vold = 0.0;
		Vnew = Vdivider;
	    }
	    else{
		if(reset == NTime2){
		    Vold = Vtest1 + Vtest2 +Vtest2 * GammaLoad;
		    Vnew = Vtest2* GammaLoad*GammaInput;
		}
	    }
	    //------------------------------------------------------
	    Itest1 = Iold;
	    Itest2 = Inew;
	    
	    if(Total_Time < 2.0*T_period){
		Iold = 0.0;
		Inew = Idivider;
	    }
	    else{
		if(tsimple < DeltaT){
		    Iold = Itest1 + Itest2 -Itest2 * GammaLoad;
		    Inew = Itest2* GammaLoad*GammaInput;
		}
	    }  
	    //------------------------------------------------------
	    tindex2 = (int)((Total_Time_Pulse)/T_period);
	    t2index2 = (int)(Total_Time_Pulse/(2.0*T_period));
	    
	    tsimple2 =Total_Time_Pulse - t2index2*2.0*T_period;
	    
	    Total_Time_minus_2T_Pulse = tsimple2 - 2.0*T_period;
	   
	    Vtest3 = Vold2;
	    Vtest4 = Vnew2;
	    
	    if(Total_Time_Pulse < 2.0*T_period){
		Vold2 = 0.0;
		Vnew2 = -Vdivider;
	    }
	    else{
		if((int)(tsimple2/DeltaT)<dtime){
		    Vold2 = Vtest3 + Vtest4 +Vtest4 * GammaLoad;
		    Vnew2 = Vtest4* GammaLoad*GammaInput;
		}
	    }
	    
	   
	    Itest3 = Iold2;
	    Itest4 = Inew2;
	    if(Total_Time_Pulse < 2.0*T_period){
		Iold2 = 0.0;
		Inew2 = -Idivider;
	    }
	    else{
		if((int)(tsimple2/DeltaT)<dtime){
		    Iold2 = Itest3 + Itest4 -Itest4 * GammaLoad;
		    Inew2 = Itest4* GammaLoad*GammaInput;
		}
	    }
	    	    
	    for(int i = 0; i < NPoints; i++){
		index = NPoints - i - 1;
	    
		timeFactor1 = tsimple - index*xratio;//position index
		timeFactor2 = Total_Time_minus_2T + index*xratio;
		timeFactor3 = tsimple2 - index*xratio;//position index
		timeFactor4 = Total_Time_minus_2T_Pulse + index*xratio;
		
		
		if(timeFactor1 < 0.0){ 
		    Vstep1 = Vold;
		    Istep1 = Iold;
		}
		else{
		    Vstep1 = Vold + Vnew;
		    Istep1 = Iold + Inew;
		}
	    
		if(timeFactor2 < 0.0){ 
		    Vstep2 = 0.0;
		    Istep2 = 0.0;
		}
		else{
		    Vstep2 = Vnew*GammaLoad;
		    Istep2 = -Inew*GammaLoad;
		}
		
		//---------------------------
		if(timeFactor3 < 0.0){ 
		    Vstep3 = Vold2;
		    Istep3 = Iold2;
		}
		else{
		    Vstep3 = Vold2 + Vnew2;
		    Istep3 = Iold2 + Inew2;
		}
		//---------------------------
		if(timeFactor4 < 0.0){ 
		    Vstep4 = 0.0;
		    Istep4 = 0.0;
		}
		else{
		    Vstep4 = Vnew2*GammaLoad;
		    Istep4 = -Inew2*GammaLoad;
		}
		//---------------------------
		
		y1[i] = (Vstep1+Vstep2+Vstep3+Vstep4)*(Istep1+Istep2+Istep3+Istep4);
		y2[i] = 0.0;
		
		if(ctime == 0){
		    y1[i]=0.0;
		}
		
	    }
	
	}
    }
        
    public double getYRangeMax(int i){//arg=1 for Voltage Max
	//Complex VPlus = EMF.computeVPlus(generator,ZL,lineZ0,lineLength);
	double tmp=0.0;
	
	ignition();
	
	
	switch(i){
	    case 1://Voltage
		    if(Vdivider >  2.0 *Vinfinity && Vinfinity > 0.0){
			tmp =  Vdivider;
		    }
		    else if(Vinfinity == 0.0){
			tmp = 2.0*Vdivider;
		    }
		    else{
			tmp = 2.0 * Vinfinity;
		    }
		break;
		
	    case 2://Current
		    if(Idivider >  2.0 *Iinfinity && Iinfinity > 0.0){
			tmp =  Idivider;
		    }
		    else if(Iinfinity == 0.0){
			tmp = 2.0*Idivider;
		    }
		    else{
			tmp = 2.0 * Iinfinity;
		    }
		break;
		
	    case 3://Power
	    
		    if((Vdivider*Idivider) >  2.0 *Pinfinity && Pinfinity > 0.0){
			tmp =  2.0*Vdivider*Idivider;
			//System.out.println("check 1    tmp = "+tmp);
		    }
		    else if(Vinfinity == 0.0){
			tmp = 2.0*Idivider*Idivider*lineZ0;
			//System.out.println("check 2    tmp = "+tmp);
		    }
		    else if(Iinfinity == 0.0){
			tmp = 2.0*Vdivider*Vdivider/lineZ0;
			//System.out.println("check 3    tmp = "+tmp);
		    }
		    else{
			tmp = 2.0 * Pinfinity;
			//System.out.println("check 4    tmp = "+tmp);
		    }
		break;
	}
	return tmp;
    }
  
}/*State.java*/
