//Antenna.java
//This is a program for a simple antenna array
//
import java.util.*;

import java.awt.*;
import java.awt.event.*;

public class Antenna extends Frame implements ActionListener, WindowListener{

//The Canvas
//About about;
    Instructions instructions;
    Panel instrFrame, cyanFrame;
DrawCanvas dcan;
RadarCanvas rcan1, rcan2;

SlidePanel slidepanel;
RadarControls rcons;
PhiControls phicontrol;
//ControlPanel controlpanel;
OutPanel outputpanel;


OutPanel   outpanel;
TitlePanel titlepanel;
private final Color bcolor=new Color(179,230,255);

//dipolelength and  dipolecurrent
//antenna A
public double dipolelengthA;
public final double dipolelengthmaxA=3.0;
public double dipolecurrentA;
public double scalingA=1.0;
public int number_dipoles = 5;
public int number_dipoles_max = 50;

//These parameters determine maxima in theta plane for graph display
public double TotalP, PlaneEMax, PlaneHMax, PlanePMax;

//Impedance of the medium
public double SpaceImp;

public double distancia, distanciamax, fase, R;
//distancia--> distance between dipoles
//fase --> phase between dipoles
//R    --> radius at which diagrams for radiation are computed. 

//arrays for electric field, magnetic field, and power for theta-plane
public Complex efield[];
public Complex hfield[];
public double efield_mag[];
public double hfield_mag[];
public double power[];
//arrays for electric field, magnetic field, and power for phi-plane
public Complex eefield[];
public Complex hhfield[];
public double eefield_mag[];
public double hhfield_mag[];
public double ppower[];
public double radiation_powerA, directivityA, radiation_resistanceA;
public double directivityAB;

final int DrawCanvasHPos=10;
final int DrawCanvasVPos= 55;
final int DrawCanvasWidth=260;
final int DrawCanvasHeight=210;


final int RadarCanvasHPos1=5+DrawCanvasHPos+DrawCanvasWidth;
final int RadarCanvasVPos1=10;
final int RadarCanvasWidth1=255;
final int RadarCanvasHeight1=255;

final int RadarCanvasHPos2=5+DrawCanvasHPos+DrawCanvasWidth;
final int RadarCanvasVPos2=RadarCanvasVPos1+RadarCanvasHeight1+5;
final int RadarCanvasWidth2=255;
final int RadarCanvasHeight2=255;

final int PhiControlsHPos=5+DrawCanvasHPos+DrawCanvasWidth;
final int PhiControlsVPos=RadarCanvasVPos1+RadarCanvasHeight1-4;
final int PhiControlsWidth=255;
final int PhiControlsHeight=12;

//Input Panel
final int SlidePanelHPos=10;
final int SlidePanelVPos=RadarCanvasVPos2+60;
final int SlidePanelWidth=DrawCanvasWidth;
final int SlidePanelHeight=RadarCanvasHeight2-60;

final int OutPanelHPos=DrawCanvasHPos;
final int OutPanelVPos=DrawCanvasVPos+DrawCanvasHeight+5;
final int OutPanelWidth=DrawCanvasWidth;
final int OutPanelHeight=33;

final int RadarControlsHPos =DrawCanvasHPos+1;
final int RadarControlsVPos =OutPanelVPos+OutPanelHeight+4;
final int RadarControlsWidth =DrawCanvasWidth-2;
final int RadarControlsHeight =19;

//final int RadarControlsHPos =RadarCanvasHPos1+RadarCanvasWidth1+10;
//final int RadarControlsVPos =RadarCanvasVPos1+1;
//final int RadarControlsWidth =95;
//final int RadarControlsHeight =70;

final int ButtonPanelHPos=RadarCanvasHPos1;
final int ButtonPanelVPos=5;
final int ButtonPanelWidth=100;
final int ButtonPanelHeight=30;

final int TitlePanelHPos=DrawCanvasHPos;
final int TitlePanelVPos=10;
final int TitlePanelWidth=260;
final int TitlePanelHeight=40;
public final Complex uno = 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 static void main(String[] args){
        Antenna f = new Antenna();
        int xmove = 20;
        int ymove = 41;
        f.setSize(624+xmove,637+ymove);
        f.setVisible(true);
        f.setLayout(null);
}

public Antenna(){
	setLayout(null);
        String lcOSName = System.getProperty("os.name").toLowerCase();
        boolean MAC_OS_X = lcOSName.startsWith("mac os x");
        boolean PC_OS = lcOSName.startsWith("windows");
        TheFonts.setMAC_OS_X(MAC_OS_X);
        TheFonts.setPC_OS(PC_OS);
	//setBackground(bcolor);
	
        int xmove = 10;
        int ymove = 34;
	
	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);

	
	efield = new Complex[361];
	hfield = new Complex[361];
	efield_mag = new double[361];
	hfield_mag = new double[361];
	power  = new double[361];

