import java.util.*;


public class NewGuide_State {
    //----------------------new variables for antenna
    public double theta_angle, theta_maximum, theta_minimum, 
		  phi_angle, phi_maximum, phi_minimum, 
		  point_distance, distance_minimum, distance_maximum, 
		  current_magnitude, current2_magnitude, wavelength, frequency, wire_radius;
    public double Directivity, TotalPowerA, TotalPower, TimeAveragePower, RadiationResistance, 
		  InputResistance, RadiationReactance, InputReactance;
    public double DipoleLength_lambda, DipoleLength_meters, DipoleLength2_lambda, 
		  DipoleLength2_meters, antenna_distance, antenna_distance_lambda,
		  antenna_distance_minimum, antenna_distance_maximum, 
		  antenna_phase, antenna_phase_degree, antenna_phase_minimum, antenna_phase_maximum, 
		  TotalP, PlanePMax, directivityAB;
    public Complex Electric_Field, Magnetic_Field;
    //---------------------------------------------------------------------------------
    public double a, a2, a_meters, a2_meters; // dimensions
    public double a_minimum, a_maximum, DeltaLength, a2_minimum, a2_maximum, DeltaLength2;
    public double mu_r, mu_r0, lambda_0, lambda; 
 
    public double epsilon_r, DeltaZ, DeltaZ2;
    public double frequency_minimum, frequency_maximum, Deltaf;
    public double angular_frequency, beta_total;
    public double beta;
    public double phase_velocity, phase_velocity0, light_velocity, light_velocity0;
    
    public Complex ZeroC;
    public double distance;
    public double medium_impedance;
    public double DVector[], RVector[], RinVector[], XVector[], XinVector[], leng[], DVMax, RVMax, 
		  RinVMax, XVMax, XVMin, XinVMax, XinVMin;
    
    public double x[], x_polar[];
    public Complex etheta[], erad[], hphigen[];
    public double ethetaM[], eradM[], ephigenM[], ex[], ey[], ez[], hthetaM[], hradM[], hphigenM[], hx[], hy[], hz[];
    public double Efield_3meters, Efield_3metersA, Efield_3metersB, Efield_3metersC;
    public double EfieldMax, EfieldRadMax, EfieldPhigenMax, EfieldCartxMax, EfieldCartyMax, EfieldCartzMax; 
    public double HfieldMax, HfieldRadMax, HfieldThetaMax, HfieldCartxMax, HfieldCartyMax, HfieldCartzMax; 
    public Complex ephi[], ephirad[], hphi[];
    public double ephiM[], ephiradM[], ephiphiM[], ephix[], ephiy[], ephiz[], hphiM[], hphiradM[], hphithetaM[], 
		  hphix[], hphiy[], hphiz[]; 
    public double EfieldphiMax, EfieldphiRadMax, EfieldphiPhiMax, EfieldCart2xMax, EfieldCart2yMax, EfieldCart2zMax; 
    public double HfieldphiMax, HfieldphiRadMax, HfieldphiThetaMax, HfieldCart2xMax, HfieldCart2yMax, HfieldCart2zMax; 
    public double Funcfar, Funcfar2, Hfar1, Efar1, Hfar2, Efar2, Efar, Hfar, Pfar;
    public Complex EfarC, HfarC, EfarC1, EfarC2, HfarC1, HfarC2;
    
    public double zpos[], zposLarge[], zLambda[], theta, phi, currentM[], currentMAX, currentMLarge[], currentMIN, zposMax;
    public double zpos2[], zposLarge2[], zLambda2[], currentM2[], currentMAX2, currentMLarge2[], currentMIN2, zposMax2;
    public double currentNormalization;
    public double currentin, currentin_maximum, currentin_minimum, currentscale,
		  currentin2, currentin2_maximum, currentin2_minimum, currentscale2;
    
    public Complex ethetaC, eradC, ephigenC, exC, eyC, ezC, hphigenC, hthetaC, hradC, hxC, hyC, hzC;
    public double etheta0, erad0, ephigen0, ex0, ey0, ez0, htheta0, hrad0, hphigen0, hx0, hy0, hz0;
    
    public int Numpoints, Nsections, NsectionsLarge, Nsections2, NsectionsLarge2;
    public Complex current[], current2[], currentLarge[], currentLarge2[], cp, cn;//current along z, current coefficients
    public double dz, dz2, angle_factor;
    public boolean inputpanelflag, Is_theta, Is_radius, IsPolar, IsA, IsB, IsEfield;
    public boolean need_update;
    public boolean microFlag2, microFlag3, microFlag4, microFlag5, microFlag4b, microFlag5b, microFlag6, microFlag7, 
		   microFlag8, microFlag9, microFlag10, microFlag11, microFlag12, microFlag13, microFlag14,
		   microFlag13b, microFlag13c, microFlag14b, microFlag14c,
		   microFlag15, microFlag16, microFlag17, microFlag18, microFlag19, microFlag20;
    
    public double Si[], Ci[], FA1, FA2, FA3, FA4, FB1, FB2, FB3, FB4, GA1, GA2, GA3, GA4, GB1, GB2, GB3, GB4;
    public int Nmaxint, ShowWhich;
    
    public boolean IsDirectivity, IsRad, IsRin, IsXrad, IsXin;
    
    public static final double mil_factor = 0.0254; // 1 mil = 0.0254 mm
    //public static final double epsilon0 = 8.8541878176E-12; //Units: F/m
    public static final double epsilon0 = 8.841941286E-12; // approximate value
    public static final double mu0 = 4.0*Math.PI*1.0e-7;//1.25663706144E-6; //Units H/m
    public Complex jay = new Complex(0.0,1.0);
    public Complex minusjay = new Complex(0.0,-1.0);
    public Complex One = new Complex(1.0,0.0);
    public Complex minusOne = new Complex(-1.0,0.0);
    
    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 NewGuide_State(){
    
	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);

    
	wire_radius = 1.0e-5; //radius of dipole wire (wavelengths) 
	
	// Tables for Sin and Cos Integrals
	Nmaxint = 1001;
        ShowWhich = 1;
        
	Si = new double[Nmaxint+1];
	Ci = new double[Nmaxint+1];
	
	Si[0] = 0.0;		    Si[1] = 0.009999944444;	Si[2] = 0.0199995556;
	Si[3] = 0.0299985;	    Si[4] = 0.0399964446;	Si[5] = 0.0499930561;
	Si[6] = 0.0599880013;	    Si[7] = 0.0699809472;	Si[8] = 0.079971561;
	Si[9] = 0.0899595098;	    Si[10] = 0.09994446111;	Si[11] = 0.1099260824;
	Si[12] = 0.1199040415;	    Si[13] = 0.1298780063;	Si[14] = 0.1398476452;
	Si[15] = 0.14981262265;	    Si[16] = 0.1597726191;	Si[17] = 0.1697272921;
	Si[18] = 0.1796763147;	    Si[19] = 0.1896193569;	Si[20] = 0.1995560885;
	Si[21] = 0.2094861802;	    Si[22] = 0.2194093027;	Si[23] = 0.2293251273;
	Si[24] = 0.2392333258;	    Si[25] = 0.2491335703;	Si[26] = 0.2590255335;
	Si[27] = 0.2689088885;	    Si[28] = 0.278783309;	Si[29] = 0.2886484692;
	Si[30] = 0.2985040438;	    Si[31] = 0.3083497081;	Si[32] = 0.3181851382;
	Si[33] = 0.3280100105;	    Si[34] = 0.3378240022;	Si[35] = 0.347626791;
	Si[36] = 0.3574180555;	    Si[37] = 0.3671974749;	Si[38] = 0.3769647291;
	Si[39] = 0.3867194986;	    Si[40] = 0.3964614648;	Si[41] = 0.4061903098;
	Si[42] = 0.4159057166;	    Si[43] = 0.425607369;	Si[44] = 0.4352949513;
	Si[45] = 0.444968149;	    Si[46] = 0.4546266484;	Si[47] = 0.4642701365;
	Si[48] = 0.4738983013;	    Si[49] = 0.4835108319;	Si[50] = 0.4931074180;
	Si[51] = 0.5026877506;	    Si[52] = 0.5122515212;	Si[53] = 0.5217984228;
	Si[54] = 0.5313281492;	    Si[55] = 0.5408403951;	Si[56] = 0.5408403951;
	Si[57] = 0.5503348563;	    Si[58] = 0.5692692137;	Si[59] = 0.5787085069;
	Si[60] = 0.5881288096;
	Si[61] = 0.5975298233;
	Si[62] = 0.6069112503;
	Si[63] = 0.6162727944;
	Si[64] = 0.6256141603;
	Si[65] = 0.6349350541;
	Si[66] = 0.6442351831;
	Si[67] = 0.6535142557;
	Si[68] = 0.6627719817;
	Si[69] = 0.6720080721;
	Si[70] = 0.6812222391;
	Si[71] = 0.6904141965;
	Si[72] = 0.6995836590;
	Si[73] = 0.7087303430;
	Si[74] = 0.7178539660;
	Si[75] = 0.7269542472;
	Si[76] = 0.7360309067;
	Si[77] = 0.7450836664;
	Si[78] = 0.7541122494;
	Si[79] = 0.7631163804;
	Si[80] = 0.7720957855;
	Si[81] = 0.7810501921;
	Si[82] = 0.7899793293;
	Si[83] = 0.7988829277;
	Si[84] = 0.8077607191;
	Si[85] = 0.8166124372;
	Si[86] = 0.8254378170;
	Si[87] = 0.8342365953;
	Si[88] = 0.8430085102;
	Si[89] = 0.8517533016;
	Si[90] = 0.8604707107;
	Si[91] = 0.8691604808;
	Si[92] = 0.8778223564;
	Si[93] = 0.8864560839;
	Si[94] = 0.8950614112;
	Si[95] = 0.9036380880;
	Si[96] = 0.9121858656;
	Si[97] = 0.9207044970;
	Si[98] = 0.9291937370;
	Si[99] = 0.9376533420;
	Si[100] = 0.9460830704;
	
	Si[101] = 0.9544826820;
	Si[102] = 0.9628519387;
	Si[103] = 0.9711906039;
	Si[104] = 0.9794984431;
	Si[105] = 0.9877752233;
	Si[106] = 0.9960207135;
	Si[107] = 1.0042346846;
	Si[108] = 1.0124169091;
	Si[109] = 1.0205671617;
	Si[110] = 1.0286852187;
	Si[111] = 1.0367708583;
	Si[112] = 1.0448238608;
	Si[113] = 1.0528440082;
	Si[114] = 1.0608310845;
	Si[115] = 1.0687848757;
	Si[116] = 1.0767051696;
	Si[117] = 1.0845917561;
	Si[118] = 1.0924444270;
	Si[119] = 1.100262976;
	Si[120] = 1.1080471990;
	Si[121] = 1.1157968937;
	Si[122] = 1.1235118599;
	Si[123] = 1.1311918994;
	Si[124] = 1.1388368160;
	Si[125] = 1.1464464157;
	Si[126] = 1.1540205063;
	Si[127] = 1.1615588978;
	Si[128] = 1.1690614023;
	Si[129] = 1.1765278340;
	Si[130] = 1.1839580091;
	Si[131] = 1.1913517459;
	Si[132] = 1.1987088649;
	Si[133] = 1.2060291886;
	Si[134] = 1.2133125418;
	Si[135] = 1.2205587513;
	Si[136] = 1.2277676460;
	Si[137] = 1.2349390571;
	Si[138] = 1.2420728180;
	Si[139] = 1.2491687640;
	Si[140] = 1.2562267328;
	Si[141] = 1.2632465642;
	Si[142] = 1.2702281004;
	Si[143] = 1.2771711854;
	Si[144] = 1.2840756658;
	Si[145] = 1.2909413902;
	Si[146] = 1.2977682094;
	Si[147] = 1.3045559767;
	Si[148] = 1.3113045473;
	Si[149] = 1.3180137788;
	Si[150] = 1.3246835312;
	Si[151] = 1.3313136664;
	Si[152] = 1.3379040489;
	Si[153] = 1.3444545453;
	Si[154] = 1.3509650245;
	Si[155] = 1.3574353577;
	Si[156] = 1.3638654183;
	Si[157] = 1.3702550823;
	Si[158] = 1.3766042275;
	Si[159] = 1.3829127345;
	Si[160] = 1.3891804859;
	Si[161] = 1.3954073666;
	Si[162] = 1.4015932640;
	Si[163] = 1.4077380678;
	Si[164] = 1.4138416698;
	Si[165] = 1.4199039644;
	Si[166] = 1.4259248482;
	Si[167] = 1.4319042202;
	Si[168] = 1.4378419816;
	Si[169] = 1.4437380361;
	Si[170] = 1.4495922897;
	Si[171] = 1.4554046507;
	Si[172] = 1.4611750299;
	Si[173] = 1.4669033404;
	Si[174] = 1.4725894974;
	Si[175] = 1.4782334189;
	Si[176] = 1.4838350249;
	Si[177] = 1.4893942379;
	Si[178] = 1.4949109830;
	Si[179] = 1.5003851872;
	Si[180] = 1.5058167803;
	Si[181] = 1.5112056942;
	Si[182] = 1.5165518633;
	Si[183] = 1.5218552243;
	Si[184] = 1.5271157165;
	Si[185] = 1.5323332813;
	Si[186] = 1.5375078626;
	Si[187] = 1.5426394066;
	Si[188] = 1.5477278621;
	Si[189] = 1.5527731800;
	Si[190] = 1.5577753137;
	Si[191] = 1.5627342192;
	Si[192] = 1.5676498545;
	Si[193] = 1.5725221801;
	Si[194] = 1.5773511591;
	Si[195] = 1.5821367567;
	Si[196] = 1.5868789407;
	Si[197] = 1.5915776810;
	Si[198] = 1.5962329502;
	Si[199] = 1.6008447231;
	Si[200] = 1.6054129768;
	Si[210] = 1.6486986362;
	Si[220] = 1.6876248272;
	Si[230] = 1.7222074818;
	Si[240] = 1.7524855008;
	Si[250] = 1.7785201734;
	Si[260] = 1.8003944505;
	Si[270] = 1.8182120765;
	Si[280] = 1.8320965891;
	Si[290] = 1.8421901946;
	Si[300] = 1.8486525280;
	Si[310] = 1.8516593077;
	Si[320] = 1.8514008970;
	Si[330] = 1.8480807828;
	Si[340] = 1.8419139833;
	Si[350] = 1.8331253987;
	Si[360] = 1.8219481156;
	Si[370] = 1.8086216809;
	Si[380] = 1.7933903548;
	Si[390] = 1.7765013604;
	Si[400] = 1.7582031389;
	Si[410] = 1.7387436265;
	Si[420] = 1.7183685637;
	Si[430] = 1.6973198507;
	Si[440] = 1.6758339594;
	Si[450] = 1.6541404144;
	Si[460] = 1.6324603525;
	Si[470] = 1.6110051718;
	Si[480] = 1.5899752782;
	Si[490] = 1.5695589381;
	Si[500] = 1.5499312449;
	Si[510] = 1.5312532047;
	Si[520] = 1.5136709468;
	Si[530] = 1.4973150636;
	Si[540] = 1.4823000826;
	Si[550] = 1.4687240727;
	Si[560] = 1.4566683847;
	Si[570] = 1.4461975285;
	Si[580] = 1.4373591823;
	Si[590] = 1.4301843341;
	Si[600] = 1.4246875513;
	Si[610] = 1.4208673734;
	Si[620] = 1.4187068241;
	Si[630] = 1.4181740348;
	Si[640] = 1.4192229740;
	Si[650] = 1.4217942744;
	Si[660] = 1.4258161486;
	Si[670] = 1.4312053853;
	Si[680] = 1.4378684161;
	Si[690] = 1.4457024427;
	Si[700] = 1.4545966142;
	Si[710] = 1.4644332441;
	Si[720] = 1.4750890554;
	Si[730] = 1.4864364451;
	Si[740] = 1.4983447533;
	Si[750] = 1.5106815309;
	Si[760] = 1.5233137914;
	Si[770] = 1.5361092381;
	Si[780] = 1.5489374581;
	Si[790] = 1.5616710702;
	Si[800] = 1.5741868217;
	Si[810] = 1.5863666225;
	Si[820] = 1.5980985106;
	Si[830] = 1.6092775419;
	Si[840] = 1.6198065968;
	Si[850] = 1.6295970996;
	Si[860] = 1.6385696454;
	Si[870] = 1.6466545309;
	Si[880] = 1.6537921861;
	Si[890] = 1.6599335052;
	Si[900] = 1.6650400758;
	Si[910] = 1.6650400758;
	Si[920] = 1.6720494480;
	Si[930] = 1.6739295283;
	Si[940] = 1.6747291725;
	Si[950] = 1.6744633423;
	Si[960] = 1.6731569801;
	Si[970] = 1.6708445697;
	Si[980] = 1.6675696169;
	Si[990] = 1.6633840566;
	Si[1000] = 1.6583475942;
	
