PARSING NASA THERMODYNAMIC DATA
PROJECT
TITLE : PARSING NASA THERMODYNAMIC DATA
OBJECTIVE : To parse and extract information from Nasa Thermodynamic data file and then calculate thermodynaics properties of various species,hence making plot of them w.r.t temperature &calculating molecular mass of the given chemical species.
REPORT
NASA has came up with polynomials that can be used to evaluate thermodynamics properties such as Cp ,H ans S using polynomials.they have also documented the co-efficients that are required to evaluate these polynomials for 1000+ species
Cp/R = a1 + a2 T + a3 T^2 + a4 T^3 + a5 t^4
H/RT = a1 + a2 T/2 + a3 T^2/3 + a4 T^3/4 + a5 T^4/5 + a6/T
S/R = a1 lnT + a2 T+ a3 T^2/2 + a4 T^3/3 + a5 T^4/4 + a7
In this project ,a THERMO.dat file is provided to us in which list of polynomials coefficients are given . There are total 14 coefficients given to us in which first seven are for high temperature coefficients and second seven coefficients are for low temperature coefficients
Basically there are two temperature range
Lower temperature range (300-1000K)
and higher temperature range (1000-5000K)
MAIN PROGRAM
in main program , we input our file i.e THERMO.dat file given to us. After that a function name \"extract_coeffi\" take fileID as input e.g in my case it is \"nasa_data\" ,now function will read and parse the thermodynamic data file and extract information from it and give it as in it its output argument.it give us various useful information like
it provide us 1. global low temperature
2. global high temperature
3. global mid temperature
4.cell = \"formula_chemical\" which contains species name in each of its cell
5. multidimentional array = \"c\" it contains coefficient value for various sps in a single page ,similarly there are 14 pages containing each coefficient per page
dimention of c (1x53x14)
next ,define variables reqiured further as we proceed
now comes the main part , Creation of folder \"NASA_DATA\" in current directory MATLAB
now changing directory to NASA_DATA ,
applying loop process for all the species elements ,there are total 53 species(calculated in extract_coeffi function) ,during each loop which is equivalent each species ,we store
Chemical_name of species
molecular_mass of species
this is calculated with the help of function \"mmcalci\"
coefficient value using output argument \"c\" obtained from function \"extract_coeffi\"
a1,a2,a3,a4,a5,a6,a7 for lower temperature range
A1,A2,A3,A4,A5,A6,A7 for higher temperature range
thermodynamic properties Cp ,H,S separately both for lower and higher temperature range
using total 6 functions each specific for specific property
now next important part involves saving of plot between Cp,H,S both for higher and lower temperature
for this we create total 53 subfolders within NASA_DATA where each subfolder contains plots of Cp,H,S vs T for 1 species .similarly by putting it under loop we make it for all species.
here name of each subfolder is automatically generated using species name
the plots between Cp,H,S vs T are obtained from function \"plotmaker\"
clear all
close all
clc
nasa_data = fopen(\'THERMO.dat\',\'r\');
[c , formula_chemical, global_lt , global_mt , global_ht] = extract_coeffi(nasa_data);
Global_low_temperature = global_lt;
Global_mid_temperature = global_mt;
Global_high_temperature = global_ht;
name = char(formula_chemical);
sps = string(name);
ltr = linspace(300,1000,100);
htr = linspace(1000,5000,100);
R = 8.314;
MATLAB = pwd;
mkdir(\'NASA_DATA\')
cd (\'NASA_DATA\')
NASA_DATA = pwd;
for i = 1:53
index = i;
Chemical_Name = sps(i);
%MOLECULAR MASS CLACULATOR
molecular_mass(i) = mmcalci(index,sps);
a1(i) = c(1,i,1);
a2(i) = c(1,i,2);
a3(i) = c(1,i,3);
a4(i) = c(1,i,4);
a5(i) = c(1,i,5);
a6(i) = c(1,i,6);
a7(i) = c(1,i,7);
A1(i) = c(1,i,8);
A2(i) = c(1,i,9);
A3(i) = c(1,i,10);
A4(i) = c(1,i,11);
A5(i) = c(1,i,12);
A6(i) = c(1,i,13);
A7(i) = c(1,i,14);
%CALCULATING THERMODYNAMIC PROPERTIES
Cp_lt{i} = cell2mat(Cp_calci_lowtemprange(i,ltr,a1,a2,a3,a4,a5));
Cp_ht{i} = cell2mat(Cp_calci_hightemprange(i,htr,A1,A2,A3,A4,A5));
H_lt{i} = cell2mat(H_calci_lowtemprange(i,ltr,a1,a2,a3,a4,a5,a6));
H_ht{i} = cell2mat(H_calci_hightemprange(i,htr,A1,A2,A3,A4,A5,A6));
S_lt{i} = cell2mat(S_calci_lowtemprange(i,ltr,a1,a2,a3,a4,a5,a7));
S_ht{i} = cell2mat(S_calci_hightemprange(i,htr,A1,A2,A3,A4,A5,A7));
%PLOT MAKER FUNCTION
dir_name = sprintf(\'DATA OF %s\',sps{i});
cd(NASA_DATA)
mkdir(dir_name)
cd(dir_name)
plotmaker(sps,i,Cp_lt,Cp_ht,H_lt,H_ht,S_lt,S_ht,ltr,htr);
cd(NASA_DATA)
end
VARIOUS FUNCTIONS USED IN MAIN PROGRAMS:-
1) extract_coeffi
this function takes fileID as input and provide usefull information in return
from which most important are those 14 coefficients in a variable \"c\"(multidimentional array),besides this we also get ,global low ,high & mid temperature , chemical name of sps. as in formula_chemical (cell format)
the function basically involves use of fopen ,fgetl to read and parse the file.
function [c , formula_chemical , global_lt , global_mt , global_ht] = extract_coeffi(fileID)
Heading = fgetl(fileID);
temperature_range = str2double(strsplit(fgetl(fileID),\' \'));
global_lt = temperature_range(2);
global_mt = temperature_range(3);
global_ht = temperature_range(4);
intro1 = fgetl(fileID);
intro2 = fgetl(fileID);
intro3 = fgetl(fileID);
%Identifying no. of Species or Blocks present in data
x = (6:4:217); % since after introduction lines species occurs at every next 4th line upto the last data line
size(x); % so we can calculate the no. of blocks by applying the above relation
Block = (1:53);
for i = 1:length(Block)
%fprintf(\'Block: %s\\n\',num2str(Block(i)))
Species_name = fgetl(fileID);
%fprintf(\'Speices name : \')
%disp(Species_name(1:7))
Formula_chemical{i} =char(Species_name(1:7));
temp_range = str2double(Species_name(68:75));
%fprintf(\'Coefficients for Higher Temperature range : (ABOVE %fK)\\n\',temp_range)
line2 = fgetl(fileID);
position_E = strfind(line2,\'E\');
A1(i) = str2double(line2(1:position_E(1)+3));
A2(i) = str2double(line2(position_E(1)+4:position_E(2)+3));
A3(i) = str2double(line2(position_E(2)+4:position_E(3)+3));
A4(i) = str2double(line2(position_E(3)+4:position_E(4)+3));
A5(i) = str2double(line2(position_E(4)+4:position_E(5)+3));
line3 = fgetl(fileID);
position_E = strfind(line3,\'E\');
A6(i) = str2double(line3(1:position_E(1)+3));
A7(i) = str2double(line3(position_E(1)+4:position_E(2)+3));
% fprintf(\'A1 = %d\\nA2 = %d\\nA3 = %d\\nA4 = %d\\nA5 = %d\\nA6 = %d\\nA7 = %d\\n\',A1(i),A2(i),A3(i),A4(i),A5(i),A6(i),A7(i))
% fprintf(\'Coefficients for Lower Temperature range : (BELOW %fK)\\n\',temp_range)
a1(i) = str2double(line3(position_E(2)+4:position_E(3)+3));
a2(i) = str2double(line3(position_E(3)+4:position_E(4)+3));
a3(i) = str2double(line3(position_E(4)+4:position_E(5)+3));
line4 = fgetl(fileID);
position_E = strfind(line4,\'E\');
a4(i) = str2double(line4(1:position_E(1)+3));
a5(i) = str2double(line4(position_E(1)+4:position_E(2)+3));
a6(i) = str2double(line4(position_E(2)+4:position_E(3)+3));
a7(i) = str2double(line4(position_E(3)+4:position_E(4)+3));
%fprintf(\'a1 = %d\\na2 = %d\\na3 = %d\\na4 = %d\\na5 = %d\\na6 = %d\\na7 = %d\\n\',a1(i),a2(i),a3(i),a4(i),a5(i),a6(i),a7(i))
end
c(:,:,1) = a1;
c(:,:,2) = a2;
c(:,:,3) = a3;
c(:,:,4) = a4;
c(:,:,5) = a5;
c(:,:,6) = a6;
c(:,:,7) = a7;
c(:,:,8) = A1;
c(:,:,9) = A2;
c(:,:,10) = A3;
c(:,:,11) = A4;
c(:,:,12) = A5;
c(:,:,13) = A6;
c(:,:,14) = A7;
formula_chemical = Formula_chemical;
end
in the code we clearly see that each coefficient i.e a1 is stored in each page of \"c\" which contain all values of a1 for each species.
2) Thermodynamic property calculator functions
there are total 6 functions for this ,as follows
1.for Cp values in lower temperature range we have function\" Cp_calci_lowtemprange \"
it takes i(index),ltr(low temperature range (300-1000K)),coefficients as input and return Cp_low value
function [Cp_low] = Cp_calci_lowtemprange(i,ltr,a1,a2,a3,a4,a5)
R = 8.314;
for j = 1:length(ltr)
Cp{i,j} =R*[a1(i)+a2(i).*ltr(j)+a3(i).*(ltr(j).^2)+a4(i).*(ltr(j).^3)+a5(i).*(ltr(j).^4)];
end
Cp_low = Cp;
2. for Cp values in higher temperature range : \"Cp_calci_hightemprange\"
function [Cp_high] = Cp_calci_hightemprange(i,htr,A1,A2,A3,A4,A5)
R = 8.314;
for j = 1:length(htr)
Cp{i,j} =R*[A1(i)+A2(i).*htr(j)+A3(i).*(htr(j).^2)+A4(i).*(htr(j).^3)+A5(i).*(htr(j).^4)];
end
Cp_high = Cp;
3. for H values in lower temperature range : \"H_calci_lowtemprange\"
function [H_low] = H_calci_lowtemprange(i,ltr,a1,a2,a3,a4,a5,a6)
R = 8.314;
for j = 1:length(ltr)
H{i,j} = (a1(i)+(a2(i)/2).*ltr(j)+(a3(i)/3).*(ltr(j).^2)+(a4(i)/4).*(ltr(j).^3)+(a5(i)/5).*(ltr(j).^4)+a6(i)./ltr(j) ).*(R.*ltr(j));
end
H_low = H;
4. for H values in higher temperature range : \"H_calci_hightemprange\"
function [H_high] = H_calci_hightemprange(i,htr,A1,A2,A3,A4,A5,A6)
R = 8.314;
for j = 1:length(htr)
H{i,j} = (A1(i)+(A2(i)/2).*htr(j)+(A3(i)/3).*(htr(j).^2)+(A4(i)/4).*(htr(j).^3)+(A5(i)/5).*(htr(j).^4)+A6(i)./htr(j) ).*(R.*htr(j));
end
H_high = H;
5. for S values in lower temperature range : \"S_calci_lowtemprange\"
function [S_low] = S_calci_lowtemprange(i,ltr,a1,a2,a3,a4,a5,a7)
R = 8.314;
for j = 1:length(ltr)
S{i,j} = R*[a1(i).*(log(ltr(j)))+a2(i).*ltr(j)+(a3(i)/2).*(ltr(j).^2)+(a4(i)/3).*(ltr(j).^3)+(a5(i)/4).*(ltr(j).^4)+a7(i)];
end
S_low = S;
6. for S values in higher temperature range : \"S_calci_hightemprange\"
function [S_high] = S_calci_hightemprange(i,htr,A1,A2,A3,A4,A5,A7)
R = 8.314;
for j = 1:length(htr)
S{i,j} = R*[A1(i).*(log(htr(j)))+A2(i).*htr(j)+(A3(i)/2).*(htr(j).^2)+(A4(i)/3).*(htr(j).^3)+(A5(i)/4).*(htr(j).^4)+A7(i)];
end
S_high = S;
3) Molecular mass calculator function : \"mmcalci\"
the function takes \"index\",\"sps\" as input where index is just equal to number of element to be searched , and sps is a list of species name as a string . In output we get molecular_mass of the species .
in this code , first atom is identified in the sps string using contains() in built function ,which give true as a output ,hence checking if condition , in next no. of time that atom is present is identified using count() in built function , after that we calculate m by given formula.
but still we dont know whether there are C3 atoms or C8 atoms ,so for this i just compare only two letters i.e first atom and its next letter ,e.g my sps string is \"C3H8\" so after completing first part now code will check for no. after that atom , for this only \"C3\" is compared with number string , if no.is present then if condition satisfied and further m calculation will be done .
hence whole string is compared step by step and finally we get molecular mass of species.
function [molecular_mass] = mmcalci(index,sps)
a = [\"C\",\"H\",\"O\",\"N\",\"AR\",\"S\"] ;
value = [12 1 16 14 39.9 32];
m = 0;
atom_repeat =string(1:10);
for j= 1:6
if contains(sps(index),a(j))
z = count(sps(index),a(j));
m = m + value(j)*z;
z =0;
for k = 1:10
q = char(sps(index));
xx = strfind(sps(index),a(j));
xx = xx(1);
q2 = string(q(xx(1):xx(1)+1));
if contains(q2,atom_repeat(k))
multiplier = str2double(atom_repeat(k));
m = m + value(j)*(multiplier - 1);
multiplier =0;
end
end
end
end
molecular_mass = m;
4. \"Plotmaker\" function , this function helps to make plot between Cp vs T, H vs T ,S vs T
in each figure there are two plots ,one for lower temperature range and one for higher temperature range.
moreover it also save our plot in the current folder directory as .jpg file ,so we get total 3 figure files with specified names.
function [] = plotmaker(sps,index,Cp_lt,Cp_ht,H_lt,H_ht,S_lt,S_ht,ltr,htr)
CP_HT = cell2mat(Cp_ht(index));
CP_LT = cell2mat(Cp_lt(index));
H_HT = cell2mat(H_ht(index));
H_LT = cell2mat(H_lt(index));
S_HT = cell2mat(S_ht(index));
S_LT = cell2mat(S_lt(index));
figure(1)
subplot(2,1,1)
plot(ltr,CP_LT)
xlabel(\"TEMPERATURE (K)\")
ylabel(\"SPs.HEAT(low temp.range)\")
title(\" CHEMICAL SPECIES \"+sps(index)+\"FOR LOW TEMPERATURE RANGE\")
subplot(2,1,2)
plot(htr,CP_HT)
xlabel(\"TEMPERATURE (K)\")
ylabel(\"SPs.HEAT(high temp.range)\")
title(\" CHEMICAL SPECIES \"+sps(index)+\"FOR HIGH TEMPERATURE RANGE\")
print(\'-f1\',\'Cp_Vs_T\',\'-djpeg\')
figure(2)
subplot(2,1,1)
plot(ltr,H_LT)
xlabel(\"TEMPERATURE (K)\")
ylabel(\"ENTHALPY(low temp.range)\")
title(\" CHEMICAL SPECIES \"+sps(index)+\"FOR LOW TEMPERATURE RANGE\")
subplot(2,1,2)
plot(htr,H_HT)
xlabel(\"TEMPERATURE (K)\")
ylabel(\"ENTHAPLY(high temp.range)\")
title(\" CHEMICAL SPECIES \"+sps(index)+\"FOR HIGH TEMPERATURE RANGE\")
print(\'-f2\',\'H_Vs_T\',\'-djpeg\')
figure(3)
subplot(2,1,1)
plot(ltr,S_LT)
xlabel(\"TEMPERATURE (K)\")
ylabel(\"ENTROPY(low temp.range)\")
title(\" CHEMICAL SPECIES \"+sps(index)+\"FOR LOW TEMPERATURE RANGE\")
subplot(2,1,2)
plot(htr,S_HT)
xlabel(\"TEMPERATURE (K)\")
ylabel(\"ENTROPY(high temp.range)\")
title(\" CHEMICAL SPECIES \"+sps(index)+\"FOR HIGH TEMPERATURE RANGE\")
print(\'-f3\',\'S_Vs_T\',\'-djpeg\')
end
This is all code part.
OUTPUTS
Displaying plots of specific heat , enthalpy , entropy for O2, N2,CO2
O2
SPECIFIC HEAT (Cp) vs TEMPERATURE (T)
ENTHALPY (H) VS TEMPERATURE (T)
ENTROPY (S) VS T
N2
SPECIFIC HEAT VS T
ENTHALPY VS T
ENTROPY VS T
CO2
SPECIFIC HEAT VS T
ENTHALPY VS T
ENTROPY VS T