%--------------------------------------------------------------------------
%% Programme to Parse NASA Thermodynamic Data
%--------------------------------------------------------------------------
clear all;
clc;
close all;
fclose all;
%--------------------------------------------------------------------------
%% Reading data from the txt file
%--------------------------------------------------------------------------
file_name = \'Nasa.txt\';
Identifier = fopen(file_name);
if Identifier == -1
disp([\'could not find the file\',file_name])
error(\'File name does not exit\')
end
%--------------------------------------------------------------------------
%% Reading the Global Temperatures
%--------------------------------------------------------------------------
fgetl(Identifier); %Skipping the 1st line
T=fgetl(Identifier);
Temp=strsplit(T,\' \');
GMin_Temp=str2double(Temp{2});
GMed_Temp=str2double(Temp{3});
GMax_Temp=str2double(Temp{4});
temp=linspace(GMin_Temp,3500,100);
mkdir(\'Thermodynamic data\');
% Skipping the data which is not required
for n=1:3;
fgetl(Identifier);
end
%--------------------------------------------------------------------------
%% Defining the sizes for the required variables
%--------------------------------------------------------------------------
No_Spe=53;
No_Coeff=14;
Coeff=zeros(No_Coeff,No_Spe);
Cp=zeros(length(temp),No_Spe);
H=zeros(length(temp),No_Spe);
S=zeros(length(temp),No_Spe);
M_Wt=zeros(1,No_Spe);
All_Spe=\'\';%Dummy String;
%--------------------------------------------------------------------------
%% Using of all the required functions for the calculate, plot and store
%% the data
%--------------------------------------------------------------------------
for i=1:No_Spe;
[Spec_Name,All_Spe]=Species(Identifier,i,All_Spe);%Func to get the name of the species
[Coeff]=Coefficents(Identifier,Coeff,i);%Func to get the coeff
[Cp]=Specific_Heat(Coeff,temp,i,Cp);%Func to calcualte Specific Heat
[H]=Enthalpy(Coeff,temp,i,H);%Fun to calculate the Enthalpy
[S]=Entropy(Coeff,temp,i,S);%Fun to calculate the Enropy
[M_Wt]=Molecular_Weight(Spec_Name,i,M_Wt);%Fun to calculate the Molecular weight
Plotall( Cp,H,S,i,Spec_Name,temp,aa)%Fun to plot the values
end
Ind_Spe=strsplit(All_Spe,\',\');
function [Coeff] = Coefficents( Identifier,Coeff,i )
a=1;
for n=1:3;
L_2=fgetl(Identifier);
EV=strfind(L_2,\'E\');
for j=1:length(EV);
if j<=1;
Coeff(a,i)=str2double(L_2(1:EV(1)+3));
else
Coeff(a,i)=str2double(L_2(EV(j-1)+4:EV(j)+3));
end
a=a+1;
end
end
end
function [ Cp ] = Specific_Heat(Coeff,T,i,Cp )
R=8.314;
for j=1:length(T)
for n=1:5
Cp(j,i)=Cp(j,i)+R*(Coeff(n,i)*T(j).^(n-1));
end
end
function [ H ] = Enthalpy( Coeff,T,i,H )
R=8.314;
for j=1:length(T);
for n=1:5
H(j,i)=H(j,i)+R*((Coeff(n,i)*T(j)^(n-1))/n);
end
H(j,i)=H(j,i)+R*(Coeff(6,i));
end
end
function [ S ] = Entropy( Coeff,T,i,S )
R=8.314;
for j=1:length(T);
for n=2:5
S(j,i)=S(j,i)+R*((Coeff(n,i)*T(j)^(n-1)));
end
S(j,i)=S(j,i)+R*(Coeff(1,i)*log(T(j))+Coeff(7,i));
end
end
function [ Spec_Name,a ] = Species( f1,i,a )
% To get data related to kind of species
L=fgetl(f1);
m=strfind(L,\' \');
Spec_Name=L(1:m(1)-1);
str=\',\';
a=strcat(a,Spec_Name,str);
end
function [ M_Wt ] = Molecular_Weight( Spec_Name,i,M_Wt )
Elements=[\'H\' \'C\' \'N\' \'O\'];
Atom_wt=[1 12 14 16];
Num=0;
for k=1:length(Spec_Name);
Num=str2double(Spec_Name(k));
for j=1:length(Elements);
if strcmp(Spec_Name(k),Elements(j))
m=j;
M_Wt(i)=M_Wt(i)+Atom_wt(m);
end
end
if(Num>=1)
M_Wt(i)=M_Wt(i)+Atom_wt(m)*(Num-1);
end
end
end
function [ ] = Plotall( Cp,H,S,i,Spec_Name,temp,aa)
mkdir(Spec_Name)
figure(1)
subplot(2,2,1)
plot(temp,Cp(:,i));
xlabel(\'Temperature\')
ylabel(\'Specific Heat\')
subplot(2,2,2);
plot(temp,H(:,i))
xlabel(\'Temperature\')
ylabel(\'Enthalpy\')
subplot(2,2,3)
plot(temp,S(:,i))
xlabel(\'Temperature\')
ylabel(\'Entropy\')
Req_Filename=sprintf(\'Conbined_Data_%s.jpg\',Spec_Name);
Species_Filename=fullfile(Spec_Name,Req_Filename);
saveas(figure(1),Species_Filename);
end