	Ci[0] = -1.0e-230;
	Ci[1] = -4.027979521;
	Ci[2] = -3.3349073389;
	Ci[3] = -2.929567224;
	Ci[4] = -2.6420601333;
	Ci[5] = -2.4191415436;
	Ci[6] = -2.2370949169;
	Ci[7] = -2.083269122;
	Ci[8] = -1.9501125528;
	Ci[9] = -1.8327542604;
	Ci[10] = -1.7278683867;
	Ci[11] = -1.6330827236;
	Ci[12] = -1.546645712;
	Ci[13] = -1.4672271896;
	Ci[14] = -1.3937931915;
	Ci[15] = -1.3255240492;
	Ci[16] = -1.2617589761;
	Ci[17] = -1.2019574825;
	Ci[18] = -1.1456718361;
	Ci[19] = -1.0925269777;
	Ci[20] = -1.0422055957;
	Ci[21] = -0.9944368448;
	Ci[22] = -0.9489876923;
	Ci[23] = -0.9056561893;
	Ci[24] = -0.8642661749;
	Ci[25] = -0.8246630626;
	Ci[26] = -0.7867104528;
	Ci[27] = -0.7502873862;
	Ci[28] = -0.7152860957;
	Ci[29] = -0.6816101535;
	Ci[30] = -0.649172933;
	Ci[31] = -0.6178963217;
	Ci[32] = -0.5877096398;
	Ci[33] = -0.5585487247;
	Ci[34] = -0.4766799229;
	Ci[35] = -0.4510873931;
	Ci[36] = -0.4766611256;
	Ci[37] = -0.4510669762;
	Ci[38] = -0.4262518553;
	Ci[39] = -0.4021777044;
	Ci[40] = -0.3788093464;
	Ci[41] = -0.3561142014;
	Ci[42] = -0.3340620354;
	Ci[43] = -0.31262474;
	Ci[44] = -0.2917761359;
	Ci[45] = -0.2714917998;
	Ci[46] = -0.2517489099;
	Ci[47] = -0.2325261071;
	Ci[48] = -0.2138033726;
	Ci[49] = -0.1955619166;
	Ci[50] = -0.1777840788;
	Ci[51] = -0.1604532390;
	Ci[52] = -0.1435537358;
	Ci[53] = -0.1270707938;
	Ci[54] = -0.1109904567;
	Ci[55] = -0.0952995274;
	Ci[56] = -0.0799855129;
	Ci[57] = -0.0650365744;
	Ci[58] = -0.0504414815;
	Ci[59] = -0.0361895707;
	Ci[60] = -0.022270707;
	Ci[61] = -0.0086752486;
	Ci[62] = 0.0046059849;
	Ci[63] = 0.0175817424;
	Ci[64] = 0.0302603686;
	Ci[65] = 0.0426498293;
	Ci[66] = 0.0547577343;
	Ci[67] = 0.0665913594;
	Ci[68] = 0.0781576659;
	Ci[69] = 0.0894633195;
	Ci[70] = 0.1005147070;
	Ci[71] = 0.1113179525;
	Ci[72] = 0.1218789322;
	Ci[73] = 0.1322032879;
	Ci[74] = 0.1422964404;
	Ci[75] = 0.1521636010;
	Ci[76] = 0.1618097827;
	Ci[77] = 0.1712398110;
	Ci[78] = 0.1804583335;
	Ci[79] = 0.1894698290;
	Ci[80] = 0.1982786160;
	Ci[81] = 0.2068888610;
	Ci[82] = 0.2153045859;
	Ci[83] = 0.2235296752;
	Ci[84] = 0.2315678824;
	Ci[85] = 0.2394228368;
	Ci[86] = 0.2470980486;
	Ci[87] = 0.2545969153;
	Ci[88] = 0.2619227264;
	Ci[89] = 0.2690786687;
	Ci[90] = 0.2760678305;
	Ci[91] = 0.2828932065;
	Ci[92] = 0.2895577018;
	Ci[93] = 0.2960641358;
	Ci[94] = 0.3024152458;
	Ci[95] = 0.3086136908;
	Ci[96] = 0.3146620547;
	Ci[97] = 0.3205628495;
	Ci[98] = 0.3263185183;
	Ci[99] = 0.3319314382;
	Ci[100] = 0.3374039229;
	
	Ci[101] = 0.3427382254;
	Ci[102] = 0.3479365405;
	Ci[103] = 0.3530010067;
	Ci[104] = 0.3579337091;
	Ci[105] = 0.3627366810;
	Ci[106] = 0.3674119060;
	Ci[107] = 0.3719613201;
	Ci[108] = 0.3763868132;
	Ci[109] = 0.3806902312;
	Ci[110] = 0.3848733774;
	Ci[111] = 0.3889380142;
	Ci[112] = 0.3928858645;
	Ci[113] = 0.3967186134;
	Ci[114] = 0.4004379090;
	Ci[115] = 0.4040453647;
	Ci[116] = 0.4075425593;
	Ci[117] = 0.4109310390;
	Ci[118] = 0.4142123185;
	Ci[119] = 0.4173878816;
	Ci[120] = 0.4204591829;
	Ci[121] = 0.4234276482;
	Ci[122] = 0.4262946760;
	Ci[123] = 0.4290616379;
	Ci[124] = 0.4317298802;
	Ci[125] = 0.4343007240;
	Ci[126] = 0.4367754665;
	Ci[127] = 0.4391553815;
	Ci[128] = 0.4414417205;
	Ci[129] = 0.4436357130;
	Ci[130] = 0.4457385675;
	Ci[131] = 0.4477514723;
	Ci[132] = 0.4496755955;
	Ci[133] = 0.4515120863;
	Ci[134] = 0.4532620753;
	Ci[135] = 0.4549266752;
	Ci[136] = 0.4565069811;
	Ci[137] = 0.4580040711;
	Ci[138] = 0.4594190071;
	Ci[139] = 0.4607528349;
	Ci[140] = 0.4620065851;
	Ci[141] = 0.4631812730;
	Ci[142] = 0.4642778995;
	Ci[143] = 0.4652974513;
	Ci[144] = 0.4662409014;
	Ci[145] = 0.4671092094;
	Ci[146] = 0.4679033219;
	Ci[147] = 0.4686241732;
	Ci[148] = 0.4692726848;
	Ci[149] = 0.4698497667;
	Ci[150] = 0.4703563172;
	Ci[151] = 0.4707932232;
	Ci[152] = 0.4711613608;
	Ci[153] = 0.4714615952;
	Ci[154] = 0.4716947815;
	Ci[155] = 0.4718617642;
	Ci[156] = 0.4719633785;
	Ci[157] = 0.4720004495;
	Ci[158] = 0.4719737932;
	Ci[159] = 0.4718842164;
	Ci[160] = 0.4717325169;
	Ci[161] = 0.4715194840;
	Ci[162] = 0.4712458984;
	Ci[163] = 0.4709125325;
	Ci[164] = 0.4705201507;
	Ci[165] = 0.4700695096;
	Ci[166] = 0.4695613580;
	Ci[167] = 0.4689964372;
	Ci[168] = 0.4683754812;
	Ci[169] = 0.4676992169;
	Ci[170] = 0.4669683642;
	Ci[171] = 0.4661836359;
	Ci[172] = 0.4653457385;
	Ci[173] = 0.4644553716;
	Ci[174] = 0.4635132286;
	Ci[175] = 0.4625199967;
	Ci[176] = 0.4614763568;
	Ci[177] = 0.4603829839;
	Ci[178] = 0.4592405471;
	Ci[179] = 0.4580497097;
	Ci[180] = 0.4568111294;
	Ci[181] = 0.4555254585;
	Ci[182] = 0.4541933436;
	Ci[183] = 0.4528154262;
	Ci[184] = 0.4513923427;
	Ci[185] = 0.4499247241;
	Ci[186] = 0.4484131966;
	Ci[187] = 0.4468583813;
	Ci[188] = 0.4452608948;
	Ci[189] = 0.4436213486;
	Ci[190] = 0.4419403497;
	Ci[191] = 0.4402185005;
	Ci[192] = 0.4384563991;
	Ci[193] = 0.4366546388;
	Ci[194] = 0.4348138088;
	Ci[195] = 0.4329344941;
	Ci[196] = 0.4310172752;
	Ci[197] = 0.4290627288;
	Ci[198] = 0.4270714273;
	Ci[199] = 0.4250439391;
	Ci[200] = 0.4229808288;
	Ci[210] = 0.4005119878;
	Ci[220] = 0.3750745990;
	Ci[230] = 0.3471756175;
	Ci[240] = 0.3172916174;
	Ci[250] = 0.2858711964;
	Ci[260] = 0.2533366161;
	Ci[270] = 0.2200848786;
	Ci[280] = 0.1864883896;
	Ci[290] = 0.1528953242;
	Ci[300] = 0.1196297860;
	Ci[310] = 0.0869918312;
	Ci[320] = 0.0552574117;
	Ci[330] = 0.0246782846;
	Ci[340] = -0.0045180779;
	Ci[350] = -0.0321285485;
	Ci[360] = -0.0579743519;
	Ci[370] = -0.0819010013;
	Ci[380] = -0.1037781504;
	Ci[390] = -0.1234993492;
	Ci[400] = -0.1409816979;
	Ci[410] = -0.1561653918;
	Ci[420] = -0.1690131568;
	Ci[430] = -0.1795095725;
	Ci[440] = -0.1876602868;
	Ci[450] = -0.1934911221;
	Ci[460] = -0.1970470797;
	Ci[470] = -0.1983912468;
	Ci[480] = -0.1976036133;
	Ci[490] = -0.1947798060;
	Ci[500] = -0.1900297497;
	Ci[510] = -0.1834762632;
	Ci[520] = -0.1752536023;
	Ci[530] = -0.1655059586;
	Ci[540] = -0.1543859262;
	Ci[550] = -0.1420529476;
	Ci[560] = -0.1286717494;
	Ci[570] = -0.1144107808;
	Ci[580] = -0.0994406647;
	Ci[590] = -0.0839326741;
	Ci[600] = -0.0680572439;
	Ci[610] = -0.0519825290;
	Ci[620] = -0.0358730193;
	Ci[630] = -0.0198882206;
	Ci[640] = -0.0041814110;
	Ci[650] = 0.0111015195;
	Ci[660] = 0.0258231381;
	Ci[670] = 0.0398554400;
	Ci[680] = 0.0530807167;
	Ci[690] = 0.0653923140;
	Ci[700] = 0.0766952785;
	Ci[710] = 0.0869068881;
	Ci[720] = 0.0959570643;
	Ci[730] = 0.1037886664;
	Ci[740] = 0.1103576658;
	Ci[750] = 0.1156332032;
	Ci[760] = 0.1195975293;
	Ci[770] = 0.1222458319;
	Ci[780] = 0.1235859542;
	Ci[790] = 0.1236380071;
	Ci[800] = 0.1224338825;
	Ci[810] = 0.1200166733;
	Ci[820] = 0.1164400055;
	Ci[830] = 0.1117672931;
	Ci[840] = 0.1060709196;
	Ci[850] = 0.0994313586;
	Ci[860] = 0.0919362396;
	Ci[870] = 0.0836793696;
	Ci[880] = 0.0747597196;
	Ci[890] = 0.0652803850;
	Ci[900] = 0.0553475313;
	Ci[910] = 0.0450693325;
	Ci[920] = 0.0345549134;
	Ci[930] = 0.0239133045;
	Ci[940] = 0.0132524187;
	Ci[950] = 0.0026780588;
	Ci[960] = -0.0077070361;
	Ci[970] = -0.0178040977;
	Ci[980] = -0.0275191811;
	Ci[990] = -0.0367639563;
	Ci[1000] = -0.0454564330;
	
	//coefficient for rational approximation od Sin and Cos integrals
	FA1 = 38.027264;    FA2 = 265.187033;	FA3 = 335.677320;   FA4 = 38.102495;
	FB1 = 40.021433;    FB2 = 322.624911;	FB3 = 570.236280;   FB4 = 157.105423;
	
	GA1 = 42.242855;    GA2 = 302.757865;	GA3 = 352.018498;   GA4 = 21.821899;
	GB1 = 48.196927;    GB2 = 482.485984;	GB3 = 1114.978885;  GB4 = 449.690326; 
    
	//new initialization for antenna
	    IsEfield = true;
	    theta_angle = 45.0;//degrees
	    theta_maximum = 180.0;
	    theta_minimum = 0.0;
	    phi_angle = 45.0;//degrees
	    phi_maximum = 360.0;
	    phi_minimum = 0.0;
	    point_distance = 10.0; //wavelength
	    distance_minimum = 0;//      "
	    distance_maximum = 1000;//   "
	    current_magnitude = currentin; //Amperes
	    current2_magnitude = currentin2; //Amperes
	    frequency = 1.0E9;//Hertz
	    
	    Numpoints = 1001;
	    a = 0.5; // wavelengths of antenna length
	    DipoleLength_lambda = a;//lambda
	
	    a_minimum = 0.0;
	    a_maximum = 5.0;// wavelengths
	    DeltaLength = (a_maximum - a_minimum)/(Numpoints - 1);
	    
	    a2 = 0.5; // wavelengths of antenna length
	    DipoleLength2_lambda = a2;//lambda
	
