CONCLUSION:
we were able to parse the data from the THERMO.dat file. Then using this data we were able properties and also make plots for these properties with respect to the temperature.
function for entropy
function s=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,l_temp_mid,t,R)
if t<=l_temp_mid
s=(a8*log(t)+a9.*t+a10.*(t.^2)./2+a11.*(t.^3)./3+a12.*(t.^4)./4+a14).*R
else
s=(a1*log(t)+a2.*t+a3.*(t.^2)./2+a4.*(t.^3)./3+a5.*(t.^4)./4+a7).*R
end
function for enthalpy
function h = enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,l_temp_mid,t,R)
if t<= l_temp_mid
h=(a8+(a9.*t./2)+(a10.*t.^2/3)+(a11.*t.^3/4)+(a12.*t.^4/5)+(a13).*R.*t)
else
h=(a1+(a2.*t./2)+(a3.*t^2/3)+(a4.*t.^3/4)+(a5.*t^4/5)+(a6).*R.*t)
end
function for specific heat
function cp= specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,l_temp_mid,R,t)
if t<=l_temp_mid
cp=(a8+a9.*t+a10.*t.^2+a11.*t.^3+a12.*t.^4).*R;
else
cp=(a1+a2.*t+a3.*t.^2+a4.*t.^3+a5.*t.^4).*R;
end
main code
clear all
close all
clc
f1=fopen('THERMO(1).dat','r');
first_line=fgetl(f1);
%global tempraturs T
T=fgetl(f1);
A=strsplit(T,' ');
global_min=str2double(A{2});
global_mid=str2double(A{3});
global_max=str2double(A{4});
%comments
c1=fgetl(f1);
c2=fgetl(f1);
c3=fgetl(f1);
for i=1:53
header=fgetl(f1);
s_header=strsplit(header,' ');
s_name(i)=str2double(s_header{1});
local_temp=strsplit(header,' ');
%species name
ss_name=strtok(header); %(local_temp{1});
l_temp_mim=str2double(local_temp{end-3});
l_temp_mid=str2double(local_temp{end-2});
l_temp_max=str2double(local_temp{end-1});
% extracting 14 coefficents
cline1=fgetl(f1)
a=strfind(cline1,'E');
a1=cline1(1:a(1)+3);
a1=str2double(a1);
a2=cline1(a(1)+4:a(2)+3);
a2=str2double(a2);
a3=cline1(a(2)+4:a(3)+3);
a3=str2double(a3);
a4=cline1(a(3)+4:a(4)+3);
a4=str2double(a4);
a5=cline1(a(4)+4:a(5)+3);
a5=str2double(a5);
cline2=fgetl(f1);
b=strfind(cline2,'E');
a6=cline2(1:b(1)+3);
a6=str2double(a6);
a7=cline2(b(1)+4:b(2)+3);
a7=str2double(a7);
a8=cline1(b(2)+4:b(3)+3);
a8=str2double(a8);
a9=cline2(b(3)+4:b(4)+3);
a9=str2double(a9);
a10=cline2(b(4)+4:b(5)+3);
a10=str2double(a10);
cline3=fgetl(f1);
c=strfind(cline3,'E');
a11=cline3(1:c(1)+3);
a11=str2double(a11);
a12=cline3(c(1)+4:c(2)+3);
a12=str2double(a12);
a13=cline3(c(2)+4:c(3)+3);
a13=str2double(a13);
a14=cline3(c(3)+4:c(4)+3);
a14=str2double(a14);
% a1,a2,a3,a4,a5,a6,a7 are high temprature coefficents
% a8,a9,a10,a11,a12,a13,a14 are low temprature coefficents
%universal gas constant R
R= 8.314;
t=linspace(l_temp_mim,l_temp_max,500);
%specific heat
cp=specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,l_temp_mid,R,t);
%Enthalpy
h=enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,l_temp_mid,t,R);
%Entropy
s=entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,l_temp_mid,t,R);
%Molecular weight
mw(i)=molecular_weight(ss_name)
%saving plot data
nasa_f=ss_name
mkdir(nasa_f)
%current=pwd
%cd(nasa_f)
figure(1)
plot(t,cp,'LineWidth',2,'Color','b')
xlabel('teprature')
ylabel('specific_heat')
title(ss_name)
grid on
saveas(figure(1),'SPECIFIC HEAT.jpg');
figure(2)
plot(t,h,'LineWidth',2,'Color','r')
xlabel('temprature')
ylabel('enthalpy')
title(ss_name)
grid on
saveas(figure(2),'ENTHALPY.jpg');
figure(3)
plot(t,s,'LineWidth',2,'Color','g')
xlabel('temprature')
ylabel('entropy')
title(ss_name)
grid on
saveas(figure(3),'ENTROPY.jpg');
end
AIM:
To read and write a code in MATHLAB for NASA thermodynamic data file and calculate the specific heat, enthalpy, entropy for all species.
OBJECTIVE:
1) To write a code to extract data in the file and identify 14 coefficients.
2) To write a function to calculate the specific heat, enthalpy, entropy by using the formulas.
3) To write a code to plotting of specific heat, enthalpy, entropy Vs temperate for all species.
4) To write a code to save the plots of each species in separate folder.
PROCEDURE:
To open and extract the date in file:
FILE PRASING:
To open the file and read the file data line by line and calculate the parameters and evaluate the polynomials we use the commands in file parsing in mathlab.
Fopen : file open is used to open the file from folder.
FgetL: read the data in the file line by line.
Strsplit: string split is used to split the string into words.
Str2num: is used to convert the string into numbers.
Strfind: string fine is used to find the letters or numbers.
Strcamp: string compare is used to comparing strings.
Mkdir: used to create a folder.
Saveas: used to save the plot images.
STEP1:
By using parsing commend fopen open the thermodynamic file
By using fgetl commend read line by line of the thermodynamic file date first line is THERMO
By using Fgetl second line is global temperature ‘T’.
By using fgetl third line comment 1 c1
By using fgetl fourth line comment 2 c2
By using fgetl fifth line comment 3 c3
STEP2:
The second line global temperature T
By using strsplit command the string T is split into words
By using str2double or str2num the string T is converted into numbers.
And assigning them as global min, global mid, global max.
STEP 3:
By using for loop and length of for loop is 1:53 assining for all the data.
By using fgetl the sixth line as HEADER.
By using string split command splitting the header line into words
By using string2double command converting the string into numbers.
STEP 4:
Identifying local temperatures from the sixth line header, by string split of header and naming local temp.
By using strtok command (the first set of characters before a delimiter is encountered)
species name.
Identifying max, mid, min temperatures in local temp by string2double command.
STEP 5:
By using fgetl command assigning lines seventh, eight, and ninth line as cline1,cline2,cline3.
Extracting 14 coefficients from the three lines using strfind commend.
E as a end porting of every string so by using E in string find command we find the strings.
Cline1 we get 5 strings extracting 5 coefficients by using string2double.
Cline2 we get 5 strings extracting 5 coefficients by using string2double.
Cline3 we get 4 strings extracting 4 coefficients by using string2double.
Assigning them as a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14.
STEP 6:
Writing the there different functions for specific heat, enthalpy, entropy by using the formula given.
Accordingly input the coefficients
But in coefficients the first 7 are high temperature and next 7 are low temperature.
t is temperature creating a array for t as linspace (l_temp_min, l_temp_max,500).
By using logic t<=l_temp_mid evaluating the for both high temperature coefficients and low temperature coefficients and calculating specific heat enthalpy and entropy.
Taking R universial gas constant 8.314
STEP 7:
Writing a function for molecular weight for every element in data
Elements = ssname
Mw=moleculer_weight(ss_name)
STEP 8:
plotting
creating figure 1, 2, 3
1)t Vs specific heat, xlable(temperature) , ylable(specific heat),title(ss_name)
2)t Vs enthalpy
3)t Vs entropy
RESULT:
The code was run and we get all the 14 coefficients and calculation results for specific heat enthalpy entropy.
We got the plots for specific heat, enthalpy, entropy in (screen shot).
We have saved every element is separate folders.
We got the plots of o2, co2, N2.