Project 1 - Parsing NASA thermodynamic data
AIM:
Parsing NASA thermodynamic data using MATLAB programming.
THEORY:
NASA came up with polynomials that can be used to evaluate thermodynamic properties such as Cp, H and S. They have also documented the coefficients that are required to evaluate these polynomials for 1000+ species. Below figure shows the structure of the file format that includes the values of the individual species coefficients along with their local temperature ranges.
Although the file looks incomprehensible, it provides many important details of the individual behaviour of the species. So, the main motive of this project is to make a program in Matlab that can extract all the coefficients of the species and make their relation with given thermodynamic properties.
The above formula are used calculate specific heat 'Cp', Enthapy 'H' and Entropy 'S'
- The FIRST 7 coefficients are HIGH-temperature coefficients and the SECOND 7 coefficients are LOW-temperature coefficients.
- Based on the that we should calculate for all species Cp,H,S and plots for all species in separate file dictionary automatically.
- Then with all species calculate the molecular weight each special in command window in matlab.
THIS IS THE MAIN SCRIPT OF THE PROGRAMME:
clear
close
clc
F=fopen('THERMO.dat','r');
fgetl(F);
G_temp = str2num(fgetl(F));
%Global temparture
G_low = G_temp(1);
G_mid = G_temp(2);
G_high= G_temp(3);
%%skipping 3 line because my 4th line is the species strating
for i=1:3
fgetl(F);
end
for K=1:53
A=fgetl(F);
%using strsplit command because it is string type so, spliting by space because it common in this line
a = strsplit(A,' ');
species_name = a{1};
%TO CACLULATE THE MOLECULAR WEIGHT OF EACH SPECIES CREATED A FUNCTION TO
%FIND ALL MOLECULAR WEIGHT
Molecular_wt = calc_of_molecular_weight(species_name)
%Local temparture
L_low = str2double(a{end-3});
L_high= str2double(a{end-2});
L_mid = str2double(a{end-1});
%now we can extract the coefficent values
B=fgetl(F);
pos=strfind(B,'E');
% variable "a" represents the coefficent values.
A1 = B(1:pos(1)+3);
A1=str2double(A1);
A2 = B(pos(1)+4:pos(2)+3);
A2=str2double(A2);
A3 = B(pos(2)+4:pos(3)+3);
A3=str2double(A3);
A4 = B(pos(3)+4:pos(4)+3);
A4=str2double(A4);
A5 = B(pos(4)+4:pos(5)+3);
A5=str2double(A5);
C=fgetl(F);
pos1=strfind(C,'E');
A6 = C(1:pos1(1)+3);
A6=str2double(A6);
A7 = C(pos1(1)+4:pos(2)+3);
A7=str2double(A7);
A8 = C(pos1(2)+4:pos(3)+3);
A8=str2double(A8);
A9 = C(pos1(3)+4:pos(4)+3);
A9=str2double(A9);
A10 = C(pos1(4)+4:pos(5)+3);
A10=str2double(A10);
D=fgetl(F);
pos2=strfind(D,'E');
A11= D(1:pos2(1)+3);
A11=str2double(A11);
A12 = D(pos2(1)+4:pos2(2)+3);
A12=str2double(A12);
A13 = D(pos2(2)+4:pos2(3)+3);
A13=str2double(A13);
A14 = D(pos2(3)+4:pos2(4)+3);
A14=str2double(A14);
%R is the universal gas numbers
% R=8.3145; %J/Mol*Km (units)
%Specific heat, Enthalpy, Entropy @ High temparture
T = linspace(L_low,L_high,500);
for i = 1:length(T)
[cp,h,s] = calc_therm_properties(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,T,L_mid);
end
mkdir(['/Users/kishoremoorthysp/Desktop/species/',species_name])
cd(['//Users/kishoremoorthysp/Desktop/species/',species_name])
%Temperature v/s Specific Heat
figure(1)
plot(T,cp,'linewidth',2,'color','r')
title(species_name)
xlabel('Local Temperature (K)')
ylabel('Specific Heat (kJ/K)')
grid on
saveas(1,'specific heat','jpg')
%Temperature v/s Enthalpy
figure(2)
plot(T,h,'linewidth',2,'color','b')
title(species_name)
xlabel('Local Temperature (K)')
ylabel('Enthalpy (kJ/K)')
grid on
saveas(2,'Enthalpy','jpg')
%Temperature v/s Entropy
figure(3)
plot(T,s,'linewidth',2,'color','k')
title(species_name)
xlabel('Local Temperature (K)')
ylabel('Entropy (kJ/K)')
grid on
saveas(3,'Entropy','jpg')
end
THIS USER DEFIND FUNCTION FOR THE MOLECULAR WEIGHT OF THE EACH SPECIES WHICH IS USED IN THE ABOVE MAIN SCRIPT PROGRAMME ARE BELOW:
%Function for calculating the molecular weignt
function [Molecular_wt] = calc_of_molecular_weight(species_name)
Elements = ['H','C','N','O','A'];
Atomic_wt = [1,12,14,16,40];
Molecular_wt = 0;
for i = 1:length(species_name)
for j= 1:length(Elements)
if strcmpi(species_name (i),Elements (j))
Molecular_wt = Molecular_wt + Atomic_wt(j);
P=j;
end
end
G = str2double (species_name(i));
if G>1
Molecular_wt=Molecular_wt+Atomic_wt(P)*(G-1);
end
end
sprintf('The molecular weight of %s is %d', species_name, Molecular_wt)
end
THIS USER DEFIND FUNCTION FOR CALCULATING THE COEFFECIENT VALUES OF THE EACH SPECIES WHICH IS USED IN THE ABOVE MAIN SCRIPT PROGRAMME ARE BELOW:
function [cp,h,s] = calc_therm_properties(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,T,L_mid)
R = 8.314;
if (T>=L_mid)
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;
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;
s = (A8*log(T)+(A9.*T)+(A10.*(T.^2)/2)+(A11.*(T.^3)/3)+(A12.*(T.^4)/4)+A14)*R;
end
end
EXPLANATION OF CODE:
- The programe strat with clear close clc.
- Then using fopen command opening the THEMO.data and 'r' represent the reading the file.
- Then command fgetl is inbuilt command in matlab uses to print the line by line in command window.
- Then first refer the header and the second line is global temperature then next 3 line are skipped using the for loop command.
- Then from 4 line the 53 species in block wise so using the for loop command for all species can be calculate the cp,H,S inside the for loop so all the species can calculated.
- In line number 4 the species_name and local temperature are there so, it can splited using strsplite command in matlab because it is string type using that it can be splited and L_low,L_high,L_mid. splite using space b/w them.
- Then next line is coefficents vulace of the temperature, the frist 7 are high and 8 to 14 are low temperature coeffecients values.
- It can splited using str2num or str2double because it is used to calculate the Cp,H,S with help of the position of the exp the number can be splited.
- Then all the 14 coeffecient are store in A1, A2,A3,....,A14. using then using the function command the molecular wieght been calculated.
- In function the initially the in species the common element are H,C,O,A,N are common for this element the atomic value is are known values and they are standard values.
- Then using the for and if loop command and strcmpi is also command used to string comparision so, if the string in line is compared in element in array and taken values from atomic array with the position , then if it not in that then it goes else therer the str2double is used then calculated.
- Then it is printed in command window using the sprintf command.
- next is to calculate the Cp,H,S. for that the function is used, there the in for loop the if the Temperature is used as array using linspace command of L_low and L_high temperature in there.
- every temperature is compared with if condition the temperaure is less than or equal to the L_mid temperature it mean using the A1 to A7 coeffecient and if else use the A8 to A14 so, that all Cp, H,S are calculated.
- Then mdrik is the command is used create the folder in specificed folder and cd command is used to changes the path of the folder to respectively.
- Then using the plot command the graph has been plotted with Temperature Vs Cp , Temperature Vs H, Temperature Vs S. saveas command used to save plotted graph as jpg formate.
- Then end the for loop which initiallly opened.
Output results
MOLECULAR WEIGHT FOR THE 53 SPECIES ARE THERE BELOW SNAP.













OUTPUT WORKSPACE OF THE PROGRAMME.

THE BELOW IS THE FOLDER WHICH HAVE BEEN AUTOMATICALLY CREATED FROM THE CODE HAVE PRAGRAMMED ABOVE, IS BELOW.


THIS IS PLOT FOR O2 SPECIES.



THIS IS PLOT FOR N2 SPECIES.



THIS IS PLOT FOR CO2 SPECIES.



CONCULUSION:
- BY USING ALL THE COMMAND IN BEFORE CHALLENGES AND WITH NEW COMMAND THE THE ABOVE PROGRAMME HAVE BEEN CODED.
- USING THE FOR LOOP AND FUNCTION COMMANDS THE ABOVE PROGRAMME HAVE CODED AND TIME ALSO BEEN SAFED.