function []=plot_swr(filename)
% To plot the SWR for a particular Heating transmitter and array
%  20100603   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
fid1 = fopen(filename);

%header1=textscan(fid1,'%s%d%s%s%s%s%s',1);
header1=textscan(fid1,'%s%s%s%s%s%s%s',1);
h=char([header1{:}]);
whos header1
whos h
tit=strcat([h(1,:),h(2,:),h(3,:),h(4,:),h(5,:),h(6,:),blanks(1),h(7,:)])

header2=textscan(fid1,'%s%s%s%s%s%s%s%s%s%s%s',1);
h2=[header2{1:11}];
header3=textscan(fid1,'%s%s%s%s%s%s%s',1);
h3=[header3{1:7}];

Ac=textscan(fid1,'%f32%f32%f32%f32%f32%f32%f32%f32%f32%f32%f32');
A=[Ac{:}];               % Converts from cell array to ordinary array
%[find(A(:,3) <0.1 )];      % finds cases with power < 0.1 kW
[A([find(A(:,3) <0.1 )],2)]=nan;

%A=load('A2T5__52_11-Mar-2010.tmp');
%B=load('A2T4__40_02-Feb-2010.tmp');  % normal
%D=load('A2T1__32_02-Feb-2010.tmp');
%E=load('A2T3__40_02-Feb-2010.tmp');

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) DDSAmpl(5) C1(6) C2(7) Ufor(8) Urev(0) phsf(10) phsrev(11) ?','s');
 par=eval(sp);
end


hold on
plot(A(:,1),A(:,par),'mx-');
xmin=min(A(:,1));
xmax=max(A(:,1));
v=axis;
v(1)=xmin;
v(2)=xmax;
if par==2 
 v(3)=0.9;
 v(4)=2.0;
end
axis(v);
grid;
%plot(A(:,1),A(:,k),'bd-.',B(:,1),B(:,k),'b+:',D(:,1),D(:,k),'g.');
%plot(D(:,1),D(:,k),'g');
%plot(E(:,1),E(:,k),'r');
%plot(E(:,1),E(:,7),'r');
%plot(E(:,1),E(:,8),'r');
%legend('normal before','normal after','stubs removed')
xlabel('Freq [kHz]')
switch par
  case 2
    ylabel('SWR')
  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]')
  otherwise 
    
end


title(tit);
%h=title
st = fclose(fid1);
hold off
end