	    a2_minimum = 0.0;
	    a2_maximum = 5.0;// wavelengths
	    DeltaLength2 = (a2_maximum - a2_minimum)/(Numpoints - 1);
	    
	    wavelength = 1.0/Math.sqrt(epsilon0 * mu0)/frequency;//meters
	    antenna_distance_lambda = 0.5;
	    antenna_distance = antenna_distance_lambda * wavelength;
	    
	    antenna_distance_minimum = 0.0; //wavelengths
	    antenna_distance_maximum = 1.0; //wavelengths
	    antenna_phase_degree = 0.0;
	    antenna_phase = Math.PI*antenna_phase_degree/180.0;
	    antenna_phase_minimum = -180.0; //degrees 
	    antenna_phase_maximum = 180.0; //degrees
	    
	    DipoleLength_meters = DipoleLength_lambda * wavelength;
	    DipoleLength2_meters = DipoleLength2_lambda * wavelength;
	    Directivity = 0.0;
	    TotalPower = 0.0;
	    RadiationResistance = 0.0;
	    InputResistance = 0.0;
	    
	    DVector = new double[Numpoints];
	    RVector = new double[Numpoints];
	    RinVector = new double[Numpoints];
	    XVector = new double[Numpoints];
	    XinVector = new double[Numpoints];
	    leng = new double[Numpoints];
	    
	//------------------------------------------------------------------
	
	x_polar = new double[361];
	for(int i=0; i<361; i++){
	    x_polar[i] = i;
	}

	currentNormalization = 1.0;
		
	epsilon_r = 1.0;
	mu_r = 1.0;
	
	angle_factor = Math.PI/180.0;
	
	medium_impedance = Math.sqrt(mu0*mu_r/(epsilon0*epsilon_r));
	frequency = 1.0E9;
	frequency_minimum = 0.0;
	frequency_maximum = 5.0E9;
	angular_frequency = 2.0 * Math.PI * frequency;
	
	currentin = 1.0; //Amperes
	currentin_maximum = 10.0; //Amperes
	currentin_minimum = 0.0;  //Amperes
	
	currentin2 = 1.0; //Amperes
	currentin2_maximum = 10.0; //Amperes
	currentin2_minimum = 0.0;  //Amperes
	
	current_magnitude = currentin; //Amperes
	current2_magnitude = currentin2; //Amperes
	
	lambda_0 = 1.0/Math.sqrt(epsilon0*mu0)/frequency;
	lambda = lambda_0;
	ZeroC = new Complex(0.0,0.0);
	light_velocity = 1.0/(Math.sqrt(epsilon0*epsilon_r*mu0*mu_r));
	light_velocity0 = 1.0/(Math.sqrt(epsilon0*mu0));
	
	Nsections = 40;
	NsectionsLarge = 501;
	
	Nsections2 = 40;
	NsectionsLarge2 = 501;
	
	phi = Math.PI/2.0;
	
	inputpanelflag = true;
	Deltaf = (frequency_maximum - frequency_minimum)/(Numpoints - 1);
	
	Is_theta = true;
	Is_radius = false;
	IsPolar = false;
	IsDirectivity = true;
	IsRad = false;
	IsRin = false;
	IsXrad = false;
	IsXin = false;
	IsA = true;
	IsB = false;
        
        need_update = false;
	
	microFlag2 = false; microFlag3 = false; microFlag4 = false; microFlag5 = false; microFlag6 = false;
	microFlag7 = false; microFlag8 = false; microFlag9 = false; microFlag10 = false; microFlag11 = false; microFlag12 = false;
	microFlag13 = false; microFlag14 = false; microFlag4b = false; microFlag5b = false; microFlag15 = false; microFlag16 = false;
	microFlag13b = false; microFlag14b = false; microFlag13c = false; microFlag14c = false;
	microFlag17 = false; microFlag18 = false; microFlag19 = false; microFlag20 = false; 
	
	scan_coefficients();
	ignition();
 }
    
    public void ignition(){
	Complex factor1, factor2, complex1, complex2, complex3, complex4, complex5,
		complex6, complex7, complex8, complex9, complex10;
	int Lratio, Lratio2;
	double seno, arrayfactor, argument1, argument2;
	
	current_magnitude = currentin;
	current2_magnitude = currentin2;
	
	wavelength = 1.0/Math.sqrt(epsilon0 * mu0 * epsilon_r * mu_r)/frequency;//meters
	
	DipoleLength_lambda = a;//lambda
	DipoleLength_meters = DipoleLength_lambda * wavelength;
	DipoleLength2_lambda = a2;//lambda
	DipoleLength2_meters = DipoleLength2_lambda * wavelength;
	
	Lratio = (int)(100*DipoleLength_meters/wavelength)+1;
	if(Lratio < 51){Lratio = 51;}
	Nsections = Lratio;
	NsectionsLarge = 501;
	
	Lratio2 = (int)(100*DipoleLength2_meters/wavelength)+1;
	if(Lratio2 < 51){Lratio2 = 51;}
	Nsections2 = Lratio2;
	NsectionsLarge2 = 501;
	
	DeltaZ = DipoleLength_meters / Nsections;
	DeltaLength = (a_maximum - a_minimum)/(Numpoints - 1);
	
	DeltaZ2 = DipoleLength2_meters / Nsections2;
	DeltaLength2 = (a2_maximum - a2_minimum)/(Numpoints - 1);
	
	antenna_distance = antenna_distance_lambda * wavelength;
	antenna_phase = Math.PI*antenna_phase_degree/180.0; 
	
	distance = point_distance*wavelength;//meters
	current = new Complex[Nsections];
	current2 = new Complex[Nsections2];
	currentLarge = new Complex[NsectionsLarge];
	currentLarge2 = new Complex[NsectionsLarge2];
	
	etheta = new Complex[361];
	ethetaM = new double[361];
	eradM = new double[361];
	ephigenM = new double[361];
	erad   = new Complex[361];
	ex   = new double[361];
	ey   = new double[361];
	ez   = new double[361];
	
	ephi = new Complex[361];
	ephiM = new double[361];
	ephiradM = new double[361];
	ephiphiM = new double[361];
	ephirad   = new Complex[361];
	ephix   = new double[361];
	ephiy   = new double[361];
	ephiz   = new double[361];
	
	hphigen = new Complex[361];
	hthetaM = new double[361];
	hradM = new double[361];
	hphigenM = new double[361];
	hx   = new double[361];
	hy   = new double[361];
	hz   = new double[361];
	
	hphi = new Complex[361];
	hphiM = new double[361];
	hphiradM = new double[361];
	hphithetaM = new double[361];
	hphiM = new double[361];
	hphix   = new double[361];
	hphiy   = new double[361];
	hphiz   = new double[361];
	
	zpos = new double[Nsections];
	zposLarge = new double[NsectionsLarge];
	zLambda = new double[NsectionsLarge];
	currentM = new double[Nsections];
	currentMLarge = new double[NsectionsLarge];
	
	zpos2 = new double[Nsections2];
	zposLarge2 = new double[NsectionsLarge2];
	zLambda2 = new double[NsectionsLarge2];
	currentM2 = new double[Nsections2];
	currentMLarge2 = new double[NsectionsLarge2];
	
	dz = DipoleLength_meters / Nsections;
	dz2 = DipoleLength2_meters / Nsections2;
	
	scanCurrent();
	
	if(DipoleLength_lambda<0.5){
		currentscale=1.0/Math.sin(Math.PI*(DipoleLength_lambda));
	}
	else{
		currentscale=1.0;
	}
	
	if(DipoleLength2_lambda<0.5){
		currentscale2=1.0/Math.sin(Math.PI*(DipoleLength2_lambda));
	}
	else{
		currentscale2=1.0;
	}
	
	angular_frequency = 2.0 * Math.PI * frequency;
	light_velocity = 1.0/(Math.sqrt(epsilon0*epsilon_r*mu0*mu_r));
	light_velocity0 = 1.0/(Math.sqrt(epsilon0*mu0));
	lambda_0 = light_velocity0/frequency;
	lambda = light_velocity/frequency;
	
	beta = 2.0*Math.PI/lambda;
	medium_impedance = Math.sqrt(mu0*mu_r/(epsilon0*epsilon_r));
    
	// Obtain Directivity, and Time-Average Power  (Far Field assumption)
	double Func[], Func2[], Func2Max, angle, angle2, betafactor, betafactor2, FuncInt, Delta, theta_angle_radians, 
	       phi_angle_radians, cospsi, sinangle2, facto1, facto2, facto3, facto4, facto5, facto6;
	int imax, Nmax;
	Nmax = 720;
	Func   = new double[Nmax+1];
	Func2   = new double[Nmax+1];
	Func2Max = 0.0;
	imax = 0;
	Delta = 0.5*Math.PI/Nmax;
	betafactor = beta*DipoleLength_meters*0.5;
	betafactor2 = beta*DipoleLength2_meters*0.5;
	
	theta_angle_radians = theta_angle*Math.PI/180.0;
	phi_angle_radians = phi_angle*Math.PI/180.0;
	
	Func[0] = 0.0;
	Func2[0] = 0.0;
	//Func[Nmax] = 0.0;
	//Func2[Nmax] = 0.0;
	
      //---  calculation when antennas are same
      if(DipoleLength_meters == DipoleLength2_meters && current_magnitude == current2_magnitude){
	
	cospsi = Math.sin(phi_angle_radians)*Math.sin(theta_angle_radians);
	arrayfactor = 2.0 * Math.cos(0.5 *(2.0 * Math.PI * antenna_distance_lambda * cospsi + antenna_phase));
	if(DipoleLength_lambda >= 1.0e-4){
	    if(theta_angle == 0.0 || theta_angle == 180.0){
		Funcfar = 0.0;
	    }
	    else{
		Funcfar = (Math.cos(betafactor*Math.cos(theta_angle_radians))-Math.cos(betafactor))/Math.sin(theta_angle_radians);
	    }	
	
	    Hfar = currentin*currentscale * Funcfar / (2.0 *Math.PI*distance) * arrayfactor;
	    Efar = medium_impedance * Hfar;
	}
	else{
	    Hfar = 0.5 * Math.sin(theta_angle_radians) * DipoleLength_lambda / point_distance;
	    Efar = medium_impedance * Hfar;
	}
	
	Pfar = 0.5 * Hfar * Efar;
	EfarC = new Complex(Efar*Math.sin(2.0*Math.PI*point_distance),Efar*Math.cos(2.0*Math.PI*point_distance));
	HfarC = new Complex(Hfar*Math.sin(2.0*Math.PI*point_distance),Hfar*Math.cos(2.0*Math.PI*point_distance));
	
	
	/*
	System.out.println("Power = "+Pfar);					  
	Func2Max=0.0;
	TotalPower=0.0;
	facto1 = 2.0 * Math.PI * antenna_distance_lambda;
	facto2 = Math.PI*DipoleLength_lambda;
	facto3 = medium_impedance*current_magnitude*current_magnitude*currentscale*currentscale;
	facto4 = 8.0*Math.PI*Math.PI;
	facto5 = 2.0*Math.PI*Math.PI/(Nmax*Nmax*2);
	facto6 = Math.PI/Nmax;
	
	if(DipoleLength_lambda >= 1.0e-4){
	    for(int j=1;j<(2*Nmax);j++){
	      angle2=j*facto6;
	      sinangle2 = Math.sin(angle2);
	      for(int i=1;i<Nmax;i++){
		angle=i*facto6;
		cospsi = Math.sin(angle)*sinangle2;
		arrayfactor = 2.0 * Math.cos(0.5 *(facto1 * cospsi + antenna_phase));
		{
		   Func2[i]= arrayfactor*arrayfactor*(facto3*
		   Math.pow((Math.cos(facto2*Math.cos(angle))-Math.cos(facto2))/Math.sin(angle),2.0)/facto4);
		   if(Func2Max<Math.abs(Func2[i])){Func2Max=Math.abs(Func2[i]);}
		   TotalPower+=(Func2[i]*Math.sin(angle)*facto5);
		   
		}
	      }
	    }
	}
	else{
	    for(int j=1;j<(2*Nmax);j++){
	      angle2=j*facto6;
	      sinangle2 = Math.sin(angle2);
	      for(int i=1;i<Nmax;i++){
		angle=i*facto6;
		cospsi = Math.sin(angle)*sinangle2;
		arrayfactor = 2.0 * Math.cos(0.5 *(facto1 * cospsi + antenna_phase));
		{
		   TotalPower+=Pfar*(point_distance*point_distance)/Math.pow(Math.sin(angle),2.0)/facto4;
		   if(Func2Max<(Pfar*(point_distance*point_distance))){Func2Max=(Pfar*(point_distance*point_distance));}
		   
		}
	      }
	    }
	}
	Directivity=(float)(4.0*Math.PI*Func2Max/TotalPower);
	System.out.println("HERE REALLY    TotalPower = "+TotalPower);
	*/
      }
      //--------------------------------------------------------------------------- antennas differ (length and/or current)
      else{
	    if(theta_angle == 0.0 || theta_angle == 180.0){
		Funcfar = 0.0;
		Funcfar2 = 0.0;
	    }
	    else{
		Funcfar = (Math.cos(betafactor*Math.cos(theta_angle_radians))-Math.cos(betafactor))/Math.sin(theta_angle_radians);
		Funcfar2 = (Math.cos(betafactor2*Math.cos(theta_angle_radians))-Math.cos(betafactor2))/Math.sin(theta_angle_radians);
	    }
	    
	    cospsi = Math.sin(phi_angle_radians)*Math.sin(theta_angle_radians);
	
	    Hfar1 = currentin*currentscale * Funcfar / (2.0 *Math.PI*distance);
	    Efar1 = medium_impedance * Hfar1;
	    
	    Hfar2 = currentin2*currentscale2 * Funcfar2 / (2.0 *Math.PI*distance);
	    Efar2 = medium_impedance * Hfar2;
	   
	    argument1 = 2.0*Math.PI*(point_distance - 0.5*antenna_distance_lambda*cospsi)+ 0.5 * antenna_phase;
	    argument2 = 2.0*Math.PI*(point_distance + 0.5*antenna_distance_lambda*cospsi)- 0.5 * antenna_phase;
	
	    EfarC1 = new Complex(Efar1*Math.sin(argument1),Efar1*Math.cos(argument1));
	    HfarC1 = new Complex(Hfar1*Math.sin(argument1),Hfar1*Math.cos(argument1));
	    
	    EfarC2 = new Complex(Efar2*Math.sin(argument2),Efar2*Math.cos(argument2));
	    HfarC2 = new Complex(Hfar2*Math.sin(argument2),Hfar2*Math.cos(argument2));
	
	    EfarC = Complex.Add(EfarC1, EfarC2);
	    HfarC = Complex.Add(HfarC1, HfarC2);
	    Pfar = 0.5 * Complex.Magnitude(EfarC) * Complex.Magnitude(HfarC);
		
	    /*				  
	    Func2Max=0.0;
	    TotalPower=0.0;
	    facto6 = Math.PI/Nmax;
	    double Hfar1Loop, Efar1Loop,Hfar2Loop, Efar2Loop, PfarLoop;
	    Complex HfarC1Loop, EfarC1Loop, HfarC2Loop, EfarC2Loop, HfarCLoop, EfarCLoop;
	
	    if(DipoleLength_lambda >= 1.0e-4){
	     for(int j=1;j<(2*Nmax);j++){
	      angle2=j*facto6;
	      sinangle2 = Math.sin(angle2);
	      for(int i=1;i<Nmax;i++){
		angle=i*facto6;
		cospsi = Math.sin(angle)*sinangle2;
				
		if(theta_angle == 0.0 || theta_angle == 180.0){
		    Funcfar = 0.0;
		    Funcfar2 = 0.0;
		}
		else{
		    Funcfar = (Math.cos(betafactor*Math.cos(theta_angle_radians))-Math.cos(betafactor))/Math.sin(theta_angle_radians);
		    Funcfar2 = (Math.cos(betafactor2*Math.cos(theta_angle_radians))-Math.cos(betafactor2))/Math.sin(theta_angle_radians);
		}
		
		Hfar1Loop = currentin*currentscale * Funcfar / (2.0 *Math.PI*distance);
		Efar1Loop = medium_impedance * Hfar1Loop;
	    
		Hfar2Loop = currentin2*currentscale2 * Funcfar2 / (2.0 *Math.PI*distance);
		Efar2Loop = medium_impedance * Hfar2Loop;
	    
		argument1 = 2.0*Math.PI*(point_distance - 0.5*antenna_distance_lambda*cospsi)+ 0.5 * antenna_phase;
		argument2 = 2.0*Math.PI*(point_distance + 0.5*antenna_distance_lambda*cospsi)- 0.5 * antenna_phase;
	
		EfarC1Loop = new Complex(Efar1Loop*Math.sin(argument1),Efar1Loop*Math.cos(argument1));
		HfarC1Loop = new Complex(Hfar1Loop*Math.sin(argument1),Hfar1Loop*Math.cos(argument1));
	    
		EfarC2Loop = new Complex(Efar2Loop*Math.sin(argument2),Efar2Loop*Math.cos(argument2));
		HfarC2Loop = new Complex(Hfar2Loop*Math.sin(argument2),Hfar2Loop*Math.cos(argument2));
	
		EfarCLoop = Complex.Add(EfarC1Loop, EfarC2Loop);
		HfarCLoop = Complex.Add(HfarC1Loop, HfarC2Loop);
		PfarLoop = 0.5 * Complex.Magnitude(EfarCLoop) * Complex.Magnitude(HfarCLoop);
		TotalPower+= PfarLoop;
		
		   if(Func2Max<PfarLoop){Func2Max=PfarLoop;}
			
	       }
	     }
	    
	    Directivity=(float)(4.0*Math.PI*Func2Max/TotalPower);
	    RadiationResistance = TotalPower * 2 /(current_magnitude * current_magnitude);
	  }
	  else{
	    
	    
	  }
	  TotalPower = (4.0*Math.PI*medium_impedance/3)*Math.pow(current_magnitude*DipoleLength_lambda*0.25,2.0); 
	  */
      }
	
	scanField();
	setThetaPlaneMaxima();
	UpdateRadiation();
	TotalPower = TotalP;
	Directivity = directivityAB;
}