	eefield = new Complex[361];
	hhfield = new Complex[361];
	eefield_mag = new double[361];
	hhfield_mag = new double[361];
	ppower  = new double[361];
	
	dipolelengthA=0.5;
	dipolecurrentA=1.0;
	
	distancia=0.5;
	fase=0.0;
	distanciamax=1.0;
	R=100.0;
	SpaceImp=(double)(120*Math.PI);
	//PhiControls
	phicontrol = new PhiControls(this);
	//add(phicontrol);
	//phicontrol.setBounds(PhiControlsHPos,PhiControlsVPos,PhiControlsWidth,PhiControlsHeight);
        phicontrol.setBounds(315+xmove,309+ymove,300,17);
        
	//Draw the Antenna Dipole
	dcan = new DrawCanvas(this);
	//add(dcan);
	//dcan.setBounds(DrawCanvasHPos+1,DrawCanvasVPos+1, DrawCanvasWidth-2, DrawCanvasHeight-2);
	//dcan.setBounds(11,56,298,258);
        
        dcan.setBounds(11+xmove,56+ymove,298,253);
        instructions = new Instructions();
        //instructions.setBounds(9,9,606,616);
        instructions.setBounds(11+xmove,315+ymove,603,309);
        //instructions.setVisible(false);
        instrFrame = new Panel();
        instrFrame.setBackground(Color.black);
        instrFrame.setBounds(10+xmove,314+ymove,605,311);
        cyanFrame = new Panel();
        cyanFrame.setBackground(Color.cyan);
        cyanFrame.setBounds(8+xmove,310+ymove,609,5);
        //instrFrame.setVisible(false);
        
        /*
        //about = new About();
        //add(about);
        //about.setBounds(9,9,606,616);
        //about.setVisible(false);
        instructions = new Instructions();
        //instructions.setBounds(9,9,606,616);
        instructions.setBounds(11,321,603,303);
        //instructions.setVisible(false);
        instrFrame = new Panel();
        instrFrame.setBackground(Color.black);
        instrFrame.setBounds(10,320,605,305);
        //instrFrame.setVisible(false);
        */
        
	setThetaPlaneMaxima();
	UpdateRadiation();
	//Draw the radiation diagram 1
	rcan1 = new RadarCanvas(this,true);
	//add(rcan1);
	//rcan1.setBounds(RadarCanvasHPos1+1,RadarCanvasVPos1+1, RadarCanvasWidth1-2, RadarCanvasHeight1-2);
	rcan1.setBounds(316+xmove,11+ymove,298,298);
        
	Panel prc1 = new Panel();
	    prc1.setBackground(Color.black);
	    //add(prc1);
	    //prc1.setBounds(RadarCanvasHPos1,RadarCanvasVPos1, RadarCanvasWidth1, RadarCanvasHeight1);
            prc1.setBounds(315+xmove,10+ymove,300,300);
            
	//Draw the radiation diagram 2
	rcan2 = new RadarCanvas(this,false);
	//add(rcan2);
	//rcan2.setBounds(RadarCanvasHPos2+1,RadarCanvasVPos2+1, RadarCanvasWidth2-2, RadarCanvasHeight2-2);
	rcan2.setBounds(316+xmove,326+ymove,298,298);
        
