Project 1 - Parsing NASA thermodynamic data
AIM :-
Program to compute parse data of NASA file and then calculate thermodynamic properties of various species. using the MATLAB
OBJECTIVE :-
Calculate the molecular weight of each species and display it in the command window.
Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.
THEROY :-
SPECIFIC HEAT :- The quantity of heat required to raise the temperature of one gram of a substance by one Celsius degree.
ENTHALPY :- The sum of the internal energy and the product of the pressure and volume of a thermodynamic system.
ENTROPY :-The measure of a system's thermal energy per unit temperature that is unavailable for doing useful work.
Formulas

where
a1 to a7 = cofficient values
T = temprature
cp = specific heat
H = enthalpy
s = entropy
R = universal gas constant
CODING PART :-
In this im creating a function an dcall this in main code.
In this function we are calculating the specific heat, enthaly and entropy with the tempreature
first creating a function called CP_H_S
Using the for loop for all values of tempreature using command length then after if the tempreature value is grater than the local temp mid values then the if condition allows to calculate the first 7 high temp cofficients if it is condition then it is gonig to calculate the low temp values.
Thats the end of the function and it is call in main code.
function [cp,h,s]=CP_H_S(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,local_mid_temp_value)
for i = 1:length(T)
if T(i)>local_mid_temp_value
cp=(a1+a2.*T+a3.*T.^2+a4.*T.^3+a5.*T.^4)*R;
h=(a1+a2.*T/2+a3.*T.^2/3+a4.*T.^3/4+a5*T.^4/5+a6./T)*R.*T;
s=(a1*log(T)+a2*T+a3*T.^2/2+a4*T.^3/3+a5*T.^4/4+a7)*R;
else
cp=(a8+a9*T+a10*T.^2+a11*T.^3+a12*T.^4)*R;
h=(a8+a9*T/2+a10*T.^2/3+a11*T.^3/4+a12*T.^4/5+a13./T)*R.*T;
s=(a8*log(T)+a9*T+a10*T.^2/2+a11*T.^3/3+a12*T.^4/4+a14)*R;
end
end
end
In this function code im going to calculate the molecular weight of each species.
For that we are creating the function and saving the species in a variable s
similarly writing the Elements and the atomic weight as well and molecular_weight is set to ZERO initially
Using the for loop for species to its entire length and similarly for elements
Here im using the if condition and comparing the species and Elements.
In the next line calculating the moleclular weight
function molecular_weigth = MOLECULAR_WEIGTH(species)
s = species;
Elements = ['C','N','H','O','A'];
Atomic_weigth = [12.02,14.01,1.008,16.00,39.948];
molecular_weigth = 0;
for i = 1:length(s)
for j = 1:length(Elements)
if strcmpi(s(i),Elements(j))
molecular_weigth = molecular_weigth+Atomic_weigth(j);
position = j;
end
end
num = str2double(s(i));
if(num)>=1
molecular_weigth = molecular_weigth + Atomic_weigth(position)*(num-1);
end
end
end
Firstly clear, close and clc
open the THERMO.dat file into matlab using foen so command.
In the file i want to access the first line then i simply write a command called fgetl then the matlab will automatically show the first line of our file similarly for all the lines
Here the file is having the local tempreature values, global temp values and cofficients i need to read all that data into matlab
For the global temp values i use strsplit it is a command used to split the string.
And the command called str2double used to change the string value to the double or numerical. then we got the global temp values.
Avoiding the comment lines in the THERMO.dat file.
There are 53 species in the file and for every specie there is an local temp values i need to read all the data and save it in workspace by numarical values
For that i use for loop for the entire 53 species and then saving local temp values like global temp values. Also for saving the cofficients unsing strsplit, str2double commands.
Then through creating the tempreature values between local high and low tempretures
calling the function to calculate the CP H S
ploting the results
calculating the molecular weight
close the file
clear all
close all
clc
f1 = fopen('THERMO.dat','r');
line1 = fgetl(f1);
line2 = fgetl(f1);
Global_Temp_values = strsplit(line2,' ');
Gobal_low_temp = str2double(Global_Temp_values{2});
Gobal_mid_temp = str2double(Global_Temp_values{3});
Gobal_high_temp =str2double(Global_Temp_values{4});
fgetl(f1);
fgetl(f1);
fgetl(f1);
for i = 1:53
line6 = fgetl(f1);
local_temp_values = strsplit(line6,' ');
species = (local_temp_values{1});
local_low_temp_value = str2double(local_temp_values{end-3});
local_mid_temp_value = str2double(local_temp_values{end-1});
local_high_temp_value = str2double(local_temp_values{end-2});
cofficients_in_line1 = fgetl(f1);
a = strfind(cofficients_in_line1,'E');
a1 = str2double(cofficients_in_line1(1:a(1)+3));
a2 = str2double(cofficients_in_line1(a(1)+4:a(2)+3));
a3 = str2double(cofficients_in_line1(a(2)+4:a(3)+3));
a4 = str2double(cofficients_in_line1(a(3)+4:a(4)+3));
a5 = str2double(cofficients_in_line1(a(4)+4:a(5)+3));
cofficients_in_line2 = fgetl(f1);
b = strfind(cofficients_in_line2,'E');
a6 = str2double(cofficients_in_line2(1:b(1)+3));
a7 = str2double(cofficients_in_line2(b(1)+4:b(2)+3));
a8 = str2double(cofficients_in_line2(b(2)+4:b(3)+3));
a9 = str2double(cofficients_in_line2(b(3)+4:b(4)+3));
a10= str2double(cofficients_in_line2(b(4)+4:b(5)+3));
cofficients_in_line3 = fgetl(f1);
c = strfind(cofficients_in_line3,'E');
a11 = str2double(cofficients_in_line3(1:c(1)+3));
a12 = str2double(cofficients_in_line3(c(1)+4:c(2)+3));
a13 = str2double(cofficients_in_line3(c(2)+4:c(3)+3));
a14 = str2double(cofficients_in_line3(c(3)+4:c(4)+3));
R = 8.314;
T = linspace(local_low_temp_value,local_high_temp_value,200);
[cp,h,s]=CP_H_S(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,T,R,local_mid_temp_value);
mkdir(['D:\matlab - species\',species]);
figure(1);
plot(T,cp,'linewidth',4,'color','r');
xlabel('Temperature');
ylabel('specific heat');
print('tempreature & specific heat','-dpng')
figure(2);
plot(T,h,'linewidth',4,'color','g');
xlabel('Temperature');
ylabel('enthalpy');
print('tempreature & enthalpy','-dpng')
figure(3);
plot(T,s,'linewidth',4,'color','b');
xlabel('Temperature');
ylabel('entropy');
print('tempreature & entropy','-dpng')
molecular_weigth = MOLECULAR_WEIGTH(species);
fprintf('Molecular weight of the species %s is %f',species, molecular_weigth);
% disp(' ');
end
RESLUTS :-



CONCLUTION :-
Hence the parsing nasa thermodynamic data file have been done successfully.