public void scanCurrent(){
    //Compute currents along transmission line
	Complex expo0, expo1, expo2, expo3, expo4, expo5, expo6, expo7, expo8, expo9, expo10, 
		field_factor1, field_factor2, field_factor3, field_factor4;
	double factorc, zstart, zstart_lambda, z, Deltaz, Delta_lambda, zstart2, zstart2_lambda, z2, Deltaz2, Delta2_lambda;
	
	currentMAX = 0.0;
	currentMAX2 = 0.0;
	//Note: z=0 at middle of transmission line
	//initial value of z
	zstart = - DipoleLength_meters * 0.5;
	zstart_lambda = -DipoleLength_lambda *0.5;
	Deltaz = DipoleLength_meters / (NsectionsLarge-1);
	Delta_lambda = DipoleLength_lambda / (NsectionsLarge-1);
	
	zstart2 = - DipoleLength2_meters * 0.5;
	zstart2_lambda = -DipoleLength2_lambda *0.5;
	Deltaz2 = DipoleLength2_meters / (NsectionsLarge2-1);
	Delta2_lambda = DipoleLength2_lambda / (NsectionsLarge2-1);
	
	//current contributions along z direction
	if(a < 0.5){
	    for(int i=0;i<NsectionsLarge;i++){
		z = zstart + Deltaz * (i);
		z2 = zstart2 + Deltaz2 * (i);
		currentLarge[i] = new Complex(current_magnitude * Math.sin(beta*(0.5*DipoleLength_meters - Math.abs(z))), 0.0);
		zposLarge[i] = z;
		zLambda[i] = zstart_lambda + Delta_lambda * i;
		currentMLarge[i] = Complex.Magnitude(currentLarge[i]);
		//currentMLarge[i] = Complex.Real(currentLarge[i]);
		if(currentMLarge[i] > currentMAX){currentMAX = currentMLarge[i];}
	    }
	    
	    currentscale = currentin/currentMAX;
	    
	    currentMAX = 0.0;
	    for(int i=0;i<NsectionsLarge;i++){
		currentLarge[i] = Complex.Multiply(currentLarge[i],new Complex(currentscale,0));
		//currentMLarge[i] = Complex.Magnitude(currentLarge[i]);
		currentMLarge[i] = Complex.Real(currentLarge[i]);
		if(currentMLarge[i] > currentMAX){currentMAX = currentMLarge[i];};
	    }
	}
	else{
	    for(int i=0;i<NsectionsLarge;i++){
		z = zstart + Deltaz * (i);
		currentLarge[i] = new Complex(current_magnitude * Math.sin(beta*(0.5*DipoleLength_meters - Math.abs(z))), 0.0);
		zposLarge[i] = z;
		zLambda[i] = zstart_lambda + Delta_lambda * i;
		//currentMLarge[i] = Complex.Magnitude(currentLarge[i]);
		currentMLarge[i] = Complex.Real(currentLarge[i]);
		if(currentMLarge[i] > currentMAX){currentMAX = currentMLarge[i];};
	    }
	}
	if(a2 < 0.5){
	    for(int i=0;i<NsectionsLarge2;i++){
		z2 = zstart2 + Deltaz2 * (i);
		currentLarge2[i] = new Complex(current2_magnitude * Math.sin(beta*(0.5*DipoleLength2_meters - Math.abs(z2))), 0.0);
		currentLarge2[i] = Complex.Multiply(currentLarge2[i],new Complex(Math.cos(antenna_phase),Math.sin(antenna_phase)));
		zposLarge2[i] = z2;
		zLambda2[i] = zstart2_lambda + Delta2_lambda * i;
		currentMLarge2[i] = Complex.Magnitude(currentLarge2[i]);
		if(currentMLarge2[i] > currentMAX2){currentMAX2 = currentMLarge2[i];}
	    }
	    currentscale2 = currentin2/currentMAX2;
	    currentMAX2 = 0.0;
	    for(int i=0;i<NsectionsLarge2;i++){
		currentLarge2[i] = Complex.Multiply(currentLarge2[i],new Complex(currentscale2,0));
		currentMLarge2[i] = Complex.Real(currentLarge2[i]);
		if(currentMLarge2[i] > currentMAX2){currentMAX2 = currentMLarge2[i];};
	    }
	}
	else{
	    for(int i=0;i<NsectionsLarge2;i++){
		z2 = zstart2 + Deltaz2 * (i);
		currentLarge2[i] = new Complex(current2_magnitude * Math.sin(beta*(0.5*DipoleLength2_meters - Math.abs(z2))), 0.0);
		currentLarge2[i] = Complex.Multiply(currentLarge2[i],new Complex(Math.cos(antenna_phase),Math.sin(antenna_phase)));
		zposLarge2[i] = z2;
		zLambda2[i] = zstart2_lambda + Delta2_lambda * i;
		//currentMLarge[i] = Complex.Magnitude(currentLarge[i]);
		currentMLarge2[i] = Complex.Real(currentLarge2[i]);
		if(currentMLarge2[i] > currentMAX2){currentMAX2 = currentMLarge2[i];};
	    }
	}
	currentscale = 1.0;
	currentscale2 = 1.0;
	//Calculate minimum of current standing wave pattern
	currentMIN = currentMAX;
	for(int i=0;i<NsectionsLarge;i++){
	    if(currentMLarge[i] < currentMIN){currentMIN = currentMLarge[i];};
	}
	
	//Calculate minimum of current standing wave pattern
	currentMIN2 = currentMAX2;
	for(int i=0;i<NsectionsLarge2;i++){
	    if(currentMLarge2[i] < currentMIN2){currentMIN2 = currentMLarge2[i];};
	}
}
//----------------------------