	Panel prc2 = new Panel();
	    prc2.setBackground(Color.black);
	    //add(prc2);
	    //prc2.setBounds(RadarCanvasHPos2,RadarCanvasVPos2, RadarCanvasWidth2, RadarCanvasHeight2);	
            prc2.setBounds(315+xmove,325+ymove,300,300);	
	
	//Draw the slide panel
	slidepanel = new SlidePanel(this);
	//add(slidepanel);
	slidepanel.setBounds(SlidePanelHPos, SlidePanelVPos,SlidePanelWidth,SlidePanelHeight);
	slidepanel.setBounds(10+xmove,396+ymove,300,229);
        
	//acan = new AngleCanvas(this);
	////add(acan);
	//acan.setBounds(PhiControlsHPos+30,PhiControlsVPos+10, 80, 80);

	//Make radar controls
	rcons = new RadarControls(this);
	//add(rcons);
	//rcons.setBounds(RadarControlsHPos, RadarControlsVPos, RadarControlsWidth, RadarControlsHeight);
        rcons.setBounds(11+xmove,359+ymove,298,31);
        
	//Outpanel
	outpanel = new OutPanel(this);
        //add(outpanel);
	//outpanel.setBounds(OutPanelHPos, OutPanelVPos, OutPanelWidth, OutPanelHeight);
        outpanel.setBounds(10+xmove,315+ymove,300,38);
        outpanel.setVisible(true);

	//TitlePanel
        titlepanel = new TitlePanel("Module 9.8","Uniform Dipole Array");
	//titlepanel = new TitlePanel(this);
	//add(titlepanel);
	//titlepanel.setBounds(TitlePanelHPos, TitlePanelVPos, TitlePanelWidth, TitlePanelHeight);
	titlepanel.setBounds(10+xmove,10+ymove,300,40);
        
	Panel pgraph = new Panel();
	    pgraph.setBackground(Color.black);
	    //add(pgraph);
	    //pgraph.setBounds(RadarControlsHPos-1,RadarControlsVPos-1,
		//	     RadarControlsWidth+2,RadarControlsHeight+2);                 
            pgraph.setBounds(10+xmove,358+ymove,300,33);
            
	Panel pcanvas = new Panel();
	    pcanvas.setBackground(Color.black);
	    //add(pcanvas);
	    //pcanvas.setBounds(DrawCanvasHPos,DrawCanvasVPos, DrawCanvasWidth, DrawCanvasHeight);
	    pcanvas.setBounds(10+xmove,55+ymove,300,255);
            
	Panel p0 = new Panel();
	    p0.setBackground(Color.cyan);
	    //add(p0);
	    //p0.setBounds(3,3,534,530);
            p0.setBounds(3+xmove,3+ymove,618,628);
	    
	Panel p00 = new Panel();
	    p00.setBackground(Color.black);
	    //add(p00);
	    //p00.setBounds(0,0,540,536);
            p00.setBounds(xmove,ymove,624,634);
	    
            //if(this_year > line.magicyear || (this_year == line.magicyear && this_month > line.magicmonth)){
	    //LicenseExpired = true;
            //} else {}
	//else
	//{ 	    
            //add(about);
            add(instructions);
            add(instrFrame);
            add(cyanFrame);
           add(phicontrol);
	   add(dcan);
	   add(rcan1);
	   add(prc1);
	   add(rcan2);
	   add(prc2);
	   add(slidepanel);
	   add(rcons);
	   add(outpanel);
	   add(titlepanel);
	   add(pgraph);
	   add(pcanvas);
	   add(p0);
	   add(p00);
	    
	   LicenseExpired = false; 	
           //}

            //Listeners
            this.addWindowListener(this);
            instructions.bupdate.addActionListener(this);
}

/*
public void paint(Graphics g){
	g.draw3DRect(0,0,getSize().width-1,getSize().height-1,false);
	
	Font licensefont = new Font("SanSerif",Font.BOLD,18); 	
	g.setColor(Color.white);	 	
	g.fillRect(0,0,945,765); 	
		
	if(LicenseExpired){
	    g.setFont(licensefont);
	
	    g.setColor(Color.red);
	    g.drawString("The software license has expired.", 50, 200);
	    g.setColor(Color.black);
	    g.drawString("Obtain updated files from www.amanogawa.com", 50, 230);
	} 

}
*/

