function []=plswr(filename)
% To plot the SWR for a particular Heating transmitter and array
%  20100607   MTR
%

hold off
close
if nargin<1 
[filename, pathname, filterindex] = uigetfile('\data1\swrlogs\*.txt', 'Pick an ascii data file', 'A');
filename=fullfile(pathname,filename);
end

[h h2 h3 A]=read_swr(filename);
arrnum=strread(h(2,:),'%d');
[dum txnum] =strread(h(4,:),'%c%d');
tit=strcat(['Array: ',h(2,:),'Tx: ',num2str(txnum,2),'   on: ',h(6,:),blanks(1),h(7,:)]);

%[find(A(:,3) <0.1 )];      % finds cases with power < 0.1 kW
[A([find(A(:,3) <0.1 )],2)]=nan;

r=input('plot other (non SWR) parameters ? [y/n]','s');
par=2;  % for SWR
if r=='y' 
 sp=input('which of SWR(2) Power(3) Pa(4) Bothpows(34) DDSAmpl(5) C1(6) C2(7) C1C2 (67) Ufor(8) Urev(9) phsf(10) phsrev(11) ?','s');
 par=eval(sp);
end

hold on
xmin=min(A(:,1));
xmax=max(A(:,1));

switch par
case 1  % Freq
 v(1)=xmin;
 v(2)=xmax;
 plot(A(:,1),A(:,par),'mx-');
 v=axis;

case 2  % SWR
 subplot(2,1,1);
 plot(A(:,1),A(:,par),'mx-');
 v=axis;
 v(1)=xmin;
 v(2)=xmax;
 v(3)=0.9;
 v(4)=2.0;
 xlabel('Freq [kHz]');
 ylabel('SWR');
 title(tit);
 axis(v);
 grid;

 subplot(2,1,2);
 plot(A(:,1),A(:,11),'mx-');
 v=axis;
 v(1)=xmin;
 v(2)=xmax;
 v(3)=0;
 v(4)=360;
 ylabel('rev phase')

case 3  % Power
 v(1)=xmin;
 v(2)=xmax;
 plot(A(:,1),A(:,par),'mx-');
 v=axis;
 title(tit);
 
case 4  % Pa
 v(1)=xmin;
 v(2)=xmax;
 plot(A(:,1),A(:,par),'mx-');
 v=axis;
 title(tit);

case 5  % DDSampl
 v(1)=xmin;
 v(2)=xmax;
 plot(A(:,1),A(:,par),'mx-');
 v=axis;
 title(tit);

case 6  % C1
 v(1)=xmin;
 v(2)=xmax;
 plot(A(:,1),A(:,par),'mx-');
 v=axis;
 title(tit);

case 7  % C2
 v(1)=xmin;
 v(2)=xmax;
 plot(A(:,1),A(:,par),'mx-');
 v=axis;
 title(tit);

case 8  % Ufor
 v(1)=xmin;
 v(2)=xmax;
 plot(A(:,1),A(:,par),'mx-');
 v=axis;
 title(tit);

case 9  % Urev
 v(1)=xmin;
 v(2)=xmax;
 plot(A(:,1),A(:,par),'mx-');
 v=axis;
 title(tit);

case 10 % phsf
 D=diff(A(:,par));
 df=diff(A(:,1));
 F=fft(D);
 plot(D);
 v=axis;
 v(1)=xmin;
 v(2)=xmax;
 v(3)=0;
 v(4)=360;
 plot(A(:,1),A(:,par),'mx-');
 title(tit);

case 11 % phsrev
 subplot(2,1,1);
 plot(A(:,1),A(:,par),'mx-');
 v=axis;
 v(1)=xmin;
 v(2)=xmax;
 v(3)=0;
 v(4)=360;
 axis(v);
 ylabel('rev phase [deg]')
 grid;
 title(tit);
 
 subplot(2,1,2);
 D=pi*diff(A(:,par))/180.0;
 whos D
 df=1000*(A(2,1)-A(1,1))
 dtf=3e8*D(:)/(2*df)
 dsize=size(D);
% F=fft(D);
 [nrows,ncols]=size(A);
% plot(A(1:nrows-1,1),D(:))
 plot(A(1:nrows-1,1),dtf(1:nrows-1:1))
% plot(A(1:nrows-1,1),F(:))
% v(3)=-180;
% v(4)= 180;
% v(1)=1;
%v(2)=nrows-1;
v=axis;

case 34  % Power(digital) & Pow (analogue)
 v=axis;
 v(1)=xmin;
 v(2)=xmax;
 v(3)=0;
 plot(A(:,1),A(:,3),'mx-');
 plot(A(:,1),A(:,4),'ro-');
 v=axis;
 v(3)=0;
 title(tit);

case 67  % C1 & C2
 v=axis;
 v(1)=xmin;
 v(2)=xmax;
 plot(A(:,1),A(:,6),'mx-');
 plot(A(:,1),A(:,7),'ro-');
 v=axis;
 title(tit);


end

axis(v);
grid;

switch arrnum
 case 1    % arnum 1
  switch txnum
    case 1
    case 2
    case 3
    case 4
    case 5
    case 6
    case 7
    case 8
    case 9
    case 10
    case 11
    case 12
  end
 case 2    % arnum 2
  switch txnum
    case 1
    case 2
    case 3
    case 4
    case 5
    case 6
    case 7
    case 8
    case 9
    case 10
    case 11
    case 12
  end
 case 3    % arnum 3
  switch txnum
    case 1
    case 2
    case 3
    case 4
    case 5
    case 6
    case 7
    case 8
    case 9
    case 10
    case 11
    case 12
  end
 otherwise
end

%legend('normal before','normal after','stubs removed')
xlabel('Freq [kHz]')
switch par
  case 2
  case 3
    ylabel('Power [kW]')
  case 4
    ylabel('Pa [kW]')
  case 5
    ylabel('DDSampl')
  case 6
    ylabel('C1 [pF]')
  case 7
    ylabel('C2 [pF]')
  case 8
    ylabel('Ufor')
  case 9
    ylabel('Urev')
  case 10
    ylabel('Phsfor [deg]')
  case 11
%    ylabel('Phsrev [deg]')
  case 34
    ylabel('P, Pa [kW]')
%    text((v(1)+v(2))/2.0,400, 'P','Color','m')
%    text((v(1)+v(2))/2.0,900, 'Pa','Color','r')
  case 67
    ylabel('C1,C2 [pF]')
    text((v(1)+v(2))/2.0,400, 'C1','Color','m')
    text((v(1)+v(2))/2.0,900, 'C2','Color','r')
  otherwise 
    
end

hold off
end
