//Oblique_State.java
//import maestro.lib.math.*;
import java.util.*;

public class Oblique_State {
    public static final double epsilon0 = 8.841941286E-12; 
    public static final double mu0 = 1.25663706144E-6; //Units H/m
    //exact values
    //private static final double epsilon0 = 8.8541878176E-12; //Units: F/m
    //private static final double mu0 = 1.25663706144E-6; //Units H/m
    //private static final double c = 1.0/Math.sqrt(epsilon0*mu0); //Units m/s
    public static final double c = 3.0E8; //Units m/s
    
    public double epsilon_r1, index1, mu_r1, conductivity1; //Units S/m
    public double epsilon_r2, index2, mu_r2, conductivity2; //Units S/m
    public double epsilon_r3, index3, mu_r3, conductivity3; //Units S/m
    public double fiber_radius; // Units m
    public double fiber_length;// Units km
    public double fiber_length_meters;// Units meters
    public double Lmax; // units km
    public double Lmax_meters; // units meters
    public double Lray; // units km
    public double Lray_meters; // units meters
    public double Travel_min, Travel_max, Travel_ray, Travel_Delay, Data_Rate, T_factor;
    
    public double critical_angle;
    public boolean isPolarizationParallel, Incident, Reflected, Total, Plot2D, IsScalePlot, Radiates, Show_index;
    double wavelength1, wavelength2, wavelength3;
    double wavelength1x, wavelength2x;
    double wavelength1z, wavelength2z;
    double phase_velocity1, phase_velocity2, phase_velocity3;
    double phase_velocity1x, phase_velocity2x;
    double phase_velocity1z, phase_velocity2z;
    double alpha1, alpha2, alpha3, beta1, beta2, beta3, beta1_z, beta1_x, beta2_z, beta2_x, beta_ratio; //attentuation coefficient and wave vector
    double E0; //Amplitudes of E-Field
    double loss_tangent1, loss_tangent2;
    double skin_depth1, skin_depth2;
    public Complex wave_impedance1, wave_impedance2;
    public double ratioZ;
    public double Deltax = 0.05;
    public double numerical_aperture, numerical_aperture2;
    public double wt, dwt;
    public int NSteps,  ShowWhich;
    
    public int width=603;
    //public int height=574;
    public int height=603;
    
    public double myarray[][];
    public double xarrayInc_M[];
    public double xarrayRef_M[];
    public double xarrayTot_M[];
        
    public Complex Reflection_Coef, Reflection_CoefH, Transmission_Coef, Transmission_CoefH;
    double wave_impedance_mag1, wave_impedance_phase1, wave_impedance_mag2, wave_impedance_phase2;
    public double theta1, theta2, theta3, theta4, theta1_deg, theta_range, theta1_lim, theta1_lim_deg;
    public double frequency, angular_frequency, total_angle, totalR_angle, totalRclad_angle;
    public double x[], ref_array[], trans_array[], refCM_array[], transCM_array[],
                  refCR_array[], transCR_array[], refCI_array[], transCI_array[];
    public Complex refC_array[], transC_array[];
    public double x_deg[], x_swp[];
    
    public int which = 1;
    public boolean plotE;
    public boolean IsVectorIn = true;
    public boolean show_normal = true;
    public boolean show_tang = true;
    
    public int Nt = 6000;
    private double PI = Math.PI;
    public int palettereference = 382;
    public int palettereferenceB = 127;
    public int palettereferenceC = 127;
    public boolean IsThreshold = false;
    public boolean IsCoarser = true;
    