public void paint(Graphics g){
    
    Font licensefont = new Font("SanSerif",Font.BOLD,18); 
    Font fonto = new Font("SanSerif",Font.PLAIN,12);
    Font fontc = new Font("SanSerif",Font.BOLD,16);
    
	Graphics2D g2d = (Graphics2D)g;
        g.setColor(Color.white);	
	g.fillRect(0,0,540,556);  	
		
	if(LicenseExpired){
	    g.setFont(licensefont);
	
	    g.setColor(Color.red);
	    g.drawString("The software license has expired.", 50, 200);
	    g.setColor(Color.black);
	    g.drawString("Obtain updated files from www.amanogawa.com", 50, 230);
	} 
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        int annonuovo = 2006;
        int anno = 2006;
        
        if(anno > this_year){
            annonuovo = anno;
        }
        else{
            annonuovo = this_year;
        }
        g.setColor(Color.red.darker());
        g.setFont(fontc);
        g.drawString("\u00a9",10,553);
        g.setFont(fonto);
        g.drawString("Amanogawa, "+annonuovo+" - All Rights Reserved",30,551);
}

public void setThetaPlaneMaxima(){
	int i, j;
        double TotalPfactor=0.0;
	PlaneEMax=0.0;
	PlaneHMax=0.0;
	PlanePMax=0.0;
	double tmp1;
	double phi, theta;
	tmp1=(double)(Math.PI/180.0);
	for(j=0;j<361;j=j+1){
	phi=tmp1*j;
	  for(i=0;i<181;i=i+1){
		theta=tmp1*i;
		
		//hfield[i]=getHfield(theta,phi);
                //TotalPfactor=TotalPfactor+(double)((hfield[i]).Magnitude()*(hfield[i]).Magnitude()*Math.sin(theta));  
		
		hfield_mag[i]=getHfield_mag(theta,phi);
                TotalPfactor=TotalPfactor+(double)((hfield_mag[i])*(hfield_mag[i])*Math.sin(theta));  
		
		if(PlaneHMax<hfield_mag[i]) PlaneHMax=(double)(hfield_mag[i]);    	
	  }
	  
	}
	
	if(PlaneHMax==0.0) PlaneHMax=1.0;
	PlaneEMax=PlaneHMax*SpaceImp;
	PlanePMax=PlaneEMax*PlaneHMax/2.0;
	TotalP=R*R*SpaceImp*TotalPfactor*0.5*(Math.PI*Math.PI)/(180.0*180.0);
}

    public void windowClosing(WindowEvent e) {
        dispose();
        System.exit(0);
    }
    
    public void windowOpened(WindowEvent evt){}
    
    public void windowIconified(WindowEvent evt){}
    
    public void windowClosed(WindowEvent evt){}
    
    public void windowDeiconified(WindowEvent evt){}
    
    public void windowActivated(WindowEvent evt){}
    
    public void windowDeactivated(WindowEvent evt){}



public void actionPerformed(ActionEvent evt){
    //if(evt.getSource()==about.bupdate){
    //    about.setVisible(false);
    //}
    if(evt.getSource()==instructions.bupdate){
        instructions.setVisible(false);
        instrFrame.setVisible(false);
        cyanFrame.setVisible(false);
    }
 }

