Challenge

Project 1 - Parsing NASA thermodynamic data

clear all
close all
clc

% getting thermo file
f = fopen('THERMO.dat','r');
fgetl(f)

% reading header
A = fgetl(f);
A = str2num(A);
global_low_temp = A(1);
global_mid_temp = A(2);
global_high_temp = A(3);


R = 8.314; %universal gas constant4 as line_3.
% skipping lines
for i = 1:3
fgetl(f);
end

%getting second line values
% name it with variables from (a1 to a5) as it has five values

for i = 1:53

part = fgetl(f);
[nmae, local_temp] = strtok(part,'G');
species_name = strtok(nmae);
temp = strsplit(local_temp);
local_low_temp = str2double(temp{2});
local_mid_temp = str2double(temp{3});
local_high_temp = str2double(temp{4});

t1 = local_low_temp;
t2 = local_mid_temp;
t3 = local_high_temp;

% getting line_1 co_eff (a1 to a5)

line_1 = fgetl(f);
a = strfind(line_1,'E');
a1 = str2double(line_1(1:a(1)+3));
a2 = str2double(line_1(a(1)+4:a(2)+3));
a3 = str2double(line_1(a(2)+4:a(3)+3));
a4 = str2double(line_1(a(3)+4:a(4)+3));
a5 = str2double(line_1(a(4)+4:a(5)+3));

% getting line_2 co_effs (a6 to a10)

line_2 = fgetl(f);
b = strfind(line_2,'E');
a6 = str2double(line_2(1:b(1)+3));
a7 = str2double(line_2(b(1)+4:b(2)+3));
a8 = str2double(line_2(b(2)+4:b(3)+3));
a9 = str2double(line_2(b(3)+4:b(4)+3));
a10 = str2double(line_2(b(4)+4:b(5)+3));

% getting line_3 co_effs (a11 to a14)

line_3 = fgetl(f);
c = strfind(line_3,'E');
a11 = str2double(line_3(1:c(1)+3));
a12 = str2double(line_3(c(1)+4:c(2)+3));
a13 = str2double(line_3(c(2)+4:c(3)+3));
a14 = str2double(line_3(c(3)+4:c(4)+3));

T = linspace(t1,t3,1000);


% getting specific_heat, enthalpy, entropy as arrays
for k = 1:length(T)
% to compare species_temperatures

if T(k)>t2

cp = (a1+(a2*T)+(a3*T.^2)+(a4*T.^3)+(a5*T.^4))*R;
H = (a1+((a2*T)./2)+((a3*T.^2)./3)+((a4*T.^3)./4)+((a5*T.^4)./5)+(a6./T))*R.*T;
S = (a1*log(T)+(a2*T)+((a3*T.^2)./2)+((a4*T.^3)./3)+((a5*T.^4)./4)+a7);

else

cp = (a8+(a9*T)+(a10*T.^2)+(a11*T.^3)+(a12*T.^4))*R;
H = (a8+((a9*T)./2)+((a10*T.^2)./3)+((a11*T.^3)./4)+((a12*T.^4)./5)+(a13./T))*R.*T;
S = (a8*log(T)+(a9*T)+((a10*T.^2)./2)+((a11*T.^3)./3)+((a12*T.^4)./4)+a14);

end
end
% plotting graphs
% temperature(T) vs specific_heat(cp)
figure(1)
plot(T,cp);
grid on
title(species_name)
xlabel('Temperature')
ylabel('Specific_heat')

% temperature(T) vs enthalpy(H)
figure(2)
plot(T,H);
grid on
title(species_name)
xlabel('Temperature')
ylabel('Enthalpy')

% Temperature(T) vs entropy(S)
figure(3)
plot(T,S);
grid on
title(species_name)
xlabel('Temperature')
ylabel('Entropy')

% species = sprintf('%s',species_name);
mkdir('C:\Users\charlie luo\Desktop\HEV\MATLAB\Temp Programs',species_name)
cd (species_name)
saveas(1,'specific heat','jpg')
saveas(2,'Enthalpy','jpg')
saveas(3,'Entropy','jpg')
cd ..

% molecular mass calculation
elements = ['H','C','O','N','A'];
atomic_weight = [1.0079 12.0107 15.999 14.0067 39.948];
mol_mass = 0;
for p = 1:length(species_name)
for q = 1:length(elements)
if strcmp(species_name(p),elements(q))
mol_mass = mol_mass + atomic_weight(q);
position = q;
end
end


n = str2num(species_name(p));
if n>1
mol_mass = mol_mass + atomic_weight(position)*(n-1);
end
sprintf('Molecular weight of %s:%f u',species_name,mol_mass)
end
end

REPORT

AIM:

  • To Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the species in the data file.
  • To Calculate the molecular weight of each species.
  • To Plot the Cp, Enthalpy and Entropy for the local temperature range (low temperature : high temperature) specific for each species.
  • To Save the plots as images with appropriate names and dump them in separate folders for each species with suitable name. .
  • Please write a detailed report to describe your logic.

EXPLANATION:

  • Open the thermodata in by using fopen.
  • Get the header file as low,mid and high.
  • Skip the first three lines by using i=1:3
  • Mention the number of species in thermodat that is 1:53
  • Get the lines of thermodta by its co-efficient from A1 to A5 as line_1 and A6 to A10 as line_2 and A11 to A1
  • Use the linspace command to find the values of T1 to T3 as 1000 values.
  • Then use the for loop to get

if T(k)>t2

cp = (a1+(a2*T)+(a3*T.^2)+(a4*T.^3)+(a5*T.^4))*R;
H = (a1+((a2*T)./2)+((a3*T.^2)./3)+((a4*T.^3)./4)+((a5*T.^4)./5)+(a6./T))*R.*T;
S = (a1*log(T)+(a2*T)+((a3*T.^2)./2)+((a4*T.^3)./3)+((a5*T.^4)./4)+a7);

else

cp = (a8+(a9*T)+(a10*T.^2)+(a11*T.^3)+(a12*T.^4))*R;
H = (a8+((a9*T)./2)+((a10*T.^2)./3)+((a11*T.^3)./4)+((a12*T.^4)./5)+(a13./T))*R.*T;
S = (a8*log(T)+(a9*T)+((a10*T.^2)./2)+((a11*T.^3)./3)+((a12*T.^4)./4)+a14);

  • Then plot the graphs for each species as figure 1,2,3

*Temperature(T) vs entha;py(H).

* Temperature(T) vs entropy(S).

* Temperature(T) vs specific_heat(cp).

  • Use mkdir command to save the file in desired folder.
  • Then calculate the molecular weight of each species by using for loop and str2num command.

RESULT:

  • The above program has done to Write a function that extracts the 14 co-efficients and calculates the enthalpy, entropy and specific heats for all the 53 species.
  • To calculate the Molecular weight of each species.
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.