public void scanField(){
    //Compute currents along transmission line
	Complex expo0, expo1, expo2, expo3, expo4, expo5, expo6, expo7, expo8, expo9, expo10, 
		field_factor1, field_factor2, field_factor1h, field_factor2h, field_factor3, field_factor4;
	double factorc, zstart, zstart2, z, Deltaz, Deltaz2;
	
	currentMAX = 0.0;
		
	//Note: z=0 at middle of transmission line
	//initial value of z
	zstart = - DipoleLength_meters * 0.5;
	Deltaz = DipoleLength_meters / Nsections;
	
	zstart2 = - DipoleLength2_meters * 0.5;
	Deltaz2 = DipoleLength2_meters / Nsections2;
	
	if(DipoleLength_lambda<0.5){
		currentscale=1.0/Math.sin(Math.PI*(DipoleLength_lambda));
	}
	else{
		currentscale=1.0;
	}
	
	if(DipoleLength2_lambda<0.5){
		currentscale2=1.0/Math.sin(Math.PI*(DipoleLength2_lambda));
	}
	else{
		currentscale2=1.0;
	}
	
	//current contributions along z direction
	for(int i=0;i<Nsections;i++){
	    z = zstart + Deltaz * (i + 0.5);
	    expo4 = Complex.Exp(Complex.Multiply(minusjay,(beta*z)));
	    expo5 = Complex.Exp(Complex.Multiply(jay,(beta*z)));
	    current[i] = new Complex(current_magnitude * currentscale * Math.sin(beta*(0.5*DipoleLength_meters - Math.abs(z))), 0.0);
	    zpos[i] = z;
	    currentM[i] = Complex.Magnitude(current[i]);
	    
	    if(currentM[i] > currentMAX){currentMAX = currentM[i];};
	}
	
	for(int i=0;i<Nsections2;i++){
	    z = zstart2 + Deltaz2 * (i + 0.5);
	    expo4 = Complex.Exp(Complex.Multiply(minusjay,(beta*z)));
	    expo5 = Complex.Exp(Complex.Multiply(jay,(beta*z)));
	    current2[i] = new Complex(current2_magnitude * currentscale2 * Math.sin(beta*(0.5*DipoleLength2_meters - Math.abs(z))), 0.0);
	    current2[i] = Complex.Multiply(current2[i],new Complex(Math.cos(antenna_phase),Math.sin(antenna_phase)));
	    zpos2[i] = z;
	    currentM2[i] = Complex.Magnitude(current2[i]);
	    
	    if(currentM2[i] > currentMAX2){currentMAX2 = currentM2[i];};
	}
	
	expo6 = Complex.Exp(Complex.Multiply(minusjay,(beta*0.5*(DipoleLength_meters - Deltaz))));
	expo7 = Complex.Exp(Complex.Multiply(jay,(beta*0.5*(DipoleLength_meters - Deltaz))));
	expo8 = Complex.Exp(Complex.Multiply(minusjay,(beta*0.5*(Deltaz - DipoleLength_meters))));
	expo9 = Complex.Exp(Complex.Multiply(jay,(beta*0.5*(Deltaz - DipoleLength_meters))));
		
	double x0, y0, z0, x1, y1, z1, r1, theta1, theta2, phi1, phi2;
	Complex e_theta, e_theta2, e_rad, e_rad2, e_phi, e_x, e_y, e_z, sum_theta, sum_rad, sum_phi, sum_x, sum_y, sum_z;
	Complex h_phi, h_x, h_y, h_z, h_rad, h_theta, sum_htheta, sum_hrad, sum_hphi, sum_hx, sum_hy, sum_hz;
	
	//double etheta0, erad0, ephigen0, ex0, ey0, ez0, htheta0, hrad0, hphigen0, hx0, hy0, hz0;
	
	double cosphi, sinphi, cosphi2, sinphi2;
	double angle_factor = Math.PI/180.0;
	cosphi = 0.0;
	sinphi = 0.0;
	cosphi2 = 0.0;
	sinphi2 = 0.0;
	
	if(phi_angle == 360.0){phi = 0.0;}
		
	    phi = phi_angle*angle_factor;
	    theta = theta_angle*angle_factor; 
		
	    sinphi2 = Math.sin(phi);
	    cosphi2 = Math.cos(phi);
		    
	    x0 = distance * Math.sin(theta) * Math.cos(phi);
	    y0 = distance * Math.sin(theta) * Math.sin(phi);
	    z0 = distance * Math.cos(theta);
		
	    sum_theta = new Complex(0.0,0.0);
	    sum_rad = new Complex(0.0,0.0);
	    sum_phi = new Complex(0.0,0.0);
	    sum_x = new Complex(0.0,0.0);
	    sum_y = new Complex(0.0,0.0);
	    sum_z = new Complex(0.0,0.0);
		
	    sum_htheta = new Complex(0.0,0.0);
	    sum_hrad = new Complex(0.0,0.0);
	    sum_hphi = new Complex(0.0,0.0);
	    sum_hx = new Complex(0.0,0.0);
	    sum_hy = new Complex(0.0,0.0);
	    sum_hz = new Complex(0.0,0.0);
				
	    for(int k=0;k<Nsections;k++){
	    
		//cartesian coordinates of running point
		//x1 = x0;
		//y1 = y0;
		//z1 = z0 - zpos[k];
		
		x1 = x0;
		y1 = y0 + antenna_distance * 0.5;
		z1 = z0 - zpos[k];
		
		//spherical coordinates of running point
		r1 = Math.sqrt(x1*x1 + y1*y1 + z1*z1);
		theta1 = Math.atan2(Math.sqrt(x1*x1 + y1*y1),z1);
		    
		phi1 = Math.atan2(y1,x1);

		sinphi = Math.sin(phi1);
		cosphi = Math.cos(phi1);
		    
		expo10 = Complex.Exp(Complex.Multiply(minusjay,(beta*r1)));
		field_factor1 = Complex.Multiply((2.0*Math.PI*1.0e-7*frequency*Deltaz*Math.sin(theta1)/r1),
						  Complex.Multiply(expo10,Complex.Multiply(jay,current[k])));
		field_factor2 = Complex.Add(1.0-1.0/((beta*r1)*(beta*r1)),Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		field_factor1h = Complex.Multiply((beta*Deltaz*Math.sin(theta1)/(4.0*Math.PI*r1)),
						  Complex.Multiply(expo10,Complex.Multiply(jay,current[k])));
		field_factor2h = Complex.Add(1.0,Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		//get electric field
		e_theta = Complex.Multiply(field_factor1,field_factor2);
		    
		field_factor3 = Complex.Multiply((4.0*Math.PI*1.0e-7*frequency*Deltaz*Math.cos(theta1)/r1),
						  Complex.Multiply(expo10,Complex.Multiply(jay,current[k])));
		field_factor4 = Complex.Subtract(field_factor2,1.0);
		    
		e_rad = Complex.Multiply(field_factor3,field_factor4);
		    
		//get magnetic field
		h_phi = Complex.Multiply(field_factor1h,field_factor2h);
		h_x = Complex.Multiply(h_phi,-sinphi);
		h_y = Complex.Multiply(h_phi,cosphi);
		h_z = new Complex(0.0,0.0);
		    
		e_x = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*cosphi),
				  Complex.Multiply(e_theta,Math.cos(theta1)*cosphi));
				      		    
		e_y = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*sinphi),
				  Complex.Multiply(e_theta,Math.cos(theta1)*sinphi));
		    
		e_z = Complex.Subtract(Complex.Multiply(e_rad,Math.cos(theta1)),
				       Complex.Multiply(e_theta,Math.sin(theta1)));
				      
		//get spherical components in the reference system of coordinates  
		e_rad = Complex.Add(Complex.Add(Complex.Multiply(e_x,Math.sin(theta)*cosphi2),
						Complex.Multiply(e_y,Math.sin(theta)*sinphi2)
					  ),Complex.Multiply(e_z,Math.cos(theta)));
		e_theta = Complex.Subtract(Complex.Add(Complex.Multiply(e_x,Math.cos(theta)*cosphi2),
					   Complex.Multiply(e_y,Math.cos(theta)*sinphi2)),Complex.Multiply(e_z,Math.sin(theta)));
					  
		e_phi = Complex.Subtract(Complex.Multiply(e_y,cosphi2),Complex.Multiply(e_x,sinphi2));
		    
		h_rad = Complex.Add(Complex.Add(Complex.Multiply(h_x,Math.sin(theta)*cosphi2),
						Complex.Multiply(h_y,Math.sin(theta)*sinphi2)),Complex.Multiply(h_z,Math.cos(theta)));
		h_theta = Complex.Subtract(Complex.Add(Complex.Multiply(h_x,Math.cos(theta)*cosphi2),
						      Complex.Multiply(h_y,Math.cos(theta)*sinphi2)),Complex.Multiply(h_z,Math.sin(theta)));		  
		h_phi = Complex.Subtract(Complex.Multiply(h_y,cosphi2),Complex.Multiply(h_x,sinphi2));
		    
		sum_theta = Complex.Add(sum_theta,e_theta);
		sum_rad   = Complex.Add(sum_rad,e_rad);
		sum_phi   = Complex.Add(sum_phi,e_phi);
		    
		sum_x     = Complex.Add(sum_x,e_x);
		sum_y     = Complex.Add(sum_y,e_y);
		sum_z     = Complex.Add(sum_z,e_z);
		    
		sum_htheta = Complex.Add(sum_htheta,h_theta);
		sum_hrad   = Complex.Add(sum_hrad,h_rad);
		sum_hphi   = Complex.Add(sum_hphi,h_phi);
		    
		sum_hx     = Complex.Add(sum_hx,h_x);
		sum_hy     = Complex.Add(sum_hy,h_y);
		sum_hz     = Complex.Add(sum_hz,h_z);
		}
		
		for(int k=0;k<Nsections2;k++){
	    
		//cartesian coordinates of running point
		//x1 = x0;
		//y1 = y0;
		//z1 = z0 - zpos[k];
		
		x1 = x0;
		y1 = y0 - antenna_distance * 0.5;
		z1 = z0 - zpos2[k];
		
		//spherical coordinates of running point
		r1 = Math.sqrt(x1*x1 + y1*y1 + z1*z1);
		theta1 = Math.atan2(Math.sqrt(x1*x1 + y1*y1),z1);
		    
		phi1 = Math.atan2(y1,x1);

		sinphi = Math.sin(phi1);
		cosphi = Math.cos(phi1);
		    
		expo10 = Complex.Exp(Complex.Multiply(minusjay,(beta*r1)));
		field_factor1 = Complex.Multiply((2.0*Math.PI*1.0e-7*frequency*Deltaz*Math.sin(theta1)/r1),
						  Complex.Multiply(expo10,Complex.Multiply(jay,current2[k])));
		field_factor2 = Complex.Add(1.0-1.0/((beta*r1)*(beta*r1)),Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		field_factor1h = Complex.Multiply((beta*Deltaz*Math.sin(theta1)/(4.0*Math.PI*r1)),
						  Complex.Multiply(expo10,Complex.Multiply(jay,current2[k])));
		field_factor2h = Complex.Add(1.0,Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		//get electric field
		e_theta = Complex.Multiply(field_factor1,field_factor2);
		    
		field_factor3 = Complex.Multiply((4.0*Math.PI*1.0e-7*frequency*Deltaz*Math.cos(theta1)/r1),
						  Complex.Multiply(expo10,Complex.Multiply(jay,current2[k])));
		field_factor4 = Complex.Subtract(field_factor2,1.0);
		    
		e_rad = Complex.Multiply(field_factor3,field_factor4);
		    
		//get magnetic field
		h_phi = Complex.Multiply(field_factor1h,field_factor2h);
		h_x = Complex.Multiply(h_phi,-sinphi);
		h_y = Complex.Multiply(h_phi,cosphi);
		h_z = new Complex(0.0,0.0);
		    
		e_x = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*cosphi),
				  Complex.Multiply(e_theta,Math.cos(theta1)*cosphi));
				      		    
		e_y = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*sinphi),
				  Complex.Multiply(e_theta,Math.cos(theta1)*sinphi));
		    
		e_z = Complex.Subtract(Complex.Multiply(e_rad,Math.cos(theta1)),
				       Complex.Multiply(e_theta,Math.sin(theta1)));
				      
		//get spherical components in the reference system of coordinates  
		e_rad = Complex.Add(Complex.Add(Complex.Multiply(e_x,Math.sin(theta)*cosphi2),
						Complex.Multiply(e_y,Math.sin(theta)*sinphi2)
					  ),Complex.Multiply(e_z,Math.cos(theta)));
		e_theta = Complex.Subtract(Complex.Add(Complex.Multiply(e_x,Math.cos(theta)*cosphi2),
					   Complex.Multiply(e_y,Math.cos(theta)*sinphi2)),Complex.Multiply(e_z,Math.sin(theta)));
					  
		e_phi = Complex.Subtract(Complex.Multiply(e_y,cosphi2),Complex.Multiply(e_x,sinphi2));
		    
		h_rad = Complex.Add(Complex.Add(Complex.Multiply(h_x,Math.sin(theta)*cosphi2),
						Complex.Multiply(h_y,Math.sin(theta)*sinphi2)),Complex.Multiply(h_z,Math.cos(theta)));
		h_theta = Complex.Subtract(Complex.Add(Complex.Multiply(h_x,Math.cos(theta)*cosphi2),
						      Complex.Multiply(h_y,Math.cos(theta)*sinphi2)),Complex.Multiply(h_z,Math.sin(theta)));		  
		h_phi = Complex.Subtract(Complex.Multiply(h_y,cosphi2),Complex.Multiply(h_x,sinphi2));
		    
		sum_theta = Complex.Add(sum_theta,e_theta);
		sum_rad   = Complex.Add(sum_rad,e_rad);
		sum_phi   = Complex.Add(sum_phi,e_phi);
		    
		sum_x     = Complex.Add(sum_x,e_x);
		sum_y     = Complex.Add(sum_y,e_y);
		sum_z     = Complex.Add(sum_z,e_z);
		    
		sum_htheta = Complex.Add(sum_htheta,h_theta);
		sum_hrad   = Complex.Add(sum_hrad,h_rad);
		sum_hphi   = Complex.Add(sum_hphi,h_phi);
		    
		sum_hx     = Complex.Add(sum_hx,h_x);
		sum_hy     = Complex.Add(sum_hy,h_y);
		sum_hz     = Complex.Add(sum_hz,h_z);
		}
		
		// Electric Field
		ethetaC = sum_theta;
		eradC = sum_rad;
		ephigenC = sum_phi;
		
		hphigenC = sum_hphi;
		hthetaC = sum_htheta;
		hradC = sum_hrad;
		
		etheta0 = Complex.Magnitude(sum_theta);
		erad0 = Complex.Magnitude(sum_rad);
		ephigen0 = Complex.Magnitude(sum_phi);
		
		ex0 = Complex.Magnitude(sum_x);
		ey0 = Complex.Magnitude(sum_y);
		ez0 = Complex.Magnitude(sum_z);
		
		// Magnetic Field
		
		htheta0 = Complex.Magnitude(sum_htheta);
		hrad0 = Complex.Magnitude(sum_hrad);
		hphigen0 = Complex.Magnitude(sum_hphi);
		
		hx0 = Complex.Magnitude(sum_hx);
		hy0 = Complex.Magnitude(sum_hy);
		hz0 = Complex.Magnitude(sum_hz);
		
		//System.out.println("Etheta = "+sum_theta+"   Erad = "+sum_rad);
		//System.out.println("Hphi = "+sum_hphi);
		//System.out.println("Etheta = "+etheta0+"   Erad = "+erad0+"   Ephigen0 = "+ephigen0);
		//System.out.println("Ex0 = "+ex0+"   Ey0 = "+ey0+"   Ez0 = "+ez0);
		//System.out.println("Htheta = "+htheta0+"   Hrad = "+hrad0+"   Hphigen0 = "+hphigen0);
		//System.out.println("Hx0 = "+hx0+"   Hy0 = "+hy0+"   Hz0 = "+hz0);
}

//---------------------------