public void UpdateRadiation(){
	int i;
	double theta;
	double phi;
	double r1, r2;
	double SpaceImp=(double)(120.0*Math.PI);
	
	double PradA, U, UmaxA; 
	
	
	//radiation power, and field loop for theta plane
	phi=phicontrol.phi*Math.PI/180-Math.PI;
	
	for(i=0;i<361;i++){
		theta=2.0*Math.PI*i/360.0;
		//hfield[i]=getHfield(theta,phi);  
		//efield[i]=new Complex(SpaceImp,0.0);
		//efield[i].Multiply(hfield[i]);
		//power[i]=(double)(efield[i].Magnitude()*efield[i].Magnitude()/(2.0*SpaceImp));
		
		hfield_mag[i]=getHfield_mag(theta,phi);  
		efield_mag[i]=SpaceImp*hfield_mag[i];
		power[i]=efield_mag[i]*efield_mag[i]/(2.0*SpaceImp);
	        	
	}
	
	for(i=0;i<361;i++){
		 //efield[i].Divide(PlaneEMax);
		 //hfield[i].Divide(PlaneHMax);
		 efield_mag[i] = efield_mag[i]/PlaneEMax;
		 hfield_mag[i] = hfield_mag[i]/PlaneHMax;
		 power[i] = power[i]/PlanePMax;
		 if(dipolelengthA == 0.0){
		    efield_mag[i] = 0.0;
		    hfield_mag[i] = 0.0;
		    power[i] = 0.0;
		 }
	}

	theta=(Math.PI/2.0);
	//calculation in phi plane
	for(i=0;i<361;i++){
		phi=(2.0*Math.PI*i/360.0)-Math.PI/2;
		//hhfield[i]=new Complex(0.0,0.0);
		//hhfield[i]=getHfield(theta,phi);
		  //eefield[i]=new Complex(SpaceImp,0.0);
		  //eefield[i].Multiply(hhfield[i]);
		  
		hhfield_mag[i]=getHfield_mag(theta,phi);
		eefield_mag[i]=SpaceImp * hhfield_mag[i];
		  
		//ppower[i]=(double)(eefield[i].Magnitude()*eefield[i].Magnitude()/(2.0*SpaceImp));
		ppower[i]=eefield_mag[i]*eefield_mag[i]/(2.0*SpaceImp);
	}	
		
		for(i=0;i<361;i++){
			 //eefield[i].Divide(PlaneEMax);
			 //hhfield[i].Divide(PlaneHMax);
			 eefield_mag[i] = eefield_mag[i]/PlaneEMax;
			 hhfield_mag[i] = eefield_mag[i]/PlaneHMax;
			 ppower[i] = (double)(ppower[i]/PlanePMax);
			 if(dipolelengthA == 0.0){
			    eefield_mag[i] = 0.0;
			    hhfield_mag[i] = 0.0;
			    ppower[i] = 0.0;
			 }
		}
	
	//directivity
	if(number_dipoles == 1 && dipolelengthA <= 0.1){
	    directivityAB = 1.5;
	}
	else{
	    directivityAB=(double)(4*Math.PI*R*R*PlanePMax/TotalP);
	}
}

public Complex getHfield(double theta, double phi){
	int i;
	double targ1, targ2, targ3, targa, targb, factor1, factor2;
	Complex myhfield, carga, cargb, complex1, complex2, array_factor;
	
	factor1 = 2.0*Math.PI*distancia*Math.sin(theta)*Math.sin(phi)-fase;
	factor2 = number_dipoles * factor1;
	
	complex1 = new Complex(1.0 - Math.cos(factor2),- Math.sin(factor2));
	complex2 = new Complex(1.0 - Math.cos(factor1),- Math.sin(factor1));
	
	    if(Complex.Magnitude(complex2) == 0.0){
		array_factor = new Complex(number_dipoles,0.0);
	    }
	    else{
		array_factor = Complex.Divide(complex1, complex2);
	    }
	
	if(dipolelengthA<0.5f){
		scalingA=(float)(1.0/Math.sin(Math.PI*(dipolelengthA)));
	}
	else{
		scalingA=1.0f;
	}
	
	
	/*
	if(dipolelengthA<0.0){
		if(dipolelengthA > 0.0){
		scalingA=(double)(1.0/Math.sin(Math.PI*(dipolelengthA)));
		}
		else{
		    scalingA=(double)(1.0/Math.sin(Math.PI*(dipolelengthA+0.000001)));
		}
	}
	else{
		scalingA=1.0;
	}
	*/
	
	//Avoid sin(theta)=0.0 situation
	if(theta!=0.0 && Math.abs(theta)!=(double)(Math.PI) ){
	  targ1=Math.PI*distancia*Math.sin(theta)*Math.sin(phi)-fase/2.0-2.0*Math.PI*R;
	  targ2=Math.PI*distancia*Math.sin(theta)*Math.sin(phi)-fase/2.0+2.0*Math.PI*R;
	  targ3=1.0/(2.0*Math.PI*R*Math.sin(theta));
	  
	  if (dipolelengthA > 0.0){
	    targa=dipolecurrentA*scalingA*(Math.cos(Math.PI*dipolelengthA*Math.cos(theta))
                                        -Math.cos(Math.PI*dipolelengthA));
	  }
	  else{
	    targa=dipolecurrentA*scalingA*(Math.cos(Math.PI*(dipolelengthA+0.000001)*Math.cos(theta))
                                        -Math.cos(Math.PI*(dipolelengthA+0.000001)));
	  }	
	  
	  carga=new Complex(-Math.sin(targ1),Math.cos(targ1));
	  	
	  carga.Multiply(targa);
	  
	  myhfield=new Complex(0.0,0.0);
	  myhfield.Add(carga);
	  myhfield.Multiply(targ3);
	  myhfield.Multiply(array_factor);
	}
	else{
		myhfield=new Complex(0.0,0.0);
	}

	  return(myhfield);
}

