function s = magnloop(r,d,p,c)
% s = magnloop(r,d,p,c)
% Magnetic Loop Antenna
% The loop lies in the x-y-plane with the origin at its center. 
% The loop ist fed at the point [r 0 0].
% The capacity is located at the point [r*cos(p) r*sin(p) 0].
% r :  Radius of the loop in m
% d :  Diameter of the tube in m
% p :  angle of the position of the capacitor in radian
% c :  Capacity in Farad.
% s :  Resulting antenna structure 

% Author:  Klaus von der Heide, e-mail:  dj5hg@qsl.net

% Defaults
% ========
if nargin<4  c = 10^-10; end
if nargin<3  p = pi;     end
if nargin<2  d = 0.05;   end
if nargin<1  r = 3.00;   end

% Constants
% =========
rr = 10;               % resistance serial to the capacitor in Ohm
m  = 1;                % number of segments per wire
n  = 32;               % number of wire segments
dp = 2*pi/n;           % angle step per segment
pp = round(p/dp);      % number of the wire segment with the capacitor

% Basic elements
% ==============
w{1} = exwire([r*cos(-0.5*dp)  r*sin(-0.5*dp)  0],...
              [r*cos(+0.5*dp)  r*sin(+0.5*dp)  0], d, 1, 1);
for k=[1:pp-1,pp+1:n-1]
   w{k+1} = wire([r*cos((k-0.5)*dp)  r*sin((k-0.5)*dp)  0],...
                 [r*cos((k+0.5)*dp)  r*sin((k+0.5)*dp)  0], d, 1);
end
k = pp;
w{k+1} = rlcser([r*cos((k-0.5)*dp)  r*sin((k-0.5)*dp)  0],...
                [r*cos((k+0.5)*dp)  r*sin((k+0.5)*dp)  0], rr, 0, c);           

% Putting all together
% ====================
s = comment(construct(w{:}),'Magnetic Loop');
