Project 1 - Parsing NASA thermodynamic data
* PARSEING THE NASA THERMODYNAMIC DATA FILE AND CALCULATING THERMODYNAMIC PROPERTIES OF VARIOUS GAS SPECIES.
PROGRAM
close all
clear all
clc
file=fopen('THERMO.dat','r') %reading the nasa thermo data file
line1=fgetl(file) % heading of data
line2=fgetl(file) % global temp value
comment1=fgetl(file) %comments
comment2=fgetl(file) %comments
comment3=fgetl(file) %comments
A =strsplit(line2,' '); %splitting the line2
global_low = str2num(A{2}); %global low temp
global_mid = str2num(A{3}); %global mid temp
global_high = str2num(A{4}); % global high temp
%extrading species information individual
for i=1:53 % 53 individual species
species=fgetl(file);
T1 = strfind(species,'.');
temp1 = species(T1(1)-3:T1(1)+3);
t_min = str2double(temp1);
temp2 = species(T1(2)-4:T1(2)+3);
t_max = str2double(temp2);
temp3 = species(T1(3)-4:T1(3)+3);
t_high = str2double(temp3);
species_name=species(1:6);
line_1 = fgetl(file);
%extracting 1st spices line
L1 = strfind(line_1,'E');
c1 = str2num(line_1(1:(L1(1)+3)));
c2 = str2num(line_1((L1(1)+4):(L1(2)+3)));
c3 = str2num(line_1((L1(2)+4):(L1(3)+3)));
c4 = str2num(line_1((L1(3)+4):(L1(4)+3)));
c5 = str2num(line_1((L1(4)+4):(L1(5)+3)));
line_2=fgetl(file);
% extracting 2nd species line
L2 = strfind(line_2,'E');
c6 = str2num(line_2(1:(L2(1)+3)));
c7 = str2num(line_2((L2(1)+4):(L1(2)+3)));
c8 = str2num(line_2((L2(2)+4):(L1(3)+3)));
c9 = str2num(line_2((L2(3)+4):(L1(4)+3)));
c10 = str2num(line_2((L2(4)+4):(L1(5)+3)));
line_3=fgetl(file);
% extracting 3rd line of species
L3 = strfind(line_3,'E');
c11 = str2num(line_3(1:(L3(1)+3)));
c12= str2num(line_3((L3(1)+4):(L1(2)+3)));
c13= str2num(line_3((L3(2)+4):(L1(3)+3)));
c14= str2num(line_3((L3(3)+4):(L1(4)+3)));
R=8.314
T = linspace(global_low,global_high,100);
mkdir(species);
cp=specific_heat(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,global_low,global_mid,global_high,T,R);
s=entropy(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,global_low,global_mid,global_high,T,R);
H=enthalpy(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,global_low,global_mid,global_high,T,R);
W=molecular_weight(species);
figure(1)
plot(T,cp)
xlabel('Temperature [K]')
ylabel('Specific Heat [J/Kg.K]')
title('Temperature vs Specific Heat')
figure(2)
plot(T,H)
xlabel('Temperature [K]')
ylabel('Enthalpy [KJ]')
title('Temperature vs Enthalpy')
figure(3)
plot(T,s)
xlabel('Temperature [K]')
ylabel('Entropy [J/k]')
title('Temperature vs Entropy')
end
FUNCTIONS
FOR SPECIFIC HEAT
function cp=specific_heat(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,global_low,global_mid,global_high,T,R);
if(T<=global_mid)
cp=R*(c8+(c9*T)+(c10*(T).^2)+(c11*(T).^3)+(c12*(T).^4));
else
cp=R*(c1+(c2*T)+(c3*(T).^2)+(c4*(T).^3)+(c5*(T).^4));
end
end
FOR ENTHALPY
function H=enthalpy(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,global_low,global_mid,global_high,T,R);
if (T<=global_mid)
H=R*T.*(c8+((c9*T)/2)+((c10*(T).^2)/3)+((c11*(T).^3)/4)+((c12*(T).^4)/5)+((c13./T)));
else
H=R*T.*(c1+((c2*T)/2)+((c3*(T).^2)/3)+((c4*(T).^3)/4)+((c5*(T).^4)/5)+((c6./T)));
end
end
FOR ENTROPY
function s=entropy(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,global_low,global_mid,global_high,T,R);
if (T<= global_mid)
s=R*(c8.*log(T)+(c9*T)+((c10*(T).^2)/2)+((c11*(T).^3)/3)+((c12*(T).^4)/4)+c14);
else
s =R*(c1.*log(T)+(c2*T)+((c3*(T).^2)/2)+((c4*(T).^3)/3)+((c5*(T).^4)/4)+c7);
end
end
FOR MOLECULAR WEIGHT
function W = molecular_weight(species)
atomic_name = ['H','C','O','N','Ar'];
atomic_weight = [1.008 12.011 15.999 14.007 39.948];
W=0
for i=1:length(species)
for j=1:length(atomic_name)
if strcmp(species(i),atomic_name(j))
W=W+atomic_weight(j);
position = j
end
end
n=str2num(species);
if n>1
W=W+atomic_weight(position)*(n-1);
end
fprintf('molecular weight of %s :-',species);
fprintf('%f',W);
disp(' ')
end
OUTPUT:
FOR 02


FOR N2



FOR CO2



WORK SPACE

MOLECULAR WEIGHT

RESULT
The code for file parsing is done
the graph for n2 o2 co2 is plotted
molecular weight is found out.