public void scan3Dfield(){
    //Compute currents along transmission line
	Complex expo0, expo1, expo2, expo3, expo4, expo5, expo6, expo7, expo8, expo9, expo10, 
		expo62, expo72, expo82, expo92,
		field_factor1, field_factor2, field_factor1h, field_factor2h, field_factor3, field_factor4;
	double factorc, zstart, zstart2, z, Deltaz, Deltaz2;
	
	EfieldMax = 0.0;//theta component, the main one for E
	EfieldRadMax = 0.0;
	EfieldPhigenMax = 0.0;
	EfieldCartxMax = 0.0;
	EfieldCartyMax = 0.0;
	EfieldCartzMax = 0.0;
	
	HfieldMax = 0.0;//phi component, the main one for H
	HfieldRadMax = 0.0;
	HfieldThetaMax = 0.0;
	HfieldCartxMax = 0.0;
	HfieldCartyMax = 0.0;
	HfieldCartzMax = 0.0;
	
	currentMAX = 0.0;
	
	//Note: z=0 at middle of transmission line
	//initial value of z
	zstart = - DipoleLength_meters * 0.5;
	Deltaz = DipoleLength_meters / Nsections;
	
	zstart2 = - DipoleLength2_meters * 0.5;
	Deltaz2 = DipoleLength2_meters / Nsections2;
	
	if(DipoleLength_lambda<0.5){
		currentscale=1.0/Math.sin(Math.PI*(DipoleLength_lambda));
	}
	else{
		currentscale=1.0;
	}
	
	if(DipoleLength2_lambda<0.5){
		currentscale2=1.0/Math.sin(Math.PI*(DipoleLength2_lambda));
	}
	else{
		currentscale2=1.0;
	}
	
	//current contributions along z direction
	
	for(int i=0;i<Nsections;i++){
	    z = zstart + Deltaz * (i + 0.5);
	    expo4 = Complex.Exp(Complex.Multiply(minusjay,(beta*z)));
	    expo5 = Complex.Exp(Complex.Multiply(jay,(beta*z)));
	    current[i] = new Complex(current_magnitude * currentscale * Math.sin(beta*(0.5*DipoleLength_meters - Math.abs(z))), 0.0);
	    zpos[i] = z;
	    currentM[i] = Complex.Magnitude(current[i]);
	    
	    if(currentM[i] > currentMAX){currentMAX = currentM[i];};
	}
	for(int i=0;i<Nsections2;i++){
	    z = zstart2 + Deltaz2 * (i + 0.5);
	    expo4 = Complex.Exp(Complex.Multiply(minusjay,(beta*z)));
	    expo5 = Complex.Exp(Complex.Multiply(jay,(beta*z)));
	    current2[i] = new Complex(current2_magnitude * currentscale2 * Math.sin(beta*(0.5*DipoleLength2_meters - Math.abs(z))), 0.0);
	    current2[i] = Complex.Multiply(current2[i],new Complex(Math.cos(antenna_phase),Math.sin(antenna_phase)));
	    zpos2[i] = z;
	    currentM2[i] = Complex.Magnitude(current2[i]);
	    
	    if(currentM2[i] > currentMAX2){currentMAX2 = currentM2[i];};
	}
	expo6 = Complex.Exp(Complex.Multiply(minusjay,(beta*0.5*(DipoleLength_meters - Deltaz))));
	expo7 = Complex.Exp(Complex.Multiply(jay,(beta*0.5*(DipoleLength_meters - Deltaz))));
	expo8 = Complex.Exp(Complex.Multiply(minusjay,(beta*0.5*(Deltaz - DipoleLength_meters))));
	expo9 = Complex.Exp(Complex.Multiply(jay,(beta*0.5*(Deltaz - DipoleLength_meters))));
	
	expo62 = Complex.Exp(Complex.Multiply(minusjay,(beta*0.5*(DipoleLength2_meters - Deltaz2))));
	expo72 = Complex.Exp(Complex.Multiply(jay,(beta*0.5*(DipoleLength2_meters - Deltaz2))));
	expo82 = Complex.Exp(Complex.Multiply(minusjay,(beta*0.5*(Deltaz2 - DipoleLength2_meters))));
	expo92 = Complex.Exp(Complex.Multiply(jay,(beta*0.5*(Deltaz2 - DipoleLength2_meters))));
		
	double x0, y0, z0, x1, y1, z1, r1, theta1, theta2, phi1, phi2;
	Complex e_theta, e_theta2, e_rad, e_rad2, e_phi, e_x, e_y, e_z, sum_theta, sum_rad, sum_phi, sum_x, sum_y, sum_z;
	Complex h_phi, h_x, h_y, h_z, h_rad, h_theta, sum_htheta, sum_hrad, sum_hphi, sum_hx, sum_hy, sum_hz;
	double cosphi, sinphi, cosphi2, sinphi2;
	cosphi = 0.0;
	sinphi = 0.0;
	cosphi2 = 0.0;
	sinphi2 = 0.0;
	
	//for(int j=0;j<360;j++){
	    //phi = angle_factor * j;
	    
	    // ***
		if(phi/angle_factor == 360.0){phi = 0.0;}
	    
	    for(int i=0;i<361;i++){
		theta = angle_factor * i; 
		
			sinphi2 = Math.sin(phi);
			cosphi2 = Math.cos(phi);
		    
		x0 = distance * Math.sin(theta) * Math.cos(phi);
		y0 = distance * Math.sin(theta) * Math.sin(phi);
		z0 = distance * Math.cos(theta);
		
		sum_theta = new Complex(0.0,0.0);
		sum_rad = new Complex(0.0,0.0);
		sum_phi = new Complex(0.0,0.0);
		sum_x = new Complex(0.0,0.0);
		sum_y = new Complex(0.0,0.0);
		sum_z = new Complex(0.0,0.0);
		
		sum_htheta = new Complex(0.0,0.0);
		sum_hrad = new Complex(0.0,0.0);
		sum_hphi = new Complex(0.0,0.0);
		sum_hx = new Complex(0.0,0.0);
		sum_hy = new Complex(0.0,0.0);
		sum_hz = new Complex(0.0,0.0);
		
		
		//Calculations for first dipole
		for(int k=0;k<Nsections;k++){
		  //cartesian coordinates of running point
		    x1 = x0;
		    y1 = y0 + antenna_distance * 0.5;
		    z1 = z0 - zpos[k];
		  //spherical coordinates of running point
		    r1 = Math.sqrt(x1*x1 + y1*y1 + z1*z1);
		    theta1 = Math.atan2(Math.sqrt(x1*x1 + y1*y1),z1);
		    
		    phi1 = Math.atan2(y1,x1);

		    sinphi = Math.sin(phi1);
		    cosphi = Math.cos(phi1);
		    
		    expo10 = Complex.Exp(Complex.Multiply(minusjay,(beta*r1)));
		    field_factor1 = Complex.Multiply((2.0*Math.PI*1.0e-7*frequency*Deltaz*Math.sin(theta1)/r1),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current[k])));
		    field_factor2 = Complex.Add(1.0-1.0/((beta*r1)*(beta*r1)),Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		    field_factor1h = Complex.Multiply((beta*Deltaz*Math.sin(theta1)/(4.0*Math.PI*r1)),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current[k])));
		    field_factor2h = Complex.Add(1.0,Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		    //get electric field
		    e_theta = Complex.Multiply(field_factor1,field_factor2);
		    
		    field_factor3 = Complex.Multiply((4.0*Math.PI*1.0e-7*frequency*Deltaz*Math.cos(theta1)/r1),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current[k])));
		    field_factor4 = Complex.Subtract(field_factor2,1.0);
		    
		    e_rad = Complex.Multiply(field_factor3,field_factor4);
		    
		    //get magnetic field
		    h_phi = Complex.Multiply(field_factor1h,field_factor2h);
		    h_x = Complex.Multiply(h_phi,-sinphi);
		    h_y = Complex.Multiply(h_phi,cosphi);;
		    h_z = new Complex(0.0,0.0);
		    
		    e_x = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*cosphi),
				      Complex.Multiply(e_theta,Math.cos(theta1)*cosphi));
				      		    
		    e_y = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*sinphi),
				      Complex.Multiply(e_theta,Math.cos(theta1)*sinphi));
		    
		    e_z = Complex.Subtract(Complex.Multiply(e_rad,Math.cos(theta1)),
				      Complex.Multiply(e_theta,Math.sin(theta1)));
				      
		    //get spherical components in the reference system of coordinates  
		    e_rad = Complex.Add(Complex.Add(Complex.Multiply(e_x,Math.sin(theta)*cosphi2),
						      Complex.Multiply(e_y,Math.sin(theta)*sinphi2)
					  ),Complex.Multiply(e_z,Math.cos(theta)));
		    e_theta = Complex.Subtract(Complex.Add(Complex.Multiply(e_x,Math.cos(theta)*cosphi2),
						      Complex.Multiply(e_y,Math.cos(theta)*sinphi2)
					  ),Complex.Multiply(e_z,Math.sin(theta)));
					  
		    e_phi = Complex.Subtract(Complex.Multiply(e_y,cosphi2),Complex.Multiply(e_x,sinphi2));
		    
		    h_rad = Complex.Add(Complex.Add(Complex.Multiply(h_x,Math.sin(theta)*cosphi2),
						      Complex.Multiply(h_y,Math.sin(theta)*sinphi2)
					  ),Complex.Multiply(h_z,Math.cos(theta)));
		    h_theta = Complex.Subtract(Complex.Add(Complex.Multiply(h_x,Math.cos(theta)*cosphi2),
						      Complex.Multiply(h_y,Math.cos(theta)*sinphi2)
					  ),Complex.Multiply(h_z,Math.sin(theta)));
					  
		    h_phi = Complex.Subtract(Complex.Multiply(h_y,cosphi2),Complex.Multiply(h_x,sinphi2));
		    
		    sum_theta = Complex.Add(sum_theta,e_theta);
		    sum_rad   = Complex.Add(sum_rad,e_rad);
		    sum_phi   = Complex.Add(sum_phi,e_phi);
		    
		    sum_x     = Complex.Add(sum_x,e_x);
		    sum_y     = Complex.Add(sum_y,e_y);
		    sum_z     = Complex.Add(sum_z,e_z);
		    
		    sum_htheta = Complex.Add(sum_htheta,h_theta);
		    sum_hrad   = Complex.Add(sum_hrad,h_rad);
		    sum_hphi   = Complex.Add(sum_hphi,h_phi);
		    
		    sum_hx     = Complex.Add(sum_hx,h_x);
		    sum_hy     = Complex.Add(sum_hy,h_y);
		    sum_hz     = Complex.Add(sum_hz,h_z);
		    
		    
		}
		
		
		//Calculations for second dipole
		for(int k=0;k<Nsections2;k++){
		  //cartesian coordinates of running point
		    x1 = x0 ;
		    y1 = y0 - antenna_distance * 0.5;
		    z1 = z0 - zpos2[k];
		  //spherical coordinates of running point
		    r1 = Math.sqrt(x1*x1 + y1*y1 + z1*z1);
		    theta1 = Math.atan2(Math.sqrt(x1*x1 + y1*y1),z1);
		    
		    phi1 = Math.atan2(y1,x1);

		    sinphi = Math.sin(phi1);
		    cosphi = Math.cos(phi1);
		    
		    expo10 = Complex.Exp(Complex.Multiply(minusjay,(beta*r1)));
		    field_factor1 = Complex.Multiply((2.0*Math.PI*1.0e-7*frequency*Deltaz*Math.sin(theta1)/r1),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current2[k])));
		    field_factor2 = Complex.Add(1.0-1.0/((beta*r1)*(beta*r1)),Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		    field_factor1h = Complex.Multiply((beta*Deltaz*Math.sin(theta1)/(4.0*Math.PI*r1)),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current2[k])));
		    field_factor2h = Complex.Add(1.0,Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		    //get electric field
		    e_theta = Complex.Multiply(field_factor1,field_factor2);
		    
		    field_factor3 = Complex.Multiply((4.0*Math.PI*1.0e-7*frequency*Deltaz*Math.cos(theta1)/r1),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current2[k])));
		    field_factor4 = Complex.Subtract(field_factor2,1.0);
		    
		    e_rad = Complex.Multiply(field_factor3,field_factor4);
		    
		    //get magnetic field
		    h_phi = Complex.Multiply(field_factor1h,field_factor2h);
		    h_x = Complex.Multiply(h_phi,-sinphi);
		    h_y = Complex.Multiply(h_phi,cosphi);;
		    h_z = new Complex(0.0,0.0);
		    
		    e_x = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*cosphi),
				      Complex.Multiply(e_theta,Math.cos(theta1)*cosphi));
				      		    
		    e_y = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*sinphi),
				      Complex.Multiply(e_theta,Math.cos(theta1)*sinphi));
		    
		    e_z = Complex.Subtract(Complex.Multiply(e_rad,Math.cos(theta1)),
				      Complex.Multiply(e_theta,Math.sin(theta1)));
				      
		    //get spherical components in the reference system of coordinates  
		    e_rad = Complex.Add(Complex.Add(Complex.Multiply(e_x,Math.sin(theta)*cosphi2),
						      Complex.Multiply(e_y,Math.sin(theta)*sinphi2)
					  ),Complex.Multiply(e_z,Math.cos(theta)));
		    e_theta = Complex.Subtract(Complex.Add(Complex.Multiply(e_x,Math.cos(theta)*cosphi2),
						      Complex.Multiply(e_y,Math.cos(theta)*sinphi2)
					  ),Complex.Multiply(e_z,Math.sin(theta)));
					  
		    e_phi = Complex.Subtract(Complex.Multiply(e_y,cosphi2),Complex.Multiply(e_x,sinphi2));
		    
		    h_rad = Complex.Add(Complex.Add(Complex.Multiply(h_x,Math.sin(theta)*cosphi2),
						      Complex.Multiply(h_y,Math.sin(theta)*sinphi2)
					  ),Complex.Multiply(h_z,Math.cos(theta)));
		    h_theta = Complex.Subtract(Complex.Add(Complex.Multiply(h_x,Math.cos(theta)*cosphi2),
						      Complex.Multiply(h_y,Math.cos(theta)*sinphi2)
					  ),Complex.Multiply(h_z,Math.sin(theta)));
					  
		    h_phi = Complex.Subtract(Complex.Multiply(h_y,cosphi2),Complex.Multiply(h_x,sinphi2));
		    
		    sum_theta = Complex.Add(sum_theta,e_theta);
		    sum_rad   = Complex.Add(sum_rad,e_rad);
		    sum_phi   = Complex.Add(sum_phi,e_phi);
		    
		    sum_x     = Complex.Add(sum_x,e_x);
		    sum_y     = Complex.Add(sum_y,e_y);
		    sum_z     = Complex.Add(sum_z,e_z);
		    
		    sum_htheta = Complex.Add(sum_htheta,h_theta);
		    sum_hrad   = Complex.Add(sum_hrad,h_rad);
		    sum_hphi   = Complex.Add(sum_hphi,h_phi);
		    
		    sum_hx     = Complex.Add(sum_hx,h_x);
		    sum_hy     = Complex.Add(sum_hy,h_y);
		    sum_hz     = Complex.Add(sum_hz,h_z);
		    
		    
		}
		
	    //---------------------------------------------------------
		// Electric Field
		//etheta[i]  = sum_theta;
		
		ethetaM[i] = Complex.Magnitude(sum_theta);
		eradM[i] = Complex.Magnitude(sum_rad);
		ephigenM[i] = Complex.Magnitude(sum_phi);
		
		if(ephigenM[i] > EfieldPhigenMax){EfieldPhigenMax = ephigenM[i];}
		if(ethetaM[i] > EfieldMax){EfieldMax = ethetaM[i];}
		if(eradM[i] > EfieldRadMax){EfieldRadMax = eradM[i];}
		
		ex[i] = Complex.Magnitude(sum_x);
		ey[i] = Complex.Magnitude(sum_y);
		ez[i] = Complex.Magnitude(sum_z);
		
		if(ex[i] > EfieldCartxMax){EfieldCartxMax = ex[i];}
		if(ey[i] > EfieldCartyMax){EfieldCartyMax = ey[i];}
		if(ez[i] > EfieldCartzMax){EfieldCartzMax = ez[i];}
		
		// Magnetic Field
		
		hthetaM[i] = Complex.Magnitude(sum_htheta);
		hradM[i] = Complex.Magnitude(sum_hrad);
		hphigenM[i] = Complex.Magnitude(sum_hphi);
		
		if(hphigenM[i] > HfieldMax){HfieldMax = hphigenM[i];}
		if(hthetaM[i] > HfieldThetaMax){HfieldThetaMax = hthetaM[i];}
		if(hradM[i] > HfieldRadMax){HfieldRadMax = hradM[i];}
		
		hx[i] = Complex.Magnitude(sum_hx);
		hy[i] = Complex.Magnitude(sum_hy);
		hz[i] = Complex.Magnitude(sum_hz);
		
		if(hx[i] > HfieldCartxMax){HfieldCartxMax = hx[i];}
		if(hy[i] > HfieldCartyMax){HfieldCartyMax = hy[i];}
		if(hz[i] > HfieldCartzMax){HfieldCartzMax = hz[i];}
		//System.out.println(i+"   "+hthetaM[i]+"  "+hradM[i]+"    "+hphigenM[i]+"    "+HfieldCartzMax);
	    }
	    
	//}
	
	//==============================================================================================================
	//calculation of azimuthal plot
	//==============================================================================================================
	theta = Math.PI/2.0;
	EfieldphiMax = 0.0;
	EfieldphiRadMax = 0.0;
	EfieldphiPhiMax = 0.0;
	EfieldCart2xMax = 0.0;
	EfieldCart2yMax = 0.0;
	EfieldCart2zMax = 0.0;
	
	HfieldphiMax = 0.0;
	HfieldphiRadMax = 0.0;
	HfieldphiThetaMax = 0.0;
	HfieldCart2xMax = 0.0;
	HfieldCart2yMax = 0.0;
	HfieldCart2zMax = 0.0;
	
	double phivar;
	for(int i=0;i<361;i++){
	    phivar = angle_factor * i;
	    
		x0 = distance * Math.sin(theta) * Math.cos(phivar);
		y0 = distance * Math.sin(theta) * Math.sin(phivar);
		z0 = distance * Math.cos(theta);
	    
		sum_theta = new Complex(0.0,0.0);
		sum_rad = new Complex(0.0,0.0);
		sum_phi = new Complex(0.0,0.0);
		sum_x = new Complex(0.0,0.0);
		sum_y = new Complex(0.0,0.0);
		sum_z = new Complex(0.0,0.0);
		
		sum_htheta = new Complex(0.0,0.0);
		sum_hrad = new Complex(0.0,0.0);
		sum_hphi = new Complex(0.0,0.0);
		sum_hx = new Complex(0.0,0.0);
		sum_hy = new Complex(0.0,0.0);
		sum_hz = new Complex(0.0,0.0);
		
		//Calculations for first dipole
		for(int k=0;k<Nsections;k++){
		  //cartesian coordinates of running point
		    x1 = x0;
		    y1 = y0 + antenna_distance *0.5;
		    z1 = z0 - zpos[k];
		  //spherical coordinates of running point
		    r1 = Math.sqrt(x1*x1 + y1*y1 + z1*z1);
		    theta1 = Math.atan2(Math.sqrt(x1*x1 + y1*y1),z1);
		    phi1 = Math.atan2(y1,x1);
		    
		    expo10 = Complex.Exp(Complex.Multiply(minusjay,(beta*r1)));
		    field_factor1 = Complex.Multiply((2.0*Math.PI*1.0e-7*frequency*Deltaz*Math.sin(theta1)/r1),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current[k])));
		    field_factor2 = Complex.Add(1.0-1.0/((beta*r1)*(beta*r1)),Complex.Multiply(minusjay,1.0/(beta*r1)));
		    field_factor1h = Complex.Multiply((beta*Deltaz*Math.sin(theta1)/(4.0*Math.PI*r1)),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current[k])));
		    field_factor2h = Complex.Add(1.0,Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		    e_theta = Complex.Multiply(field_factor1,field_factor2);
		    
		    field_factor3 = Complex.Multiply((4.0*Math.PI*1.0e-7*frequency*Deltaz*Math.cos(theta1)/r1),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current[k])));
		    field_factor4 = Complex.Subtract(field_factor2,1.0);
		    
		    e_rad = Complex.Multiply(field_factor3,field_factor4);
		    
		    e_x = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*Math.cos(phi1)),
				      Complex.Multiply(e_theta,Math.cos(theta1)*Math.cos(phi1)));
		    e_y = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*Math.sin(phi1)),
				      Complex.Multiply(e_theta,Math.cos(theta1)*Math.sin(phi1)));
		    e_z = Complex.Subtract(Complex.Multiply(e_rad,Math.cos(theta1)),
				      Complex.Multiply(e_theta,Math.sin(theta1)));
				      
		    h_phi = Complex.Multiply(field_factor1h,field_factor2h);
		    h_x = Complex.Multiply(h_phi,-Math.sin(phi1));
		    h_y = Complex.Multiply(h_phi,Math.cos(phi1));
		    h_z = new Complex(0.0,0.0);
				      
		    //get spherical components in the reference system of coordinates 
		    e_rad = Complex.Add(Complex.Add(Complex.Multiply(e_x,Math.sin(theta)*Math.cos(phivar)),
						      Complex.Multiply(e_y,Math.sin(theta)*Math.sin(phivar))
					  ),Complex.Multiply(e_z,Math.cos(theta)));
		    e_theta = Complex.Subtract(Complex.Add(Complex.Multiply(e_x,Math.cos(theta)*Math.cos(phivar)),
						      Complex.Multiply(e_y,Math.cos(theta)*Math.sin(phivar))
					  ),Complex.Multiply(e_z,Math.sin(theta)));
		    e_phi = Complex.Subtract(Complex.Multiply(e_y,Math.cos(phivar)),Complex.Multiply(e_x,Math.sin(phivar)));
		    
		    h_rad = Complex.Add(Complex.Add(Complex.Multiply(h_x,Math.sin(theta)*Math.cos(phivar)),
						      Complex.Multiply(h_y,Math.sin(theta)*Math.sin(phivar))
					  ),Complex.Multiply(h_z,Math.cos(theta)));
		    h_theta = Complex.Subtract(Complex.Add(Complex.Multiply(h_x,Math.cos(theta)*Math.cos(phivar)),
						      Complex.Multiply(h_y,Math.cos(theta)*Math.sin(phivar))
					  ),Complex.Multiply(h_z,Math.sin(theta)));
		    h_phi = Complex.Subtract(Complex.Multiply(h_y,Math.cos(phivar)),Complex.Multiply(h_x,Math.sin(phivar)));
		   		      
		    sum_theta = Complex.Add(sum_theta,e_theta);
		    sum_rad   = Complex.Add(sum_rad,e_rad);
		    sum_phi   = Complex.Add(sum_phi,e_phi);
		    
		    sum_x     = Complex.Add(sum_x,e_x);
		    sum_y     = Complex.Add(sum_y,e_y);
		    sum_z     = Complex.Add(sum_z,e_z);
		    
		    sum_htheta = Complex.Add(sum_htheta,h_theta);
		    sum_hrad   = Complex.Add(sum_hrad,h_rad);
		    sum_hphi   = Complex.Add(sum_hphi,h_phi);
		    
		    sum_hx     = Complex.Add(sum_hx,h_x);
		    sum_hy     = Complex.Add(sum_hy,h_y);
		    sum_hz     = Complex.Add(sum_hz,h_z);
		    
		}
		
		
		//Calculations for second dipole
		for(int k=0;k<Nsections2;k++){
		  //cartesian coordinates of running point
		    x1 = x0;
		    y1 = y0 - antenna_distance * 0.5;
		    z1 = z0 - zpos2[k];
		  //spherical coordinates of running point
		    r1 = Math.sqrt(x1*x1 + y1*y1 + z1*z1);
		    theta1 = Math.atan2(Math.sqrt(x1*x1 + y1*y1),z1);
		    phi1 = Math.atan2(y1,x1);
		    
		    expo10 = Complex.Exp(Complex.Multiply(minusjay,(beta*r1)));
		    field_factor1 = Complex.Multiply((2.0*Math.PI*1.0e-7*frequency*Deltaz*Math.sin(theta1)/r1),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current2[k])));
		    field_factor2 = Complex.Add(1.0-1.0/((beta*r1)*(beta*r1)),Complex.Multiply(minusjay,1.0/(beta*r1)));
		    field_factor1h = Complex.Multiply((beta*Deltaz*Math.sin(theta1)/(4.0*Math.PI*r1)),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current2[k])));
		    field_factor2h = Complex.Add(1.0,Complex.Multiply(minusjay,1.0/(beta*r1)));
		    
		    e_theta = Complex.Multiply(field_factor1,field_factor2);
		    
		    field_factor3 = Complex.Multiply((4.0*Math.PI*1.0e-7*frequency*Deltaz*Math.cos(theta1)/r1),
						   Complex.Multiply(expo10,Complex.Multiply(jay,current2[k])));
		    field_factor4 = Complex.Subtract(field_factor2,1.0);
		    
		    e_rad = Complex.Multiply(field_factor3,field_factor4);
		    
		    e_x = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*Math.cos(phi1)),
				      Complex.Multiply(e_theta,Math.cos(theta1)*Math.cos(phi1)));
		    e_y = Complex.Add(Complex.Multiply(e_rad,Math.sin(theta1)*Math.sin(phi1)),
				      Complex.Multiply(e_theta,Math.cos(theta1)*Math.sin(phi1)));
		    e_z = Complex.Subtract(Complex.Multiply(e_rad,Math.cos(theta1)),
				      Complex.Multiply(e_theta,Math.sin(theta1)));
				      
		    h_phi = Complex.Multiply(field_factor1h,field_factor2h);
		    h_x = Complex.Multiply(h_phi,-Math.sin(phi1));
		    h_y = Complex.Multiply(h_phi,Math.cos(phi1));
		    h_z = new Complex(0.0,0.0);
				      
		    //get spherical components in the reference system of coordinates 
		    e_rad = Complex.Add(Complex.Add(Complex.Multiply(e_x,Math.sin(theta)*Math.cos(phivar)),
						      Complex.Multiply(e_y,Math.sin(theta)*Math.sin(phivar))
					  ),Complex.Multiply(e_z,Math.cos(theta)));
		    e_theta = Complex.Subtract(Complex.Add(Complex.Multiply(e_x,Math.cos(theta)*Math.cos(phivar)),
						      Complex.Multiply(e_y,Math.cos(theta)*Math.sin(phivar))
					  ),Complex.Multiply(e_z,Math.sin(theta)));
		    e_phi = Complex.Subtract(Complex.Multiply(e_y,Math.cos(phivar)),Complex.Multiply(e_x,Math.sin(phivar)));
		    
		    h_rad = Complex.Add(Complex.Add(Complex.Multiply(h_x,Math.sin(theta)*Math.cos(phivar)),
						      Complex.Multiply(h_y,Math.sin(theta)*Math.sin(phivar))
					  ),Complex.Multiply(h_z,Math.cos(theta)));
		    h_theta = Complex.Subtract(Complex.Add(Complex.Multiply(h_x,Math.cos(theta)*Math.cos(phivar)),
						      Complex.Multiply(h_y,Math.cos(theta)*Math.sin(phivar))
					  ),Complex.Multiply(h_z,Math.sin(theta)));
		    h_phi = Complex.Subtract(Complex.Multiply(h_y,Math.cos(phivar)),Complex.Multiply(h_x,Math.sin(phivar)));
		   		      
		    sum_theta = Complex.Add(sum_theta,e_theta);
		    sum_rad   = Complex.Add(sum_rad,e_rad);
		    sum_phi   = Complex.Add(sum_phi,e_phi);
		    
		    sum_x     = Complex.Add(sum_x,e_x);
		    sum_y     = Complex.Add(sum_y,e_y);
		    sum_z     = Complex.Add(sum_z,e_z);
		    
		    sum_htheta = Complex.Add(sum_htheta,h_theta);
		    sum_hrad   = Complex.Add(sum_hrad,h_rad);
		    sum_hphi   = Complex.Add(sum_hphi,h_phi);
		    
		    sum_hx     = Complex.Add(sum_hx,h_x);
		    sum_hy     = Complex.Add(sum_hy,h_y);
		    sum_hz     = Complex.Add(sum_hz,h_z);
		    
		}
		
	    //---------------------------------------------------------
		//ephi[i]  = sum_theta;
		ephiM[i] = Complex.Magnitude(sum_theta);
		ephiradM[i] = Complex.Magnitude(sum_rad);
		ephiphiM[i] = Complex.Magnitude(sum_phi);
		ephix[i] = Complex.Magnitude(sum_x);
		ephiy[i] = Complex.Magnitude(sum_y);
		ephiz[i] = Complex.Magnitude(sum_z);
		
		if(ephiM[i] > EfieldphiMax){EfieldphiMax = ephiM[i];}
		if(ephiradM[i] > EfieldphiRadMax){EfieldphiRadMax = ephiradM[i];}
		if(ephiphiM[i] > EfieldphiPhiMax){EfieldphiPhiMax = ephiphiM[i];}
		if(ephix[i] > EfieldCart2xMax){EfieldCart2xMax = ephix[i];}
		if(ephiy[i] > EfieldCart2yMax){EfieldCart2yMax = ephiy[i];}
		if(ephiz[i] > EfieldCart2zMax){EfieldCart2zMax = ephiz[i];}
		
		// Magnetic Field
		
		hphithetaM[i] = Complex.Magnitude(sum_htheta);
		hphiradM[i] = Complex.Magnitude(sum_hrad);
		hphiM[i] = Complex.Magnitude(sum_hphi);
		
		if(hphiM[i] > HfieldphiMax){HfieldphiMax = hphiM[i];}
		if(hphithetaM[i] > HfieldphiThetaMax){HfieldphiThetaMax = hphithetaM[i];}
		if(hphiradM[i] > HfieldphiRadMax){HfieldphiRadMax = hphiradM[i];}
		
		hphix[i] = Complex.Magnitude(sum_hx);
		hphiy[i] = Complex.Magnitude(sum_hy);
		hphiz[i] = Complex.Magnitude(sum_hz);
		
		if(hphix[i] > HfieldCart2xMax){HfieldCart2xMax = hphix[i];}
		if(hphiy[i] > HfieldCart2yMax){HfieldCart2yMax = hphiy[i];}
		if(hphiz[i] > HfieldCart2zMax){HfieldCart2zMax = hphiz[i];}
	    }
	//}
	
	/*
	//get absolute maximum
	double maxcart = 0.0;
	double threshold = 1.0e-10;
	
	if(EfieldCart2xMax > maxcart){maxcart = EfieldCart2xMax;}
	if(EfieldCart2yMax > maxcart){maxcart = EfieldCart2yMax;}
	if(EfieldCart2zMax > maxcart){maxcart = EfieldCart2zMax;}
	if(EfieldCartxMax > maxcart){maxcart = EfieldCartxMax;}
	if(EfieldCartyMax > maxcart){maxcart = EfieldCartyMax;}
	if(EfieldCartzMax > maxcart){maxcart = EfieldCartzMax;}
	if(EfieldphiMax > maxcart){maxcart = EfieldphiMax;}
	if(EfieldphiRadMax > maxcart){maxcart = EfieldphiRadMax;}
	if(EfieldphiPhiMax > maxcart){maxcart = EfieldphiPhiMax;}
	if(EfieldPhigenMax > maxcart){maxcart = EfieldPhigenMax;}
	if(EfieldMax > maxcart){maxcart = EfieldMax;}
	if(EfieldRadMax > maxcart){maxcart = EfieldRadMax;}
	
	double normthreshold = maxcart*threshold;
	
	//if plots are below 1.0E-10 of absolute maximum, they are set to zero.
	if(EfieldCartxMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ex[i] = 0.0;
	    }
	}
	
	if(EfieldCartyMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ey[i] = 0.0;
	    }
	}
	
	if(EfieldCartzMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ez[i] = 0.0;
	    }
	}
	
	if(EfieldCart2xMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ephix[i] = 0.0;
	    }
	}
	
	if(EfieldCart2yMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ephiy[i] = 0.0;
	    }
	}
	
	if(EfieldCart2zMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ephiz[i] = 0.0;
	    }
	}
	
	if(EfieldMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ethetaM[i] = 0.0;
	    }
	}
	
	if(EfieldRadMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		eradM[i] = 0.0;
	    }
	}
	
	if(EfieldPhigenMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ephigenM[i] = 0.0;
	    }
	}
		
	if(EfieldphiMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ephiM[i] = 0.0;
	    }
	}
	
	if(EfieldphiRadMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ephiradM[i] = 0.0;
	    }
	}
	
	if(EfieldphiPhiMax < maxcart*normthreshold){
	    for(int i=0;i<361;i++){
		ephiphiM[i] = 0.0;
	    }
	}
	*/
	
	double rescale;
	rescale = Math.max(EfieldMax,EfieldphiMax);
	EfieldMax = rescale;
	EfieldphiMax = rescale;
	
	rescale = Math.max(EfieldRadMax,EfieldphiRadMax);
	EfieldRadMax = rescale;
	EfieldphiRadMax = rescale;
	
	rescale = Math.max(EfieldPhigenMax,EfieldphiPhiMax);
	EfieldPhigenMax = rescale;
	EfieldphiPhiMax = rescale;
	
	rescale = Math.max(EfieldCartxMax,EfieldCart2xMax);
	EfieldCartxMax = rescale;
	EfieldCart2xMax = rescale;
	
	rescale = Math.max(EfieldCartyMax,EfieldCart2yMax);
	EfieldCartyMax = rescale;
	EfieldCart2yMax = rescale;
	
	rescale = Math.max(EfieldCartzMax,EfieldCart2zMax);
	EfieldCartzMax = rescale;
	EfieldCart2zMax = rescale;
	
	rescale = Math.max(HfieldCartxMax,HfieldCart2xMax);
	HfieldCartxMax = rescale;
	HfieldCart2xMax = rescale;
	
	rescale = Math.max(HfieldCartyMax,HfieldCart2yMax);
	HfieldCartyMax = rescale;
	HfieldCart2yMax = rescale;
	
	rescale = Math.max(HfieldMax,HfieldphiMax);
	HfieldMax = rescale;
	HfieldphiMax = rescale;
	
	rescale = Math.max(HfieldThetaMax,HfieldphiThetaMax);
	HfieldThetaMax = rescale;
	HfieldphiThetaMax = rescale;
	
	rescale = Math.max(HfieldRadMax,HfieldphiRadMax);
	HfieldRadMax = rescale;
	HfieldphiRadMax = rescale;
	
}
public void scan_reactance(){
	
}