    public boolean LicenseExpired;
    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 Oblique_State(){   
        theta4 = Math.PI/2.0;//0.0;
        NSteps = 180;//Change this to vary animation speed
	wt = 0.0;
	dwt = Math.PI*2/(NSteps);
        Show_index = false;
        T_factor = 6.0;
        theta1 = Math.PI/15.0;
        //theta1 = Math.asin(Math.sqrt((epsilon_r2-epsilon_r3)/epsilon_r1));
        //theta1_deg = Math.asin(Math.sqrt((epsilon_r2-epsilon_r3)/epsilon_r1))*180/Math.PI;
        theta1_deg = 12.0;
        theta_range = Math.asin(Math.sqrt((epsilon_r2-epsilon_r3)/epsilon_r1))*180/Math.PI;
	theta2 = Math.PI/4.0;
	epsilon_r1 = 1.0;
        index1 = Math.sqrt(epsilon_r1);
	mu_r1 = 1.0;
	conductivity1 = 0.0;
	epsilon_r2 = 2.55;
        index2 = Math.sqrt(epsilon_r2);
	mu_r2 = 1.0;
	conductivity2 = 0.0;
        epsilon_r3 = 2.4;
        index3 = Math.sqrt(epsilon_r3);
	mu_r3 = 1.0;
	conductivity2 = 0.0;
	isPolarizationParallel = true;
	frequency = 350.0E12;
        fiber_radius = 100.0E-6; // meters
	
        fiber_length = 1.0; // km
        fiber_length_meters = 1000.0; // meters
	Lmax = fiber_length * Math.sqrt(epsilon_r2/epsilon_r3);
        Lmax_meters = Lmax * 1000.0;
        Lray = fiber_length / Math.cos(theta2);
        Lray_meters = Lmax * 1000.0;
                
        Incident = true;
        Reflected = false;
        Total = false;
        Plot2D = false;
        IsScalePlot = false;
        plotE = true;
        Radiates = false;
        
        numerical_aperture = Math.sqrt((epsilon_r2-epsilon_r3));
        if(numerical_aperture > 1.0){numerical_aperture = 1.0;}
        numerical_aperture2 = Math.sqrt((epsilon_r2-epsilon_r3)/epsilon_r1);
        if(numerical_aperture2 > 1.0){numerical_aperture2 = 1.0;}
        
        ShowWhich = 1;
        
        myarray = new double[width+1][height+1];
        xarrayInc_M = new double[height+1];
        xarrayRef_M = new double[height+1];
        xarrayTot_M = new double[height+1];
        x_swp = new double[height+1];
       
	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();
	scan_coefficients();
    }
    
    public synchronized void increment(){
	wt+=dwt;
	if(wt > Math.PI * 2){
		wt -= 2 * Math.PI;
	}
        //System.out.println(wt);
    }
    