public double getHfield_mag(double theta, double phi){
	int i;
	double targ1, targ2, targ3, targa, targb, factor1, factor2;
	Complex myhfield, carga, cargb, complex1, complex2, array_factor;
    
	factor1 = 2.0*Math.PI*distancia*Math.sin(theta+0.0001)*Math.sin(phi+0.0001)-fase;
	factor2 = number_dipoles * factor1;
	
	complex1 = new Complex(1.0 - Math.cos(factor2),- Math.sin(factor2));
	complex2 = new Complex(1.0 - Math.cos(factor1),- Math.sin(factor1));
	
	    if(Complex.Magnitude(complex2) == 0.0){
		array_factor = new Complex(number_dipoles,0.0);
	    }
	    else{
		array_factor = Complex.Divide(complex1, complex2);
	    }
	 
	if(dipolelengthA<0.5f){
		scalingA=(float)(1.0/Math.sin(Math.PI*(dipolelengthA)));
	}
	else{
		scalingA=1.0f;
	}
	
	/*   
	if(dipolelengthA<0.0){
		if(dipolelengthA > 0.0){
		scalingA=(double)(1.0/Math.sin(Math.PI*(dipolelengthA)));
		}
		else{
		    scalingA=(double)(1.0/Math.sin(Math.PI*(dipolelengthA+0.000001)));
		}
	}
	else{
		scalingA=1.0;
	}
	*/
	
	//Avoid sin(theta)=0.0 situation
	if(theta!=0.0 && Math.abs(theta)!=(double)(Math.PI) ){
	  targ1=Math.PI*distancia*Math.sin(theta)*Math.sin(phi)-fase/2.0-2.0*Math.PI*R;
	  targ2=Math.PI*distancia*Math.sin(theta)*Math.sin(phi)-fase/2.0+2.0*Math.PI*R;
	  targ3=1.0/(2.0*Math.PI*R*Math.sin(theta));
	  
	  if (dipolelengthA > 0.0){
	    targa=dipolecurrentA*scalingA*(Math.cos(Math.PI*dipolelengthA*Math.cos(theta))
                                        -Math.cos(Math.PI*dipolelengthA));
	  }
	  else{
	    targa=dipolecurrentA*scalingA*(Math.cos(Math.PI*(dipolelengthA+0.000001)*Math.cos(theta))
                                        -Math.cos(Math.PI*(dipolelengthA+0.000001)));
	  }	
	  
	  carga=new Complex(-Math.sin(targ1),Math.cos(targ1));
	  	
	  carga.Multiply(targa);
	  
	  myhfield=new Complex(0.0,0.0);
	  myhfield.Add(carga);
	  myhfield.Multiply(targ3);
	  myhfield.Multiply(array_factor);
	}
	else{
		myhfield=new Complex(0.0,0.0);
	}

	  return(Complex.Magnitude(myhfield));
}

}//End of Antenna class