//-----------------------------------------------------------------------------------------------------------------------

public void setThetaPlaneMaxima(){
	double PlaneEMax, PlaneHMax;
	double phi, theta;
	double tmp1;
	Complex efield;
	Complex hfield;

	int i, j;
        TotalP=0.0;
	PlaneEMax=0.0;
	PlaneHMax=0.0;
	PlanePMax=0.0;
	
	tmp1=Math.PI/180.0;
	
	for(j=0;j<360;j=j+1){
	
	    phi=tmp1*j;
	    
	    for(i=0;i<180;i=i+1){
		theta=tmp1*i;
		hfield=getHfield(theta,phi);
                TotalP=TotalP+(hfield).Magnitude()*(hfield).Magnitude()*Math.sin(theta);  
		
		if(PlaneHMax<hfield.Magnitude()) {
		    PlaneHMax=(hfield.Magnitude());  
		}  	
	    }
	}
	
	if(PlaneHMax==0.0){
	    PlaneHMax=1.0;
	}
	
	PlaneEMax=PlaneHMax*medium_impedance;
	PlanePMax=PlaneEMax*PlaneHMax/2.0;
	TotalP=point_distance*point_distance*medium_impedance*TotalP*0.5*(Math.PI*Math.PI)/(180.0*180.0);
	//System.out.println("Potenza totale = "+TotalP+"   PlanePMax = "+PlanePMax);
}