    public void ignition(){
        
        angular_frequency = 2.0 * Math.PI * frequency; // rad/s
        theta1_lim = Math.asin(Math.sqrt((epsilon_r2-epsilon_r3)/epsilon_r1));
        theta1_lim_deg = Math.asin(Math.sqrt((epsilon_r2-epsilon_r3)/epsilon_r1))*180/Math.PI;
	theta1_deg = MaestroA.rounder(theta1*180.0/Math.PI,4);
        //System.out.println(theta1_lim+"   "+theta1_lim_deg);
	beta1  = EMF.getBeta(epsilon_r1,mu_r1,conductivity1,angular_frequency);
	beta2  = EMF.getBeta(epsilon_r2,mu_r2,conductivity2,angular_frequency);
        beta3  = EMF.getBeta(epsilon_r3,mu_r3,conductivity3,angular_frequency);
        
	beta_ratio = beta2/beta1;
        beta1_z = beta1 * Math.sin(theta1);
        beta1_x = Math.sqrt(beta1*beta1 - beta1_z*beta1_z);
        
        alpha1 = EMF.getAlpha(epsilon_r1,mu_r1,conductivity1,angular_frequency);
	alpha2 = EMF.getAlpha(epsilon_r2,mu_r2,conductivity2,angular_frequency);
	
	wavelength1 = EMF.getWaveLength(epsilon_r1,mu_r1,conductivity1,angular_frequency);
	wavelength2 = EMF.getWaveLength(epsilon_r2,mu_r2,conductivity2,angular_frequency);
        wavelength3 = EMF.getWaveLength(epsilon_r3,mu_r3,conductivity3,angular_frequency);
        wavelength1z = wavelength1/Math.sin(theta1);
        wavelength2z = wavelength2/Math.sin(theta2);
	wavelength1x = wavelength1/Math.cos(theta1);
        wavelength2x = wavelength2/Math.cos(theta2);
        
	phase_velocity1 = EMF.getPhaseVelocity(epsilon_r1,mu_r1,conductivity1,angular_frequency);
	phase_velocity2 = EMF.getPhaseVelocity(epsilon_r2,mu_r2,conductivity2,angular_frequency);
	phase_velocity3 = EMF.getPhaseVelocity(epsilon_r3,mu_r3,conductivity3,angular_frequency);
        
        phase_velocity1z = phase_velocity1/Math.sin(theta1);
	phase_velocity2z = phase_velocity2/Math.sin(theta2);
	
        phase_velocity1x = phase_velocity1/Math.cos(theta1);
	phase_velocity2x = phase_velocity2/Math.cos(theta2);
        
	wave_impedance1 = EMF.getWaveImpedance(epsilon_r1,mu_r1,conductivity1,angular_frequency);
	wave_impedance2 = EMF.getWaveImpedance(epsilon_r2,mu_r2,conductivity2,angular_frequency);
	
        index1 = Math.sqrt(epsilon_r1);
        index2 = Math.sqrt(epsilon_r2);
        index3 = Math.sqrt(epsilon_r3);
        
        ratioZ = Complex.Real(Complex.Divide(wave_impedance1,wave_impedance2));
        try{
            theta2 = Math.asin(beta1*Math.sin(theta1)/beta2);//Snell's law
        }
        catch(Exception ec){
	    theta2 = 0.0;
	}
        
        try{
            theta3 = Math.PI*0.5 -Math.abs(theta2);
        }
        catch(Exception ec){
	    theta3 = 0.0;
	}
        
        try{
            if((Math.sqrt(epsilon_r2/epsilon_r3)*Math.sin(theta3))<=1){
                theta4 = Math.asin(beta2*Math.sin(theta3)/beta3);
                Radiates = true;
            }
            else{
                Radiates = false;
                theta4 = Math.PI/2.0;//0.0;
            }
        }
        catch(Exception ec){
	    theta4 = 0.0;
	}
        
        try{
            
            if(epsilon_r2 > epsilon_r3){
                critical_angle = 180/Math.PI*Math.asin(Math.sqrt(epsilon_r3/epsilon_r2));    
            }
            else{
                critical_angle = 91.0;
            }
        }
        catch(Exception ec){
	    critical_angle = 91.0;
	}
        
        beta2_z = beta1 * Math.sin(theta1);
        beta2_x = Math.sqrt(Math.abs(beta2*beta2 - beta2_z*beta2_z));
        
        if(epsilon_r2 > epsilon_r3){
            try{
                theta_range = Math.asin(Math.sqrt((epsilon_r2-epsilon_r3)/epsilon_r1))*180/Math.PI;
            }
            catch(Exception ec){
                theta_range = 0.0;
            }
            if(theta_range != theta_range){
                theta_range = 90.0;
            }
        }
        else{
            theta_range = 0.0;
        }
                
        numerical_aperture = Math.sqrt((epsilon_r2-epsilon_r3));
        if(numerical_aperture > 1.0){numerical_aperture = 1.0;}
        numerical_aperture2 = Math.sqrt((epsilon_r2-epsilon_r3)/epsilon_r1);
        if(numerical_aperture2 > 1.0){numerical_aperture2 = 1.0;}
        
        fiber_length_meters = fiber_length * 1000; //
        Lmax = fiber_length * Math.sqrt(epsilon_r2/epsilon_r3);
        Lmax_meters = Lmax * 1000.0;
        Lray = fiber_length / Math.cos(theta2);
        Lray_meters = Lray * 1000.0;
	
        // All in microseconds
        Travel_max = Lmax_meters * index2/c;
        Travel_min = fiber_length_meters * index2/c;
        Travel_ray = Lray_meters * index2/c;
        Travel_Delay = Travel_max - Travel_min; 
        
        Data_Rate = 1.0/(2*Travel_Delay);  // bits per second
        
        //System.out.println("L = "+fiber_length+"  Lmax = "+Lmax+"  Lray = "+Lray);
        //System.out.println(" ");
        //System.out.println("Tmin = "+Travel_min+"  Tmax = "+Travel_max+"  Tray = "+Travel_ray);
        //System.out.println("Data Rate = "+Data_Rate+"  TDelay = "+Travel_Delay+"");
        
        
        
        
        
	Reflection_Coef =  EMF.getOblique_Reflection_Coefficient(theta1, epsilon_r1, epsilon_r2,
	    mu_r1, mu_r2, conductivity1, conductivity2, angular_frequency, isPolarizationParallel);
	    
        Reflection_CoefH = Complex.Multiply(Reflection_Coef,new Complex(-1.0,0.0));
        
	Transmission_Coef = EMF.getOblique_Transmission_Coefficient(theta1, epsilon_r1, epsilon_r2,
	    mu_r1, mu_r2, conductivity1, conductivity2, angular_frequency, isPolarizationParallel);
	
        Transmission_CoefH = Complex.Multiply(ratioZ,Transmission_Coef);
        
        //System.out.println("r = "+Complex.Magnitude(Reflection_Coef)+"   rH = "+Complex.Magnitude(Reflection_CoefH));
        //System.out.println("t = "+Complex.Magnitude(Transmission_Coef)+"   tH = "+Complex.Magnitude(Transmission_CoefH));
        
        total_angle = MaestroA.rounder(180.0/Math.PI*Math.atan(Math.sqrt((mu_r2*epsilon_r2)/(mu_r1*epsilon_r1))),4);
        if((mu_r1*epsilon_r1) <= (mu_r2*epsilon_r2) ){
            totalR_angle = 91.0;
        }
        else{
            totalR_angle = MaestroA.rounder(180.0/Math.PI*Math.asin(Math.sqrt((mu_r2*epsilon_r2)/(mu_r1*epsilon_r1))),4);
        }
        
        //if((mu_r2*epsilon_r2) <= (mu_r3*epsilon_r3) ){
        //    totalRclad_angle = 91.0;
        //}
        //else
        {
            if(epsilon_r2 > epsilon_r3){
                totalRclad_angle = MaestroA.rounder(180.0/Math.PI*Math.asin(Math.sqrt((mu_r3*epsilon_r3)/(mu_r2*epsilon_r2))),4);
            }
            else{
                totalRclad_angle = 90.0;
            }
        }
        
            int mid = height/2;
            int mid2 = width/2;
            Complex useT, useR;
            
            if(isPolarizationParallel){
                useR = Reflection_CoefH;
                useT = Transmission_CoefH;
                //System.out.println("Phase R = "+useR.Arg1()+"   Phase T = "+useT.Arg1());
            }
            else{
                useR = Reflection_Coef;
                useT = Transmission_Coef;
                //System.out.println("Phase R = "+useR.Arg1()+"  "+useR.Arg2()+"   Phase T = "+useT.Arg1()+"  "+useT.Arg2());
            }
            
            
            if(Plot2D){
                if(Incident){
                    if(useT.Imaginary() == 0.0){
                        for(int j = 0; j < width+1; j++){
                            for(int i = 0; i < mid+1; i++){
                                myarray[j][i] = 
                                    300.0*Math.cos(wt - beta1_x/beta1*(double)(i-mid)*Deltax + beta1_z/beta1*(double)(j-mid2)*Deltax);
                            }
                            for(int i = mid+1; i < height+1; i++){
                                myarray[j][i] = 300.0*useT.Real()*Math.cos(wt - beta2_x/beta1*(double)(i-mid)*Deltax + beta2_z/beta1*(double)(j-mid2)*Deltax);
                            }
                        }
                    }
                    else{
                        for(int j = 0; j < width+1; j++){
                            for(int i = 0; i < mid+1; i++){
                                myarray[j][i] = 
                                    300.0*Math.cos(wt - beta1_x/beta1*(double)(i-mid)*Deltax + beta1_z/beta1*(double)(j-mid2)*Deltax);
                            }
                            for(int i = mid+1; i < height+1; i++){    
                                    myarray[j][i] = 300.0*useT.Magnitude()
                                                    * Math.exp(-Math.abs(beta2_x/beta1)*(double)(i-mid)*Deltax)
                                                    * Math.cos(wt + beta1_z/beta1*(double)(j-mid2)*Deltax + useT.Arg2());
                            }   
                        }
                    }
                }// end of if(Incident)
                //--------------------------------------------------------------
                if(Reflected){
                    if(useT.Imaginary() == 0.0){
                        for(int j = 0; j < width+1; j++){
                            for(int i = 0; i < mid+1; i++){
                                myarray[j][i] = 300.0*useR.Real()*Math.cos(wt + beta1_x/beta1*(double)(i-mid)*Deltax + beta1_z/beta1*(double)(j-mid2)*Deltax);
                            }
                            for(int i = mid+1; i < height+1; i++){
                                 myarray[j][i] = 300.0*useT.Real()*
                                    Math.cos(wt - beta2_x/beta1*(double)(i-mid)*Deltax + beta2_z/beta1*(double)(j-mid2)*Deltax);
                            }
                        }
                    }
                    else{
                        for(int j = 0; j < width+1; j++){
                            for(int i = 0; i < mid+1; i++){
                                myarray[j][i] = 300.0*useR.Magnitude()*Math.cos(wt + beta1_x/beta1*(double)(i-mid)*Deltax + beta1_z/beta1*(double)(j-mid2)*Deltax+useR.Arg2());
                            }
                            for(int i = mid+1; i < height+1; i++){    
                                myarray[j][i] = 300.0*useT.Magnitude() 
                                                * Math.exp(-Math.abs(beta2_x/beta1)*(double)(i-mid)*Deltax)
                                                * Math.cos(wt + beta1_z/beta1*(double)(j-mid2)*Deltax + useT.Arg2());
                            }
                        }
                    }
                }// end of if(Reflected)
                //--------------------------------------------------------------
                if(Total){
                    
                    if(useT.Imaginary() == 0.0){
                        for(int j = 0; j < width+1; j++){
                            for(int i = 0; i < mid+1; i++){
                                myarray[j][i] = 
                                300.0*Math.cos(wt - beta1_x/beta1*(double)(i-mid)*Deltax + beta1_z/beta1*(double)(j-mid2)*Deltax)+
                                300.0*useR.Magnitude()*Math.cos(wt + beta1_x/beta1*(double)(i-mid)*Deltax + beta1_z/beta1*(double)(j-mid2)*Deltax+useR.Arg2());
                            }
                            for(int i = mid+1; i < height+1; i++){
                                myarray[j][i] = 300.0*useT.Real()*
                                                  Math.cos(wt - beta2_x/beta1*(double)(i-mid)*Deltax + beta2_z/beta1*(double)(j-mid2)*Deltax);
                            }
                        }
                    }
                    else{
                        for(int j = 0; j < width+1; j++){
                            for(int i = 0; i < mid+1; i++){
                                myarray[j][i] = 
                                300.0*Math.cos(wt - beta1_x/beta1*(double)(i-mid)*Deltax + beta1_z/beta1*(double)(j-mid2)*Deltax)+
                                300.0*useR.Magnitude()*Math.cos(wt + beta1_x/beta1*(double)(i-mid)*Deltax + beta1_z/beta1*(double)(j-mid2)*Deltax+useR.Arg2());
                                //300.0*useR.Real()*Math.cos(wt + beta1_x/beta1*(double)(i-mid)*Deltax - beta1_z/beta1*(double)(j)*Deltax);
                            }
                            for(int i = mid+1; i < height+1; i++){    
                                myarray[j][i] = 300.0*useT.Magnitude() 
                                           * Math.exp(-Math.abs(beta2_x/beta1)*(double)(i-mid)*Deltax)
                                            * Math.cos(wt + beta1_z/beta1*(double)(j-mid2)*Deltax + useT.Arg2());
                            }
                        }
                    }
                }//end of if(Total)
                //--------------------------------------------------------------
                
                
                //for(int j = 0; j < width+1; j++){
                  //          for(int i = 0; i < height+1; i++){
                    //            myarray[j][i] = Math.abs(myarray[j][i]); 
                      //      }
                //}
                
                
            }// end of if(Plot2D)
            
                if(useT.Imaginary() == 0.0){
                    for(int i = 0; i < mid+1; i++){
                        xarrayTot_M[i] = Complex.Magnitude(
                        Complex.Add(
                        new Complex(Math.cos(beta1_x/beta1*(double)(i-mid)*Deltax), Math.sin(beta1_x/beta1*(double)(i-mid)*Deltax)),
                        new Complex(useR.Magnitude()*Math.cos(beta1_x/beta1*(double)(i-mid)*Deltax+useR.Arg2()), 
                                   -useR.Magnitude()*Math.sin(beta1_x/beta1*(double)(i-mid)*Deltax+useR.Arg2())))
                        );
                    }
                    for(int i = mid+1; i < height+1; i++){
                        xarrayTot_M[i] = useT.Magnitude(); 
                        //* Complex.Magnitude(new Complex(Math.cos(beta2_x/beta2*(double)(i-mid)*Deltax), 
                        //    Math.sin(beta2_x/beta1*(double)(i-mid)*Deltax)));
                    }
                }
                else{
                    for(int i = 0; i < mid+1; i++){
                        xarrayTot_M[i] = Complex.Magnitude(
                            Complex.Add(
                            new Complex(Math.cos(beta1_x/beta1*(double)(i-mid)*Deltax), Math.sin(beta1_x/beta1*(double)(i-mid)*Deltax)),
                            new Complex(useR.Magnitude()*Math.cos(beta1_x/beta1*(double)(i-mid)*Deltax+useR.Arg2()), 
                            -useR.Magnitude()*Math.sin(beta1_x/beta1*(double)(i-mid)*Deltax+useR.Arg2())))
                            );
                    }
                    for(int i = mid+1; i < height+1; i++){
                                xarrayTot_M[i] = useT.Magnitude()*
                                                 Math.exp(-Math.abs(beta2_x/beta1)*(double)(i-mid)*Deltax);
                    }
                    
                }
                for(int i = 0; i < height+1; i++){
                         x_swp[i] = i;
                         
                         //System.out.println(i+"   "+xarrayTot_M[i]);
                }
            
    }
    
