function s = dipole(l,d,p,a,phase,m)
% s = dipole(l,d,p,a,phase,m)
% Dipole
% l   :  length  (default = 1.0 m)
% d   :  wire diameter (default = 0.002 m)
% p   :  position vector [x y z] of wire midpoint (default = [0 0 0])
% a   :  orientation vector [azimuth tilt] of the dipole in degrees
%        (default = [90 0] the dipole is along the y-axis)
% phase: excitation phase in radian (default: 0)
% m   :  number of segments (default: 7)
%
% dipole without parameters is a dipole for 2 m at the origin along the y-axis
        
% Autor:  Klaus von der Heide, e-mail:  dj5hg@qsl.net

% Defaults
% ========
if nargin<6  m = 7;       end    % number of segments
if nargin<5  phase = 0;   end
if nargin<4  a = [90 0];  end
if nargin<3  p = [0 0 0]; end
if nargin<2  d = 0.002;   end
if nargin<1  l = 1.0;     end

% Constants
% =========
phi   = a(1)*pi/180;
theta = a(2)*pi/180;
[x1,y1,z1] = sph2cart(-phi,-theta,l/2);
[x2,y2,z2] = sph2cart(+phi,+theta,l/2);
en1 = p + [x1 y1 z1];            % endpoint 1 of dipole
en2 = p + [x2 y2 z2];            % endpoint 2 of dipole

% Antenna Model
% =============
s = comment(exwire(en1, en2, d, m, exp(i*phase)),'Dipol');
