Project 1 - Parsing NASA thermodynamic data
AIM: To write a program in matlab to parse the NASA thermodynamic data file and then calculate the thermodynamic properties of various gas species.
The equations that we are going to use in the Functions to calculate cp, H,S are:
Where,
Cp=specific heat
R =molar gas constant
T=temperature
S=Entropy
H=Enthalpy
a=coefficients
close all
clear all
clc
%R=molar gas constant
R=8.314;
%syntax to open the file THERMO.dat
f1=fopen('THERMO.dat','r')
%To read lines
l1=fgetl(f1);
l2=fgetl(f1);
value=strsplit(l2,' ');
%To get global temperatures from file in number form
global_lowtemp=str2num(value{2})
global_midtemp=str2num(value{3})
global_hightemp=str2num(value{4})
%temperature range
T=linspace(global_lowtemp,clear all
global_hightemp,1000);
%skipping these 3 lines
l3=fgetl(f1);
l4=fgetl(f1);
l5=fgetl(f1);
%Reading species ,calcuating cp,h,s and plotting
for i=1:53
tline=fgetl(f1);
A=strsplit(tline,' ');
name_of_species=(A{1});
lowtemp= str2num(A{end-3});
midtemp=str2num(A{end-2});
hightemp=str2num(A{end-1});
%Finding 7 higher coefficients and 7 lower coefficients
tline1=fgetl(f1);
a=findstr(tline1,'E');
a1=tline1(1:a(1)+3);
a1=str2num(a1);
a2=tline1(a(1)+4:a(2)+3);
a2=str2num(a2);
a3=tline1(a(2)+4:a(3)+3);
a3=str2num(a3);
a4=tline1(a(3)+4:a(4)+3);
a4=str2num(a4);
a5=tline1(a(4)+4:a(5)+3);
a5=str2num(a5);
tline2=fgetl(f1);
a=findstr(tline2,'E');
a6=tline2(1:a(1)+3);
a6=str2num(a6);
a7=tline2(a(1)+4:a(2)+3);
a7=str2num(a7);
a8=tline2(a(2)+4:a(3)+3);
a8=str2num(a8);
a9=tline2(a(3)+4:a(4)+3);
a9=str2num(a9);
a10=tline2(a(4)+4:a(5)+3);
a10=str2num(a10);
tline3=fgetl(f1);
a=findstr(tline3,'E');
a11=tline3(1:a(1)+3);
a11=str2num(a11);
a12=tline3(a(1)+4:a(2)+3);
a12=str2num(a12);
a13=tline3(a(2)+4:a(3)+3);
a13=str2num(a13);
a14=tline3(a(3)+4:a(4)+3);
a14=str2num(a14);
%calculate specific heat(cp),Enthalpy(H),Entropy(S)
Cp=Specific_heat(a1,a2,a3,a4,a5,a8,a9,a10,a11,a12,T,R,global_midtemp);
H=Enthalpy(a1,a2,a3,a4,a5,a6,a8,a9,a10,a11,a12,a13,T,R,global_midtemp);
S=Entropy(a1,a2,a3,a4,a5,a7,a8,a9,a10,a11,a12,a14,T,R,global_midtemp);
%calculating molecular weight and printing it.
Molecular_weight=wt(name_of_species);
fprintf('molecular weight of %s= %f\n',name_of_species,Molecular_weight);
%PLOTTING CP,H,T
cd('C:\Users\hhh\Desktop\matlab\NASA FILES')
%creating the folder
mkdir(name_of_species);
cd(name_of_species);
%plotting T vs cp
figure(1)
plot(T,Cp,'linewidth',5,'color','r')
xlabel('Temperature(T)')
ylabel('Specific heat(cp)')
grid on
title(name_of_species)
saveas(figure(1),'specific heat.jpg');
%Plotting T vs H
figure(2)
plot(T,H,'linewidth',5,'color','b')
xlabel('Temperature(T)')
ylabel('Enthalpy(H)')
grid on
title(name_of_species)
saveas(figure(2),'Enthalpy.jpg');
%Plotting T vs S
figure(3)
plot(T,S,'linewidth',5,'color','y')
xlabel('Temperature(T)')
ylabel('Entropy(S)')
grid on
title(name_of_species)
saveas(figure(3),'Entropy.jpg');
cd('C:\Users\hhh\Documents\MATLAB\nasa files')
end