function [Ne,Ni,Vp,Vf,Te,E,f]=Analyze_LangmuirWOgraphics(FileID,V,I,Area,Mass)
set(0,'DefaultFigureVisible','off');
addpath('EEDF/');
% Define bacic physical constants needed
e=1.6*10^-19;
m=9.1*10^-31;
kB=1.3806503*10^-23;
Mi=Mass*1.660538921*10^-27;
% figure('color','white')
% plot inputted data
%plot(V,I,'.k');
%Normalize the data (This is for better fit accrucy)
H=max(I);
%define fitting parameters starting values
% a=[.001 -1 1 1 .001]; % original
a=[1 -10 10 0.5 .001];
H=max(I);
% Perform fit
a=nlinfit(V,I/H,'langmuir',a)
system(sprintf('echo %d %e %e %e %e %e >> Dpndcs/langmuirfit',FileID,a(1),a(2),a(3),a(4),a(5)))
% calculate ion  and electron saturation current
Iion=H*langmuir(a,2*min(V));
Ies=H*langmuir(a,3*max(V));
% calculate and plot fitted I-V
V=min(V):.1:max(V);
z=H*langmuir(a,V);
%hold
%plot(V,z,'r');
%xlabel('Probe Voltage (Volts)')
%ylabel('Probe Current (Amperes)')
%legend('data','fit')
%saveas(gcf, strcat('FigsFits/',int2str(FileID)), 'jpeg');
fileID = fopen(strcat('IndData/',int2str(FileID), 'fit.dat'),'w');
formatSpec = '%e %e\n';[ncols,nrows] = size(V);
for row = 1:nrows
    fprintf(fileID,formatSpec,V(1,row),z(1,row));
end;fclose(fileID);
%print -r600 -djpeg 'int2str(FileID)'
%input('Is the fit OK Press enter for YES. If NO, Press Cotrol C change value of a in line 13 and start again')
%calculate Plasma potential Vp
Vp=a(3)*atanh((((1+a(1)^2)^.5)-1)/a(1))-a(2);
VV=2*min(V):.1:3*max(V);
% Calculate Flouting Potential Vf
Z=H*langmuir(a,VV);
k=find(Z>=0);
k=min(k);
Vf=VV(k);
% find first and second derivatives and plot second derivative
d1f=diff(Z)./diff(VV);
VV(1)=[];
d1f=d1f;
d2f=diff(d1f)./diff(VV);
VV(1)=[];
%figure ('color','white')
%plot(VV,d2f);
%xlabel('Probe Voltage (Volts)')
%ylabel('Second Derivative (Ampere/Volt^2)')
%grid on 
%saveas(gcf, strcat('FigsScndDers/',int2str(FileID)), 'jpeg');
fileID = fopen(strcat('IndData/',int2str(FileID), 'd2f.dat'),'w');
formatSpec = '%e %e\n';[ncols,nrows] = size(VV);
for row = 1:nrows
    fprintf(fileID,formatSpec,VV(1,row),d2f(1,row));
end;fclose(fileID);
% Calculate Vp
%VVa=VV(find(max(d2f))):.1:VV(find(min(d2f)));
VVa=0:.1:20;%dodelat
Z=H*langmuir(a,VVa);
d1f=diff(Z)./diff(VVa);
VVa(1)=[];
d1f=d1f;
d2f=diff(d1f)./diff(VVa);
VVa(1)=[];
k=find(d2f>0);
k=max(k);
Vp=VVa(k)
% Calculate and plot electron energy distribution function
k=find(VV)<=Vp;
t=Vp:.1:3*max(VV);
xx=abs(t.^(1/2));
ff=diff(diff(langmuir(a,t)));
ff=[ff 0 0];
f=-xx.*ff;
E=t-Vp;
T=(2/3)*trapz(E,E.*f)/trapz(t,f);
k=find(E>100);
E(k)=[];
f(k)=[];
ScaleP=((8*m)^.5)/(Area*e^1.5)
%figure('color','white')
%plot(E,f,'k');
fileID = fopen(strcat('IndData/',int2str(FileID), 'eedf.dat'),'w');
formatSpec = '%e %e\n';[ncols,nrows] = size(E);
for row = 1:nrows
    fprintf(fileID,formatSpec,E(1,row),ScaleP*f(1,row));
end;fclose(fileID);
% Fit EEDF to Maxwell-Boltzman Distribution law
a=[.0003 .1];
try
a=nlinfit(E,f,'maxwell',a);
system(sprintf('echo %d %e %e >> Dpndcs/maxwellfit',FileID,a(1),a(2)))
fm=maxwell(a,E);
% Fit EEDF to Druyvesteyn distribution Law
b=[.0001 .01];
b=nlinfit(E,f,'Dry',b);
system(sprintf('echo %d %e %e >> Dpndcs/Dryfit',FileID,b(1),b(2)))
fd=Dry(b,E);
end
%hold
%plot(E,fm,'r');
fileID = fopen(strcat('IndData/',int2str(FileID), 'fm.dat'),'w');
formatSpec = '%e %e\n';[ncols,nrows] = size(E);
for row = 1:nrows
    fprintf(fileID,formatSpec,E(1,row),ScaleP*fm(1,row));
end;fclose(fileID);
%plot(E,fd);
fileID = fopen(strcat('IndData/',int2str(FileID), 'fd.dat'),'w');
formatSpec = '%e %e\n';[ncols,nrows] = size(E);
for row = 1:nrows
    fprintf(fileID,formatSpec,E(1,row),ScaleP*fd(1,row));
end;fclose(fileID);
%xlabel('Electron Energy (eV)')
%ylabel('EEDF (eV^-3/2)')
%legend('Experimental EEDF','Fit to Maxwell-Boltzman','Fit to Druyvesteyn')
%saveas(gcf, strcat('FigsEEDFs/',int2str(FileID)), 'jpeg');
KK=trapz(E,f);
Ne=KK*((8*m)^.5)/(Area*e^1.5); %Original
%end
% Show final results
Ni=(abs(Iion)/(0.52*Area*e^1.5))*(Mi/T)^.5;
Iis=Iion
Ies
Ne
Ni
Te=T
Vp
Vf
system(sprintf('echo %d %e >> Dpndcs/Ne',FileID,Ne))
system(sprintf('echo %d %e >> Dpndcs/Ni',FileID,Ni))
system(sprintf('echo %d %e >> Dpndcs/Iis',FileID,Iis))
system(sprintf('echo %d %e >> Dpndcs/Ies',FileID,Ies))
system(sprintf('echo %d %e >> Dpndcs/Ies2Iis',FileID,Ies/Iis))
system(sprintf('echo %d %e >> Dpndcs/Te',FileID,Te))
system(sprintf('echo %d %e >> Dpndcs/Vp',FileID,Vp))
system(sprintf('echo %d %e >> Dpndcs/Vf',FileID,Vf))
