function pmx = gr2x2yagi7(az,el,pwr,agr)
% pmx = gr2x2yagi7(az,el,pwr,agr)
% Feld in 1.80m ber Grund fr eine 2*2-Gruppe von 7-Element-Yagi-Antennen.
% az  :  Azimut in Grad
% el  :  Elevation in Grad
% pwr :  Leistung in Watt
% agr :  wenn agr~=0 werden Bilder der Antenne und der Richtdiagramme gezeigt
% pmx :  maximal zulssige Leistung

% Autor:   Klaus von der Heide, DJ5HG.
% e-mail:  v.d.heide@on-line.de
% e-mail:  dj5hg@qsl.net

% Defaults
% ========
if nargin<1   az = 180; end  % aktueller Azimutwinkel
if nargin<2   el = 0;   end  % aktuelle Elevation
if nargin<3  pwr = 500; end  % Sendeleistung
if nargin<4  agr = 1;   end  % Bild der Antenne

% Constants
% =========
hg  = 6.00;       % Spitze des Mastes 
hd  = hg - 0.50;  % Hhe des Drehpunktes
ha  = 4.25;       % Hhe des Abspannpunktes
dz  = 0.50;       % Abstand der Horizontalrohre
do  = 1.50;       % Abstand der oberen Yagis von der Elevationsachse
du  = 1.40;       % Abstand der unteren Yagis von der Elevationsachse
dy  = 1.05;       % halber Horizontal-Abstand der Yagis
r1  = 3.00;       % Abstand des unteren Abspannpunktes 1 vom Mastfuss
r2  = 3.00;       % Abstand des unteren Abspannpunktes 2 vom Mastfuss
r3  = 3.00;       % Abstand des unteren Abspannpunktes 3 vom Mastfuss
az1 = 60;         % Winkel zwischen Nord und unterem Abspannpunkt 1
az2 = 180;        % Winkel zwischen Nord und unterem Abspannpunkt 2
az3 = 300;        % Winkel zwischen Nord und unterem Abspannpunkt 3
rr  = -5;         % Gebiet der Nahfeldberechnung in m : Rckwrts
rv  = 30;         % Gebiet der Nahfeldberechnung in m : Vorwrts
rs  = 10;         % Gebiet der Nahfeldberechnung in m : Seitwrts

% Construction
% ============
gr4 = group(yagi7,[0 -dy -du; 0 -dy +do; 0 +dy -du; 0 +dy +do]);
tub = wires([0 -dy -du-0.1; 0 +dy -du-0.1; 0 -dy-0.1 0; 0 -dy-0.1 -dz],...
            [0 -dy +do+0.1; 0 +dy +do+0.1; 0 +dy+0.1 0; 0 +dy+0.1 -dz],...
            [0.04           0.04           0.05         0.04         ],...
            [31             31             19           19           ]);
ver = construct(gr4,tub);    % vertikal drehbares System
dre = rotation(translation(rotation(ver,[el 90 0]),[0 0 hd]),[0 0 az+180]);   % Drehung und Anhebung
mst = wire([0 0 0],[0 0 hg],0.06,81);
asp = wires([0                  0                  ha; 0                  0                  ha; 0                  0                  ha],...
            [r1*cos(az1*pi/180) -r1*sin(az1*pi/180) 0; r2*cos(az2*pi/180) -r2*sin(az2*pi/180) 0; r3*cos(az3*pi/180) -r3*sin(az3*pi/180) 0],...
            0.003,91);
ges = comment(construct(dre,mst,asp),{'28-Element-Gruppe';'144MHz'}); 

% Computation
% ===========
%if agr  
   rphv(ver,144); 
   antgraph(ges);   
%else
   fig = findobj('Type','figure');
   nfield(ges,144,rr:rv,-rs:rs,1.8,pwr);
   
   % Graphics
   % ========
   set(gcf,'Name','28-El')
%   delete(findobj(setdiff(findobj('Type','figure'),fig),'Name','Antenne'))
   fiw = findobj(setdiff(findobj('Type','figure'),fig),'Name','WATT');
   pwm = get(fiw,'UserData');
   delete(fiw)
   pmx = min(min(pwm(pwm>0)));
   ax  = axis;
   tp1 = [ax(1)+0.017*(ax(2)-ax(1))  ax(4)-0.035*(ax(4)-ax(3))  ax(4)-0.075*(ax(4)-ax(3))];
   tp2 = [ax(1)+0.015*(ax(2)-ax(1))  ax(3)+0.035*(ax(4)-ax(3))];
   text(tp1(1),tp1(2),['28 El. Power = ' num2str(pwr) ' W'],'Fontsize',15,'Color','w')
   th = text(tp1(1),tp1(3),['maximal zulssige Leistung :  ' num2str(pmx) ' W'],'Fontsize',15);
   if pmx<pwr
      set(th,'Color','r')
   else
      set(th,'Color','g')
   end
   text(tp2(1),tp2(2),['Az = ' num2str(az) '     El = ' num2str(el) ''],...
      'Fontsize',13,'Color','w','FontName','Courier')
%end