    public void scan_coefficients(){
	x = new double[9001];
	x_deg = new double[9001];
	ref_array = new double[9001];
	trans_array = new double[9001];
	refC_array = new Complex[9001];
	transC_array = new Complex[9001];
        refCM_array = new double[9001];
	transCM_array = new double[9001];
	refCR_array = new double[9001];
	transCR_array = new double[90001];
        refCI_array = new double[9001];
	transCI_array = new double[9001];
	
        for(int i=0;i<9001;i++){
	    x_deg[i] = (double)i;
	}
	
        EMF.getOblique_Reflection_Coefficient(epsilon_r1, epsilon_r2, mu_r1, mu_r2, conductivity1, conductivity2,
				      angular_frequency, isPolarizationParallel, ref_array,x);
	EMF.getOblique_Transmission_Coefficient(epsilon_r1, epsilon_r2, mu_r1, mu_r2, conductivity1, conductivity2,
				      angular_frequency, isPolarizationParallel, trans_array,x);
                                      
        EMF.getOblique_Reflection_CoefficientC(epsilon_r1, epsilon_r2, mu_r1, mu_r2, conductivity1, conductivity2,
				      angular_frequency, isPolarizationParallel, refC_array,x);
	
        
        EMF.getOblique_Transmission_CoefficientC(epsilon_r1, epsilon_r2, mu_r1, mu_r2, conductivity1, conductivity2,
				      angular_frequency, isPolarizationParallel, transC_array,x);
        
        double ratio;
        ratio = Math.sqrt((mu_r1*epsilon_r2)/(mu_r2*epsilon_r1));
        
        
        if(plotE){}
        else{
            if(wavelength1 != wavelength2){
                for(int i=0;i<9001;i++){
                    refC_array[i] = Complex.Multiply(refC_array[i], new Complex(-1.0,0.0));
                    transC_array[i] = Complex.Multiply(transC_array[i], new Complex(ratio,0.0));
                }
            }
        }
        
        for(int i=0;i<9001;i++){
            refCR_array[i] = Complex.Real(refC_array[i]);
            transCR_array[i] = Complex.Real(transC_array[i]);
            refCI_array[i] = Complex.Imaginary(refC_array[i]);
            transCI_array[i] = Complex.Imaginary(transC_array[i]);
	    refCM_array[i] = Complex.Magnitude(refC_array[i]);
            transCM_array[i] = Complex.Magnitude(transC_array[i]);
            //System.out.println(i+"  "+refCR_array[i]+"   "+refCI_array[i]);
        }
        
    }
    
   
}