%function factorsplot() 
%   addpath('C:\Documents and Settings\achim\My Documents\MagMeasurements\OTF\') 
% Opens file (strplt-.rxx i.e. a strplt file with first line:
%   ;Imag, sImag, SL, sSL, TF, sTF, THsp, sTHsp
%   removed. 
%
%
%   reverses sign of strength slg for negative currents
%   plots result
%
%       strplt-
%
% fn='strplt-.102'
%fn(1)='strplt-.102'  % factor 0.8 reference
%fn(2)='strplt-.118'   % factor 0.85
%fn(3)='strplt-.119'   % factor 0.88
%fn(4)='strplt-.116'   % factor 0.9 
%fn(5)='strplt-.120'   % factor 0.92
%fn(6)='strplt-.117'   % factor 0.95
factor = [0.8 0.85 0.88 0.9 0.9 0.92 0.95 ]
fnc=cellstr(['strplt-.102';'strplt-.118';'strplt-.119';'strplt-.116';'strplt-.121';'strplt-.120';'strplt-.117']);
% now char(fnc(1)) refers to first string
markertype =cellstr(['-ok';'-+b';'-+g';'-*k';'-or';'-+y';'-+c'])

for i=1:1:7
ffc(i) = cellstr(fullfile('C:\Documents and Settings\achim\My Documents\MagMeasurements\OTF\',char(fnc(i))));
%ffc(i) = cellstr(fullfile('F:\HEPwork\MagMeas\OTF\',char(fnc(i))));

% char(ffc(1))  refers to first full file name
ff=char(ffc(i))
%ff2 = fullfile('C:\Documents and Settings\achim\My Documents\MagMeasurements\OTF\',...
%           fn2);
%ff3 = fullfile('C:\Documents and Settings\achim\My Documents\MagMeasurements\OTF\',...
%           fn3);
%end     
%for  i=1:1:6
%i=2  
%ff=char(ffc(i))
[Imag, sImag, SL, sSL, TF, sTF, THsp, sTHsp]=textread(char(ffc(i)), '%f %f %f %f %f %f %f %f');
%convert SL,sSL from Tesla to Gauss:
n(i)=length(Imag)
%ImagmA(:,i)=1000*Imag(i);
slg=10000.*SL;
clear Imag sImag SL sSL TF sTF THsp sTHsp
%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
axis([0 40 0 120])
plot(slg,char(markertype(i)),'LineWidth',2)
if i==7
legend1 = legend('0.8','0.85','0.88','0.9','0.9','0.92','0.95');
end
%grid on
hold on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2)
axis([0 40 0 20])
plot(slg,char(markertype(i)),'LineWidth',2)
if i == 7
legend2 = legend('0.8','0.85','0.88','0.9','0.9','0.92','0.95');
end
%grid on
hold on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(3)
j=i
if i==4
    hold on
end
if i >= 5
    j=i-1
end
%subplot(3,2,j)
%axis([0 40 0 10])
% plot(slg,char(markertype(i)))
%stem(slg,char(markertype(i)))
% legend(i)=legend(mat2str(factor(i)))
%title(['Factor=',mat2str(factor(i))])
%xlabel('Cycles');
%ylabel('Rem. Field [Gauss]')
%titlestring=['Factor=',mat2str(factor(i))]
%title{['',mat2str(i)]}

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%plot(slg)
%stem(slg);
figure(1)
%                          0.8 0.85 0.88 0.9 0.9 0.92 0.95
% legend1 = legend('0.8','0.85','0.88','0.9','0.9','0.92','0.95');
title('Remaining Field for several factors')
xlabel('Cycles');
ylabel('Remaining Field [Gauss]')
grid on
figure(2)
title('Remaining Field for several factors')
xlabel('Cycles');
ylabel('Remaining Field [Gauss]')
grid on
%                          0.8 0.85 0.88 0.9 0.9 0.92 0.95
%legend1 = legend(axes1,{'0.8','0.85','0.88','0.9','0.9','0.92','0.95'});
%;
%plot(slg(1:n));
% plot(Imag, slg);
% plot(Imag(n-20:n),slg(n-20:n));
% Assign sign to slg depending on sign of current
%for i=1:1:n
%    if (Imag(i) < 0)
%        slg(i)= -slg(i);
%    end 
%end
% plot(Imag, slg);
% plot(Imag(n/2:n),slg(n/2:n));
% set(gca,'Layer','top');
%plot(Imag(2:n),slg(2:n)); 
%plot(Imag(n-20:n),slg(n-20:n));
%grid on;
%%%%%%%%%%%%%%% End