Project 1 - Parsing NASA thermodynamic data
AIM:
To extract all the coefficients of the species mention in the data file and calculate their parameters like enthalpy,entropy and specific heat.To plot the variations of these parameters for the specified temperature range. To determine the molecular masses of the individual species mention in the data file.
PROGRAM :
%primary parsuing code
clear all
close all
clc
%opening and reading the requriedthe reading file
file = fopen("THERMO.dat",'r')
%Heading
for i=1:5
fgetl(file);
end
%species information
for i=1:53
species = fgetl(file);
species_name = species(1:6);
Line_1 =fgetl(file);
L1 = strfind(Line_1,'E');
c1 = str2num(Line_1(1:(L1(1)+3)));
c2 = str2num(Line_1((L1(1)+4):(L1(2)+3)));
c3 = str2num(Line_1((L1(2)+4):(L1(3)+3)));
c4 = str2num(Line_1((L1(3)+4):(L1(4)+3)));
c5 = str2num(Line_1((L1(4)+4):(L1(5)+3)));
line_2 = fgetl(file);
L2 = strfind(line_2,'E');
c6 = str2num(line_2(1:(L2(1)+3)));
c7 = str2num(line_2((L2(1)+4):(L2(2)+3)));
c8 = str2num(line_2((L2(2)+4):(L2(3)+3)));
c9 = str2num(line_2((L2(3)+4):(L2(4)+3)));
c10 = str2num(line_2((L2(4)+4):(L2(5)+3)));
line_3 = fgetl(file);
L2 = strfind(line_3,'E');
c11 = str2num(line_3(1:(L2(1)+3)));
c12 = str2num(line_3((L2(1)+4):(L2(2)+3)));
c13= str2num(line_3((L2(2)+4):(L2(3)+3)));
c14 = str2num(line_3((L2(3)+4):(L2(4)+3)));
%creating folder for each species
t=sprintf('%s',species_name);
mkdir(t);
%Temperature ranges assumed for calculation purpose
Temperature = linspace(300,5000,100);
%universal gas constant
R = 8.314;
%calculating of prroperties based on the lower and upper Temperature
for j = 1:length(Temperature)
if Temperature(j)<3000
Cp = (c1+c2.*Temperature+c3.*Temperature.^2+c4.*Temperature.^3+c5.*Temperature.^4).*R;
H = (c1+(c2.*Temperature)./2+(c3.*Temperature.^2)/3+(c4.*Temperature.^3)/4+(c5.*Temperature.^4/5)+c6./Temperature).*Temperature.*R;
S = (c1*log(Temperature)+c2.*Temperature+(c3.*Temperature.^2)/2+(c4.*Temperature.^3)/3+(c5.*Temperature.^4)/4+c7)*R;
else
Cp =(c8+c9.*Temperature+c10.*Temperature.^2+c11.*Temperature.^3+c12.*Temperature.^4 ).*R;
H = (c8+(c9.*Temperature)./2+(c10.*Temperature.^2)/3+(c11.*Temperature.^3)/4+(c12.*Temperature.^4/5)+c6./Temperature).*Temperature.*R;
S = (c8*log(Temperature)+c9.*Temperature+(c10.*Temperature.^2)/2+(c11.*Temperature.^3)/3+(c12.*Temperature.^4)/4+c14)*R;
end
end
%plotting
%Temperature vs entropy
figure(1)
plot(Temperature,S,"linewidth",4,"color","y")
title('T vs S')
xlabel('Temperature')
ylabel('entropy')
%Temperature vs enthalpy
figure(2)
plot(Temperature,H,"linewidth",4,"color","r")
title('T vs H')
xlabel('Temperature')
ylabel('enthalpy')
%Temperature vs specific heat
figure(3)
plot(Temperature,Cp,"linewidth",4,"color","b")
title('T vs Cp')
xlabel('Temperature')
ylabel('specific heat')
cd(t)
%saving the plots
saveas(1,'entropy.jpg');
saveas(1,'enthalpy.jpg');issue in images output
saveas(1,'specific heat.jpg');
cd ..
% mm = molecular_mass(species_name)
end
fclose(file)
EXPLINATION:
Initially open the thermodynamic data file and read the data file in the file and store the data to thevariables F.
Then read the header file of the thermodynamic data and calculate the low and high temperatures from the second line of the data file .
By using fget(),strspit()andstr2num() command find out the global low and high temperatures in the second line
Then calculate the 14 coefficients for all thespecies in the given thermodynamic data file
In the data file each species has three lines in which 14 coefficients are there
By using the for loop calculate the 14 coefficients of the species
By using the strfind()command find out the no of exponentials in first line, by which we can find out the no of co efficients in first line
onces you find out ,then convert the coefficients fromsrring form to the number form by using str2num()command.
By doing the above steps for line two and three, we can calculate the 14 coefficients of the species
once you find out the coefficient for yhe speciesthen calculate the entropy,enthalpy and specific heat
We find the coefficients are Low temperature :High temperature coefficients and calculate the S,H and cp
Assuming univarsal gas constant R=8.314j/mol-k and assuming the temperature ranges from 100 to 5000 take 100 values for linspace() command
Once you calculate the entropy,enthalpy and specific heat for all the species plot the graph between temperature vs entropy , temperature vs enthalpy and temperature vs specific heat
Store the all three plots for all the species in the file
Finally calculate the molecular weight for all the species to run a separate program for all the species
function mm = molecular_masses(species_name)
species = upper(species_name);
constituents = ['H','C','N','O','A'];
Atomic_weight = [1.00794 12.0107 14.0067 15.9994 39.948];
mm = 0
for i=1:length(species)
for j=1:length(constituents)
if strcmp(species(i),constituents(j))
mm = mm + Atomic_weight(j);
u = j;
end
end
n = str2num(species(i));
if n>1
mm = mm+Atomic_weight(u)*(n-1);
end
end
end
The method for calculating molecular masses is shown in the above program
GRAPHS:
FOR O2



FOR N2



FFOR CO2


COMMANDS :
file =
20
Warning: Directory already exists.
> In parsing_nasa_thermodynamic_data (line 47)
Error using checkArgsForHandleToPrint
Handle input argument contains nonhandle values.
Error in checkArgsForHandleToPrint
Error in print>LocalCreatePrintJob (line 101)
handles = checkArgsForHandleToPrint(0, varargin{:});
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in saveas (line 181)
print( h, name, ['-d' dev{i}] )
Error in parsing_nasa_thermodynamic_data (line 97)
saveas(1,'enthalpy.jpg');issue in images output