Project 1 - Parsing NASA thermodynamic data
PARSING NASA THERMODYNAMIC DATA
AIM
To read and calculate the specific heat,enthalpy,entropy from all the species from the given NASA thermodynamic data file.
OBJECTIVES
1) To write a function that extracts the 14 co_efficients (a1-a14) and calculate the specific heat,enthalpy,entropy .
2) To plot the cp,enthalpy and entropy for the local temparature range of each species.
3) Saving the plots as images with corresponding species name and dumping them in separate folders for each species with suitable name.
INTRODUCTION
FILE PARSING
This challenge having a NASA thermodynamic data file,inorder to read the data file line by line and for calculating the required parameters , evaluation
of the polynomial,we are using some MATLAB commands to extract the data and evaluate,this process of parsing the data to obtain the objectives
is called as file parsing.
COMMANDS USED
fopen - this command is used to open the data file from the folder
fgetl - used to read the required data and also to skip the data
strsplit - string splitting, used to split the string in to number of words
str2num - string to number, used to convert the string in to numbers
strfind / findstr - used to find the letter or a number in the data
mkdir - used to create a folder
saveas - used to save the plots as images
CODE
clear all
close all
clc
f1=fopen('THERMO.dat','r');
for i = 1:5
fgetl(f1)
end
for i = 1:53
Tline = fgetl(f1)
A = strsplit(Tline,' ')
species = A{1}
llt = str2num(A{end - 3})
lht = str2num(A{end - 2})
lmt = str2num(A{end - 1})
T = linspace(llt,lht,500)
R = 8.314
coeff_line1=fgetl(f1)
a=strfind(coeff_line1,'E')
a1 = coeff_line1(1:a(1)+3)
A1 = str2double(a1)
a2 = coeff_line1(a(1)+4:a(2)+3)
A2 = str2double(a2)
a3 = coeff_line1(a(2)+4:a(3)+3)
A3 = str2double(a3)
a4 = coeff_line1(a(3)+4:a(4)+3)
A4 = str2double(a4)
a5 = coeff_line1(a(4)+4:a(5)+3)
A5 = str2double(a5)
coeff_line2=fgetl(f1)
b=strfind(coeff_line2,'E')
a6 = coeff_line2(1:b(1)+3)
A6 = str2double(a6)
a7 = coeff_line2(b(1)+4:b(2)+3)
A7 = str2double(a7)
a8 = coeff_line2(b(2)+4:b(3)+3)
A8 = str2double(a8)
a9 = coeff_line2(b(3)+4:b(4)+3)
A9 = str2double(a9)
a10 = coeff_line2(b(4)+4:b(5)+3)
A10 = str2double(a10)
coeff_line3=fgetl(f1)
c=strfind(coeff_line3,'E')
a11 = coeff_line3(1:c(1)+3)
A11 = str2double(a11)
a12 = coeff_line3(c(1)+4:c(2)+3)
A12 = str2double(a12)
a13 = coeff_line3(c(2)+4:c(3)+3)
A13 = str2double(a13)
a14 = coeff_line3(c(3)+4:c(4)+3)
A14 = str2double(a14)
[cp] = specific_heat (A1,A2,A3,A4,A5,A8,A9,A10,A11,A12,lmt,T,R);
[S] = entropy_s(A1,A2,A3,A4,A5,A7,A8,A9,A10,A11,A12,A14,lmt,T,R)
[H] = enthalpy_H(A1,A2,A3,A4,A5,A6,A8,A9,A10,A11,A12,A13,T,lmt,R)
%create a folder
mkdir (species)
%change directory
cd(species)
%PLot
figure(1)
plot(T,cp)
xlabel('Temperature')
ylabel('Specific_heat')
saveas(figure(1),'cp vs T.jpg')
figure(2)
xlabel('Temperature')
ylabel('Entropy')
plot(T,S)
saveas(figure(1),'S vs T.jpg')
figure(3)
plot(T,H)
xlabel('Temperature')
ylabel('Enthalpy')
saveas(figure(3),'H vs T.jpg')
cd ..
end
Specific_heat file code
function[cp] = specific_heat (A1,A2,A3,A4,A5,A8,A9,A10,A11,A12,lmt,T,R)
if (T<=lmt)
cp = R*( A8 + A9*T + A10*T.^2 + A11*T.^3 + A12*T.^4);
else
cp = R*( A1 + (A2*T) + ((A3*(T).^2)) + A4*T.^3 + A5*T.^4)
end
end
Entropy file code
function [S] = entropy_s(A1,A2,A3,A4,A5,A7,A8,A9,A10,A11,A12,A14,lmt,T,R)
if (T<=lmt)
S = R*((A8*log(T)) + (A9*T) + (A10*(T.^2)/2) + (A11*(T.^3)/3) + (A12*(T.^4)/4) + (A14))
else
S =R*(( A1*log(T)) + (A2*T) + (A3*(T.^2)/2) + (A4*(T.^3)/3) + (A5*(T.^4)/4) + (A7))
end
end
Enthalpy code
function [H] = enthalpy_H(A1,A2,A3,A4,A5,A6,A8,A9,A10,A11,A12,A13,T,lmt,R)
if (T<=lmt)
H = R*T.*((A8) + ((A9*T)/2) + ((A10*(T).^2)/3) + ((A11*(T).^3)/4) + ((A12*(T).^4)/5) + (A13./T))
else
H = R*T.* ( A1 + ((A2*T)/2) + ((A3*(T).^2)/3) + ((A4*(T).^3)/4) + ((A5*(T).^4)/5) + (A6./T))
end
end
\

- ploting the cp v/s temparature, H v/s temp and S v/s temp using plot command
- the corresponding x and y labels,titles and figure number is given in each case



- this will take part inside the previous loop and thus the curve will ploted for each 53 species
- folder is created using mkdir command


OBJECTIVE : calculate the molecular weight of each species and display it in the command window.
CODE
function[w]=mol_weight(species_name)
atomic_names=['H','C','O','N','A'];
atomic_weights=[1,12,16,14,40];
w=0;
for i=1:length(species_name)
for j=1:length(atomic_names)
if strcmpi(species_name(i),atomic_names(j))
w=w+atomic_weights(j);
pos=j;
end
n=str2num(species_name(i));
end
if n>=1
w=w+atomic_weights(pos)*(n-1);
k=fprintf('Molecular weight of %s = %f',species_name,w);
end
end
Thank You