Project 1 - Parsing NASA thermodynamic data
File parsing is the method of reding the stream of data and buliding the a memory model for the content of data .This aims at faciliating performing some kind of transformation.
The explaination of code is as follows
1.firstly to read the data file fopen command is used and to get information fgetl command is used.

2. our second step is to extract the temperatute from the delimeter as shown in above fig so for that we use the command strsplit which slpits the strings in to cell arrays the general syntax is strsplit(str,delimeter) and its gives output as { }{'300'},{'1000'},{'5000'} and we assign the cell matrix to the variable a.
3.we convert the string matrix present in the cell array to the number matrix using the command str2num the general syntax str2num(string)
after converting the string to number array we assign each number as the global _high_temp,global_mid_temp and global_low_temp.
and we have global_high_temp=str2num(a{4}) and it returns as global _high_temp=1000, global_low_temp=str2num(a{2} it will return as global_low_temp=300, , global_mid_temp=str2num(a{3}) it return as global_mid_temp=1000

4.as the above three line are not important so they are read using the command fgatl
5.Next step we shuld the extract the coeffiecents for calculating the enthlapy,enthropy,specific heat before that we will extract the low temp coeffiecients using the command strsplit when we use the command syrsplit its going to split the delilmeterof line in
to 9 call arrays as{o},{L},{1/900},(1},{G},{200},{350},{1000}. the first string is 'o' hence its assgined to variable' spieces' . in order to locate position of low temperatures first we locate refernce point from that point we acn locate positions of local temperature in this case our refernce point is G to locate the position we use the command strfind and the syntax for trhe command styrfind is A=strfind(t_line,'G') the first input indicates the delimeter and second resprent the string whose position we wanted to know and it returns as A=45 from the point point G we can locate local tempaeratures as temp=tline(A+4:length(t_line2)) it means the local tempeartures 1 i.e 200 is at position of49 i.e. from 4 places of the r ight hnad side of G and it contiues till the end of t_line(2) we assign each temperature to the local_high temp,local_mid_temp and local_low_temp.
6.Our next step is to extarct the co_eficients for that we locate the position of the E for that we use strfind command is used and its returns the position of E at different locations i.e @12 . 27 .42 , 57,75 and we assign it to variable b .and the first co-efficient is extracted
as b1=(1:b(1)+3) here b(1) indicates thee first position of E i.e. 12 hence we get the strings up to positions of the E (left hand side of E) and we have 3 strings after E i.e right hand side of E hence we have used +3. and we convert string to the number using the command str2num and we assign value it to b1. and in extaction of second coefficient
we do as b2=t_line2(b(1)+4:b(2)+3)since the first string of b2 starts from the 4thplace ofthe b(1) i.e.@16 place and till the secondposition of b(2) i.e@27 and we add3 to the b(2) to get right strings of b(2) and we use str2num command to convert string to number. For extraction of b3 we do as b3=t_line(b(2)+4:b(3)+3) since the first string of b3 starts from the 4thplace ofthe b(2) i.e.@31 place and till the secondposition of b(3) i.e@42 and we add3 to the b(3) to get right strings of b(3) and we use str2num command to convert string to number. similar we do for extaction of b4 , b5,b6,b7,b8,b9,b10,b11,b12,b13,b14. and we reapeat steps using for loop for the other speices.
7.we have written separate functions to caluclate the specific heat,enthlapy,enthropy and molecular weight. and we used command mkdir to create seperrate floder by specifying the directory. for changing the directory we used commandcd in porder to save the plots of specific heat,enthlapy,enthropy in each indivual species of file.
The code for Specific heat
function [CP]=specific_heat(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R)
if t>local_mid_temp
CP=(b1+(b2.*t)+(b3.*(t.^2))+(b4.*(t.^3))+(b5.*(t.^4))).*R
else
CP=(b8+(b9.*t)+(b10.*(t.^2))+(b11.*(t.^3))+(b12.*(t.^4))).*R
end
The code for Enthropy
function [S]=entropy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R)
if(t>local_mid_temp)
S=(b1.*log(t))+(b2.*t)+((b3.*(t.^2))/2)+((b4.*(t.^3))+(b5.*(t.^4))+b7)*R
else
S=((b8.*log(t))+(b9.*t)+((b10.*(t.^2))/2)+((b11.*(t.^3))+(b12.*(t.^4))+b14))*R
end
The code for Enthlapy
function [H]=enthlapy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R)
if(t>local_mid_temp)
H=(b1+(b2.*t)/2)+((b3.*(t.^2))/3)+((b4.*(t.^3))/4)+((b5.*(t.^4))/5)+(b6./t).*t*R;
else
H=(b8+(b9.*t)/2)+((b10.*(t.^2))/3)+((b11.*(t.^3))/4)+((b12.*(t.^4))/5)+(b13./t).*t*R;
end
The main code
clear all
close all
clc
f1=fopen('thermo.dat','r');
fgetl(f1);
t_line=fgetl(f1);
a=strsplit(t_line,' ')
global_low_temp=str2double(a{2});
global_mid_temp=str2double(a{3});
global_high_temp=str2double(a{4});
fgetl(f1);
fgetl(f1);
fgetl(f1);
for i=1:53
t_line2=fgetl(f1);
s=strsplit(t_line2,' ');
spieces_name=s{1};
A=strfind(t_line2,'G');
temp_values=t_line2(A+4:length(t_line2));
B=strsplit(temp_values,' ');
local_low_temp=str2double(B{1});
local_mid_temp=str2double(B{2});
local_high_temp=str2double(B{3});
t_line=fgetl(f1);
b=strfind(t_line,'E');
b1=t_line(1:b(1)+3);
b1=str2num(b1);
b2=t_line(b(1)+4:b(2)+3);
b2=str2num(b2);
b3=t_line(b(2)+4:b(3)+3);
b3=str2num(b3);
b4=t_line(b(3)+4:b(4)+3);
b4=str2num(b4);
b5=t_line(b(4)+4:b(5)+3)
b5=str2num(b5);
line2=fgetl(f1);
b6=line2(1:b(1)+3);
b6=str2num(b6);
b7=line2(b(1)+4:b(2)+3);
b7=str2num(b7);
b8=line2(b(2)+4:b(3)+3);
b8=str2num(b8);
b9=line2(b(3)+4:b(4)+3);
b9=str2num(b9);
b10=line2(b(4)+4:b(5)+3);
b10=str2num(b10);
line3=fgetl(f1);
b11=line3(1:b(1)+3);
b11=str2num(b11);
b12=line3(b(1)+4:b(2)+3);
b12=str2num(b12);
b13=line3(b(2)+4:b(3)+3);
b13=str2num(b13);
b14=line3(b(3)+4:b(4)+3) ;
b14=str2num(b14);
R=8.314;
t=linspace(local_low_temp,local_high_temp,100);
[CP]=specific_heat(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
[H]=enthlapy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
[S]=entropy(b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,local_low_temp,local_mid_temp,local_high_temp,t,R);
mkdir(spieces_name);
cd(spieces_name);
figure(1)
plot(t,CP,'linewidth',3)
xlabel('temperature')
ylabel('specific_heat')
saveas(1,'specific_heat.jpg')
figure(2)
plot(t,H,'linewidth',3)
xlabel('temperature')
ylabel('Enthlapy')
saveas(2,'Enthlapy.jpg')
figure(3)
plot(t,S,'linewidth',3)
xlabel('temperature')
ylabel('Entropy')
saveas(3,'Enthropy.jpg')
cd ..
% molecular weight
mol_wt=molecular_weight(spieces_name);
end
fclose(f1)
The code for Molecular weight
function [mol_wt]=molecular_weight(spieces_name)
elements=['H','C','O','N','A','S'];
atomic_mass=[1.00794 12.0107 15.99 14.0067 39.948 32];
mol_wt=0
for i=1:length(spieces_name)
for j=1:length(elements)
if strcmp(spieces_name(i),elements(j));
mol_wt=mol_wt+atomic_mass(j)
z=j;
end
end
end
t=str2double(spieces_name(i));
if(t>1)
mol_wt=mol_wt+(atomic_mass(z)*(t-1));
end
end
The plot for o2
specific Heat for o2

Enthalapy for o2

Enthropy 02
The specific heat co2

Enthalpy for co2

Enthropy for c02
THE dpecific heat for N2

the Enthlapy for N2

the Enthropy for N2

the file for different species

molecular weight

Error noticed

the error is because of
here inspite of doing b(1)+4 its written as b(1)+2 and its corrected as b(1)+4