function [node,elem,mg,mp,M,gamma,ki,time,dt,solvertype,acc,mindt,maxdt,minel,maxel] = readdata(file)
%Reads the input deck 'file' and outputs the necessary cell structures
%      file: The file to read
%      node: The numbering and placement of the nodes
%      elem: The numbering and placement of the elements
%      mg: The evaporation-condensation mobility at the node of grain boundary
%      mp: The evaporation-condensation mobility at the node of pore
%         M: The diffusion mobility at the node
%     gamma: Interface tension at an angle of zero degrees
%        ki: Constant used to determine the interface tension
%      time: How long to run the simulation
%        dt: The initial time step
%solvertype: The flag which indicated which solver to use
%acc: accuracy
%     mindt: The minimum time step
%     minel: The minimum element size
%     maxel: The maximum element size


%Read the file
[type,id,one,two,three,four]=textread(file,'%s %u %f %f %f %f','delimiter',',','commentstyle','matlab');

node=[];
elem=[];

%Parse the file into the appropriate variables
for i=1:length(type);   
    if length(type{i})==2
        if type{i}=='g0'
            %Interface tension at an angle of zero degrees
            gamma=one(i);
        elseif type{i}=='ki'
            %Constant used to determine the interface tension
            ki=one(i);    
        end
    elseif length(type{i})==3
        %The tolerances
        if type{i}=='tol'
            acc=one(i);
            minel=two(i);
            maxel=three(i);
        %The mobilities    
        elseif type{i}=='mob'
            mg=one(i);    
            mp=two(i);
            M=three(i);
        end
    elseif length(type{i})==4    
        if type{i}=='node'
            x=one(i);
            y=two(i);
            %Node placement
            node(id(i),1)=x;
            node(id(i),2)=y;
        elseif type{i}=='elem'
            x=one(i);
            y=two(i);
            z=three(i);
            %Nodes on the element
            elem(id(i),1)=x;
            elem(id(i),2)=y;
            elem(id(i),3)=z;
        elseif type{i}=='time'
            %Time parameters
            solvertype=id(i);
            time=one(i);
            dt=two(i);
            mindt=three(i);
            maxdt=four(i);         
        end
    end 
end
