function ExpRead2

% Since it's not quite easy to plot the Thermo-Calc simulation results,
% this script is dedicated for the easy handle of TC results using matlab.
% The basic idea contains reading the EXP file, and then plot them. As I,
% myself is not a expert in TC, hence my understanding of EXP file is far
% from complete. I will keed updating it to include new file format I'll
% meet. Feel free to contact me by renqingqiang@gmail.com. 

[file,path] = uigetfile('*.exp','EXP file generated by Thermo-Calc');

f=strcat(path,file);

fid = fopen(f,'r');
fid0 = fopen(strcat(file,'.dat'),'w');
tline = 'qingqiang'; % I do this just for fun.
while(~feof(fid))
    if (length(tline) >= 9 && strcmp(tline(1:9),'$ PLOTTED'))
        tmp = regexp(tline, '\s+', 'split');
        xaxis = char(tmp(length(tmp)-2));
        yaxis = char(tmp(length(tmp)));
        tline = fgetl(fid);
        tline = fgetl(fid);
        tline = fgetl(fid);
        index = tline(length(tline));
        fprintf(fid0,'%s \t %s \t %s \n',xaxis,yaxis,index); 
%         fprintf(fid0,'%s \n', '  ');
        tline = fgetl(fid);
        tmp = regexp(tline, '\s+', 'split');
        if (strcmp(tmp(length(tmp)),'M'))
            while (tline(1) ~= 'B' && ~strcmp(tline(1:9),'$ PLOTTED'))
                fprintf(fid0,'%s \n',tline);
                tline = fgetl(fid);
            end
        else
            while (~strcmp(tmp(length(tmp)),'M'))
                tline = fgetl(fid);
                tmp = regexp(tline, '\s+', 'split');
            end
            while (tline(1) ~= 'B' && ~strcmp(tline(1:9),'$ PLOTTED'))
                fprintf(fid0,'%s \n',tline);
                tline = fgetl(fid);
            end
        end
    else
        tline = fgetl(fid);
    end
end
fclose('all');
end
