clear all
close all
clc
%file parsing
f1=fopen("THERMO.dat",'r');
fgetl(f1)
A=fgetl(f1);
b= strsplit(A,'');
global_low_temp = str2double(A(2));
global_high_temp= str2double(A(3));
global_mid_temp = str2double(A(4));
%skipping next three lines
for i=1:3
fgetl(f1);
end
%Reading the species
for i=1:53
header=fgetl(f1);
X=strsplit(header,' ');
species_name=(X{1});
Z=length(X);
local_low_temp = str2double(X{Z-3});
local_high_temp= str2double(X{Z-2});
local_mid_temp = str2double(X{Z-1});
t1=local_low_temp;
t2=local_mid_temp;
t3=local_high_temp;
%getting first line coeffecients (a1-a5)
line_1 =fgetl(f1);
a=strfind(line_1,'E');
a1=str2double(line_1(1:a(1)+3));
a2=str2double(line_1(a(1)+4:a(2)+3));
a3=str2double(line_1(a(2)+4:a(3)+3));
a4=str2double(line_1(a(3)+4:a(4)+3));
a5=str2double(line_1(a(4)+4:a(5)+3));
%getting second line coeffecients (a6-a10)
line_2 =fgetl(f1);
a_1=strfind(line_2,'E');
a6=str2double(line_2(1:a_1(1)+3));
a7=str2double(line_2(a_1(1)+4:a_1(2)+3));
a8=str2double(line_2(a_1(2)+4:a_1(3)+3));
a9=str2double(line_2(a_1(3)+4:a_1(4)+3));
a10=str2double(line_2(a_1(4)+4:a_1(5)+3));
%getting third line coeffecients (a10-a14)
line_3 =fgetl(f1);
a_2=strfind(line_3,'E');
a11=str2double(line_3(1:a_2(1)+3));
a12=str2double(line_3(a_2(1)+4:a_1(2)+3));
a13=str2double(line_3(a_2(2)+4:a_1(3)+3));
a14=str2double(line_3(a_2(3)+4:a_1(4)+3));
% creating folder
mkdir(['This pc = documents\matlab\spieces\spiecesname']);
t=linspace(t1,t3,1000);
R=8.314;
%To get array of specific heat,enthalpy and entropy
for k=1:length(t)
% To compare the species temperature to assign the coefficeints
% a1=a7(high temp coeff),a8-a14 (low temp coeff)
if t(k)>t2
% high temperature coefficients
cp(k)=(a1+a2^t(k)+a3*t(k)^2+a4*t(k)^3+a5*t(k)^4*R);
H(k)=(a1+(a2*t(k))/2+(a3*t(k)^2)/3+(a4*t(k)^3)/4+(a5*t(k)^4)/5+(a6/t(k)))*R*t(k);
S(k)=(a1*log(t(k))+a2*t(k)+(a3*t(k)^2)/2+(a4*t(k)^3)/3+(a5*t(k)^4)/4+a7)*R;
else
% low temperature coefficients
cp(k)=(a8+a9^t(k)+a10*t(k)^2+a11*t(k)^3+a12*t(k)^4*R);
H(k)=(a8+(a9*t(k))/2+(a10*t(k)^2)/3+(a11*t(k)^3)/4+(a12*t(k)^4)/5+(a13/t(k)))*R*t(k);
S(k)=(a8*log(t(k))+a9*t(k)+(a10*t(k)^2)/2+(a11*t(k)^3)/3+(a12*t(k)^4)/4+a14)*R;
end
end
% plotting the graphs
figure(1);
plot(t,cp);
grid on;
title (species_name);
xlabel('temperature');
ylabel('specific heat');
figure(2);
plot(t,H);
grid on;
title (species_name);
xlabel('temperature');
ylabel('enthalpy');
figure(3);
plot(t,S);
grid on;
title (species_name);
xlabel('temperature');
ylabel('entropy');
(['This pc = documents\matlab\spieces\spiecesname',species_name]);
% Changing the directory and saving the file
saveas(1,'specific heat','jpg');
saveas(2,'enthalpy','jpg');
saveas(3,'entropy','jpg');
end
fclose(f1)
outputs
ans =
'THERMO'
ans=
0
errors
saveas(2,'enthalpy','jpg');
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
Warning: Directory already exists.
> In file (line 69)
In this program iam starting with clear all close all clc and then iam tried the file parising by starting with %file parsing then iam cosuming f1 vaule by using fopen thermo file which was given in the question and fgetl comand is multiple of f1 then cosuming the a and b,a is fgetl(f1) abd b vaule is given by strsplit is given for split the vaule for different temparture in the file vaule and assuming the global low,med,high vaule and its split by the b vaule and skipping the next three lines and opening the for loop and giving the i vaule,header,x,speieces name,z, and more and more vaule then enterong local temp in three stages and giving in the name of t1,t2,t3.