You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: readPseudopot.m
    path of file: ./repos/M-SPARC/src
    
    the code of the file until where you have to start completion: function S = readPseudopot(S, ityp, psdfname, element)
% @brief    READPSEUDOPOT reads the pseudopotential file (psp8 format).
%
% @param ityp       Element type index.
% @param psdfname   The pseudopotential filename, with suffix.
% @param element    Element type.
%
% @authors  Qimen Xu <qimenxu@gatech.edu>
%           Abhiraj Sharma <asharma424@gatech.edu>
%           Phanish Suryanarayana <phanish.suryanarayana@ce.gatech.edu>
%
% @copyright (c) 2019 Material Physics & Mechanics Group, Georgia Tech
%

%filename = sprintf('%s/%s',S.inputfile_path, psdfname);
filename = fullfile(S.inputfile_path, psdfname);

fid = fopen(filename,'r') ;


    
function S = readPseudopot(S, ityp, psdfname, element)
% @brief    READPSEUDOPOT reads the pseudopotential file (psp8 format).
%
% @param ityp       Element type index.
% @param psdfname   The pseudopotential filename, with suffix.
% @param element    Element type.
%
% @authors  Qimen Xu <qimenxu@gatech.edu>
%           Abhiraj Sharma <asharma424@gatech.edu>
%           Phanish Suryanarayana <phanish.suryanarayana@ce.gatech.edu>
%
% @copyright (c) 2019 Material Physics & Mechanics Group, Georgia Tech
%

%filename = sprintf('%s/%s',S.inputfile_path, psdfname);
filename = fullfile(S.inputfile_path, psdfname);

fid = fopen(filename,'r') ;

assert(fid~=-1,'Error: Cannot open pseudopotential file %s',filename);

textscan(fid,'%s',1,'delimiter','\n') ;
fscanf(fid,'%s',1);
Z = fscanf(fid,'%f',1);
textscan(fid,'%s',1,'delimiter','\n');
A = textscan(fid,'%f %f %f %f %f %f') ;

lmax = A{1,3};
lloc = A{1,4}; 
% lloc = 4; % forcing nonlocal component to 4!
mmax = A{1,5};

textscan(fid,'%s',1,'delimiter','\n') ;
Ax = textscan(fid,'%f %f %f') ;
textscan(fid,'%s',1,'delimiter','\n') ;
fchrg = Ax{2};

A = textscan(fid,'%f %f %f %f %f');
nproj = ones(lmax+1,1);
for i = 0:lmax
	nproj(i+1) = A{1,i+1};
end