Project 1 - Parsing NASA thermodynamic data
Aim:
The aim of the project isto extract the values in thermodynamic data and use these values for the calclation of enthalpy, entropy and specific heats.
Procedure
In this project we have given a data of NASA thermodynamic data and we have to extract allthe 14 datas
- Firsty we have to load the data using load command
- Read the datas and store them in variables.
- Calculate values of specific heats, entropy and enthalpy.
- Using plot command plot the relations in the form of plots.
- Type a function to calculate molecular weight and call the funcion.
- Calculatemolecular weight by giving proper variables.
clear all
close all
clc
%Universal Gas Constant
R= 8.314;
f1= fopen('THERMO.dat','r');
Title= fgetl (f1);
G= fscanf (f1,'%f',[1 3]);
%Temperature
global_low_temp= G(1);
global_mid_temp= G(2);
global_high_temp= G(3);
%Skiping the comments
for i=1:4;
fgetl(f1);
end
for i=1:53;
tline=fgetl(f1);
% Reading a line and separating the co-efficients
species= tline(1:8)
% Reading co-efficients simultaneously
line1= fgetl(f1);
%Finding the the string E and seperating co-efficients using it
A1=strfind(line1,'E');
%Finding Individual Co-efficients
a1=line1(1:A1(1)+3);
a1=str2num(a1);
a2=line1(A1(1)+4:A1(2)+3);
a2=str2num(a2);
a3=line1(A1(2)+4:A1(3)+3);
a3=str2num(a3);
a4=line1(A1(3)+4:A1(4)+3);
a4=str2num(a4);
a5=line1(A1(4)+4:A1(5)+3);
a5=str2num(a5);
line2=fgetl(f1);
a6=line1(1:A1(1)+3);
a6=str2num(a6);
a7=line1(A1(1)+4:A1(2)+3);
a7=str2num(a7);
a8=line1(A1(2)+4:A1(3)+3);
a8=str2num(a8);
a9=line1(A1(3)+4:A1(4)+3);
a9=str2num(a9);
a10=line1(A1(4)+4:A1(5)+3);
a10=str2num(a10);
line3=fgetl(f1);
a11=line1(1:A1(1)+3);
a11=str2num(a11);
a12=line1(A1(1)+4:A1(2)+3);
a12=str2num(a12);
a13=line1(A1(2)+4:A1(3)+3);
a13=str2num(a13);
a14=line1(A1(3)+4:A1(4)+3);
a14=str2num(a14);
a15=line1(A1(4)+4:A1(5)+3);
a15=str2num(a15);
%Storing the data in a subfolder
subfolder_name= species;
mkdir(['C:UsersjoelkDesktopMATLAB ProgramsProject- Parsing Thermodynamic Data Graph Data-',subfolder_name]);
%Calculating Cp, Enthalpy and Entrophy
%Considering the local temperature range
%Low Temperature range < 1000K (200K-1000K)
%Average Temperature= 1000k
%High Temperature range= > 1000K (1000K-35000K)
T=linspace(200,3500,100);
for j=1:length(T);
if T(j)>1000
Cp=R*(a1+(a2.*T)+a3.*(T.^2)+a4.*(T.^3)+a5.*(T.^4));
H=R*T.*((a1+(a2.*T)/2)+(a3.*T.^2)/3+(a4.*T.^3)/4+(a5.*T.^4)/5+a6.*T);
S=R*(a1*log(T)+a2.*T+(a3.*T.^2)/2+(a4.*T.^3)/3+ (a5.*(T.^4)/4)+a7);
else
Cp=R*(a8+(a9.*T)+a10.*(T.^2)+a11.*(T.^3)+a12.*(T.^4));
H=R*T.*((a8+(a9.*T)/2)+(a10.*T.^2)/3+(a11.*T.^3)/4+(a12.*T.^4)/5+a13.*T);
S=R*(a8*log(T)+a9.*T+(a10.*T.^2)/2+(a11.*T.^3)/3+ (a12.*(T.^4)/4)+a14);
end
end
%Plotting
figure(1)
plot(T,Cp,'linewidth',2,'color','r')
title(species)
xlabel('Temperature')
ylabel('Specific Heat')
grid on
figure(2)
plot(T,H,'linewidth',2,'color','b')
title(species)
xlabel('Temperaute')
ylabel('Enthalpy')
grid on
figure(3)
plot(T,S,'linewidth',2,'color','g')
title(species)
xlabel('Temperature')
ylabel('Entrophy')
grid on
%Directory for saving the graphs
filepath=(['C:UsersjoelkDesktopMATLAB ProgramsProject- Parsing Thermodynamic Data Graph Data-',subfolder_name]);
cd(filepath)
saveas(1,'Graph- T vs Cp.jpg')
saveas(2,'Graph- T vs H.jpg')
saveas(3,'Graph- T vs S.jpg')
%Calling Molecular Weight function
cd('C:UsersjoelkDesktopMATLAB Programs')
Molecular_weight= molecular_weights(species)
%Saving the molecular weight
f2=fopen('Molecular Weights.txt','a+');
fprintf(f2,'Molecular Weight of %s is %f n',species,Molecular_weight);
end
fclose(f1);
Molecular weight function
s= {'H' 'C' 'N' 'O' 'AR'};
%Atomic weights of each species
aw= [1 12 14 16 40];
%Intial molecular weight
mw= 0;
for i= 1:length(species)
for j= 1:length(s)
if strcmp(species(i),s(j))
mw= mw + aw(j);
%Sorting the position of matched element
position=j;
end
end
n= str2double(species(i));
if n>1
mw=mw+aw(position)*(n-1);
end
end