function res = GetAtomicFormFactor(Element,q);
% function res = GetAtomicFormFactor(Element,q);
% returns Atomic form factor fo(Q) using Kissel data
%
%    f0[k] = c + SUM [ a_i*EXP(-b_i*(q^2)) ]
%                i=1,5
% where 
% q = sin(theta) / lambda
% c, a_i and b_i are the coefficients tabulated in file f0.dat
%
% Format file f0.dat
% Z Element a1  a2  a3  a4  a5  c  b1  b2  b3  b4  b5
%
% NOTE: This is fo. Anomalous contribution is not included
% JJ 29.03.2006

here=pwd ;                                         % present directory
DefaultDirectory = [here '\ScatteringFactors'];

fid = fopen([DefaultDirectory 'f0.dat'],'r');
if fid == -1,
    fid = fopen('f0.dat','r');
end;

while ~feof(fid)
    rawline = deblank(fgetl(fid));
    if rawline(1) == '#'
        continue
    elseif ~isempty(strfind(rawline,[' ' Element ' ']));
        param = sscanf(rawline,['%f %*s %f %f %f %f %f %f %f %f %f %f %f\n'],12);
        break
    end;
end;
fclose(fid);

% Calculate f0 using kissel parameters
%
Z    = param(1);
a(1) = param(2);
a(2) = param(3);
a(3) = param(4);
a(4) = param(5);
a(5) = param(6);
c    = param(7);
b(1) = param(8);
b(2) = param(9);
b(3) = param(10);
b(4) = param(11);
b(5) = param(12);

f0 = c;
for n=1:5
    f0 = f0 + a(n).*exp(-b(n).*q.^2);
end;

res = f0;
