function solstruct = importsolcoresol(varargin)

if length(varargin) == 0
    filename = '/Users/pdb13/Google Drive/Imperial Documents/PhD/Matlab/Drift Diffusion/Solcore/solcore5/examples/solcoresol_eq.txt';
elseif length(varargin) == 1
    filename = varargin{1,1};
elseif length(varargin) > 1
    warning('Only one imput argument allowed- first argument will be used as filepath'); 
end


%% Import data from text file.
% Script for importing data from the following text file:
%
%    /Users/pdb13/Google Drive/Imperial Documents/PhD/Matlab/Drift Diffusion/Solcore/solcore5/examples/solcoresol_eq.txt
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.

% Auto-generated by MATLAB on 2019/03/20 10:08:22

%% Format for each line of text:
%   column1: double (%f)
%	column2: double (%f)
%   column3: double (%f)
%	column4: double (%f)
%   column5: double (%f)
%	column6: double (%f)
%   column7: double (%f)
%	column8: double (%f)
%   column9: double (%f)
%	column10: double (%f)
%   column11: double (%f)
%	column12: double (%f)
%   column13: double (%f)
%	column14: double (%f)
%   column15: double (%f)
%	column16: double (%f)
%   column17: double (%f)
%	column18: double (%f)
%   column19: double (%f)
%	column20: double (%f)
%   column21: double (%f)
%	column22: double (%f)
%   column23: double (%f)
%	column24: double (%f)
%   column25: double (%f)
%	column26: double (%f)
%   column27: double (%f)
%	column28: double (%f)
%   column29: double (%f)
%	column30: double (%f)
%   column31: double (%f)
%	column32: double (%f)
%   column33: double (%f)
%	column34: double (%f)
%   column35: double (%f)
%	column36: double (%f)
%   column37: double (%f)
%	column38: double (%f)
%   column39: double (%f)
%	column40: double (%f)
%   column41: double (%f)
%	column42: double (%f)
%   column43: double (%f)
%	column44: double (%f)
%   column45: double (%f)
%	column46: double (%f)
%   column47: double (%f)
%	column48: double (%f)
%   column49: double (%f)
%	column50: double (%f)
%   column51: double (%f)
%	column52: double (%f)
%   column53: double (%f)
%	column54: double (%f)
%   column55: double (%f)
%	column56: double (%f)
%   column57: double (%f)
%	column58: double (%f)
%   column59: double (%f)
%	column60: double (%f)
%   column61: double (%f)
%	column62: double (%f)
%   column63: double (%f)
%	column64: double (%f)
%   column65: double (%f)
%	column66: double (%f)
%   column67: double (%f)
%	column68: double (%f)
%   column69: double (%f)
%	column70: double (%f)
%   column71: double (%f)
%	column72: double (%f)
%   column73: double (%f)
%	column74: double (%f)
%   column75: double (%f)
%	column76: double (%f)
%   column77: double (%f)
%	column78: double (%f)
%   column79: double (%f)
%	column80: double (%f)
%   column81: double (%f)
%	column82: double (%f)
%   column83: double (%f)
%	column84: double (%f)
%   column85: double (%f)
%	column86: double (%f)
%   column87: double (%f)
%	column88: double (%f)
%   column89: double (%f)
%	column90: double (%f)
%   column91: double (%f)
%	column92: double (%f)
%   column93: double (%f)
%	column94: double (%f)
%   column95: double (%f)
%	column96: double (%f)
%   column97: double (%f)
%	column98: double (%f)
%   column99: double (%f)
%	column100: double (%f)
%   column101: double (%f)
%	column102: double (%f)
%   column103: double (%f)
%	column104: double (%f)
%   column105: double (%f)
%	column106: double (%f)
%   column107: double (%f)
%	column108: double (%f)
%   column109: double (%f)
%	column110: double (%f)
%   column111: double (%f)
%	column112: double (%f)
%   column113: double (%f)
%	column114: double (%f)
%   column115: double (%f)
%	column116: double (%f)
%   column117: double (%f)
%	column118: double (%f)
%   column119: double (%f)
%	column120: double (%f)
%   column121: double (%f)
%	column122: double (%f)
%   column123: double (%f)
%	column124: double (%f)
%   column125: double (%f)
%	column126: double (%f)
%   column127: double (%f)
%	column128: double (%f)
%   column129: double (%f)
%	column130: double (%f)
%   column131: double (%f)
%	column132: double (%f)
%   column133: double (%f)
%	column134: double (%f)
%   column135: double (%f)
%	column136: double (%f)
%   column137: double (%f)
%	column138: double (%f)
%   column139: double (%f)
%	column140: double (%f)
%   column141: double (%f)
%	column142: double (%f)
%   column143: double (%f)
%	column144: double (%f)
%   column145: double (%f)
%	column146: double (%f)
%   column147: double (%f)
%	column148: double (%f)
%   column149: double (%f)
%	column150: double (%f)
%   column151: double (%f)
%	column152: double (%f)
%   column153: double (%f)
%	column154: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%24f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%25f%f%[^\n\r]';

%% Open the text file.
fileID = fopen(filename,'r');

%% Read columns of data according to the format.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', '', 'WhiteSpace', '', 'TextType', 'string', 'EmptyValue', NaN,  'ReturnOnError', false);

%% Close the text file.
fclose(fileID);

%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.

%% Create output variable
solM = [dataArray{1:end-1}];
%% Clear temporary variables
clearvars filename formatSpec fileID dataArray ans;

% Write to arrays in solstruct
% Sets Ec(0) to zero as reference

solstruct.x = solM(1,:);
solstruct.n = solM(2,:);
solstruct.p = solM(3,:);
solstruct.V = solM(4,:)-solM(4,1);      % Referenced to LHS
solstruct.Ec = solM(5,:)-solM(5,1);
solstruct.Ev = solM(6,:)-solM(5,1);
solstruct.Efn = solM(7,:)-solM(5,1);
solstruct.Efp = solM(8,:)-solM(5,1);
solstruct.Phi_EA = solstruct.Ec+solstruct.V;
solstruct.Phi_IP = solstruct.Ev+solstruct.V;

end