public void UpdateRadiation(){
	int i;
	double theta;
	double phi;
	double r1, r2;
	double PradA,PradB, U, UmaxA, UmaxB; 
	
	//directivity loop
	UmaxA=0.0;
	PradA=0.0;
	
	for(i=0;i<180;i++){
		theta=(i*Math.PI/180.0);
		//Avoid sin(theta)=0.0 situation
		if(theta!=0.0 && Math.abs(theta)!=(Math.PI) ){
		    if(DipoleLength_lambda > 0.0){
			U=(medium_impedance*currentin*currentin*currentscale*currentscale*
			Math.pow((Math.cos(Math.PI*DipoleLength_lambda*Math.cos(theta))
			-Math.cos(Math.PI*DipoleLength_lambda))/Math.sin(theta),2.0)
			/(8.0*Math.PI*Math.PI));
		    }
		    else{
			U=(medium_impedance*currentin*currentin*currentscale*currentscale*
			Math.pow((Math.cos(Math.PI*(DipoleLength_lambda+0.000001)*Math.cos(theta))
			-Math.cos(Math.PI*(DipoleLength_lambda+0.000001)))/Math.sin(theta),2.0)
			/(8.0*Math.PI*Math.PI));
		    }
		    if(UmaxA<Math.abs(U)) UmaxA=Math.abs(U);
			PradA+=(U*Math.sin(theta)*2.0*Math.PI*Math.PI/180.0);
		    }
	}
	
	    UmaxB=0.0;
	    PradB=0.0;
	    for(i=0;i<180;i++){
		theta=(i*Math.PI/180.0);
		//Avoid sin(theta)=0.0 situation
		if(theta!=0.0f && Math.abs(theta)!=(Math.PI)){
		    if(DipoleLength2_lambda > 0.0){
			U=(medium_impedance*currentin2*currentin2*currentscale2*currentscale2*
			Math.pow((Math.cos(Math.PI*DipoleLength2_lambda*Math.cos(theta))
			-Math.cos(Math.PI*DipoleLength2_lambda))/Math.sin(theta),2.0)
			/(8.0*Math.PI*Math.PI));
		    }
		    else{
			U=(medium_impedance*currentin2*currentin2*currentscale2*currentscale2*
			Math.pow((Math.cos(Math.PI*(DipoleLength2_lambda+0.000001)*Math.cos(theta))
			-Math.cos(Math.PI*(DipoleLength2_lambda+0.000001)))/Math.sin(theta),2.0)
			/(8.0*Math.PI*Math.PI));
		    }
		   if(UmaxB<Math.abs(U)) UmaxB=Math.abs(U);
		   PradB+=(U*Math.sin(theta)*2.0*Math.PI*Math.PI/180.0);
		}
	}
		
	directivityAB=(4*Math.PI*point_distance*point_distance*PlanePMax/TotalP);
	
	//System.out.println("Directivity = "+directivityAB+"   "+PlanePMax+"   "+TotalP);
}

public Complex getHfield(double theta, double phi){
	int i;
	double targ1, targ2, targ3, targa, targb;
	Complex myhfield, carga, cargb;

	if(DipoleLength_lambda<0.5){
		if(DipoleLength_lambda > 0.0){
		currentscale=(1.0/Math.sin(Math.PI*(DipoleLength_lambda)));
		}
		else{
		    currentscale=(1.0/Math.sin(Math.PI*(DipoleLength_lambda+0.000001)));
		}
	}
	else{
		currentscale=1.0;
	}
	if(DipoleLength2_lambda<0.5){
		if(DipoleLength2_lambda > 0.0){
		    currentscale2=(1.0/Math.sin(Math.PI*(DipoleLength2_lambda)));
		}
		else{
		    currentscale2=(1.0/Math.sin(Math.PI*(DipoleLength2_lambda+0.000001)));
		}
	}
	else{
		currentscale2=1.0;
	}
	//Avoid sin(theta)=0.0 situation
	if(theta!=0.0 && Math.abs(theta)!=(Math.PI) ){
	  targ1=Math.PI*antenna_distance_lambda*Math.sin(theta)*Math.sin(phi)-antenna_phase/2.0-2.0*Math.PI*point_distance;
	  targ2=Math.PI*antenna_distance_lambda*Math.sin(theta)*Math.sin(phi)-antenna_phase/2.0+2.0*Math.PI*point_distance;
	  targ3=1.0/(2.0*Math.PI*point_distance*Math.sin(theta));
	  
	  if (DipoleLength_lambda > 0.0){
	    targa=currentin*currentscale*(Math.cos(Math.PI*DipoleLength_lambda*Math.cos(theta))
                                        -Math.cos(Math.PI*DipoleLength_lambda));
	  }
	  else{
	    targa=currentin*currentscale*(Math.cos(Math.PI*(DipoleLength_lambda+0.000001)*Math.cos(theta))
                                        -Math.cos(Math.PI*(DipoleLength_lambda+0.000001)));
	  }	
	  if (DipoleLength2_lambda > 0.0){  
	    targb=currentin2*currentscale2*(Math.cos(Math.PI*DipoleLength2_lambda*Math.cos(theta))
                                        -Math.cos(Math.PI*DipoleLength2_lambda));
	  }
	  else{
	    targb=currentin2*currentscale2*(Math.cos(Math.PI*(DipoleLength2_lambda+0.000001)*Math.cos(theta))
                                        -Math.cos(Math.PI*(DipoleLength2_lambda+0.000001)));
	  }
	  carga=new Complex(-Math.sin(targ1),Math.cos(targ1));
	  cargb=new Complex( Math.sin(targ2),Math.cos(targ2));
			
	  carga.Multiply(targa);
	  cargb.Multiply(targb);

	  myhfield=new Complex(0.0,0.0);
	  myhfield.Add(carga);
	  myhfield.Add(cargb);

	  myhfield.Multiply(targ3);
	}
	else{
		myhfield=new Complex(0.0,0.0);
	}

	  return(myhfield);
}

//------------------------------------------------------------------------------------------------------------------------


//Gets array for plot of Field as function of frequency    
public void scan_coefficients(){
	
	double len;
	double Func[], Func2[], Func2Max, angle, seno;
	int Nmax;
	Nmax = 1800;
	
	Func   = new double[Nmax+1];
	Func2   = new double[Nmax+1];
	
	DVMax = 0.0;
	RVMax = 0.0;
	RinVMax = 0.0;
	XVMax = 0.0;
	XVMin = 0.0;
	XinVMin = 0.0;
	
	for(int iL=0;iL<Numpoints;iL++){
	    //-----------------------------------------------------
	    len = a_minimum + DeltaLength * iL;	    
	    leng[iL] = len;
	    if(len == 0.0){
		DVector[0] = 0.0;
		RVector[0] = 0.0;
		RinVector[0] = 0.0;
		XVector[0] = 0.0;
		XinVector[0] = -1.0e-230;
	    }
	    else{
		Func2Max=0.0;
		TotalPower=0.0;
	
		if(len >= 1.0e-4){
		    for(int i=1;i<Nmax;i++){
			angle=i*Math.PI/Nmax;
			{
			    //Func2[i]= (medium_impedance*current_magnitude*current_magnitude*currentscale*currentscale*
			    Func2[i]= (medium_impedance*
					Math.pow((Math.cos(Math.PI*len*Math.cos(angle))-Math.cos(Math.PI*len))/Math.sin(angle),2.0)
					/(8.0*Math.PI*Math.PI));
			    if(Func2Max<Math.abs(Func2[i])){Func2Max=Math.abs(Func2[i]);}
			    TotalPower+=(float)(Func2[i]*Math.sin(angle)*2.0*Math.PI*Math.PI/Nmax);
			}
		    }
	
		    DVector[iL] =(float)(4.0*Math.PI*Func2Max/TotalPower);
		    RVector[iL] = TotalPower * 2 ;
		}
		else{
		    DVector[iL] = 1.5;
		    //TotalPower = (4.0*Math.PI*medium_impedance/3)*Math.pow(current_magnitude*DipoleLength_lambda*0.25,2.0); 
		    TotalPower = (4.0*Math.PI*medium_impedance/3)*Math.pow(DipoleLength_lambda*0.25,2.0); 
		    RVector[iL] = 2.0*TotalPower;
		}
		
		seno = Math.pow(Math.sin(Math.PI*len),2.0);
		if((int)len == len){
		    RinVector[iL] = 2.0E230;
		}
		else{
		    RinVector[iL] = RVector[iL]/seno;
		}
	
		if(DVector[iL] > DVMax){DVMax = DVector[iL];}
		if(RVector[iL] > RVMax){RVMax = RVector[iL];}
		//if(RinVector[iL] > RinVMax){RinVMax = RinVector[iL];}
		
		
		// calculate reactance --------
		int indice;
		double var1, var2, var3, Sint1, Sint2, Cint1, Cint2, Cint3, seg1, seg2, seg3, radius;
		double v8, v6, v4, v2, fut, gut;
		radius = wire_radius;
		Sint1 = 0.0; Sint2 = 0.0; Cint1 = 0.0; Cint2 = 0.0; Cint3 = 0.0;
		
		if(len == 0.0){
		    XVector[iL] = 0.0;
		}	
		else{
		    indice = 0;
		
		    var1 = 2.0*Math.PI*len;
		    var2 = 4.0*Math.PI*len;
		    var3 = 4.0*Math.PI*radius*radius/len;
		    seg1 = 0.0; seg2 = 0.0 ; seg3 = 0.0;
	    	
		    if(var1 < 2.0 && var1>0.0){
			indice = (int)(var1 *100.0); 
			seg1 = (var1*100.0 - indice);
			Sint1 = (1-seg1)*Si[indice] + seg1*Si[indice+1];
			Cint1 = (1-seg1)*Ci[indice] + seg1*Ci[indice+1];
		    }
		    else if(var1 >= 2.0 && var1 < 10.0){
			indice = 10*(int)(var1 *10.0); 
			seg1 = (var1*100.0 - indice)/10;
			Sint1 = (1-seg1)*Si[indice] + seg1*Si[indice+10];
			Cint1 = (1-seg1)*Ci[indice] + seg1*Ci[indice+10];
		    }
		    else{
			v2 = var1 * var1;
			v4 = v2 * v2;
			v6 = v2 * v4;
			v8 = v4 * v4;
		
			fut = (v8 + FA1 * v6 + FA2 * v4 + FA3 * v2 + FA4)/(var1 * (v8 + FB1 * v6 + FB2 * v4 + FB3 * v2 + FB4));
			gut = (v8 + GA1 * v6 + GA2 * v4 + GA3 * v2 + GA4)/(var1 * (v8 + GB1 * v6 + GB2 * v4 + GB3 * v2 + GB4));
			Sint1 = 0.5*Math.PI - fut * Math.cos(var1) - gut * Math.sin(var1);
			Cint1 = fut * Math.sin(var1) - gut * Math.cos(var1);
		    }
	    
		    if(var2 < 2.0 && var2>0.0){
			indice = (int)(var2 *100.0); 
			seg2 = (var2*100.0 - indice);
			Sint2 = (1-seg2)*Si[indice] + seg2*Si[indice+1];
			Cint2 = (1-seg2)*Ci[indice] + seg2*Ci[indice+1];
		    }
		    else if(var2 >= 2.0 && var2 < 10.0){
			indice = 10*(int)(var2 *10.0); 
			seg2 = (var2*100.0 - indice)/10;
			Sint2 = (1-seg2)*Si[indice] + seg2*Si[indice+10];
			Cint2 = (1-seg2)*Ci[indice] + seg2*Ci[indice+10];
		    }
		    else{
			v2 = var2 * var2;
			v4 = v2 * v2;
			v6 = v2 * v4;
			v8 = v4 * v4;
		
			fut = (v8 + FA1 * v6 + FA2 * v4 + FA3 * v2 + FA4)/(var1 * (v8 + FB1 * v6 + FB2 * v4 + FB3 * v2 + FB4));
			gut = (v8 + GA1 * v6 + GA2 * v4 + GA3 * v2 + GA4)/(var1 * (v8 + GB1 * v6 + GB2 * v4 + GB3 * v2 + GB4));
			Sint2 = 0.5*Math.PI - fut * Math.cos(var2) - gut * Math.sin(var2);
			Cint2 = fut * Math.sin(var2) - gut * Math.cos(var2);
		    }
	
		    if(var3 < 0.01 && var3>0.0){
			//approximation for small values of argument of Cos integral 
			//In Abramowitz-Stegun, one notices that for small values 
			//(Ci(x) - ln x - 0.5772156649) is approximately -0.25 for all values of x below 0.01
			Cint3 = -0.25*var3*var3 + Math.log(var3)+0.5772156649;
		    }
		    else if(var3 >= 0.01 && var3 < 2.0){
			indice = (int)(var3 *100.0); 
			seg3 = (var3*100.0 - indice);
			Cint3 = (1-seg3)*Ci[indice] + seg3*Ci[indice+1];
		    }
		    else if(var3 >= 2.0 && var3 < 10.0){
			indice = 10*(int)(var3 *10.0); 
			seg3 = (var3*100.0 - indice)/10;
			Cint3 = (1-seg3)*Ci[indice] + seg3*Ci[indice+10];
		    }
		    else{
			v2 = var3 * var3;
			v4 = v2 * v2;
			v6 = v2 * v4;
			v8 = v4 * v4;
			//Rational approximation for Cos integral
			fut = (v8 + FA1 * v6 + FA2 * v4 + FA3 * v2 + FA4)/(var1 * (v8 + FB1 * v6 + FB2 * v4 + FB3 * v2 + FB4));
			gut = (v8 + GA1 * v6 + GA2 * v4 + GA3 * v2 + GA4)/(var1 * (v8 + GB1 * v6 + GB2 * v4 + GB3 * v2 + GB4));
		
			Cint3 = fut * Math.sin(var3) - gut * Math.cos(var3);
		    }
	      
		    XVector[iL] = (0.25/Math.PI) * medium_impedance 
			     *((2.0*Sint1 + Math.cos(2.0*Math.PI*len)*(2.0*Sint1 - Sint2))
			     - Math.sin(2.0*Math.PI*len)*(2.0*Cint1 - Cint2 - Cint3));
		    XinVector[iL] = XVector[iL] /Math.pow(Math.sin(Math.PI*len),2.0);
		}
		//-------------------------------------------------------- end reactance calculation
		if(XVector[iL] > XVMax){XVMax = XVector[iL];}
		if(XVector[iL] < XVMin){XVMin = XVector[iL];}
		if(iL > Numpoints/10){
		    if(XinVector[iL] < XinVMin){XinVMin = XinVector[iL]; }
		}
	    }
	    
	    RinVMax = 2000.0;
	    XinVMax = 2000.0;
	    //XinVMin = -2000.0;
	    
	    //-----------------------------------------------------------------
	}
   } 
}
